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

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