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

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