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

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