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

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