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

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