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

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