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

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