Blame SOURCES/gdb-6.6-buildid-locate-rpm.patch

190f2a
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
190f2a
From: Fedora GDB patches <invalid@email.com>
190f2a
Date: Fri, 27 Oct 2017 21:07:50 +0200
190f2a
Subject: gdb-6.6-buildid-locate-rpm.patch
190f2a
190f2a
;;=push+jan
190f2a
190f2a
diff --git a/gdb/aclocal.m4 b/gdb/aclocal.m4
190f2a
--- a/gdb/aclocal.m4
190f2a
+++ b/gdb/aclocal.m4
190f2a
@@ -11,7 +11,223 @@
190f2a
 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
190f2a
 # PARTICULAR PURPOSE.
190f2a
 
190f2a
+# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
190f2a
+# serial 1 (pkg-config-0.24)
190f2a
+# 
190f2a
+# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
190f2a
+#
190f2a
+# This program is free software; you can redistribute it and/or modify
190f2a
+# it under the terms of the GNU General Public License as published by
190f2a
+# the Free Software Foundation; either version 2 of the License, or
190f2a
+# (at your option) any later version.
190f2a
+#
190f2a
+# This program is distributed in the hope that it will be useful, but
190f2a
+# WITHOUT ANY WARRANTY; without even the implied warranty of
190f2a
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
190f2a
+# General Public License for more details.
190f2a
+#
190f2a
+# You should have received a copy of the GNU General Public License
190f2a
+# along with this program; if not, write to the Free Software
190f2a
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
190f2a
+#
190f2a
+# As a special exception to the GNU General Public License, if you
190f2a
+# distribute this file as part of a program that contains a
190f2a
+# configuration script generated by Autoconf, you may include it under
190f2a
+# the same distribution terms that you use for the rest of that program.
190f2a
+
190f2a
+# PKG_PROG_PKG_CONFIG([MIN-VERSION])
190f2a
+# ----------------------------------
190f2a
+AC_DEFUN([PKG_PROG_PKG_CONFIG],
190f2a
+[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
190f2a
+m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
190f2a
+m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
190f2a
+AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
190f2a
+AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
190f2a
+AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
190f2a
+
190f2a
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
190f2a
+	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
190f2a
+fi
190f2a
+if test -n "$PKG_CONFIG"; then
190f2a
+	_pkg_min_version=m4_default([$1], [0.9.0])
190f2a
+	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
190f2a
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
190f2a
+		AC_MSG_RESULT([yes])
190f2a
+	else
190f2a
+		AC_MSG_RESULT([no])
190f2a
+		PKG_CONFIG=""
190f2a
+	fi
190f2a
+fi[]dnl
190f2a
+])# PKG_PROG_PKG_CONFIG
190f2a
+
190f2a
+# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
190f2a
+#
190f2a
+# Check to see whether a particular set of modules exists.  Similar
190f2a
+# to PKG_CHECK_MODULES(), but does not set variables or print errors.
190f2a
+#
190f2a
+# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
190f2a
+# only at the first occurence in configure.ac, so if the first place
190f2a
+# it's called might be skipped (such as if it is within an "if", you
190f2a
+# have to call PKG_CHECK_EXISTS manually
190f2a
+# --------------------------------------------------------------
190f2a
+AC_DEFUN([PKG_CHECK_EXISTS],
190f2a
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
190f2a
+if test -n "$PKG_CONFIG" && \
190f2a
+    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
190f2a
+  m4_default([$2], [:])
190f2a
+m4_ifvaln([$3], [else
190f2a
+  $3])dnl
190f2a
+fi])
190f2a
+
190f2a
+# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
190f2a
+# ---------------------------------------------
190f2a
+m4_define([_PKG_CONFIG],
190f2a
+[if test -n "$$1"; then
190f2a
+    pkg_cv_[]$1="$$1"
190f2a
+ elif test -n "$PKG_CONFIG"; then
190f2a
+    PKG_CHECK_EXISTS([$3],
190f2a
+                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
190f2a
+		      test "x$?" != "x0" && pkg_failed=yes ],
190f2a
+		     [pkg_failed=yes])
190f2a
+ else
190f2a
+    pkg_failed=untried
190f2a
+fi[]dnl
190f2a
+])# _PKG_CONFIG
190f2a
+
190f2a
+# _PKG_SHORT_ERRORS_SUPPORTED
190f2a
+# -----------------------------
190f2a
+AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
190f2a
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
190f2a
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
190f2a
+        _pkg_short_errors_supported=yes
190f2a
+else
190f2a
+        _pkg_short_errors_supported=no
190f2a
+fi[]dnl
190f2a
+])# _PKG_SHORT_ERRORS_SUPPORTED
190f2a
+
190f2a
+
190f2a
+# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
190f2a
+# [ACTION-IF-NOT-FOUND])
190f2a
+#
190f2a
+#
190f2a
+# Note that if there is a possibility the first call to
190f2a
+# PKG_CHECK_MODULES might not happen, you should be sure to include an
190f2a
+# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
190f2a
+#
190f2a
+#
190f2a
+# --------------------------------------------------------------
190f2a
+AC_DEFUN([PKG_CHECK_MODULES],
190f2a
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
190f2a
+AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
190f2a
+AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
190f2a
+
190f2a
+pkg_failed=no
190f2a
+AC_MSG_CHECKING([for $1])
190f2a
+
190f2a
+_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
190f2a
+_PKG_CONFIG([$1][_LIBS], [libs], [$2])
190f2a
+
190f2a
+m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
190f2a
+and $1[]_LIBS to avoid the need to call pkg-config.
190f2a
+See the pkg-config man page for more details.])
190f2a
+
190f2a
+if test $pkg_failed = yes; then
190f2a
+   	AC_MSG_RESULT([no])
190f2a
+        _PKG_SHORT_ERRORS_SUPPORTED
190f2a
+        if test $_pkg_short_errors_supported = yes; then
190f2a
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
190f2a
+        else 
190f2a
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
190f2a
+        fi
190f2a
+	# Put the nasty error message in config.log where it belongs
190f2a
+	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
190f2a
+
190f2a
+	m4_default([$4], [AC_MSG_ERROR(
190f2a
+[Package requirements ($2) were not met:
190f2a
+
190f2a
+$$1_PKG_ERRORS
190f2a
+
190f2a
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
190f2a
+installed software in a non-standard prefix.
190f2a
+
190f2a
+_PKG_TEXT])[]dnl
190f2a
+        ])
190f2a
+elif test $pkg_failed = untried; then
190f2a
+     	AC_MSG_RESULT([no])
190f2a
+	m4_default([$4], [AC_MSG_FAILURE(
190f2a
+[The pkg-config script could not be found or is too old.  Make sure it
190f2a
+is in your PATH or set the PKG_CONFIG environment variable to the full
190f2a
+path to pkg-config.
190f2a
+
190f2a
+_PKG_TEXT
190f2a
+
190f2a
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
190f2a
+        ])
190f2a
+else
190f2a
+	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
190f2a
+	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
190f2a
+        AC_MSG_RESULT([yes])
190f2a
+	$3
190f2a
+fi[]dnl
190f2a
+])# PKG_CHECK_MODULES
190f2a
+
190f2a
+
190f2a
+# PKG_INSTALLDIR(DIRECTORY)
190f2a
+# -------------------------
190f2a
+# Substitutes the variable pkgconfigdir as the location where a module
190f2a
+# should install pkg-config .pc files. By default the directory is
190f2a
+# $libdir/pkgconfig, but the default can be changed by passing
190f2a
+# DIRECTORY. The user can override through the --with-pkgconfigdir
190f2a
+# parameter.
190f2a
+AC_DEFUN([PKG_INSTALLDIR],
190f2a
+[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
190f2a
+m4_pushdef([pkg_description],
190f2a
+    [pkg-config installation directory @<:@]pkg_default[@:>@])
190f2a
+AC_ARG_WITH([pkgconfigdir],
190f2a
+    [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
190f2a
+    [with_pkgconfigdir=]pkg_default)
190f2a
+AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
190f2a
+m4_popdef([pkg_default])
190f2a
+m4_popdef([pkg_description])
190f2a
+]) dnl PKG_INSTALLDIR
190f2a
+
190f2a
+
190f2a
+# PKG_NOARCH_INSTALLDIR(DIRECTORY)
190f2a
+# -------------------------
190f2a
+# Substitutes the variable noarch_pkgconfigdir as the location where a
190f2a
+# module should install arch-independent pkg-config .pc files. By
190f2a
+# default the directory is $datadir/pkgconfig, but the default can be
190f2a
+# changed by passing DIRECTORY. The user can override through the
190f2a
+# --with-noarch-pkgconfigdir parameter.
190f2a
+AC_DEFUN([PKG_NOARCH_INSTALLDIR],
190f2a
+[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
190f2a
+m4_pushdef([pkg_description],
190f2a
+    [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
190f2a
+AC_ARG_WITH([noarch-pkgconfigdir],
190f2a
+    [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
190f2a
+    [with_noarch_pkgconfigdir=]pkg_default)
190f2a
+AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
190f2a
+m4_popdef([pkg_default])
190f2a
+m4_popdef([pkg_description])
190f2a
+]) dnl PKG_NOARCH_INSTALLDIR
190f2a
+
190f2a
+
190f2a
+# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
190f2a
+# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
190f2a
+# -------------------------------------------
190f2a
+# Retrieves the value of the pkg-config variable for the given module.
190f2a
+AC_DEFUN([PKG_CHECK_VAR],
190f2a
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
190f2a
+AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
190f2a
+
190f2a
+_PKG_CONFIG([$1], [variable="][$3]["], [$2])
190f2a
+AS_VAR_COPY([$1], [pkg_cv_][$1])
190f2a
+
190f2a
+AS_VAR_IF([$1], [""], [$5], [$4])dnl
190f2a
+])# PKG_CHECK_VAR
190f2a
+
190f2a
 m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
190f2a
+
190f2a
 # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
190f2a
 
190f2a
 # Copyright (C) 2001-2017 Free Software Foundation, Inc.
190f2a
diff --git a/gdb/build-id.c b/gdb/build-id.c
190f2a
--- a/gdb/build-id.c
190f2a
+++ b/gdb/build-id.c
190f2a
@@ -35,6 +35,8 @@
190f2a
 #include "elf/common.h"
190f2a
 #include "elf-bfd.h"
190f2a
 #include <sys/stat.h>
190f2a
+#include "elf/external.h"
190f2a
+#include "inferior.h"
190f2a
 
190f2a
 #define BUILD_ID_VERBOSE_NONE 0
190f2a
 #define BUILD_ID_VERBOSE_FILENAMES 1
190f2a
@@ -640,8 +642,366 @@ build_id_to_filename (const struct bfd_build_id *build_id, char **link_return)
190f2a
   return result;
190f2a
 }
190f2a
 
190f2a
+#ifdef HAVE_LIBRPM
190f2a
+
190f2a
+#include <rpm/rpmlib.h>
190f2a
+#include <rpm/rpmts.h>
190f2a
+#include <rpm/rpmdb.h>
190f2a
+#include <rpm/header.h>
190f2a
+#ifdef DLOPEN_LIBRPM
190f2a
+#include <dlfcn.h>
190f2a
+#endif
190f2a
+
190f2a
+/* This MISSING_RPM_HASH tracker is used to collect all the missing rpm files
190f2a
+   and avoid their duplicities during a single inferior run.  */
190f2a
+
190f2a
+static struct htab *missing_rpm_hash;
190f2a
+
190f2a
+/* This MISSING_RPM_LIST tracker is used to collect and print as a single line
190f2a
+   all the rpms right before the nearest GDB prompt.  It gets cleared after
190f2a
+   each such print (it is questionable if we should clear it after the print).
190f2a
+   */
190f2a
+
190f2a
+struct missing_rpm
190f2a
+  {
190f2a
+    struct missing_rpm *next;
190f2a
+    char rpm[1];
190f2a
+  };
190f2a
+static struct missing_rpm *missing_rpm_list;
190f2a
+static int missing_rpm_list_entries;
190f2a
+
190f2a
+/* Returns the count of newly added rpms.  */
190f2a
+
190f2a
+static int
190f2a
+missing_rpm_enlist (const char *filename)
190f2a
+{
190f2a
+  static int rpm_init_done = 0;
190f2a
+  rpmts ts;
190f2a
+  rpmdbMatchIterator mi;
190f2a
+  int count = 0;
190f2a
+
190f2a
+#ifdef DLOPEN_LIBRPM
190f2a
+  /* Duplicate here the declarations to verify they match.  The same sanity
190f2a
+     check is present also in `configure.ac'.  */
190f2a
+  extern char * headerFormat(Header h, const char * fmt, errmsg_t * errmsg);
190f2a
+  static char *(*headerFormat_p) (Header h, const char * fmt, errmsg_t *errmsg);
190f2a
+  extern int rpmReadConfigFiles(const char * file, const char * target);
190f2a
+  static int (*rpmReadConfigFiles_p) (const char * file, const char * target);
190f2a
+  extern rpmdbMatchIterator rpmdbFreeIterator(rpmdbMatchIterator mi);
190f2a
+  static rpmdbMatchIterator (*rpmdbFreeIterator_p) (rpmdbMatchIterator mi);
190f2a
+  extern Header rpmdbNextIterator(rpmdbMatchIterator mi);
190f2a
+  static Header (*rpmdbNextIterator_p) (rpmdbMatchIterator mi);
190f2a
+  extern rpmts rpmtsCreate(void);
190f2a
+  static rpmts (*rpmtsCreate_p) (void);
190f2a
+  extern rpmts rpmtsFree(rpmts ts);
190f2a
+  static rpmts (*rpmtsFree_p) (rpmts ts);
190f2a
+  extern rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmTag rpmtag,
190f2a
+                                              const void * keyp, size_t keylen);
190f2a
+  static rpmdbMatchIterator (*rpmtsInitIterator_p) (const rpmts ts,
190f2a
+						    rpmTag rpmtag,
190f2a
+						    const void *keyp,
190f2a
+						    size_t keylen);
190f2a
+#else	/* !DLOPEN_LIBRPM */
190f2a
+# define headerFormat_p headerFormat
190f2a
+# define rpmReadConfigFiles_p rpmReadConfigFiles
190f2a
+# define rpmdbFreeIterator_p rpmdbFreeIterator
190f2a
+# define rpmdbNextIterator_p rpmdbNextIterator
190f2a
+# define rpmtsCreate_p rpmtsCreate
190f2a
+# define rpmtsFree_p rpmtsFree
190f2a
+# define rpmtsInitIterator_p rpmtsInitIterator
190f2a
+#endif	/* !DLOPEN_LIBRPM */
190f2a
+
190f2a
+  gdb_assert (filename != NULL);
190f2a
+
190f2a
+  if (strcmp (filename, BUILD_ID_MAIN_EXECUTABLE_FILENAME) == 0)
190f2a
+    return 0;
190f2a
+
190f2a
+  if (is_target_filename (filename))
190f2a
+    return 0;
190f2a
+
190f2a
+  if (filename[0] != '/')
190f2a
+    {
190f2a
+      warning (_("Ignoring non-absolute filename: <%s>"), filename);
190f2a
+      return 0;
190f2a
+    }
190f2a
+
190f2a
+  if (!rpm_init_done)
190f2a
+    {
190f2a
+      static int init_tried;
190f2a
+
190f2a
+      /* Already failed the initialization before?  */
190f2a
+      if (init_tried)
190f2a
+      	return 0;
190f2a
+      init_tried = 1;
190f2a
+
190f2a
+#ifdef DLOPEN_LIBRPM
190f2a
+      {
190f2a
+	void *h;
190f2a
+
190f2a
+	h = dlopen (DLOPEN_LIBRPM, RTLD_LAZY);
190f2a
+	if (!h)
190f2a
+	  {
190f2a
+	    warning (_("Unable to open \"%s\" (%s), "
190f2a
+		      "missing debuginfos notifications will not be displayed"),
190f2a
+		     DLOPEN_LIBRPM, dlerror ());
190f2a
+	    return 0;
190f2a
+	  }
190f2a
+
190f2a
+	if (!((headerFormat_p = (char *(*) (Header h, const char * fmt, errmsg_t *errmsg)) dlsym (h, "headerFormat"))
190f2a
+	      && (rpmReadConfigFiles_p = (int (*) (const char * file, const char * target)) dlsym (h, "rpmReadConfigFiles"))
190f2a
+	      && (rpmdbFreeIterator_p = (rpmdbMatchIterator (*) (rpmdbMatchIterator mi)) dlsym (h, "rpmdbFreeIterator"))
190f2a
+	      && (rpmdbNextIterator_p = (Header (*) (rpmdbMatchIterator mi)) dlsym (h, "rpmdbNextIterator"))
190f2a
+	      && (rpmtsCreate_p = (rpmts (*) (void)) dlsym (h, "rpmtsCreate"))
190f2a
+	      && (rpmtsFree_p = (rpmts (*) (rpmts ts)) dlsym (h, "rpmtsFree"))
190f2a
+	      && (rpmtsInitIterator_p = (rpmdbMatchIterator (*) (const rpmts ts, rpmTag rpmtag, const void *keyp, size_t keylen)) dlsym (h, "rpmtsInitIterator"))))
190f2a
+	  {
190f2a
+	    warning (_("Opened library \"%s\" is incompatible (%s), "
190f2a
+		      "missing debuginfos notifications will not be displayed"),
190f2a
+		     DLOPEN_LIBRPM, dlerror ());
190f2a
+	    if (dlclose (h))
190f2a
+	      warning (_("Error closing library \"%s\": %s\n"), DLOPEN_LIBRPM,
190f2a
+		       dlerror ());
190f2a
+	    return 0;
190f2a
+	  }
190f2a
+      }
190f2a
+#endif	/* DLOPEN_LIBRPM */
190f2a
+
190f2a
+      if (rpmReadConfigFiles_p (NULL, NULL) != 0)
190f2a
+	{
190f2a
+	  warning (_("Error reading the rpm configuration files"));
190f2a
+	  return 0;
190f2a
+	}
190f2a
+
190f2a
+      rpm_init_done = 1;
190f2a
+    }
190f2a
+
190f2a
+  ts = rpmtsCreate_p ();
190f2a
+
190f2a
+  mi = rpmtsInitIterator_p (ts, RPMTAG_BASENAMES, filename, 0);
190f2a
+  if (mi != NULL)
190f2a
+    {
190f2a
+      for (;;)
190f2a
+	{
190f2a
+	  Header h;
190f2a
+	  char *debuginfo, **slot, *s, *s2;
190f2a
+	  errmsg_t err;
190f2a
+	  size_t srcrpmlen = sizeof (".src.rpm") - 1;
190f2a
+	  size_t debuginfolen = sizeof ("-debuginfo") - 1;
190f2a
+	  rpmdbMatchIterator mi_debuginfo;
190f2a
+
190f2a
+	  h = rpmdbNextIterator_p (mi);
190f2a
+	  if (h == NULL)
190f2a
+	    break;
190f2a
+
190f2a
+	  /* Verify the debuginfo file is not already installed.  */
190f2a
+
190f2a
+	  debuginfo = headerFormat_p (h, "%{sourcerpm}-debuginfo.%{arch}",
190f2a
+				      &err;;
190f2a
+	  if (!debuginfo)
190f2a
+	    {
190f2a
+	      warning (_("Error querying the rpm file `%s': %s"), filename,
190f2a
+	               err);
190f2a
+	      continue;
190f2a
+	    }
190f2a
+	  /* s = `.src.rpm-debuginfo.%{arch}' */
190f2a
+	  s = strrchr (debuginfo, '-') - srcrpmlen;
190f2a
+	  s2 = NULL;
190f2a
+	  if (s > debuginfo && memcmp (s, ".src.rpm", srcrpmlen) == 0)
190f2a
+	    {
190f2a
+	      /* s2 = `-%{release}.src.rpm-debuginfo.%{arch}' */
190f2a
+	      s2 = (char *) memrchr (debuginfo, '-', s - debuginfo);
190f2a
+	    }
190f2a
+	  if (s2)
190f2a
+	    {
190f2a
+	      /* s2 = `-%{version}-%{release}.src.rpm-debuginfo.%{arch}' */
190f2a
+	      s2 = (char *) memrchr (debuginfo, '-', s2 - debuginfo);
190f2a
+	    }
190f2a
+	  if (!s2)
190f2a
+	    {
190f2a
+	      warning (_("Error querying the rpm file `%s': %s"), filename,
190f2a
+	               debuginfo);
190f2a
+	      xfree (debuginfo);
190f2a
+	      continue;
190f2a
+	    }
190f2a
+	  /* s = `.src.rpm-debuginfo.%{arch}' */
190f2a
+	  /* s2 = `-%{version}-%{release}.src.rpm-debuginfo.%{arch}' */
190f2a
+	  memmove (s2 + debuginfolen, s2, s - s2);
190f2a
+	  memcpy (s2, "-debuginfo", debuginfolen);
190f2a
+	  /* s = `XXXX.%{arch}' */
190f2a
+	  /* strlen ("XXXX") == srcrpmlen + debuginfolen */
190f2a
+	  /* s2 = `-debuginfo-%{version}-%{release}XX.%{arch}' */
190f2a
+	  /* strlen ("XX") == srcrpmlen */
190f2a
+	  memmove (s + debuginfolen, s + srcrpmlen + debuginfolen,
190f2a
+		   strlen (s + srcrpmlen + debuginfolen) + 1);
190f2a
+	  /* s = `-debuginfo-%{version}-%{release}.%{arch}' */
190f2a
+
190f2a
+	  /* RPMDBI_PACKAGES requires keylen == sizeof (int).  */
190f2a
+	  /* RPMDBI_LABEL is an interface for NVR-based dbiFindByLabel().  */
190f2a
+	  mi_debuginfo = rpmtsInitIterator_p (ts, (rpmTag) RPMDBI_LABEL, debuginfo, 0);
190f2a
+	  xfree (debuginfo);
190f2a
+	  if (mi_debuginfo)
190f2a
+	    {
190f2a
+	      rpmdbFreeIterator_p (mi_debuginfo);
190f2a
+	      count = 0;
190f2a
+	      break;
190f2a
+	    }
190f2a
+
190f2a
+	  /* The allocated memory gets utilized below for MISSING_RPM_HASH.  */
190f2a
+	  debuginfo = headerFormat_p (h,
190f2a
+				      "%{name}-%{version}-%{release}.%{arch}",
190f2a
+				      &err;;
190f2a
+	  if (!debuginfo)
190f2a
+	    {
190f2a
+	      warning (_("Error querying the rpm file `%s': %s"), filename,
190f2a
+	               err);
190f2a
+	      continue;
190f2a
+	    }
190f2a
+
190f2a
+	  /* Base package name for `debuginfo-install'.  We do not use the
190f2a
+	     `yum' command directly as the line
190f2a
+		 yum --enablerepo='*debug*' install NAME-debuginfo.ARCH
190f2a
+	     would be more complicated than just:
190f2a
+		 debuginfo-install NAME-VERSION-RELEASE.ARCH
190f2a
+	     Do not supply the rpm base name (derived from .src.rpm name) as
190f2a
+	     debuginfo-install is unable to install the debuginfo package if
190f2a
+	     the base name PKG binary rpm is not installed while for example
190f2a
+	     PKG-libs would be installed (RH Bug 467901).
190f2a
+	     FUTURE: After multiple debuginfo versions simultaneously installed
190f2a
+	     get supported the support for the VERSION-RELEASE tags handling
190f2a
+	     may need an update.  */
190f2a
+
190f2a
+	  if (missing_rpm_hash == NULL)
190f2a
+	    {
190f2a
+	      /* DEL_F is passed NULL as MISSING_RPM_LIST's HTAB_DELETE
190f2a
+		 should not deallocate the entries.  */
190f2a
+
190f2a
+	      missing_rpm_hash = htab_create_alloc (64, htab_hash_string,
190f2a
+			       (int (*) (const void *, const void *)) streq,
190f2a
+						    NULL, xcalloc, xfree);
190f2a
+	    }
190f2a
+	  slot = (char **) htab_find_slot (missing_rpm_hash, debuginfo, INSERT);
190f2a
+	  /* XCALLOC never returns NULL.  */
190f2a
+	  gdb_assert (slot != NULL);
190f2a
+	  if (*slot == NULL)
190f2a
+	    {
190f2a
+	      struct missing_rpm *missing_rpm;
190f2a
+
190f2a
+	      *slot = debuginfo;
190f2a
+
190f2a
+	      missing_rpm = (struct missing_rpm *) xmalloc (sizeof (*missing_rpm) + strlen (debuginfo));
190f2a
+	      strcpy (missing_rpm->rpm, debuginfo);
190f2a
+	      missing_rpm->next = missing_rpm_list;
190f2a
+	      missing_rpm_list = missing_rpm;
190f2a
+	      missing_rpm_list_entries++;
190f2a
+	    }
190f2a
+	  else
190f2a
+	    xfree (debuginfo);
190f2a
+	  count++;
190f2a
+	}
190f2a
+
190f2a
+      rpmdbFreeIterator_p (mi);
190f2a
+    }
190f2a
+
190f2a
+  rpmtsFree_p (ts);
190f2a
+
190f2a
+  return count;
190f2a
+}
190f2a
+
190f2a
+static int
190f2a
+missing_rpm_list_compar (const char *const *ap, const char *const *bp)
190f2a
+{
190f2a
+  return strcoll (*ap, *bp);
190f2a
+}
190f2a
+
190f2a
+/* It returns a NULL-terminated array of strings needing to be FREEd.  It may
190f2a
+   also return only NULL.  */
190f2a
+
190f2a
+static void
190f2a
+missing_rpm_list_print (void)
190f2a
+{
190f2a
+  char **array, **array_iter;
190f2a
+  struct missing_rpm *list_iter;
190f2a
+  struct cleanup *cleanups;
190f2a
+
190f2a
+  if (missing_rpm_list_entries == 0)
190f2a
+    return;
190f2a
+
190f2a
+  array = (char **) xmalloc (sizeof (*array) * missing_rpm_list_entries);
190f2a
+  cleanups = make_cleanup (xfree, array);
190f2a
+
190f2a
+  array_iter = array;
190f2a
+  for (list_iter = missing_rpm_list; list_iter != NULL;
190f2a
+       list_iter = list_iter->next)
190f2a
+    {
190f2a
+      *array_iter++ = list_iter->rpm;
190f2a
+    }
190f2a
+  gdb_assert (array_iter == array + missing_rpm_list_entries);
190f2a
+
190f2a
+  qsort (array, missing_rpm_list_entries, sizeof (*array),
190f2a
+	 (int (*) (const void *, const void *)) missing_rpm_list_compar);
190f2a
+
190f2a
+  printf_unfiltered (_("Missing separate debuginfos, use: %s"),
190f2a
+#ifdef DNF_DEBUGINFO_INSTALL
190f2a
+		     "dnf "
190f2a
+#endif
190f2a
+		     "debuginfo-install");
190f2a
+  for (array_iter = array; array_iter < array + missing_rpm_list_entries;
190f2a
+       array_iter++)
190f2a
+    {
190f2a
+      putchar_unfiltered (' ');
190f2a
+      puts_unfiltered (*array_iter);
190f2a
+    }
190f2a
+  putchar_unfiltered ('\n');
190f2a
+
190f2a
+  while (missing_rpm_list != NULL)
190f2a
+    {
190f2a
+      list_iter = missing_rpm_list;
190f2a
+      missing_rpm_list = list_iter->next;
190f2a
+      xfree (list_iter);
190f2a
+    }
190f2a
+  missing_rpm_list_entries = 0;
190f2a
+
190f2a
+  do_cleanups (cleanups);
190f2a
+}
190f2a
+
190f2a
+static void
190f2a
+missing_rpm_change (void)
190f2a
+{
190f2a
+  debug_flush_missing ();
190f2a
+
190f2a
+  gdb_assert (missing_rpm_list == NULL);
190f2a
+  if (missing_rpm_hash != NULL)
190f2a
+    {
190f2a
+      htab_delete (missing_rpm_hash);
190f2a
+      missing_rpm_hash = NULL;
190f2a
+    }
190f2a
+}
190f2a
+
190f2a
+enum missing_exec
190f2a
+  {
190f2a
+    /* Init state.  EXEC_BFD also still could be NULL.  */
190f2a
+    MISSING_EXEC_NOT_TRIED,
190f2a
+    /* We saw a non-NULL EXEC_BFD but RPM has no info about it.  */
190f2a
+    MISSING_EXEC_NOT_FOUND,
190f2a
+    /* We found EXEC_BFD by RPM and we either have its symbols (either embedded
190f2a
+       or separate) or the main executable's RPM is now contained in
190f2a
+       MISSING_RPM_HASH.  */
190f2a
+    MISSING_EXEC_ENLISTED
190f2a
+  };
190f2a
+static enum missing_exec missing_exec = MISSING_EXEC_NOT_TRIED;
190f2a
+
190f2a
+#endif	/* HAVE_LIBRPM */
190f2a
+
190f2a
+void
190f2a
+debug_flush_missing (void)
190f2a
+{
190f2a
+#ifdef HAVE_LIBRPM
190f2a
+  missing_rpm_list_print ();
190f2a
+#endif
190f2a
+}
190f2a
+
190f2a
 /* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
190f2a
-     Try to install the hash file ...
190f2a
+     yum --enablerepo='*debug*' install ...
190f2a
    avoidance.  */
190f2a
 
190f2a
 struct missing_filepair
190f2a
@@ -695,11 +1055,17 @@ missing_filepair_change (void)
190f2a
       /* All their memory came just from missing_filepair_OBSTACK.  */
190f2a
       missing_filepair_hash = NULL;
190f2a
     }
190f2a
+#ifdef HAVE_LIBRPM
190f2a
+  missing_exec = MISSING_EXEC_NOT_TRIED;
190f2a
+#endif
190f2a
 }
190f2a
 
190f2a
 static void
190f2a
 debug_print_executable_changed (void)
190f2a
 {
190f2a
+#ifdef HAVE_LIBRPM
190f2a
+  missing_rpm_change ();
190f2a
+#endif
190f2a
   missing_filepair_change ();
190f2a
 }
190f2a
 
190f2a
@@ -766,14 +1132,39 @@ debug_print_missing (const char *binary, const char *debug)
190f2a
 
190f2a
   *slot = missing_filepair;
190f2a
 
190f2a
-  /* We do not collect and flush these messages as each such message
190f2a
-     already requires its own separate lines.  */
190f2a
+#ifdef HAVE_LIBRPM
190f2a
+  if (missing_exec == MISSING_EXEC_NOT_TRIED)
190f2a
+    {
190f2a
+      char *execfilename;
190f2a
 
190f2a
-  fprintf_unfiltered (gdb_stdlog,
190f2a
-		      _("Missing separate debuginfo for %s\n"), binary);
190f2a
-  if (debug != NULL)
190f2a
-    fprintf_unfiltered (gdb_stdlog, _("Try to install the hash file %s\n"),
190f2a
-			debug);
190f2a
+      execfilename = get_exec_file (0);
190f2a
+      if (execfilename != NULL)
190f2a
+	{
190f2a
+	  if (missing_rpm_enlist (execfilename) == 0)
190f2a
+	    missing_exec = MISSING_EXEC_NOT_FOUND;
190f2a
+	  else
190f2a
+	    missing_exec = MISSING_EXEC_ENLISTED;
190f2a
+	}
190f2a
+    }
190f2a
+  if (missing_exec != MISSING_EXEC_ENLISTED)
190f2a
+    if ((binary[0] == 0 || missing_rpm_enlist (binary) == 0)
190f2a
+	&& (debug == NULL || missing_rpm_enlist (debug) == 0))
190f2a
+#endif	/* HAVE_LIBRPM */
190f2a
+      {
190f2a
+	/* We do not collect and flush these messages as each such message
190f2a
+	   already requires its own separate lines.  */
190f2a
+
190f2a
+	fprintf_unfiltered (gdb_stdlog,
190f2a
+			    _("Missing separate debuginfo for %s\n"), binary);
190f2a
+        if (debug != NULL)
190f2a
+	  fprintf_unfiltered (gdb_stdlog, _("Try: %s %s\n"),
190f2a
+#ifdef DNF_DEBUGINFO_INSTALL
190f2a
+			      "dnf"
190f2a
+#else
190f2a
+			      "yum"
190f2a
+#endif
190f2a
+			      " --enablerepo='*debug*' install", debug);
190f2a
+      }
190f2a
 }
190f2a
 
190f2a
 /* See build-id.h.  */
190f2a
diff --git a/gdb/config.in b/gdb/config.in
190f2a
--- a/gdb/config.in
190f2a
+++ b/gdb/config.in
190f2a
@@ -33,6 +33,9 @@
190f2a
 /* Define to BFD's default target vector. */
190f2a
 #undef DEFAULT_BFD_VEC
190f2a
 
190f2a
+/* librpm version specific library name to dlopen. */
190f2a
+#undef DLOPEN_LIBRPM
190f2a
+
190f2a
 /* Define to 1 if translation of program messages to the user's native
190f2a
    language is requested. */
190f2a
 #undef ENABLE_NLS
190f2a
@@ -270,6 +273,9 @@
190f2a
 /* Define if Python 2.7 is being used. */
190f2a
 #undef HAVE_LIBPYTHON2_7
190f2a
 
190f2a
+/* Define if librpm library is being used. */
190f2a
+#undef HAVE_LIBRPM
190f2a
+
190f2a
 /* Define to 1 if you have the <libunwind-ia64.h> header file. */
190f2a
 #undef HAVE_LIBUNWIND_IA64_H
190f2a
 
190f2a
diff --git a/gdb/configure b/gdb/configure
190f2a
--- a/gdb/configure
190f2a
+++ b/gdb/configure
190f2a
@@ -749,6 +749,11 @@ CODESIGN_CERT
190f2a
 HAVE_NATIVE_GCORE_TARGET
190f2a
 TARGET_OBS
190f2a
 subdirs
190f2a
+RPM_LIBS
190f2a
+RPM_CFLAGS
190f2a
+PKG_CONFIG_LIBDIR
190f2a
+PKG_CONFIG_PATH
190f2a
+PKG_CONFIG
190f2a
 GDB_DATADIR
190f2a
 DEBUGDIR
190f2a
 MAKEINFO_EXTRA_FLAGS
190f2a
@@ -853,6 +858,7 @@ with_gdb_datadir
190f2a
 with_relocated_sources
190f2a
 with_auto_load_dir
190f2a
 with_auto_load_safe_path
190f2a
+with_rpm
190f2a
 enable_targets
190f2a
 enable_64_bit_bfd
190f2a
 enable_gdbcli
190f2a
@@ -912,6 +918,11 @@ CCC
190f2a
 CPP
190f2a
 MAKEINFO
190f2a
 MAKEINFOFLAGS
190f2a
+PKG_CONFIG
190f2a
+PKG_CONFIG_PATH
190f2a
+PKG_CONFIG_LIBDIR
190f2a
+RPM_CFLAGS
190f2a
+RPM_LIBS
190f2a
 YACC
190f2a
 YFLAGS
190f2a
 XMKMF'
190f2a
@@ -1583,6 +1594,8 @@ Optional Packages:
190f2a
                           [--with-auto-load-dir]
190f2a
   --without-auto-load-safe-path
190f2a
                           do not restrict auto-loaded files locations
190f2a
+  --with-rpm              query rpm database for missing debuginfos (yes/no,
190f2a
+                          def. auto=librpm.so)
190f2a
   --with-libunwind-ia64   use libunwind frame unwinding for ia64 targets
190f2a
   --with-curses           use the curses library instead of the termcap
190f2a
                           library
190f2a
@@ -1640,6 +1653,13 @@ Some influential environment variables:
190f2a
   MAKEINFO    Parent configure detects if it is of sufficient version.
190f2a
   MAKEINFOFLAGS
190f2a
               Parameters for MAKEINFO.
190f2a
+  PKG_CONFIG  path to pkg-config utility
190f2a
+  PKG_CONFIG_PATH
190f2a
+              directories to add to pkg-config's search path
190f2a
+  PKG_CONFIG_LIBDIR
190f2a
+              path overriding pkg-config's built-in search path
190f2a
+  RPM_CFLAGS  C compiler flags for RPM, overriding pkg-config
190f2a
+  RPM_LIBS    linker flags for RPM, overriding pkg-config
190f2a
   YACC        The `Yet Another Compiler Compiler' implementation to use.
190f2a
               Defaults to the first program found out of: `bison -y', `byacc',
190f2a
               `yacc'.
190f2a
@@ -6575,6 +6595,494 @@ _ACEOF
190f2a
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_auto_load_safe_path" >&5
190f2a
 $as_echo "$with_auto_load_safe_path" >&6; }
190f2a
 
190f2a
+# Integration with rpm library to support missing debuginfo suggestions.
190f2a
+# --without-rpm: Disable any rpm support.
190f2a
+# --with-rpm=libname.so: Try to dynamically open `libname.so' during runtime.
190f2a
+#   Even with runtime missing `libname.so' GDB will still other run correctly.
190f2a
+#   Missing `libname.so' during ./configure will abort the configuration.
190f2a
+# --with-rpm=librpm.so: Like `--with-rpm=libname.so' but try to find specific
190f2a
+#   minor version first such as `librpm-4.6.so' as minor version differences
190f2a
+#   mean API+ABI incompatibility.  If the specific match versioned library name
190f2a
+#   could not be found still open dynamically at least `librpm.so'.
190f2a
+# --with-rpm: Like `--with-rpm=librpm.so' but if any of its detection fails try
190f2a
+#   to find librpm for compilation-time linking by pkg-config.  GDB binary will
190f2a
+#   be probably linked with the version specific library (as `librpm-4.6.so').
190f2a
+#   Failure to find librpm by pkg-config will abort the configuration.
190f2a
+# (default) --with-rpm=auto: Like `--with-rpm=librpm.so' but if even pkg-config
190f2a
+#   cannot find librpm use to the rpmless compilation (like `--without-rpm').
190f2a
+
190f2a
+
190f2a
+# Check whether --with-rpm was given.
190f2a
+if test "${with_rpm+set}" = set; then :
190f2a
+  withval=$with_rpm;
190f2a
+else
190f2a
+  with_rpm="auto"
190f2a
+fi
190f2a
+
190f2a
+
190f2a
+
190f2a
+
190f2a
+if test "x$with_rpm" != "xno"; then
190f2a
+  if test "x$with_rpm" = "xyes"; then
190f2a
+    LIBRPM="librpm.so"
190f2a
+    RPM_REQUIRE=true
190f2a
+    DLOPEN_REQUIRE=false
190f2a
+  elif test "x$with_rpm" = "xauto"; then
190f2a
+    LIBRPM="librpm.so"
190f2a
+    RPM_REQUIRE=false
190f2a
+    DLOPEN_REQUIRE=false
190f2a
+  else
190f2a
+    LIBRPM="$with_rpm"
190f2a
+    RPM_REQUIRE=true
190f2a
+    DLOPEN_REQUIRE=true
190f2a
+  fi
190f2a
+  LIBRPM_STRING='"'"$LIBRPM"'"'
190f2a
+
190f2a
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking specific librpm version" >&5
190f2a
+$as_echo_n "checking specific librpm version... " >&6; }
190f2a
+  HAVE_DLOPEN_LIBRPM=false
190f2a
+  save_LIBS="$LIBS"
190f2a
+  LIBS="$LIBS -ldl"
190f2a
+  if test "$cross_compiling" = yes; then :
190f2a
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
190f2a
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
190f2a
+as_fn_error "cannot run test program while cross compiling
190f2a
+See \`config.log' for more details." "$LINENO" 5; }
190f2a
+else
190f2a
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
190f2a
+/* end confdefs.h.  */
190f2a
+
190f2a
+#include <rpm/rpmlib.h>
190f2a
+#include <dlfcn.h>
190f2a
+#include <errno.h>
190f2a
+
190f2a
+int
190f2a
+main ()
190f2a
+{
190f2a
+
190f2a
+    void *h;
190f2a
+    const char *const *rpmverp;
190f2a
+    FILE *f;
190f2a
+
190f2a
+    f = fopen ("conftest.out", "w");
190f2a
+    if (!f)
190f2a
+      {
190f2a
+	fprintf (stderr, "Cannot write \"%s\": %s\n", "conftest.out",
190f2a
+		 strerror (errno));
190f2a
+	return 1;
190f2a
+      }
190f2a
+    h = dlopen ($LIBRPM_STRING, RTLD_LAZY);
190f2a
+    if (!h)
190f2a
+      {
190f2a
+	fprintf (stderr, "dlopen (\"%s\"): %s\n", $LIBRPM_STRING, dlerror ());
190f2a
+	return 1;
190f2a
+      }
190f2a
+    rpmverp = dlsym (h, "RPMVERSION");
190f2a
+    if (!rpmverp)
190f2a
+      {
190f2a
+	fprintf (stderr, "dlsym (\"RPMVERSION\"): %s\n", dlerror ());
190f2a
+	return 1;
190f2a
+      }
190f2a
+    fprintf (stderr, "RPMVERSION is: \"");
190f2a
+    fprintf (stderr, "%s\"\n", *rpmverp);
190f2a
+
190f2a
+    /* Try to find the specific librpm version only for "librpm.so" as we do
190f2a
+       not know how to assemble the version string otherwise.  */
190f2a
+
190f2a
+    if (strcmp ("librpm.so", $LIBRPM_STRING) != 0)
190f2a
+      {
190f2a
+	fprintf (f, "%s\n", $LIBRPM_STRING);
190f2a
+	return 0;
190f2a
+      }
190f2a
+    else
190f2a
+      {
190f2a
+	char *h2_name;
190f2a
+	void *h2;
190f2a
+	int major, minor;
190f2a
+
190f2a
+	if (sscanf (*rpmverp, "%d.%d", &major, &minor) != 2)
190f2a
+	  {
190f2a
+	    fprintf (stderr, "Unable to parse RPMVERSION.\n");
190f2a
+	    fprintf (f, "%s\n", $LIBRPM_STRING);
190f2a
+	    return 0;
190f2a
+	  }
190f2a
+	/* Avoid the square brackets by malloc.  */
190f2a
+	h2_name = malloc (64);
190f2a
+	sprintf (h2_name, "librpm-%d.%d.so", major, minor);
190f2a
+	h2 = dlopen (h2_name, RTLD_LAZY);
190f2a
+	if (!h2)
190f2a
+	  {
190f2a
+	    fprintf (stderr, "dlopen (\"%s\"): %s\n", h2_name, dlerror ());
190f2a
+	    fprintf (f, "%s\n", $LIBRPM_STRING);
190f2a
+	    return 0;
190f2a
+	  }
190f2a
+	if (h2 != h)
190f2a
+	  {
190f2a
+	    fprintf (stderr, "dlopen of \"%s\" and \"%s\" are different.\n",
190f2a
+		     $LIBRPM_STRING, h2_name);
190f2a
+	    fprintf (f, "%s\n", $LIBRPM_STRING);
190f2a
+	    return 0;
190f2a
+	  }
190f2a
+	/* Found the valid .so name with a specific version.  */
190f2a
+	fprintf (f, "%s\n", h2_name);
190f2a
+	return 0;
190f2a
+      }
190f2a
+
190f2a
+  ;
190f2a
+  return 0;
190f2a
+}
190f2a
+_ACEOF
190f2a
+if ac_fn_c_try_run "$LINENO"; then :
190f2a
+
190f2a
+    DLOPEN_LIBRPM="`cat conftest.out`"
190f2a
+    if test "x$DLOPEN_LIBRPM" != "x"; then
190f2a
+      HAVE_DLOPEN_LIBRPM=true
190f2a
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLOPEN_LIBRPM" >&5
190f2a
+$as_echo "$DLOPEN_LIBRPM" >&6; }
190f2a
+    fi
190f2a
+
190f2a
+fi
190f2a
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
190f2a
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
190f2a
+fi
190f2a
+
190f2a
+  rm -f conftest.out
190f2a
+
190f2a
+
190f2a
+
190f2a
+  if $HAVE_DLOPEN_LIBRPM; then
190f2a
+
190f2a
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking rpm library API compatibility" >&5
190f2a
+$as_echo_n "checking rpm library API compatibility... " >&6; }
190f2a
+    # The compilation requires -Werror to verify anything.
190f2a
+    save_CFLAGS="$CFLAGS"
190f2a
+    CFLAGS="$CFLAGS -Werror"
190f2a
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
190f2a
+/* end confdefs.h.  */
190f2a
+
190f2a
+/* Duplicate here the declarations to verify they match "elfread.c".  */
190f2a
+#include <rpm/rpmlib.h>
190f2a
+#include <rpm/rpmts.h>
190f2a
+#include <rpm/rpmdb.h>
190f2a
+#include <rpm/header.h>
190f2a
+extern char * headerFormat(Header h, const char * fmt, errmsg_t * errmsg);
190f2a
+extern int rpmReadConfigFiles(const char * file, const char * target);
190f2a
+extern rpmdbMatchIterator rpmdbFreeIterator(rpmdbMatchIterator mi);
190f2a
+extern Header rpmdbNextIterator(rpmdbMatchIterator mi);
190f2a
+extern rpmts rpmtsCreate(void);
190f2a
+extern rpmts rpmtsFree(rpmts ts);
190f2a
+extern rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmTag rpmtag,
190f2a
+					    const void * keyp, size_t keylen);
190f2a
+
190f2a
+int
190f2a
+main ()
190f2a
+{
190f2a
+
190f2a
+  ;
190f2a
+  return 0;
190f2a
+}
190f2a
+_ACEOF
190f2a
+if ac_fn_c_try_compile "$LINENO"; then :
190f2a
+
190f2a
+      LIBRPM_COMPAT=true
190f2a
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
190f2a
+$as_echo "yes" >&6; }
190f2a
+
190f2a
+else
190f2a
+
190f2a
+      LIBRPM_COMPAT=false
190f2a
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190f2a
+$as_echo "no" >&6; }
190f2a
+
190f2a
+fi
190f2a
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
190f2a
+    CFLAGS="$save_CFLAGS"
190f2a
+
190f2a
+    if ! $LIBRPM_COMPAT; then
190f2a
+      HAVE_DLOPEN_LIBRPM=false
190f2a
+    fi
190f2a
+  fi
190f2a
+
190f2a
+  if $HAVE_DLOPEN_LIBRPM; then
190f2a
+    DLOPEN_LIBRPM_STRING='"'"$DLOPEN_LIBRPM"'"'
190f2a
+
190f2a
+cat >>confdefs.h <<_ACEOF
190f2a
+#define DLOPEN_LIBRPM $DLOPEN_LIBRPM_STRING
190f2a
+_ACEOF
190f2a
+
190f2a
+
190f2a
+$as_echo "#define HAVE_LIBRPM 1" >>confdefs.h
190f2a
+
190f2a
+  else
190f2a
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190f2a
+$as_echo "no" >&6; }
190f2a
+    LIBS="$save_LIBS"
190f2a
+    if $DLOPEN_REQUIRE; then
190f2a
+      as_fn_error "Specific name $LIBRPM was requested but it could not be opened." "$LINENO" 5
190f2a
+    fi
190f2a
+
190f2a
+
190f2a
+
190f2a
+
190f2a
+
190f2a
+
190f2a
+
190f2a
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
190f2a
+	if test -n "$ac_tool_prefix"; then
190f2a
+  # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
190f2a
+set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
190f2a
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
190f2a
+$as_echo_n "checking for $ac_word... " >&6; }
190f2a
+if test "${ac_cv_path_PKG_CONFIG+set}" = set; then :
190f2a
+  $as_echo_n "(cached) " >&6
190f2a
+else
190f2a
+  case $PKG_CONFIG in
190f2a
+  [\\/]* | ?:[\\/]*)
190f2a
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
190f2a
+  ;;
190f2a
+  *)
190f2a
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
190f2a
+for as_dir in $PATH
190f2a
+do
190f2a
+  IFS=$as_save_IFS
190f2a
+  test -z "$as_dir" && as_dir=.
190f2a
+    for ac_exec_ext in '' $ac_executable_extensions; do
190f2a
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
190f2a
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
190f2a
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
190f2a
+    break 2
190f2a
+  fi
190f2a
+done
190f2a
+  done
190f2a
+IFS=$as_save_IFS
190f2a
+
190f2a
+  ;;
190f2a
+esac
190f2a
+fi
190f2a
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
190f2a
+if test -n "$PKG_CONFIG"; then
190f2a
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
190f2a
+$as_echo "$PKG_CONFIG" >&6; }
190f2a
+else
190f2a
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190f2a
+$as_echo "no" >&6; }
190f2a
+fi
190f2a
+
190f2a
+
190f2a
+fi
190f2a
+if test -z "$ac_cv_path_PKG_CONFIG"; then
190f2a
+  ac_pt_PKG_CONFIG=$PKG_CONFIG
190f2a
+  # Extract the first word of "pkg-config", so it can be a program name with args.
190f2a
+set dummy pkg-config; ac_word=$2
190f2a
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
190f2a
+$as_echo_n "checking for $ac_word... " >&6; }
190f2a
+if test "${ac_cv_path_ac_pt_PKG_CONFIG+set}" = set; then :
190f2a
+  $as_echo_n "(cached) " >&6
190f2a
+else
190f2a
+  case $ac_pt_PKG_CONFIG in
190f2a
+  [\\/]* | ?:[\\/]*)
190f2a
+  ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path.
190f2a
+  ;;
190f2a
+  *)
190f2a
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
190f2a
+for as_dir in $PATH
190f2a
+do
190f2a
+  IFS=$as_save_IFS
190f2a
+  test -z "$as_dir" && as_dir=.
190f2a
+    for ac_exec_ext in '' $ac_executable_extensions; do
190f2a
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
190f2a
+    ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
190f2a
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
190f2a
+    break 2
190f2a
+  fi
190f2a
+done
190f2a
+  done
190f2a
+IFS=$as_save_IFS
190f2a
+
190f2a
+  ;;
190f2a
+esac
190f2a
+fi
190f2a
+ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG
190f2a
+if test -n "$ac_pt_PKG_CONFIG"; then
190f2a
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5
190f2a
+$as_echo "$ac_pt_PKG_CONFIG" >&6; }
190f2a
+else
190f2a
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190f2a
+$as_echo "no" >&6; }
190f2a
+fi
190f2a
+
190f2a
+  if test "x$ac_pt_PKG_CONFIG" = x; then
190f2a
+    PKG_CONFIG=""
190f2a
+  else
190f2a
+    case $cross_compiling:$ac_tool_warned in
190f2a
+yes:)
190f2a
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
190f2a
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
190f2a
+ac_tool_warned=yes ;;
190f2a
+esac
190f2a
+    PKG_CONFIG=$ac_pt_PKG_CONFIG
190f2a
+  fi
190f2a
+else
190f2a
+  PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
190f2a
+fi
190f2a
+
190f2a
+fi
190f2a
+if test -n "$PKG_CONFIG"; then
190f2a
+	_pkg_min_version=0.9.0
190f2a
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5
190f2a
+$as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; }
190f2a
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
190f2a
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
190f2a
+$as_echo "yes" >&6; }
190f2a
+	else
190f2a
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190f2a
+$as_echo "no" >&6; }
190f2a
+		PKG_CONFIG=""
190f2a
+	fi
190f2a
+fi
190f2a
+
190f2a
+pkg_failed=no
190f2a
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for RPM" >&5
190f2a
+$as_echo_n "checking for RPM... " >&6; }
190f2a
+
190f2a
+if test -n "$RPM_CFLAGS"; then
190f2a
+    pkg_cv_RPM_CFLAGS="$RPM_CFLAGS"
190f2a
+ elif test -n "$PKG_CONFIG"; then
190f2a
+    if test -n "$PKG_CONFIG" && \
190f2a
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"rpm\""; } >&5
190f2a
+  ($PKG_CONFIG --exists --print-errors "rpm") 2>&5
190f2a
+  ac_status=$?
190f2a
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
190f2a
+  test $ac_status = 0; }; then
190f2a
+  pkg_cv_RPM_CFLAGS=`$PKG_CONFIG --cflags "rpm" 2>/dev/null`
190f2a
+		      test "x$?" != "x0" && pkg_failed=yes
190f2a
+else
190f2a
+  pkg_failed=yes
190f2a
+fi
190f2a
+ else
190f2a
+    pkg_failed=untried
190f2a
+fi
190f2a
+if test -n "$RPM_LIBS"; then
190f2a
+    pkg_cv_RPM_LIBS="$RPM_LIBS"
190f2a
+ elif test -n "$PKG_CONFIG"; then
190f2a
+    if test -n "$PKG_CONFIG" && \
190f2a
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"rpm\""; } >&5
190f2a
+  ($PKG_CONFIG --exists --print-errors "rpm") 2>&5
190f2a
+  ac_status=$?
190f2a
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
190f2a
+  test $ac_status = 0; }; then
190f2a
+  pkg_cv_RPM_LIBS=`$PKG_CONFIG --libs "rpm" 2>/dev/null`
190f2a
+		      test "x$?" != "x0" && pkg_failed=yes
190f2a
+else
190f2a
+  pkg_failed=yes
190f2a
+fi
190f2a
+ else
190f2a
+    pkg_failed=untried
190f2a
+fi
190f2a
+
190f2a
+
190f2a
+
190f2a
+if test $pkg_failed = yes; then
190f2a
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190f2a
+$as_echo "no" >&6; }
190f2a
+
190f2a
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
190f2a
+        _pkg_short_errors_supported=yes
190f2a
+else
190f2a
+        _pkg_short_errors_supported=no
190f2a
+fi
190f2a
+        if test $_pkg_short_errors_supported = yes; then
190f2a
+	        RPM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "rpm" 2>&1`
190f2a
+        else
190f2a
+	        RPM_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "rpm" 2>&1`
190f2a
+        fi
190f2a
+	# Put the nasty error message in config.log where it belongs
190f2a
+	echo "$RPM_PKG_ERRORS" >&5
190f2a
+
190f2a
+	HAVE_LIBRPM=false
190f2a
+elif test $pkg_failed = untried; then
190f2a
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190f2a
+$as_echo "no" >&6; }
190f2a
+	HAVE_LIBRPM=false
190f2a
+else
190f2a
+	RPM_CFLAGS=$pkg_cv_RPM_CFLAGS
190f2a
+	RPM_LIBS=$pkg_cv_RPM_LIBS
190f2a
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
190f2a
+$as_echo "yes" >&6; }
190f2a
+	HAVE_LIBRPM=true
190f2a
+fi
190f2a
+
190f2a
+    if $HAVE_LIBRPM; then
190f2a
+
190f2a
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking rpm library API compatibility" >&5
190f2a
+$as_echo_n "checking rpm library API compatibility... " >&6; }
190f2a
+    # The compilation requires -Werror to verify anything.
190f2a
+    save_CFLAGS="$CFLAGS"
190f2a
+    CFLAGS="$CFLAGS -Werror"
190f2a
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
190f2a
+/* end confdefs.h.  */
190f2a
+
190f2a
+/* Duplicate here the declarations to verify they match "elfread.c".  */
190f2a
+#include <rpm/rpmlib.h>
190f2a
+#include <rpm/rpmts.h>
190f2a
+#include <rpm/rpmdb.h>
190f2a
+#include <rpm/header.h>
190f2a
+extern char * headerFormat(Header h, const char * fmt, errmsg_t * errmsg);
190f2a
+extern int rpmReadConfigFiles(const char * file, const char * target);
190f2a
+extern rpmdbMatchIterator rpmdbFreeIterator(rpmdbMatchIterator mi);
190f2a
+extern Header rpmdbNextIterator(rpmdbMatchIterator mi);
190f2a
+extern rpmts rpmtsCreate(void);
190f2a
+extern rpmts rpmtsFree(rpmts ts);
190f2a
+extern rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmTag rpmtag,
190f2a
+					    const void * keyp, size_t keylen);
190f2a
+
190f2a
+int
190f2a
+main ()
190f2a
+{
190f2a
+
190f2a
+  ;
190f2a
+  return 0;
190f2a
+}
190f2a
+_ACEOF
190f2a
+if ac_fn_c_try_compile "$LINENO"; then :
190f2a
+
190f2a
+      LIBRPM_COMPAT=true
190f2a
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
190f2a
+$as_echo "yes" >&6; }
190f2a
+
190f2a
+else
190f2a
+
190f2a
+      LIBRPM_COMPAT=false
190f2a
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190f2a
+$as_echo "no" >&6; }
190f2a
+
190f2a
+fi
190f2a
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
190f2a
+    CFLAGS="$save_CFLAGS"
190f2a
+
190f2a
+      if ! $LIBRPM_COMPAT; then
190f2a
+	HAVE_LIBRPM=false
190f2a
+	RPM_PKG_ERRORS="Found $LIBRPM API is incompatibile with this GDB"
190f2a
+      fi
190f2a
+    fi
190f2a
+
190f2a
+    if $HAVE_LIBRPM; then
190f2a
+
190f2a
+$as_echo "#define HAVE_LIBRPM 1" >>confdefs.h
190f2a
+
190f2a
+      CFLAGS="$CFLAGS $RPM_CFLAGS"
190f2a
+      LIBS="$LIBS $RPM_LIBS"
190f2a
+    else
190f2a
+      if $RPM_REQUIRE; then
190f2a
+	as_fn_error "$RPM_PKG_ERRORS" "$LINENO" 5
190f2a
+      else
190f2a
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $RPM_PKG_ERRORS" >&5
190f2a
+$as_echo "$as_me: WARNING: $RPM_PKG_ERRORS" >&2;}
190f2a
+      fi
190f2a
+    fi
190f2a
+  fi
190f2a
+fi
190f2a
+
190f2a
 
190f2a
 
190f2a
 subdirs="$subdirs testsuite"
190f2a
diff --git a/gdb/configure.ac b/gdb/configure.ac
190f2a
--- a/gdb/configure.ac
190f2a
+++ b/gdb/configure.ac
190f2a
@@ -166,6 +166,199 @@ AC_DEFINE_DIR(AUTO_LOAD_SAFE_PATH, escape_dir,
190f2a
 	      [Directories safe to hold auto-loaded files.])
190f2a
 AC_MSG_RESULT([$with_auto_load_safe_path])
190f2a
 
190f2a
+# Integration with rpm library to support missing debuginfo suggestions.
190f2a
+# --without-rpm: Disable any rpm support.
190f2a
+# --with-rpm=libname.so: Try to dynamically open `libname.so' during runtime.
190f2a
+#   Even with runtime missing `libname.so' GDB will still other run correctly.
190f2a
+#   Missing `libname.so' during ./configure will abort the configuration.
190f2a
+# --with-rpm=librpm.so: Like `--with-rpm=libname.so' but try to find specific
190f2a
+#   minor version first such as `librpm-4.6.so' as minor version differences
190f2a
+#   mean API+ABI incompatibility.  If the specific match versioned library name
190f2a
+#   could not be found still open dynamically at least `librpm.so'.
190f2a
+# --with-rpm: Like `--with-rpm=librpm.so' but if any of its detection fails try
190f2a
+#   to find librpm for compilation-time linking by pkg-config.  GDB binary will
190f2a
+#   be probably linked with the version specific library (as `librpm-4.6.so').
190f2a
+#   Failure to find librpm by pkg-config will abort the configuration.
190f2a
+# (default) --with-rpm=auto: Like `--with-rpm=librpm.so' but if even pkg-config
190f2a
+#   cannot find librpm use to the rpmless compilation (like `--without-rpm').
190f2a
+
190f2a
+AC_ARG_WITH([rpm],
190f2a
+  [AS_HELP_STRING([--with-rpm],
190f2a
+                  [query rpm database for missing debuginfos (yes/no, def. auto=librpm.so)])], [], [with_rpm="auto"])
190f2a
+
190f2a
+m4_pattern_allow([^AC_MSG_ERROR$])
190f2a
+m4_pattern_allow([^AC_MSG_WARN$])
190f2a
+if test "x$with_rpm" != "xno"; then
190f2a
+  if test "x$with_rpm" = "xyes"; then
190f2a
+    LIBRPM="librpm.so"
190f2a
+    RPM_REQUIRE=true
190f2a
+    DLOPEN_REQUIRE=false
190f2a
+  elif test "x$with_rpm" = "xauto"; then
190f2a
+    LIBRPM="librpm.so"
190f2a
+    RPM_REQUIRE=false
190f2a
+    DLOPEN_REQUIRE=false
190f2a
+  else
190f2a
+    LIBRPM="$with_rpm"
190f2a
+    RPM_REQUIRE=true
190f2a
+    DLOPEN_REQUIRE=true
190f2a
+  fi
190f2a
+  LIBRPM_STRING='"'"$LIBRPM"'"'
190f2a
+
190f2a
+  AC_MSG_CHECKING([specific librpm version])
190f2a
+  HAVE_DLOPEN_LIBRPM=false
190f2a
+  save_LIBS="$LIBS"
190f2a
+  LIBS="$LIBS -ldl"
190f2a
+  AC_RUN_IFELSE(AC_LANG_PROGRAM([[
190f2a
+#include <rpm/rpmlib.h>
190f2a
+#include <dlfcn.h>
190f2a
+#include <errno.h>
190f2a
+  ]], [[
190f2a
+    void *h;
190f2a
+    const char *const *rpmverp;
190f2a
+    FILE *f;
190f2a
+
190f2a
+    f = fopen ("conftest.out", "w");
190f2a
+    if (!f)
190f2a
+      {
190f2a
+	fprintf (stderr, "Cannot write \"%s\": %s\n", "conftest.out",
190f2a
+		 strerror (errno));
190f2a
+	return 1;
190f2a
+      }
190f2a
+    h = dlopen ($LIBRPM_STRING, RTLD_LAZY);
190f2a
+    if (!h)
190f2a
+      {
190f2a
+	fprintf (stderr, "dlopen (\"%s\"): %s\n", $LIBRPM_STRING, dlerror ());
190f2a
+	return 1;
190f2a
+      }
190f2a
+    rpmverp = dlsym (h, "RPMVERSION");
190f2a
+    if (!rpmverp)
190f2a
+      {
190f2a
+	fprintf (stderr, "dlsym (\"RPMVERSION\"): %s\n", dlerror ());
190f2a
+	return 1;
190f2a
+      }
190f2a
+    fprintf (stderr, "RPMVERSION is: \"");
190f2a
+    fprintf (stderr, "%s\"\n", *rpmverp);
190f2a
+
190f2a
+    /* Try to find the specific librpm version only for "librpm.so" as we do
190f2a
+       not know how to assemble the version string otherwise.  */
190f2a
+
190f2a
+    if (strcmp ("librpm.so", $LIBRPM_STRING) != 0)
190f2a
+      {
190f2a
+	fprintf (f, "%s\n", $LIBRPM_STRING);
190f2a
+	return 0;
190f2a
+      }
190f2a
+    else
190f2a
+      {
190f2a
+	char *h2_name;
190f2a
+	void *h2;
190f2a
+	int major, minor;
190f2a
+
190f2a
+	if (sscanf (*rpmverp, "%d.%d", &major, &minor) != 2)
190f2a
+	  {
190f2a
+	    fprintf (stderr, "Unable to parse RPMVERSION.\n");
190f2a
+	    fprintf (f, "%s\n", $LIBRPM_STRING);
190f2a
+	    return 0;
190f2a
+	  }
190f2a
+	/* Avoid the square brackets by malloc.  */
190f2a
+	h2_name = malloc (64);
190f2a
+	sprintf (h2_name, "librpm-%d.%d.so", major, minor);
190f2a
+	h2 = dlopen (h2_name, RTLD_LAZY);
190f2a
+	if (!h2)
190f2a
+	  {
190f2a
+	    fprintf (stderr, "dlopen (\"%s\"): %s\n", h2_name, dlerror ());
190f2a
+	    fprintf (f, "%s\n", $LIBRPM_STRING);
190f2a
+	    return 0;
190f2a
+	  }
190f2a
+	if (h2 != h)
190f2a
+	  {
190f2a
+	    fprintf (stderr, "dlopen of \"%s\" and \"%s\" are different.\n",
190f2a
+		     $LIBRPM_STRING, h2_name);
190f2a
+	    fprintf (f, "%s\n", $LIBRPM_STRING);
190f2a
+	    return 0;
190f2a
+	  }
190f2a
+	/* Found the valid .so name with a specific version.  */
190f2a
+	fprintf (f, "%s\n", h2_name);
190f2a
+	return 0;
190f2a
+      }
190f2a
+  ]]), [
190f2a
+    DLOPEN_LIBRPM="`cat conftest.out`"
190f2a
+    if test "x$DLOPEN_LIBRPM" != "x"; then
190f2a
+      HAVE_DLOPEN_LIBRPM=true
190f2a
+      AC_MSG_RESULT($DLOPEN_LIBRPM)
190f2a
+    fi
190f2a
+  ])
190f2a
+  rm -f conftest.out
190f2a
+
190f2a
+  m4_define([CHECK_LIBRPM_COMPAT], [
190f2a
+    AC_MSG_CHECKING([rpm library API compatibility])
190f2a
+    # The compilation requires -Werror to verify anything.
190f2a
+    save_CFLAGS="$CFLAGS"
190f2a
+    CFLAGS="$CFLAGS -Werror"
190f2a
+    AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[
190f2a
+/* Duplicate here the declarations to verify they match "elfread.c".  */
190f2a
+#include <rpm/rpmlib.h>
190f2a
+#include <rpm/rpmts.h>
190f2a
+#include <rpm/rpmdb.h>
190f2a
+#include <rpm/header.h>
190f2a
+extern char * headerFormat(Header h, const char * fmt, errmsg_t * errmsg);
190f2a
+extern int rpmReadConfigFiles(const char * file, const char * target);
190f2a
+extern rpmdbMatchIterator rpmdbFreeIterator(rpmdbMatchIterator mi);
190f2a
+extern Header rpmdbNextIterator(rpmdbMatchIterator mi);
190f2a
+extern rpmts rpmtsCreate(void);
190f2a
+extern rpmts rpmtsFree(rpmts ts);
190f2a
+extern rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmTag rpmtag,
190f2a
+					    const void * keyp, size_t keylen);
190f2a
+    ]]), [
190f2a
+      LIBRPM_COMPAT=true
190f2a
+      AC_MSG_RESULT(yes)
190f2a
+    ], [
190f2a
+      LIBRPM_COMPAT=false
190f2a
+      AC_MSG_RESULT(no)
190f2a
+    ])
190f2a
+    CFLAGS="$save_CFLAGS"
190f2a
+  ])
190f2a
+
190f2a
+  if $HAVE_DLOPEN_LIBRPM; then
190f2a
+    CHECK_LIBRPM_COMPAT
190f2a
+    if ! $LIBRPM_COMPAT; then
190f2a
+      HAVE_DLOPEN_LIBRPM=false
190f2a
+    fi
190f2a
+  fi
190f2a
+
190f2a
+  if $HAVE_DLOPEN_LIBRPM; then
190f2a
+    DLOPEN_LIBRPM_STRING='"'"$DLOPEN_LIBRPM"'"'
190f2a
+    AC_DEFINE_UNQUOTED(DLOPEN_LIBRPM, $DLOPEN_LIBRPM_STRING, [librpm version specific library name to dlopen.])
190f2a
+    AC_DEFINE(HAVE_LIBRPM, 1, [Define if librpm library is being used.])
190f2a
+  else
190f2a
+    AC_MSG_RESULT(no)
190f2a
+    LIBS="$save_LIBS"
190f2a
+    if $DLOPEN_REQUIRE; then
190f2a
+      AC_MSG_ERROR([Specific name $LIBRPM was requested but it could not be opened.])
190f2a
+    fi
190f2a
+    PKG_CHECK_MODULES(RPM, rpm, [HAVE_LIBRPM=true], [HAVE_LIBRPM=false])
190f2a
+
190f2a
+    if $HAVE_LIBRPM; then
190f2a
+      CHECK_LIBRPM_COMPAT
190f2a
+      if ! $LIBRPM_COMPAT; then
190f2a
+	HAVE_LIBRPM=false
190f2a
+	RPM_PKG_ERRORS="Found $LIBRPM API is incompatibile with this GDB"
190f2a
+      fi
190f2a
+    fi
190f2a
+
190f2a
+    if $HAVE_LIBRPM; then
190f2a
+      AC_DEFINE(HAVE_LIBRPM, 1, [Define if librpm library is being used.])
190f2a
+      CFLAGS="$CFLAGS $RPM_CFLAGS"
190f2a
+      LIBS="$LIBS $RPM_LIBS"
190f2a
+    else
190f2a
+      if $RPM_REQUIRE; then
190f2a
+	AC_MSG_ERROR($RPM_PKG_ERRORS)
190f2a
+      else
190f2a
+	AC_MSG_WARN($RPM_PKG_ERRORS)
190f2a
+      fi
190f2a
+    fi
190f2a
+  fi
190f2a
+fi
190f2a
+ 
190f2a
 AC_CONFIG_SUBDIRS(testsuite)
190f2a
 
190f2a
 # Check whether to support alternative target configurations
190f2a
diff --git a/gdb/corelow.c b/gdb/corelow.c
190f2a
--- a/gdb/corelow.c
190f2a
+++ b/gdb/corelow.c
190f2a
@@ -366,7 +366,7 @@ build_id_locate_exec (int from_tty)
190f2a
         symfile_objfile->flags |= OBJF_BUILD_ID_CORE_LOADED;
190f2a
     }
190f2a
   else
190f2a
-    debug_print_missing (_("the main executable file"), build_id_filename);
190f2a
+    debug_print_missing (BUILD_ID_MAIN_EXECUTABLE_FILENAME, build_id_filename);
190f2a
 
190f2a
   do_cleanups (back_to);
190f2a
 
190f2a
diff --git a/gdb/event-top.c b/gdb/event-top.c
190f2a
--- a/gdb/event-top.c
190f2a
+++ b/gdb/event-top.c
190f2a
@@ -40,6 +40,7 @@
190f2a
 #include "buffer.h"
190f2a
 #include "ser-event.h"
190f2a
 #include "gdb_select.h"
190f2a
+#include "symfile.h"
190f2a
 
190f2a
 /* readline include files.  */
190f2a
 #include "readline/readline.h"
190f2a
@@ -359,6 +360,8 @@ display_gdb_prompt (const char *new_prompt)
190f2a
   /* Reset the nesting depth used when trace-commands is set.  */
190f2a
   reset_command_nest_depth ();
190f2a
 
190f2a
+  debug_flush_missing ();
190f2a
+
190f2a
   /* Do not call the python hook on an explicit prompt change as
190f2a
      passed to this function, as this forms a secondary/local prompt,
190f2a
      IE, displayed but not set.  */
190f2a
@@ -774,7 +777,10 @@ command_line_handler (char *rl)
190f2a
       command_handler (cmd);
190f2a
 
190f2a
       if (ui->prompt_state != PROMPTED)
190f2a
-	display_gdb_prompt (0);
190f2a
+	{
190f2a
+	  debug_flush_missing ();
190f2a
+	  display_gdb_prompt (0);
190f2a
+	}
190f2a
     }
190f2a
 }
190f2a
 
190f2a
diff --git a/gdb/symfile.h b/gdb/symfile.h
190f2a
--- a/gdb/symfile.h
190f2a
+++ b/gdb/symfile.h
190f2a
@@ -540,6 +540,8 @@ void map_symbol_filenames (symbol_filename_ftype *fun, void *data,
190f2a
 /* build-id support.  */
190f2a
 extern struct bfd_build_id *build_id_addr_get (CORE_ADDR addr);
190f2a
 extern void debug_print_missing (const char *binary, const char *debug);
190f2a
+extern void debug_flush_missing (void);
190f2a
+#define BUILD_ID_MAIN_EXECUTABLE_FILENAME _("the main executable file")
190f2a
 
190f2a
 /* From dwarf2read.c */
190f2a