eb9d945
[base]
eb9d945
eb9d945
2007-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
eb9d945
eb9d945
	Port to GDB-6.7.
eb9d945
6a80c39
2008-01-22  Jan Kratochvil  <jan.kratochvil@redhat.com>
6a80c39
	option "build-id-core-loads": Fix it to be an "on"/"off" type.
6a80c39
	More intuitive build-id missing files messages.
6a80c39
	Lookup also the main executable from the rpm database.
6a80c39
	Suppress duplicite buil-id missing files warnings.
6a80c39
4d1104a
2008-01-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
4d1104a
	Print the shared libraries names unconditionally.
4d1104a
917a6fb
2008-02-21  Jan Kratochvil  <jan.kratochvil@redhat.com>
917a6fb
	Rename `debug build-id' to `build-id-verbose'.
917a6fb
	Provide its level 0 to disable the build-id messages.
917a6fb
	Resolve the RH Bug 432164.
917a6fb
25ff8a1
2008-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
25ff8a1
25ff8a1
	Port to GDB-6.8pre.
25ff8a1
25ff8a1
Index: gdb-6.7.50.20080227/gdb/Makefile.in
25ff8a1
===================================================================
25ff8a1
--- gdb-6.7.50.20080227.orig/gdb/Makefile.in	2008-03-01 10:30:49.000000000 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/Makefile.in	2008-03-01 10:38:01.000000000 +0100
25ff8a1
@@ -392,7 +392,7 @@ INSTALLED_LIBS=-lbfd -lreadline -lopcode
25ff8a1
 CLIBS = $(SIM) $(READLINE) $(OPCODES) $(BFD) $(INTL) $(LIBIBERTY) $(LIBDECNUMBER) \
6a80c39
 	$(XM_CLIBS) $(TM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ \
6a80c39
 	$(LIBICONV) $(LIBEXPAT) \
6a80c39
-	$(LIBIBERTY) $(WIN32LIBS)
6a80c39
+	$(LIBIBERTY) $(WIN32LIBS) -lrpm
6a80c39
 CDEPS = $(XM_CDEPS) $(TM_CDEPS) $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) \
6a80c39
 	$(OPCODES) $(INTL_DEPS) $(LIBIBERTY) $(CONFIG_DEPS)
6a80c39
 
25ff8a1
@@ -2029,7 +2029,8 @@ corelow.o: corelow.c $(defs_h) $(arch_ut
4e2e788
 	$(inferior_h) $(symtab_h) $(command_h) $(bfd_h) $(target_h) \
4e2e788
 	$(gdbcore_h) $(gdbthread_h) $(regcache_h) $(regset_h) $(symfile_h) \
4e2e788
 	$(exec_h) $(readline_h) $(gdb_assert_h) \
25ff8a1
-	$(exceptions_h) $(solib_h) $(filenames_h)
25ff8a1
+	$(exceptions_h) $(solib_h) $(filenames_h) $(auxv_h) $(elf_common_h) \
25ff8a1
+	$(objfiles_h) $(gdbcmd_h)
4e2e788
 core-regset.o: core-regset.c $(defs_h) $(command_h) $(gdbcore_h) \
eb9d945
 	$(inferior_h) $(target_h) $(regcache_h) $(gdb_string_h) $(gregset_h)
4e2e788
 cp-abi.o: cp-abi.c $(defs_h) $(value_h) $(cp_abi_h) $(command_h) $(gdbcmd_h) \
25ff8a1
@@ -2884,7 +2885,8 @@ symfile.o: symfile.c $(defs_h) $(bfdlink
4e2e788
 	$(gdb_stabs_h) $(gdb_obstack_h) $(completer_h) $(bcache_h) \
4e2e788
 	$(hashtab_h) $(readline_h) $(gdb_assert_h) $(block_h) \
4e2e788
 	$(gdb_string_h) $(gdb_stat_h) $(observer_h) $(exec_h) \
25ff8a1
-	$(parser_defs_h) $(varobj_h) $(elf_bfd_h) $(solib_h)
25ff8a1
+	$(parser_defs_h) $(varobj_h) $(elf_bfd_h) $(solib_h) $(gdb_stdint_h) \
25ff8a1
+	$(libbfd_h) $(elf_bfd_h) $(elf_external_h)
4e2e788
 symfile-mem.o: symfile-mem.c $(defs_h) $(symtab_h) $(gdbcore_h) \
4e2e788
 	$(objfiles_h) $(exceptions_h) $(gdbcmd_h) $(target_h) $(value_h) \
4e2e788
 	$(symfile_h) $(observer_h) $(auxv_h) $(elf_common_h)
25ff8a1
Index: gdb-6.7.50.20080227/gdb/corelow.c
25ff8a1
===================================================================
25ff8a1
--- gdb-6.7.50.20080227.orig/gdb/corelow.c	2008-02-09 14:45:33.000000000 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/corelow.c	2008-03-01 10:30:50.000000000 +0100
25ff8a1
@@ -45,6 +45,10 @@
4e2e788
 #include "exceptions.h"
4e2e788
 #include "solib.h"
25ff8a1
 #include "filenames.h"
4e2e788
+#include "auxv.h"
4e2e788
+#include "elf/common.h"
4e2e788
+#include "objfiles.h"
4e2e788
+#include "gdbcmd.h"
4e2e788
 
4e2e788
 
4e2e788
 #ifndef O_LARGEFILE
25ff8a1
@@ -248,6 +252,56 @@ add_to_thread_list (bfd *abfd, asection 
4e2e788
     inferior_ptid = pid_to_ptid (thread_id);	/* Yes, make it current */
4e2e788
 }
4e2e788
 
4e2e788
+static int build_id_core_loads = 1;
4e2e788
+
4e2e788
+static void 
4e2e788
+build_id_locate_exec (int from_tty)
4e2e788
+{
4e2e788
+  CORE_ADDR at_entry;
4e2e788
+  struct build_id *build_id;
4e2e788
+  char *exec_filename, *debug_filename;
4e2e788
+  char *build_id_filename;
4e2e788
+
4e2e788
+  if (exec_bfd != NULL)
4e2e788
+    return;
4e2e788
+
4e2e788
+  if (target_auxv_search (&current_target, AT_ENTRY, &at_entry) <= 0)
4e2e788
+    return;
4e2e788
+
4e2e788
+  build_id = build_id_addr_get (at_entry);
4e2e788
+  if (build_id == NULL)
4e2e788
+    return;
4e2e788
+
4e2e788
+  exec_filename = build_id_to_filename (build_id, &build_id_filename, 0);
4e2e788
+  if (exec_filename != NULL)
4e2e788
+    exec_file_attach (exec_filename, from_tty);
4e2e788
+  else
4d1104a
+    build_id_print_missing (_("the main executable file"), build_id_filename);
4e2e788
+  xfree (build_id_filename);
4e2e788
+
4e2e788
+  /* `.note.gnu.build-id' section exists even for files without a separate
4e2e788
+     debuginfo.  */
4e2e788
+  debug_filename = build_id_to_filename (build_id, &build_id_filename, 1);
4e2e788
+  if (debug_filename != NULL)
4e2e788
+    {
4e2e788
+      symbol_file_add_main (debug_filename, from_tty);
4e2e788
+      xfree (debug_filename);
4e2e788
+    }
4e2e788
+  else
4e2e788
+    {
4e2e788
+      if (exec_filename != NULL)
4e2e788
+	symbol_file_add_main (exec_filename, from_tty);
6a80c39
+      /* For EXEC_FILENAME NULL we were already complaining above.  */
6a80c39
+      if (symfile_objfile == NULL && exec_filename != NULL)
4d1104a
+	build_id_print_missing (exec_filename, build_id_filename);
4e2e788
+    }
4e2e788
+  xfree (build_id_filename);
4e2e788
+
4e2e788
+  xfree (exec_filename);
4e2e788
+
435483c
+  /* No automatic SOLIB_ADD as the libraries would get read twice.  */
4e2e788
+}
4e2e788
+
4e2e788
 /* This routine opens and sets up the core file bfd.  */
4e2e788
 
4e2e788
 static void
25ff8a1
@@ -344,6 +398,15 @@ core_open (char *filename, int from_tty)
435483c
   ontop = !push_target (&core_ops);
435483c
   discard_cleanups (old_chain);
4e2e788
 
435483c
+  if (ontop)
435483c
+    {
435483c
+      /* Find the build_id identifiers.  If it gets executed after
435483c
+         POST_CREATE_INFERIOR we would clash with asking to discard the already
435483c
+         loaded VDSO symbols.  */
4e2e788
+      if (build_id_core_loads != 0)
4e2e788
+        build_id_locate_exec (from_tty);
435483c
+    }
4e2e788
+
435483c
   /* This is done first, before anything has a chance to query the
435483c
      inferior for information such as symbols.  */
435483c
   post_create_inferior (&core_ops, from_tty);
25ff8a1
@@ -692,4 +755,11 @@ _initialize_corelow (void)
4e2e788
 
4e2e788
   if (!coreops_suppress_target)
4e2e788
     add_target (&core_ops);
4e2e788
+
6a80c39
+  add_setshow_boolean_cmd ("build-id-core-loads", class_files,
6a80c39
+			   &build_id_core_loads, _("\
6a80c39
+Set whether CORE-FILE loads the build-id associated files automatically."), _("\
6a80c39
+Show whether CORE-FILE loads the build-id associated files automatically.."),
6a80c39
+			   NULL, NULL, NULL,
6a80c39
+			   &setlist, &showlist);
4e2e788
 }
25ff8a1
Index: gdb-6.7.50.20080227/gdb/doc/gdb.texinfo
25ff8a1
===================================================================
25ff8a1
--- gdb-6.7.50.20080227.orig/gdb/doc/gdb.texinfo	2008-03-01 10:30:50.000000000 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/doc/gdb.texinfo	2008-03-01 10:38:02.000000000 +0100
25ff8a1
@@ -12208,6 +12208,27 @@ information files.
917a6fb
 
917a6fb
 @end table
917a6fb
 
917a6fb
+You can also adjust the current verbosity of the @dfn{build id} locating.
917a6fb
+
917a6fb
+@table @code
917a6fb
+
917a6fb
+@kindex set build-id-verbose 
917a6fb
+@item set build-id-verbose 0
917a6fb
+No additional messages are printed.
917a6fb
+
917a6fb
+@item set build-id-verbose 1
917a6fb
+Missing separate debug filenames are printed.
917a6fb
+
917a6fb
+@item set build-id-verbose 2
917a6fb
+Missing separate debug filenames are printed and also all the parsing of the
917a6fb
+binaries to find their @dfn{build id} content is printed.
917a6fb
+
917a6fb
+@kindex show build-id-verbose
917a6fb
+@item show build-id-verbose
917a6fb
+Show the current verbosity value for the @dfn{build id} content locating.
917a6fb
+
917a6fb
+@end table
917a6fb
+
917a6fb
 @cindex @code{.gnu_debuglink} sections
917a6fb
 @cindex debug link sections
917a6fb
 A debug link is a special section of the executable file named
25ff8a1
Index: gdb-6.7.50.20080227/gdb/solib-svr4.c
25ff8a1
===================================================================
25ff8a1
--- gdb-6.7.50.20080227.orig/gdb/solib-svr4.c	2008-03-01 10:30:48.000000000 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/solib-svr4.c	2008-03-01 10:30:50.000000000 +0100
25ff8a1
@@ -967,9 +967,34 @@ svr4_current_sos (void)
eb9d945
 		free_so (new);
eb9d945
 	      else
eb9d945
 		{
4e2e788
-		  strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
4e2e788
-		  new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
4e2e788
-		  strcpy (new->so_original_name, new->so_name);
4e2e788
+		  struct build_id *build_id;
4e2e788
+
4e2e788
+		  strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
4e2e788
+		  new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
4e2e788
+		  /* May get overwritten below.  */
4e2e788
+		  strcpy (new->so_name, new->so_original_name);
4e2e788
+
4e2e788
+		  build_id = build_id_addr_get (LM_DYNAMIC_FROM_LINK_MAP (new));
4e2e788
+		  if (build_id != NULL)
4e2e788
+		    {
4e2e788
+		      char *name, *build_id_filename;
4e2e788
+
4e2e788
+		      /* Missing the build-id matching separate debug info file
4e2e788
+			 would be handled while SO_NAME gets loaded.  */
4e2e788
+		      name = build_id_to_filename (build_id, &build_id_filename, 0);
4e2e788
+		      if (name != NULL)
4e2e788
+			{
4e2e788
+			  strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
4e2e788
+			  new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
4e2e788
+			  xfree (name);
4e2e788
+			}
4e2e788
+		      else
4d1104a
+			build_id_print_missing (new->so_name,
4d1104a
+						build_id_filename);
4e2e788
+		      xfree (build_id_filename);
4e2e788
+		      xfree (build_id);
4e2e788
+		    }
4e2e788
+
4e2e788
 		  if (debug_solib)
4e2e788
 		    {
4e2e788
 		      fprintf_unfiltered (gdb_stdlog, 
25ff8a1
Index: gdb-6.7.50.20080227/gdb/symfile.c
25ff8a1
===================================================================
25ff8a1
--- gdb-6.7.50.20080227.orig/gdb/symfile.c	2008-03-01 10:30:48.000000000 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/symfile.c	2008-03-01 10:47:02.000000000 +0100
25ff8a1
@@ -54,6 +54,9 @@
eb9d945
 #include "varobj.h"
4e2e788
 #include "elf-bfd.h"
25ff8a1
 #include "solib.h"
4e2e788
+#include "gdb_stdint.h"
4e2e788
+#include "libbfd.h"
4e2e788
+#include "elf/external.h"
4e2e788
 
4e2e788
 #include <sys/types.h>
4e2e788
 #include <fcntl.h>
25ff8a1
@@ -62,6 +65,7 @@
4e2e788
 #include <ctype.h>
4e2e788
 #include <time.h>
4e2e788
 #include <sys/time.h>
4e2e788
+#include <sys/param.h>
4e2e788
 
4e2e788
 
4e2e788
 int (*deprecated_ui_load_progress_hook) (const char *section, unsigned long num);
25ff8a1
@@ -1235,16 +1239,65 @@ symbol_file_clear (int from_tty)
4e2e788
       printf_unfiltered (_("No symbol file now.\n"));
4e2e788
 }
4e2e788
 
4e2e788
+/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
4e2e788
+   FIXME: NOTE decoding should be unified with the BFD core notes decoding.  */
4e2e788
+
917a6fb
+#define BUILD_ID_VERBOSE_NONE 0
917a6fb
+#define BUILD_ID_VERBOSE_FILENAMES 1
917a6fb
+#define BUILD_ID_VERBOSE_BINARY_PARSE 2
917a6fb
+static int build_id_verbose = BUILD_ID_VERBOSE_FILENAMES;
4e2e788
+static void
917a6fb
+show_build_id_verbose (struct ui_file *file, int from_tty,
917a6fb
+		       struct cmd_list_element *c, const char *value)
4e2e788
+{
917a6fb
+  fprintf_filtered (file, _("Verbosity level of the build-id locator is %s.\n"),
4e2e788
+		    value);
4e2e788
+}
4e2e788
+
4e2e788
 struct build_id
4e2e788
   {
4e2e788
     size_t size;
4e2e788
     gdb_byte data[1];
4e2e788
   };
4e2e788
 
4e2e788
-/* Locate NT_GNU_BUILD_ID from ABFD and return its content.  */
4e2e788
+struct build_id *
4e2e788
+build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size)
4e2e788
+{
4e2e788
+  bfd_byte *p;
4e2e788
+
4e2e788
+  p = buf;
4e2e788
+  while (p < buf + size)
4e2e788
+    {
4e2e788
+      /* FIXME: bad alignment assumption.  */
4e2e788
+      Elf_External_Note *xnp = (Elf_External_Note *) p;
4e2e788
+      size_t namesz = H_GET_32 (templ, xnp->namesz);
4e2e788
+      size_t descsz = H_GET_32 (templ, xnp->descsz);
4e2e788
+      bfd_byte *descdata = xnp->name + BFD_ALIGN (namesz, 4);
4e2e788
+
4e2e788
+      if (H_GET_32 (templ, xnp->type) == NT_GNU_BUILD_ID
4e2e788
+	  && namesz == sizeof "GNU"
4e2e788
+	  && memcmp (xnp->name, "GNU", sizeof "GNU") == 0)
4e2e788
+	{
4e2e788
+	  size_t size = descsz;
4e2e788
+	  gdb_byte *data = (void *) descdata;
4e2e788
+	  struct build_id *retval;
4e2e788
+
4e2e788
+	  retval = xmalloc (sizeof *retval - 1 + size);
4e2e788
+	  retval->size = size;
4e2e788
+	  memcpy (retval->data, data, size);
4e2e788
+
4e2e788
+	  return retval;
4e2e788
+	}
4e2e788
+      p = descdata + BFD_ALIGN (descsz, 4);
4e2e788
+    }
4e2e788
+  return NULL;
4e2e788
+}
4e2e788
+
4e2e788
+/* Separate debuginfo files have corrupted PHDR but SHDR is correct there.
4e2e788
+   Locate NT_GNU_BUILD_ID from ABFD and return its content.  */
4e2e788
 
4e2e788
 static struct build_id *
4e2e788
-build_id_bfd_get (bfd *abfd)
4e2e788
+build_id_bfd_shdr_get (bfd *abfd)
4e2e788
 {
4e2e788
   struct build_id *retval;
4e2e788
 
25ff8a1
@@ -1260,6 +1313,348 @@ build_id_bfd_get (bfd *abfd)
4e2e788
   return retval;
4e2e788
 }
4e2e788
 
4e2e788
+/* Core files may have missing (corrupt) SHDR but PDHR is correct there.
4e2e788
+   bfd_elf_bfd_from_remote_memory () has too much overhead by
4e2e788
+   allocating/reading all the available ELF PT_LOADs.  */
4e2e788
+
4e2e788
+static struct build_id *
4e2e788
+build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum,
4e2e788
+		   Elf_Internal_Phdr *i_phdr)
4e2e788
+{
4e2e788
+  int i;
4e2e788
+  struct build_id *retval = NULL;
4e2e788
+
4e2e788
+  for (i = 0; i < e_phnum; i++)
4e2e788
+    if (i_phdr[i].p_type == PT_NOTE && i_phdr[i].p_filesz > 0)
4e2e788
+      {
4e2e788
+	Elf_Internal_Phdr *hdr = &i_phdr[i];
4e2e788
+	gdb_byte *buf;
4e2e788
+	int err;
4e2e788
+
4e2e788
+	buf = xmalloc (hdr->p_filesz);
4e2e788
+	err = target_read_memory (loadbase + i_phdr[i].p_vaddr, buf,
4e2e788
+				  hdr->p_filesz);
4e2e788
+	if (err == 0)
4e2e788
+	  retval = build_id_buf_get (templ, buf, hdr->p_filesz);
4e2e788
+	else
4e2e788
+	  retval = NULL;
4e2e788
+	xfree (buf);
4e2e788
+	if (retval != NULL)
4e2e788
+	  break;
4e2e788
+      }
4e2e788
+  return retval;
4e2e788
+}
4e2e788
+
4e2e788
+/* First we validate the file by reading in the ELF header and checking
4e2e788
+   the magic number.  */
4e2e788
+
4e2e788
+static inline bfd_boolean
4e2e788
+elf_file_p (Elf64_External_Ehdr *x_ehdrp64)
4e2e788
+{
4e2e788
+  gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
4e2e788
+  gdb_assert (offsetof (Elf64_External_Ehdr, e_ident)
4e2e788
+	      == offsetof (Elf32_External_Ehdr, e_ident));
4e2e788
+  gdb_assert (sizeof (((Elf64_External_Ehdr *) 0)->e_ident)
4e2e788
+	      == sizeof (((Elf32_External_Ehdr *) 0)->e_ident));
4e2e788
+
4e2e788
+  return ((x_ehdrp64->e_ident[EI_MAG0] == ELFMAG0)
4e2e788
+	  && (x_ehdrp64->e_ident[EI_MAG1] == ELFMAG1)
4e2e788
+	  && (x_ehdrp64->e_ident[EI_MAG2] == ELFMAG2)
4e2e788
+	  && (x_ehdrp64->e_ident[EI_MAG3] == ELFMAG3));
4e2e788
+}
4e2e788
+
4e2e788
+/* Translate an ELF file header in external format into an ELF file header in
4e2e788
+   internal format.  */
4e2e788
+
4e2e788
+#define H_GET_WORD(bfd, ptr) (is64 ? H_GET_64 (bfd, (ptr))		\
4e2e788
+				   : H_GET_32 (bfd, (ptr)))
4e2e788
+#define H_GET_SIGNED_WORD(bfd, ptr) (is64 ? H_GET_S64 (bfd, (ptr))	\
4e2e788
+					  : H_GET_S32 (bfd, (ptr)))
4e2e788
+
4e2e788
+static void
4e2e788
+elf_swap_ehdr_in (bfd *abfd,
4e2e788
+		  const Elf64_External_Ehdr *src64,
4e2e788
+		  Elf_Internal_Ehdr *dst)
4e2e788
+{
4e2e788
+  int is64 = bfd_get_arch_size (abfd) == 64;
4e2e788
+#define SRC(field) (is64 ? src64->field \
4e2e788
+			 : ((const Elf32_External_Ehdr *) src64)->field)
4e2e788
+
4e2e788
+  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
4e2e788
+  memcpy (dst->e_ident, SRC (e_ident), EI_NIDENT);
4e2e788
+  dst->e_type = H_GET_16 (abfd, SRC (e_type));
4e2e788
+  dst->e_machine = H_GET_16 (abfd, SRC (e_machine));
4e2e788
+  dst->e_version = H_GET_32 (abfd, SRC (e_version));
4e2e788
+  if (signed_vma)
4e2e788
+    dst->e_entry = H_GET_SIGNED_WORD (abfd, SRC (e_entry));
4e2e788
+  else
4e2e788
+    dst->e_entry = H_GET_WORD (abfd, SRC (e_entry));
4e2e788
+  dst->e_phoff = H_GET_WORD (abfd, SRC (e_phoff));
4e2e788
+  dst->e_shoff = H_GET_WORD (abfd, SRC (e_shoff));
4e2e788
+  dst->e_flags = H_GET_32 (abfd, SRC (e_flags));
4e2e788
+  dst->e_ehsize = H_GET_16 (abfd, SRC (e_ehsize));
4e2e788
+  dst->e_phentsize = H_GET_16 (abfd, SRC (e_phentsize));
4e2e788
+  dst->e_phnum = H_GET_16 (abfd, SRC (e_phnum));
4e2e788
+  dst->e_shentsize = H_GET_16 (abfd, SRC (e_shentsize));
4e2e788
+  dst->e_shnum = H_GET_16 (abfd, SRC (e_shnum));
4e2e788
+  dst->e_shstrndx = H_GET_16 (abfd, SRC (e_shstrndx));
4e2e788
+
4e2e788
+#undef SRC
4e2e788
+}
4e2e788
+
4e2e788
+/* Translate an ELF program header table entry in external format into an
4e2e788
+   ELF program header table entry in internal format.  */
4e2e788
+
4e2e788
+void
4e2e788
+elf_swap_phdr_in (bfd *abfd,
4e2e788
+		  const Elf64_External_Phdr *src64,
4e2e788
+		  Elf_Internal_Phdr *dst)
4e2e788
+{
4e2e788
+  int is64 = bfd_get_arch_size (abfd) == 64;
4e2e788
+#define SRC(field) (is64 ? src64->field					\
4e2e788
+			 : ((const Elf32_External_Phdr *) src64)->field)
4e2e788
+
4e2e788
+  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
4e2e788
+
4e2e788
+  dst->p_type = H_GET_32 (abfd, SRC (p_type));
4e2e788
+  dst->p_flags = H_GET_32 (abfd, SRC (p_flags));
4e2e788
+  dst->p_offset = H_GET_WORD (abfd, SRC (p_offset));
4e2e788
+  if (signed_vma)
4e2e788
+    {
4e2e788
+      dst->p_vaddr = H_GET_SIGNED_WORD (abfd, SRC (p_vaddr));
4e2e788
+      dst->p_paddr = H_GET_SIGNED_WORD (abfd, SRC (p_paddr));
4e2e788
+    }
4e2e788
+  else
4e2e788
+    {
4e2e788
+      dst->p_vaddr = H_GET_WORD (abfd, SRC (p_vaddr));
4e2e788
+      dst->p_paddr = H_GET_WORD (abfd, SRC (p_paddr));
4e2e788
+    }
4e2e788
+  dst->p_filesz = H_GET_WORD (abfd, SRC (p_filesz));
4e2e788
+  dst->p_memsz = H_GET_WORD (abfd, SRC (p_memsz));
4e2e788
+  dst->p_align = H_GET_WORD (abfd, SRC (p_align));
4e2e788
+
4e2e788
+#undef SRC
4e2e788
+}
4e2e788
+
4e2e788
+#undef H_GET_SIGNED_WORD
4e2e788
+#undef H_GET_WORD
4e2e788
+
4e2e788
+static Elf_Internal_Phdr *
4e2e788
+elf_get_phdr (bfd *templ, bfd_vma ehdr_vma, unsigned *e_phnum_pointer,
4e2e788
+              bfd_vma *loadbase_pointer)
4e2e788
+{
4e2e788
+  /* sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr)  */
4e2e788
+  Elf64_External_Ehdr x_ehdr64;	/* Elf file header, external form */
4e2e788
+  Elf_Internal_Ehdr i_ehdr;	/* Elf file header, internal form */
4e2e788
+  bfd_size_type x_phdrs_size;
4e2e788
+  gdb_byte *x_phdrs_ptr;
4e2e788
+  Elf_Internal_Phdr *i_phdrs;
4e2e788
+  int err;
4e2e788
+  unsigned int i;
4e2e788
+  bfd_vma loadbase;
4e2e788
+  int loadbase_set;
4e2e788
+
4e2e788
+  gdb_assert (templ != NULL);
4e2e788
+  gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
4e2e788
+
4e2e788
+  /* Read in the ELF header in external format.  */
4e2e788
+  err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr64, sizeof x_ehdr64);
4e2e788
+  if (err)
4e2e788
+    {
917a6fb
+      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
4e2e788
+        warning (_("build-id: Error reading ELF header at address 0x%lx"),
4e2e788
+		 (unsigned long) ehdr_vma);
4e2e788
+      return NULL;
4e2e788
+    }
4e2e788
+
4e2e788
+  /* Now check to see if we have a valid ELF file, and one that BFD can
4e2e788
+     make use of.  The magic number must match, the address size ('class')
4e2e788
+     and byte-swapping must match our XVEC entry.  */
4e2e788
+
4e2e788
+  if (! elf_file_p (&x_ehdr64)
4e2e788
+      || x_ehdr64.e_ident[EI_VERSION] != EV_CURRENT
4e2e788
+      || !((bfd_get_arch_size (templ) == 64
4e2e788
+            && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS64)
4e2e788
+           || (bfd_get_arch_size (templ) == 32
4e2e788
+	       && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS32)))
4e2e788
+    {
917a6fb
+      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
4e2e788
+        warning (_("build-id: Unrecognized ELF header at address 0x%lx"),
4e2e788
+		 (unsigned long) ehdr_vma);
4e2e788
+      return NULL;
4e2e788
+    }
4e2e788
+
4e2e788
+  /* Check that file's byte order matches xvec's */
4e2e788
+  switch (x_ehdr64.e_ident[EI_DATA])
4e2e788
+    {
4e2e788
+    case ELFDATA2MSB:		/* Big-endian */
4e2e788
+      if (! bfd_header_big_endian (templ))
4e2e788
+	{
917a6fb
+	  if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
4e2e788
+	    warning (_("build-id: Unrecognized "
4e2e788
+		       "big-endian ELF header at address 0x%lx"),
4e2e788
+		     (unsigned long) ehdr_vma);
4e2e788
+	  return NULL;
4e2e788
+	}
4e2e788
+      break;
4e2e788
+    case ELFDATA2LSB:		/* Little-endian */
4e2e788
+      if (! bfd_header_little_endian (templ))
4e2e788
+	{
917a6fb
+	  if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
4e2e788
+	    warning (_("build-id: Unrecognized "
4e2e788
+		       "little-endian ELF header at address 0x%lx"),
4e2e788
+		     (unsigned long) ehdr_vma);
4e2e788
+	  return NULL;
4e2e788
+	}
4e2e788
+      break;
4e2e788
+    case ELFDATANONE:		/* No data encoding specified */
4e2e788
+    default:			/* Unknown data encoding specified */
917a6fb
+      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
4e2e788
+	warning (_("build-id: Unrecognized "
4e2e788
+		   "ELF header endianity at address 0x%lx"),
4e2e788
+		 (unsigned long) ehdr_vma);
4e2e788
+      return NULL;
4e2e788
+    }
4e2e788
+
4e2e788
+  elf_swap_ehdr_in (templ, &x_ehdr64, &i_ehdr);
4e2e788
+
4e2e788
+  /* The file header tells where to find the program headers.
4e2e788
+     These are what we use to actually choose what to read.  */
4e2e788
+
4e2e788
+  if (i_ehdr.e_phentsize != (bfd_get_arch_size (templ) == 64
4e2e788
+                             ? sizeof (Elf64_External_Phdr)
4e2e788
+			     : sizeof (Elf32_External_Phdr))
4e2e788
+      || i_ehdr.e_phnum == 0)
4e2e788
+    {
917a6fb
+      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
4e2e788
+	warning (_("build-id: Invalid ELF program headers from the ELF header "
4e2e788
+		   "at address 0x%lx"), (unsigned long) ehdr_vma);
4e2e788
+      return NULL;
4e2e788
+    }
4e2e788
+
4e2e788
+  x_phdrs_size = (bfd_get_arch_size (templ) == 64 ? sizeof (Elf64_External_Phdr)
4e2e788
+						: sizeof (Elf32_External_Phdr));
4e2e788
+
4e2e788
+  i_phdrs = xmalloc (i_ehdr.e_phnum * (sizeof *i_phdrs + x_phdrs_size));
4e2e788
+  x_phdrs_ptr = (void *) &i_phdrs[i_ehdr.e_phnum];
4e2e788
+  err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (bfd_byte *) x_phdrs_ptr,
4e2e788
+			    i_ehdr.e_phnum * x_phdrs_size);
4e2e788
+  if (err)
4e2e788
+    {
4e2e788
+      free (i_phdrs);
917a6fb
+      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
4e2e788
+        warning (_("build-id: Error reading "
4e2e788
+		   "ELF program headers at address 0x%lx"),
cc17157
+		 (unsigned long) (ehdr_vma + i_ehdr.e_phoff));
4e2e788
+      return NULL;
4e2e788
+    }
4e2e788
+
4e2e788
+  loadbase = ehdr_vma;
4e2e788
+  loadbase_set = 0;
4e2e788
+  for (i = 0; i < i_ehdr.e_phnum; ++i)
4e2e788
+    {
4e2e788
+      elf_swap_phdr_in (templ, (Elf64_External_Phdr *)
4e2e788
+			       (x_phdrs_ptr + i * x_phdrs_size), &i_phdrs[i]);
4e2e788
+      /* IA-64 vDSO may have two mappings for one segment, where one mapping
4e2e788
+	 is executable only, and one is read only.  We must not use the
4e2e788
+	 executable one (PF_R is the first one, PF_X the second one).  */
4e2e788
+      if (i_phdrs[i].p_type == PT_LOAD && (i_phdrs[i].p_flags & PF_R))
4e2e788
+	{
4e2e788
+	  /* Only the first PT_LOAD segment indicates the file bias.
4e2e788
+	     Next segments may have P_VADDR arbitrarily higher.
4e2e788
+	     If the first segment has P_VADDR zero any next segment must not
4e2e788
+	     confuse us, the first one sets LOADBASE certainly enough.  */
4e2e788
+	  if (!loadbase_set && i_phdrs[i].p_offset == 0)
4e2e788
+	    {
4e2e788
+	      loadbase = ehdr_vma - i_phdrs[i].p_vaddr;
4e2e788
+	      loadbase_set = 1;
4e2e788
+	    }
4e2e788
+	}
4e2e788
+    }
4e2e788
+
917a6fb
+  if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
4e2e788
+    warning (_("build-id: Found ELF header at address 0x%lx, loadbase 0x%lx"),
4e2e788
+	     (unsigned long) ehdr_vma, (unsigned long) loadbase);
4e2e788
+
4e2e788
+  *e_phnum_pointer = i_ehdr.e_phnum;
4e2e788
+  *loadbase_pointer = loadbase;
4e2e788
+  return i_phdrs;
4e2e788
+}
4e2e788
+
4e2e788
+/* BUILD_ID_ADDR_GET gets ADDR located somewhere in the object.
4e2e788
+   Find the first section before ADDR containing an ELF header.
4e2e788
+   We rely on the fact the sections from multiple files do not mix.
4e2e788
+   FIXME: We should check ADDR is contained _inside_ the section with possibly
4e2e788
+   missing content (P_FILESZ < P_MEMSZ).  These omitted sections are currently
4e2e788
+   hidden by _BFD_ELF_MAKE_SECTION_FROM_PHDR.  */
4e2e788
+
4e2e788
+static CORE_ADDR build_id_addr;
4e2e788
+struct build_id_addr_sect
4e2e788
+  {
4e2e788
+    struct build_id_addr_sect *next;
4e2e788
+    asection *sect;
4e2e788
+  };
4e2e788
+static struct build_id_addr_sect *build_id_addr_sect;
4e2e788
+
4e2e788
+static void build_id_addr_candidate (bfd *abfd, asection *sect, void *obj)
4e2e788
+{
4e2e788
+  if (build_id_addr >= bfd_section_vma (abfd, sect))
4e2e788
+    {
4e2e788
+      struct build_id_addr_sect *candidate;
4e2e788
+
4e2e788
+      candidate = xmalloc (sizeof *candidate);
4e2e788
+      candidate->next = build_id_addr_sect;
4e2e788
+      build_id_addr_sect = candidate;
4e2e788
+      candidate->sect = sect;
4e2e788
+    }
4e2e788
+}
4e2e788
+
4e2e788
+struct build_id *
4e2e788
+build_id_addr_get (CORE_ADDR addr)
4e2e788
+{
4e2e788
+  struct build_id_addr_sect *candidate;
4e2e788
+  struct build_id *retval = NULL;
4e2e788
+  Elf_Internal_Phdr *i_phdr = NULL;
4e2e788
+  bfd_vma loadbase = 0;
4e2e788
+  unsigned e_phnum = 0;
4e2e788
+
4e2e788
+  if (core_bfd == NULL)
4e2e788
+    return NULL;
4e2e788
+
4e2e788
+  build_id_addr = addr;
4e2e788
+  gdb_assert (build_id_addr_sect == NULL);
4e2e788
+  bfd_map_over_sections (core_bfd, build_id_addr_candidate, NULL);
4e2e788
+
4e2e788
+  /* Sections are sorted in the high-to-low VMAs order.
4e2e788
+     Stop the search on the first ELF header we find.
4e2e788
+     Do not continue the search even if it does not contain NT_GNU_BUILD_ID.  */
4e2e788
+
4e2e788
+  for (candidate = build_id_addr_sect; candidate != NULL;
4e2e788
+       candidate = candidate->next)
4e2e788
+    {
4e2e788
+      i_phdr = elf_get_phdr (core_bfd,
4e2e788
+			     bfd_section_vma (core_bfd, candidate->sect),
4e2e788
+			     &e_phnum, &loadbase);
4e2e788
+      if (i_phdr != NULL)
4e2e788
+	break;
4e2e788
+    }
4e2e788
+
4e2e788
+  if (i_phdr != NULL)
4e2e788
+    {
4e2e788
+      retval = build_id_phdr_get (core_bfd, loadbase, e_phnum, i_phdr);
4e2e788
+      xfree (i_phdr);
4e2e788
+    }
4e2e788
+
4e2e788
+  while (build_id_addr_sect != NULL)
4e2e788
+    {
4e2e788
+      candidate = build_id_addr_sect;
4e2e788
+      build_id_addr_sect = candidate->next;
4e2e788
+      xfree (candidate);
4e2e788
+    }
4e2e788
+
4e2e788
+  return retval;
4e2e788
+}
4e2e788
+
4e2e788
 /* Return if FILENAME has NT_GNU_BUILD_ID matching the CHECK value.  */
4e2e788
 
4e2e788
 static int
25ff8a1
@@ -1274,7 +1669,7 @@ build_id_verify (const char *filename, s
4e2e788
   if (abfd == NULL)
4e2e788
     return 0;
4e2e788
 
4e2e788
-  found = build_id_bfd_get (abfd);
4e2e788
+  found = build_id_bfd_shdr_get (abfd);
4e2e788
 
4e2e788
   if (found == NULL)
4e2e788
     warning (_("File \"%s\" has no build-id, file skipped"), filename);
25ff8a1
@@ -1290,8 +1685,9 @@ build_id_verify (const char *filename, s
eb9d945
   return retval;
eb9d945
 }
4e2e788
 
4e2e788
-static char *
4e2e788
-build_id_to_debug_filename (struct build_id *build_id)
4e2e788
+char *
4e2e788
+build_id_to_filename (struct build_id *build_id, char **link_return,
4e2e788
+		      int add_debug_suffix)
4e2e788
 {
4e2e788
   char *link, *s, *retval = NULL;
4e2e788
   gdb_byte *data = build_id->data;
25ff8a1
@@ -1299,7 +1695,9 @@ build_id_to_debug_filename (struct build
4e2e788
 
4e2e788
   /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
4e2e788
   link = xmalloc (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
4e2e788
-		  + 2 * size + (sizeof ".debug" - 1) + 1);
4e2e788
+		  + 2 * size
4e2e788
+		  + (add_debug_suffix ? sizeof ".debug" - 1 : 0)
4e2e788
+		  + 1);
4e2e788
   s = link + sprintf (link, "%s/.build-id/", debug_file_directory);
4e2e788
   if (size > 0)
4e2e788
     {
25ff8a1
@@ -1310,12 +1708,14 @@ build_id_to_debug_filename (struct build
4e2e788
     *s++ = '/';
4e2e788
   while (size-- > 0)
4e2e788
     s += sprintf (s, "%02x", (unsigned) *data++);
4e2e788
-  strcpy (s, ".debug");
4e2e788
+  if (add_debug_suffix)
4e2e788
+    strcpy (s, ".debug");
4e2e788
+  else
4e2e788
+    *s = 0;
4e2e788
 
4e2e788
   /* lrealpath() is expensive even for the usually non-existent files.  */
4e2e788
   if (access (link, F_OK) == 0)
4e2e788
     retval = lrealpath (link);
4e2e788
-  xfree (link);
4e2e788
 
4e2e788
   if (retval != NULL && !build_id_verify (retval, build_id))
4e2e788
     {
25ff8a1
@@ -1323,9 +1723,202 @@ build_id_to_debug_filename (struct build
4e2e788
       retval = NULL;
4e2e788
     }
4e2e788
 
4e2e788
+  if (link_return != NULL)
4e2e788
+    *link_return = link;
4e2e788
+  else
4e2e788
+    xfree (link);
4e2e788
+
917a6fb
   return retval;
917a6fb
 }
917a6fb
 
6a80c39
+#include <rpm/rpmmessages.h>
6a80c39
+#include <rpm/rpmlib.h>
6a80c39
+#include <rpm/rpmts.h>
6a80c39
+#include <rpm/rpmdb.h>
6a80c39
+#include <rpm/header.h>
6a80c39
+
6a80c39
+static void
6a80c39
+rpm_print_debuginfo (const char *filename)
6a80c39
+{
6a80c39
+  static int rpm_init_done = 0;
6a80c39
+  rpmts ts;
6a80c39
+  rpmdbMatchIterator mi;
6a80c39
+
6a80c39
+  if (!rpm_init_done)
6a80c39
+    {
6a80c39
+      if (rpmReadConfigFiles(NULL, NULL) != 0)
6a80c39
+	{
6a80c39
+	  warning (_("Error reading the rpm configuration files"));
6a80c39
+	  return;
6a80c39
+	}
6a80c39
+      rpm_init_done = 1;
6a80c39
+    }
6a80c39
+
6a80c39
+  ts = rpmtsCreate ();
6a80c39
+  
6a80c39
+  mi = rpmtsInitIterator (ts, RPMTAG_BASENAMES, filename, 0);
6a80c39
+  if (mi != NULL)
6a80c39
+    {
6a80c39
+      int printed = 0;
6a80c39
+
6a80c39
+      for (;;)
6a80c39
+	{
6a80c39
+	  Header h;
6a80c39
+	  char *s;
6a80c39
+	  const char *errmsg;
6a80c39
+
6a80c39
+	  h = rpmdbNextIterator (mi);
6a80c39
+	  if (h == NULL)
6a80c39
+	    break;
6a80c39
+
6a80c39
+	  s = headerSprintf (h, " %{name}", rpmTagTable, rpmHeaderFormats,
6a80c39
+			     &errmsg);
6a80c39
+	  if (s == NULL)
6a80c39
+	    warning (_("Error querying rpm file `%s': %s"), filename, errmsg);
6a80c39
+	  else
6a80c39
+	    {
6a80c39
+	      if (!printed)
6a80c39
+	        {
6a80c39
+		  fprintf_unfiltered (gdb_stdout,
6a80c39
+				      _("Getting all the debuginfos: %s"),
6a80c39
+				      "debuginfo-install");
6a80c39
+		  printed = 1;
6a80c39
+		}
6a80c39
+	      /* Space (' ') delimited was insted by HEADERSPRINTF above.  */
6a80c39
+	      fputs_unfiltered (s, gdb_stdout);
6a80c39
+	    }
6a80c39
+	}
6a80c39
+
6a80c39
+      if (printed)
6a80c39
+	fputs_unfiltered ("\n", gdb_stdout);
6a80c39
+
6a80c39
+      rpmdbFreeIterator (mi);
6a80c39
+    }
6a80c39
+
6a80c39
+  rpmtsFree (ts);
6a80c39
+}
6a80c39
+
6a80c39
+struct missing_debuginfos
6a80c39
+  {
6a80c39
+    char *binary;
6a80c39
+    char *debug;
6a80c39
+    char data[1];
6a80c39
+  };
6a80c39
+
6a80c39
+static struct htab *missing_debuginfos_hash;
6a80c39
+static struct obstack missing_debuginfos_obstack;
6a80c39
+
6a80c39
+static void *
6a80c39
+missing_debuginfos_xcalloc (size_t nmemb, size_t nmemb_size)
6a80c39
+{
6a80c39
+  void *retval;
6a80c39
+  size_t size = nmemb * nmemb_size;
6a80c39
+  
6a80c39
+  retval = obstack_alloc (&missing_debuginfos_obstack, size);
6a80c39
+  memset (retval, 0, size);
917a6fb
+  return retval;
917a6fb
+}
917a6fb
+
6a80c39
+static hashval_t
6a80c39
+missing_debuginfos_hash_func (const struct missing_debuginfos *elem)
6a80c39
+{
6a80c39
+  return htab_hash_string (elem->binary) ^ htab_hash_string (elem->debug);
6a80c39
+}
6a80c39
+
6a80c39
+static int
6a80c39
+missing_debuginfos_eq (const struct missing_debuginfos *elem1,
6a80c39
+		       const struct missing_debuginfos *elem2)
6a80c39
+{
6a80c39
+  return strcmp (elem1->binary, elem2->binary) == 0
6a80c39
+         && strcmp (elem1->debug, elem2->debug) == 0;
6a80c39
+}
6a80c39
+
6a80c39
+static void
6a80c39
+missing_debuginfos_change (void)
6a80c39
+{
6a80c39
+  if (missing_debuginfos_hash != NULL)
6a80c39
+    {
6a80c39
+      obstack_free (&missing_debuginfos_obstack, NULL);
6a80c39
+      /* All their memory came just from MISSING_DEBUGINFOS_OBSTACK.  */
6a80c39
+      missing_debuginfos_hash = NULL;
6a80c39
+    }
6a80c39
+}
6a80c39
+
6a80c39
+static void
6a80c39
+missing_debuginfos_change_inferior_created (struct target_ops *objfile,
6a80c39
+					    int from_tty)
6a80c39
+{
6a80c39
+  missing_debuginfos_change ();
6a80c39
+}
6a80c39
+
6a80c39
+void
4d1104a
+build_id_print_missing (const char *binary, const char *debug)
6a80c39
+{
6a80c39
+  char *exec_filename = NULL;
6a80c39
+  size_t binary_len0 = strlen (binary) + 1;
6a80c39
+  size_t debug_len0 = strlen (debug) + 1;
6a80c39
+  struct missing_debuginfos *missing_debuginfos;
6a80c39
+  struct missing_debuginfos **slot;
6a80c39
+
917a6fb
+  if (build_id_verbose < BUILD_ID_VERBOSE_FILENAMES)
917a6fb
+    return;
917a6fb
+
6a80c39
+  if (missing_debuginfos_hash == NULL)
6a80c39
+    {
6a80c39
+      obstack_init (&missing_debuginfos_obstack);
6a80c39
+      missing_debuginfos_hash = htab_create_alloc (64,
6a80c39
+	(hashval_t (*) (const void *)) missing_debuginfos_hash_func,
6a80c39
+	(int (*) (const void *, const void *)) missing_debuginfos_eq, NULL,
6a80c39
+	missing_debuginfos_xcalloc, NULL);
6a80c39
+    }
6a80c39
+
6a80c39
+  missing_debuginfos = obstack_alloc (&missing_debuginfos_obstack,
6a80c39
+				      sizeof (*missing_debuginfos) - 1
6a80c39
+				      + binary_len0 + debug_len0);
6a80c39
+  missing_debuginfos->binary = missing_debuginfos->data;
6a80c39
+  memcpy (missing_debuginfos->binary, binary, binary_len0);
6a80c39
+  missing_debuginfos->debug = missing_debuginfos->binary + binary_len0;
6a80c39
+  memcpy (missing_debuginfos->debug, debug, debug_len0);
6a80c39
+
6a80c39
+  slot = (struct missing_debuginfos **) htab_find_slot (missing_debuginfos_hash,
6a80c39
+							missing_debuginfos,
6a80c39
+							INSERT);
6a80c39
+
6a80c39
+  /* While it may be still printed duplicitely with the missing debuginfo file
6a80c39
+   * it is due to once printing about the binary file build-id link and once
6a80c39
+   * about the .debug file build-id link as both the build-id symlinks are
6a80c39
+   * located in the debuginfo package.  */
6a80c39
+
6a80c39
+  if (*slot != NULL)
6a80c39
+    {
6a80c39
+      obstack_free (&missing_debuginfos_obstack, missing_debuginfos);
6a80c39
+      return;
6a80c39
+    }
6a80c39
+  *slot = missing_debuginfos;
6a80c39
+
4d1104a
+  fprintf_unfiltered (gdb_stdlog, _("Missing separate debuginfo for %s\n"),
4d1104a
+		      binary);
6a80c39
+
6a80c39
+  fprintf_unfiltered (gdb_stdlog, _("Try: %s %s\n"),
6a80c39
+		      "yum --enablerepo='*-debuginfo' install", debug);
6a80c39
+
6a80c39
+  if (exec_bfd != NULL)
6a80c39
+    exec_filename = bfd_get_filename (exec_bfd);
6a80c39
+  if (exec_filename != NULL)
6a80c39
+    {
6a80c39
+      static char *last_exec_filename;
6a80c39
+
6a80c39
+      if (last_exec_filename == NULL
6a80c39
+	  || strcmp (exec_filename, last_exec_filename) != 0)
6a80c39
+	{
6a80c39
+	  xfree (last_exec_filename);
6a80c39
+	  last_exec_filename = xstrdup (exec_filename);
6a80c39
+
6a80c39
+	  rpm_print_debuginfo (exec_filename);
6a80c39
+	}
6a80c39
+    }
6a80c39
+}
6a80c39
+
6a80c39
 static char *
6a80c39
 get_debug_link_info (struct objfile *objfile, unsigned long *crc32_out)
6a80c39
 {
25ff8a1
@@ -1411,32 +2004,36 @@ static char *
25ff8a1
 find_separate_debug_file (struct objfile *objfile)
25ff8a1
 {
25ff8a1
   asection *sect;
25ff8a1
-  char *basename;
25ff8a1
-  char *dir;
25ff8a1
-  char *debugfile;
25ff8a1
+  char *basename = NULL;
25ff8a1
+  char *dir = NULL;
25ff8a1
+  char *debugfile = NULL;
25ff8a1
   char *name_copy;
25ff8a1
-  char *canon_name;
25ff8a1
+  char *canon_name = NULL;
25ff8a1
   bfd_size_type debuglink_size;
4e2e788
   unsigned long crc32;
4e2e788
   int i;
4e2e788
   struct build_id *build_id;
4e2e788
+  char *build_id_filename = NULL;
4e2e788
 
4e2e788
-  build_id = build_id_bfd_get (objfile->obfd);
4e2e788
+  build_id = build_id_bfd_shdr_get (objfile->obfd);
4e2e788
   if (build_id != NULL)
4e2e788
     {
4e2e788
       char *build_id_name;
4e2e788
 
4e2e788
-      build_id_name = build_id_to_debug_filename (build_id);
4e2e788
-      free (build_id);
4e2e788
+      build_id_name = build_id_to_filename (build_id, &build_id_filename, 1);
4e2e788
+      xfree (build_id);
4e2e788
       /* Prevent looping on a stripped .debug file.  */
4e2e788
       if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
4e2e788
         {
4e2e788
-	  warning (_("\"%s\": separate debug info file has no debug info"),
4e2e788
+	  warning (_("\"%s\": The separate debug info file has no debug info"),
4e2e788
 		   build_id_name);
4e2e788
 	  xfree (build_id_name);
4e2e788
 	}
4e2e788
       else if (build_id_name != NULL)
4e2e788
-        return build_id_name;
4e2e788
+        {
4e2e788
+	  xfree (build_id_filename);
4e2e788
+	  return build_id_name;
4e2e788
+	}
4e2e788
     }
4e2e788
 
4e2e788
   basename = get_debug_link_info (objfile, &crc32);
25ff8a1
@@ -1444,7 +2041,7 @@ find_separate_debug_file (struct objfile
4e2e788
   if (basename == NULL)
4e2e788
     /* There's no separate debug info, hence there's no way we could
4e2e788
        load it => no warning.  */
4e2e788
-    return NULL;
25ff8a1
+    goto cleanup_return_debugfile;
4e2e788
 
4e2e788
   dir = xstrdup (objfile->name);
4e2e788
 
25ff8a1
@@ -1460,23 +2057,19 @@ find_separate_debug_file (struct objfile
25ff8a1
   gdb_assert (i >= 0 && IS_DIR_SEPARATOR (dir[i]));
25ff8a1
   dir[i+1] = '\0';
25ff8a1
 
25ff8a1
-  debugfile = alloca (strlen (debug_file_directory) + 1
25ff8a1
-                      + strlen (dir)
25ff8a1
-                      + strlen (DEBUG_SUBDIRECTORY)
25ff8a1
-                      + strlen ("/")
25ff8a1
-                      + strlen (basename)
25ff8a1
-                      + 1);
25ff8a1
+  debugfile = xmalloc (strlen (debug_file_directory) + 1
25ff8a1
+		       + strlen (dir)
25ff8a1
+		       + strlen (DEBUG_SUBDIRECTORY)
25ff8a1
+		       + strlen ("/")
25ff8a1
+		       + strlen (basename)
25ff8a1
+		       + 1);
25ff8a1
 
25ff8a1
   /* First try in the same directory as the original file.  */
25ff8a1
   strcpy (debugfile, dir);
25ff8a1
   strcat (debugfile, basename);
4e2e788
 
4e2e788
   if (separate_debug_file_exists (debugfile, crc32, objfile->name))
25ff8a1
-    {
25ff8a1
-      xfree (basename);
25ff8a1
-      xfree (dir);
25ff8a1
-      return xstrdup (debugfile);
25ff8a1
-    }
25ff8a1
+    goto cleanup_return_debugfile;
25ff8a1
 
25ff8a1
   /* Then try in the subdirectory named DEBUG_SUBDIRECTORY.  */
25ff8a1
   strcpy (debugfile, dir);
25ff8a1
@@ -1485,11 +2078,7 @@ find_separate_debug_file (struct objfile
25ff8a1
   strcat (debugfile, basename);
4e2e788
 
4e2e788
   if (separate_debug_file_exists (debugfile, crc32, objfile->name))
25ff8a1
-    {
25ff8a1
-      xfree (basename);
25ff8a1
-      xfree (dir);
25ff8a1
-      return xstrdup (debugfile);
25ff8a1
-    }
25ff8a1
+    goto cleanup_return_debugfile;
25ff8a1
 
25ff8a1
   /* Then try in the global debugfile directory.  */
25ff8a1
   strcpy (debugfile, debug_file_directory);
25ff8a1
@@ -1498,11 +2087,7 @@ find_separate_debug_file (struct objfile
25ff8a1
   strcat (debugfile, basename);
4e2e788
 
4e2e788
   if (separate_debug_file_exists (debugfile, crc32, objfile->name))
25ff8a1
-    {
25ff8a1
-      xfree (basename);
25ff8a1
-      xfree (dir);
25ff8a1
-      return xstrdup (debugfile);
25ff8a1
-    }
25ff8a1
+    goto cleanup_return_debugfile;
25ff8a1
 
25ff8a1
   /* If the file is in the sysroot, try using its base path in the
25ff8a1
      global debugfile directory.  */
25ff8a1
@@ -1517,20 +2102,19 @@ find_separate_debug_file (struct objfile
25ff8a1
       strcat (debugfile, basename);
4e2e788
 
eb9d945
       if (separate_debug_file_exists (debugfile, crc32, objfile->name))
25ff8a1
-	{
25ff8a1
-	  xfree (canon_name);
25ff8a1
-	  xfree (basename);
25ff8a1
-	  xfree (dir);
25ff8a1
-	  return xstrdup (debugfile);
25ff8a1
-	}
25ff8a1
+        goto cleanup_return_debugfile;
eb9d945
     }
25ff8a1
-  
25ff8a1
-  if (canon_name)
25ff8a1
-    xfree (canon_name);
25ff8a1
 
25ff8a1
+  debugfile = NULL;
4e2e788
+  if (build_id_filename != NULL)
25ff8a1
+    build_id_print_missing (objfile->name, build_id_filename);
4e2e788
+
25ff8a1
+cleanup_return_debugfile:
25ff8a1
+  xfree (build_id_filename);
25ff8a1
+  xfree (canon_name);
25ff8a1
   xfree (basename);
25ff8a1
   xfree (dir);
25ff8a1
-  return NULL;
25ff8a1
+  return debugfile;
25ff8a1
 }
25ff8a1
 
eb9d945
 
25ff8a1
@@ -4220,4 +4804,16 @@ the global debug-file directory prepende
4e2e788
 				     NULL,
4e2e788
 				     show_debug_file_directory,
4e2e788
 				     &setlist, &showlist);
4e2e788
+
917a6fb
+  add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
917a6fb
+			    _("\
917a6fb
+Set debugging level of the build-id locator."), _("\
917a6fb
+Show debugging level of the build-id locator."), _("\
917a6fb
+Level 1 (default) enables printing the missing debug filenames,\n\
917a6fb
+level 2 also prints the parsing of binaries to find the identificators."),
4e2e788
+			    NULL,
917a6fb
+			    show_build_id_verbose,
917a6fb
+			    &setlist, &showlist);
6a80c39
+
6a80c39
+  observer_attach_inferior_created (missing_debuginfos_change_inferior_created);
4e2e788
 }
25ff8a1
Index: gdb-6.7.50.20080227/gdb/symfile.h
25ff8a1
===================================================================
25ff8a1
--- gdb-6.7.50.20080227.orig/gdb/symfile.h	2008-02-03 23:13:29.000000000 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/symfile.h	2008-03-01 10:30:50.000000000 +0100
25ff8a1
@@ -358,6 +358,13 @@ extern int symfile_map_offsets_to_segmen
eb9d945
 struct symfile_segment_data *get_symfile_segment_data (bfd *abfd);
eb9d945
 void free_symfile_segment_data (struct symfile_segment_data *data);
4e2e788
 
4e2e788
+/* build-id support.  */
4e2e788
+struct build_id;
4e2e788
+extern struct build_id *build_id_addr_get (CORE_ADDR addr);
4e2e788
+extern char *build_id_to_filename (struct build_id *build_id,
4e2e788
+				   char **link_return, int add_debug_suffix);
4d1104a
+extern void build_id_print_missing (const char *binary, const char *debug);
4e2e788
+
4e2e788
 /* From dwarf2read.c */
4e2e788
 
4e2e788
 extern int dwarf2_has_info (struct objfile *);