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

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