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

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