keiths / rpms / gdb

Forked from rpms/gdb 5 months ago
Clone
8c4c91e
Index: gdb-7.0.50.20100115/gdb/corelow.c
eb11e3c
===================================================================
8c4c91e
--- gdb-7.0.50.20100115.orig/gdb/corelow.c	2010-01-04 15:57:43.000000000 +0100
8c4c91e
+++ gdb-7.0.50.20100115/gdb/corelow.c	2010-01-15 11:14:05.000000000 +0100
8c4c91e
@@ -46,6 +46,10 @@
4e2e788
 #include "solib.h"
25ff8a1
 #include "filenames.h"
8c4c91e
 #include "progspace.h"
4e2e788
+#include "auxv.h"
4e2e788
+#include "elf/common.h"
4e2e788
+#include "objfiles.h"
4e2e788
+#include "gdbcmd.h"
4e2e788
 
4e2e788
 
4e2e788
 #ifndef O_LARGEFILE
8c4c91e
@@ -290,6 +294,52 @@ add_to_thread_list (bfd *abfd, asection 
407ebe9
     inferior_ptid = ptid;			 /* Yes, make it current */
4e2e788
 }
4e2e788
 
4e2e788
+static int build_id_core_loads = 1;
4e2e788
+
338fe93
+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;
536aae5
+  struct cleanup *back_to;
4e2e788
+
580e056
+  if (exec_bfd != NULL || symfile_objfile != 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
+
536aae5
+  /* SYMFILE_OBJFILE should refer to the main executable (not only to its
536aae5
+     separate debug info file).  gcc44+ keeps .eh_frame only in the main
536aae5
+     executable without its duplicate .debug_frame in the separate debug info
536aae5
+     file - such .eh_frame would not be found if SYMFILE_OBJFILE would refer
536aae5
+     directly to the separate debug info file.  */
536aae5
+
4e2e788
+  exec_filename = build_id_to_filename (build_id, &build_id_filename, 0);
536aae5
+  back_to = make_cleanup (xfree, build_id_filename);
4e2e788
+
536aae5
+  if (exec_filename != NULL)
4e2e788
+    {
536aae5
+      make_cleanup (xfree, exec_filename);
536aae5
+      exec_file_attach (exec_filename, from_tty);
536aae5
+      symbol_file_add_main (exec_filename, from_tty);
580e056
+      if (symfile_objfile != NULL)
580e056
+        symfile_objfile->flags |= OBJF_BUILD_ID_CORE_LOADED;
4e2e788
+    }
4e2e788
+  else
536aae5
+    debug_print_missing (_("the main executable file"), build_id_filename);
4e2e788
+
536aae5
+  do_cleanups (back_to);
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
8c4c91e
@@ -387,6 +437,12 @@ core_open (char *filename, int from_tty)
407ebe9
   push_target (&core_ops);
435483c
   discard_cleanups (old_chain);
4e2e788
 
407ebe9
+  /* Find the build_id identifiers.  If it gets executed after
407ebe9
+     POST_CREATE_INFERIOR we would clash with asking to discard the already
407ebe9
+     loaded VDSO symbols.  */
407ebe9
+  if (build_id_core_loads != 0)
407ebe9
+    build_id_locate_exec (from_tty);
4e2e788
+
407ebe9
   /* Do this before acknowledging the inferior, so if
8c4c91e
      post_create_inferior throws (can happen easilly if you're loading
8c4c91e
      a core file with the wrong exec), we aren't left with threads
8c4c91e
@@ -925,4 +981,11 @@ _initialize_corelow (void)
1592379
   init_core_ops ();
4e2e788
 
1592379
   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
 }
8c4c91e
Index: gdb-7.0.50.20100115/gdb/doc/gdb.texinfo
eb11e3c
===================================================================
8c4c91e
--- gdb-7.0.50.20100115.orig/gdb/doc/gdb.texinfo	2010-01-15 03:23:50.000000000 +0100
8c4c91e
+++ gdb-7.0.50.20100115/gdb/doc/gdb.texinfo	2010-01-15 11:12:33.000000000 +0100
8c4c91e
@@ -14258,6 +14258,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
+
338fe93
+@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
8c4c91e
Index: gdb-7.0.50.20100115/gdb/solib-svr4.c
eb11e3c
===================================================================
8c4c91e
--- gdb-7.0.50.20100115.orig/gdb/solib-svr4.c	2010-01-15 03:22:13.000000000 +0100
8c4c91e
+++ gdb-7.0.50.20100115/gdb/solib-svr4.c	2010-01-15 11:12:33.000000000 +0100
8c4c91e
@@ -1116,9 +1116,49 @@ svr4_current_sos (void)
c499105
 		     safe_strerror (errcode));
c499105
 	  else
c499105
 	    {
c499105
-	      strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
c499105
-	      new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
c499105
-	      strcpy (new->so_original_name, new->so_name);
c499105
+	      struct build_id *build_id;
c499105
+
c499105
+	      strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
c499105
+	      new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
c499105
+	      /* May get overwritten below.  */
c499105
+	      strcpy (new->so_name, new->so_original_name);
c499105
+
c499105
+	      build_id = build_id_addr_get (LM_DYNAMIC_FROM_LINK_MAP (new));
c499105
+	      if (build_id != NULL)
c499105
+		{
c499105
+		  char *name, *build_id_filename;
c499105
+
c499105
+		  /* Missing the build-id matching separate debug info file
c499105
+		     would be handled while SO_NAME gets loaded.  */
c499105
+		  name = build_id_to_filename (build_id, &build_id_filename, 0);
c499105
+		  if (name != NULL)
4e2e788
+		    {
c499105
+		      strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
c499105
+		      new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
c499105
+		      xfree (name);
4e2e788
+		    }
c499105
+		  else
580e056
+		    {
580e056
+		      debug_print_missing (new->so_name, build_id_filename);
580e056
+
580e056
+		      /* In the case the main executable was found according to
580e056
+			 its build-id (from a core file) prevent loading
580e056
+			 a different build of a library with accidentally the
580e056
+			 same SO_NAME.
580e056
+
580e056
+			 It suppresses bogus backtraces (and prints "??" there
580e056
+			 instead) if the on-disk files no longer match the
580e056
+			 running program version.  */
580e056
+
580e056
+		      if (symfile_objfile != NULL
580e056
+			  && (symfile_objfile->flags
580e056
+			      & OBJF_BUILD_ID_CORE_LOADED) != 0)
580e056
+			new->so_name[0] = 0;
580e056
+		    }
4e2e788
+
c499105
+		  xfree (build_id_filename);
c499105
+		  xfree (build_id);
c499105
+		}
c499105
 	    }
c499105
 	  xfree (buffer);
c499105
 
8c4c91e
Index: gdb-7.0.50.20100115/gdb/elfread.c
eb11e3c
===================================================================
8c4c91e
--- gdb-7.0.50.20100115.orig/gdb/elfread.c	2010-01-15 03:22:13.000000000 +0100
8c4c91e
+++ gdb-7.0.50.20100115/gdb/elfread.c	2010-01-15 11:43:30.000000000 +0100
8c4c91e
@@ -36,6 +36,10 @@
8c4c91e
 #include "gdb-stabs.h"
8c4c91e
 #include "complaints.h"
8c4c91e
 #include "demangle.h"
4e2e788
+#include "libbfd.h"
8c4c91e
+#include "gdbcore.h"
8c4c91e
+#include "gdbcmd.h"
8c4c91e
+#include "observer.h"
4e2e788
 
8c4c91e
 extern void _initialize_elfread (void);
4e2e788
 
8c4c91e
@@ -567,6 +571,20 @@ elf_symtab_read (struct objfile *objfile
8c4c91e
 	}
8c4c91e
     }
8c4c91e
 }
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
+}
8c4c91e
 
4e2e788
 struct build_id
4e2e788
   {
8c4c91e
@@ -574,10 +592,44 @@ struct build_id
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
 
8c4c91e
@@ -593,6 +645,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
8c4c91e
@@ -607,7 +1001,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);
8c4c91e
@@ -626,14 +1020,16 @@ 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
 {
0911f37
   char *link, *debugdir, *retval = NULL;
0911f37
+  char *link_all = NULL;
4e2e788
 
4e2e788
   /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
0911f37
-  link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
0911f37
-		 + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
0911f37
+  link = xmalloc (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
0911f37
+		  + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
0911f37
 
0911f37
   /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
0911f37
      cause "/.build-id/..." lookups.  */
8c4c91e
@@ -664,7 +1060,10 @@ build_id_to_debug_filename (struct build
0911f37
 	*s++ = '/';
0911f37
       while (size-- > 0)
0911f37
 	s += sprintf (s, "%02x", (unsigned) *data++);
0911f37
-      strcpy (s, ".debug");
0911f37
+      if (add_debug_suffix)
0911f37
+	strcpy (s, ".debug");
0911f37
+      else
0911f37
+	*s = 0;
0911f37
 
0911f37
       /* lrealpath() is expensive even for the usually non-existent files.  */
0911f37
       if (access (link, F_OK) == 0)
8c4c91e
@@ -677,17 +1076,188 @@ build_id_to_debug_filename (struct build
0911f37
 	}
4e2e788
 
0911f37
       if (retval != NULL)
0911f37
-	break;
0911f37
+	{
0911f37
+	  /* LINK_ALL is not used below in this non-NULL RETVAL case.  */
0911f37
+	  break;
0911f37
+	}
0911f37
+
0911f37
+	if (link_all == NULL)
0911f37
+	  link_all = xstrdup (link);
0911f37
+	else
0911f37
+	  {
0911f37
+	    size_t len_orig = strlen (link_all);
0911f37
+
0911f37
+	    link_all = xrealloc (link_all, len_orig + 1 + strlen (link) + 1);
0911f37
+
0911f37
+	    /* Use whitespace instead of DIRNAME_SEPARATOR to be compatible with
0911f37
+	       its possible use as an argument for installation command.  */
0911f37
+	    link_all[len_orig] = ' ';
0911f37
+
0911f37
+	    strcpy (&link_all[len_orig + 1], link);
0911f37
+	  }
4e2e788
 
0911f37
       debugdir = debugdir_end;
4e2e788
     }
0911f37
   while (*debugdir != 0);
4e2e788
 
4e2e788
+  if (link_return != NULL)
0911f37
+    {
0911f37
+      if (retval != NULL)
0911f37
+       {
0911f37
+         *link_return = link;
0911f37
+         link = NULL;
0911f37
+       }
0911f37
+      else
0911f37
+       {
0911f37
+         *link_return = link_all;
0911f37
+         link_all = NULL;
0911f37
+       }
0911f37
+    }
0911f37
+  xfree (link);
0911f37
+  xfree (link_all);
0911f37
+
8c4c91e
   return retval;
8c4c91e
 }
8c4c91e
 
338fe93
+/* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
eb11e3c
+     Try to install the hash file ...
338fe93
+   avoidance.  */
338fe93
+
338fe93
+struct missing_filepair
6a80c39
+  {
6a80c39
+    char *binary;
6a80c39
+    char *debug;
6a80c39
+    char data[1];
6a80c39
+  };
6a80c39
+
338fe93
+static struct htab *missing_filepair_hash;
338fe93
+static struct obstack missing_filepair_obstack;
6a80c39
+
6a80c39
+static void *
338fe93
+missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size)
6a80c39
+{
6a80c39
+  void *retval;
6a80c39
+  size_t size = nmemb * nmemb_size;
338fe93
+
338fe93
+  retval = obstack_alloc (&missing_filepair_obstack, size);
6a80c39
+  memset (retval, 0, size);
8c4c91e
+  return retval;
8c4c91e
+}
8c4c91e
+
6a80c39
+static hashval_t
338fe93
+missing_filepair_hash_func (const struct missing_filepair *elem)
6a80c39
+{
338fe93
+  hashval_t retval = 0;
338fe93
+
338fe93
+  retval ^= htab_hash_string (elem->binary);
338fe93
+  if (elem->debug != NULL)
338fe93
+    retval ^= htab_hash_string (elem->debug);
338fe93
+
338fe93
+  return retval;
6a80c39
+}
6a80c39
+
6a80c39
+static int
338fe93
+missing_filepair_eq (const struct missing_filepair *elem1,
338fe93
+		       const struct missing_filepair *elem2)
6a80c39
+{
6a80c39
+  return strcmp (elem1->binary, elem2->binary) == 0
c030186
+         && ((elem1->debug == NULL) == (elem2->debug == NULL))
c030186
+         && (elem1->debug == NULL || strcmp (elem1->debug, elem2->debug) == 0);
6a80c39
+}
6a80c39
+
6a80c39
+static void
338fe93
+missing_filepair_change (void)
6a80c39
+{
338fe93
+  if (missing_filepair_hash != NULL)
6a80c39
+    {
338fe93
+      obstack_free (&missing_filepair_obstack, NULL);
338fe93
+      /* All their memory came just from missing_filepair_OBSTACK.  */
338fe93
+      missing_filepair_hash = NULL;
6a80c39
+    }
6a80c39
+}
6a80c39
+
6a80c39
+static void
407ebe9
+debug_print_executable_changed (void)
6a80c39
+{
338fe93
+  missing_filepair_change ();
6a80c39
+}
6a80c39
+
338fe93
+/* Notify user the file BINARY with (possibly NULL) associated separate debug
338fe93
+   information file DEBUG is missing.  DEBUG may or may not be the build-id
338fe93
+   file such as would be:
338fe93
+     /usr/lib/debug/.build-id/dd/b1d2ce632721c47bb9e8679f369e2295ce71be.debug
338fe93
+   */
338fe93
+
6a80c39
+void
338fe93
+debug_print_missing (const char *binary, const char *debug)
6a80c39
+{
6a80c39
+  size_t binary_len0 = strlen (binary) + 1;
338fe93
+  size_t debug_len0 = debug ? strlen (debug) + 1 : 0;
c030186
+  struct missing_filepair missing_filepair_find;
338fe93
+  struct missing_filepair *missing_filepair;
338fe93
+  struct missing_filepair **slot;
6a80c39
+
917a6fb
+  if (build_id_verbose < BUILD_ID_VERBOSE_FILENAMES)
917a6fb
+    return;
917a6fb
+
338fe93
+  if (missing_filepair_hash == NULL)
6a80c39
+    {
338fe93
+      obstack_init (&missing_filepair_obstack);
338fe93
+      missing_filepair_hash = htab_create_alloc (64,
338fe93
+	(hashval_t (*) (const void *)) missing_filepair_hash_func,
338fe93
+	(int (*) (const void *, const void *)) missing_filepair_eq, NULL,
338fe93
+	missing_filepair_xcalloc, NULL);
6a80c39
+    }
6a80c39
+
c030186
+  /* Use MISSING_FILEPAIR_FIND first instead of calling obstack_alloc with
c030186
+     obstack_free in the case of a (rare) match.  The problem is ALLOC_F for
c030186
+     MISSING_FILEPAIR_HASH allocates from MISSING_FILEPAIR_OBSTACK maintenance
c030186
+     structures for MISSING_FILEPAIR_HASH.  Calling obstack_free would possibly
c030186
+     not to free only MISSING_FILEPAIR but also some such structures (allocated
c030186
+     during the htab_find_slot call).  */
c030186
+
c030186
+  missing_filepair_find.binary = (char *) binary;
c030186
+  missing_filepair_find.debug = (char *) debug;
c030186
+  slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
c030186
+						      &missing_filepair_find,
c030186
+						      INSERT);
c030186
+
c030186
+  /* While it may be still printed duplicitely with the missing debuginfo file
c030186
+   * it is due to once printing about the binary file build-id link and once
c030186
+   * about the .debug file build-id link as both the build-id symlinks are
c030186
+   * located in the debuginfo package.  */
c030186
+
c030186
+  if (*slot != NULL)
c030186
+    return;
c030186
+
338fe93
+  missing_filepair = obstack_alloc (&missing_filepair_obstack,
338fe93
+				      sizeof (*missing_filepair) - 1
6a80c39
+				      + binary_len0 + debug_len0);
338fe93
+  missing_filepair->binary = missing_filepair->data;
338fe93
+  memcpy (missing_filepair->binary, binary, binary_len0);
338fe93
+  if (debug != NULL)
338fe93
+    {
338fe93
+      missing_filepair->debug = missing_filepair->binary + binary_len0;
338fe93
+      memcpy (missing_filepair->debug, debug, debug_len0);
338fe93
+    }
338fe93
+  else
338fe93
+    missing_filepair->debug = NULL;
6a80c39
+
338fe93
+  *slot = missing_filepair;
6a80c39
+
09c22fd
+  /* We do not collect and flush these messages as each such message
09c22fd
+     already requires its own separate lines.  */
6a80c39
+
09c22fd
+  fprintf_unfiltered (gdb_stdlog,
09c22fd
+		      _("Missing separate debuginfo for %s\n"), binary);
09c22fd
+  if (debug != NULL)
eb11e3c
+    fprintf_unfiltered (gdb_stdlog, _("Try to install the hash file %s\n"),
eb11e3c
+			debug);
6a80c39
+}
6a80c39
+
6a80c39
 static char *
8c4c91e
-find_separate_debug_file_by_buildid (struct objfile *objfile)
8c4c91e
+find_separate_debug_file_by_buildid (struct objfile *objfile,
8c4c91e
+				     char **build_id_filename_return)
6a80c39
 {
8c4c91e
   asection *sect;
8c4c91e
   char *basename, *name_copy, *debugdir;
8c4c91e
@@ -699,12 +1269,16 @@ find_separate_debug_file_by_buildid (str
4e2e788
   int i;
4e2e788
   struct build_id *build_id;
4e2e788
 
4e2e788
-  build_id = build_id_bfd_get (objfile->obfd);
8c4c91e
+  if (build_id_filename_return)
8c4c91e
+    *build_id_filename_return = NULL;
8c4c91e
+
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);
8c4c91e
+      build_id_name = build_id_to_filename (build_id, build_id_filename_return,
8c4c91e
+					    1);
407ebe9
       xfree (build_id);
4e2e788
       /* Prevent looping on a stripped .debug file.  */
4e2e788
       if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
8c4c91e
@@ -714,7 +1288,7 @@ find_separate_debug_file_by_buildid (str
4e2e788
 	  xfree (build_id_name);
4e2e788
 	}
4e2e788
       else if (build_id_name != NULL)
4e2e788
-        return build_id_name;
8c4c91e
+	return build_id_name;
4e2e788
     }
8c4c91e
   return NULL;
8c4c91e
 }
8c4c91e
@@ -887,9 +1461,10 @@ elf_symfile_read (struct objfile *objfil
8c4c91e
      `.gnu_debuglink' may no longer be present with `.note.gnu.build-id'.  */
8c4c91e
   else
8c4c91e
     {
8c4c91e
-      char *debugfile;
8c4c91e
+      char *debugfile, *build_id_filename;
8c4c91e
 
8c4c91e
-      debugfile = find_separate_debug_file_by_buildid (objfile);
8c4c91e
+      debugfile = find_separate_debug_file_by_buildid (objfile,
8c4c91e
+						       &build_id_filename);
8c4c91e
 
8c4c91e
       if (debugfile == NULL)
8c4c91e
 	debugfile = find_separate_debug_file_by_debuglink (objfile);
8c4c91e
@@ -900,6 +1475,12 @@ elf_symfile_read (struct objfile *objfil
8c4c91e
 	  symbol_file_add_separate (abfd, symfile_flags, objfile);
8c4c91e
 	  xfree (debugfile);
8c4c91e
 	}
8c4c91e
+      /* Check if any separate debug info has been extracted out.  */
8c4c91e
+      else if (bfd_get_section_by_name (objfile->obfd, ".gnu_debuglink")
8c4c91e
+	       != NULL)
8c4c91e
+	debug_print_missing (objfile->name, build_id_filename);
8c4c91e
+
8c4c91e
+      xfree (build_id_filename);
8c4c91e
     }
8c4c91e
 }
4e2e788
 
8c4c91e
@@ -1072,4 +1653,16 @@ void
8c4c91e
 _initialize_elfread (void)
8c4c91e
 {
8c4c91e
   add_symtab_fns (&elf_sym_fns);
8c4c91e
+
8c4c91e
+  add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
8c4c91e
+			    _("\
8c4c91e
+Set debugging level of the build-id locator."), _("\
8c4c91e
+Show debugging level of the build-id locator."), _("\
8c4c91e
+Level 1 (default) enables printing the missing debug filenames,\n\
8c4c91e
+level 2 also prints the parsing of binaries to find the identificators."),
8c4c91e
+			    NULL,
8c4c91e
+			    show_build_id_verbose,
8c4c91e
+			    &setlist, &showlist);
8c4c91e
+
8c4c91e
+  observer_attach_executable_changed (debug_print_executable_changed);
4e2e788
 }
8c4c91e
Index: gdb-7.0.50.20100115/gdb/symfile.h
eb11e3c
===================================================================
8c4c91e
--- gdb-7.0.50.20100115.orig/gdb/symfile.h	2010-01-15 03:22:13.000000000 +0100
8c4c91e
+++ gdb-7.0.50.20100115/gdb/symfile.h	2010-01-15 11:12:33.000000000 +0100
8c4c91e
@@ -392,6 +392,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);
338fe93
+extern void debug_print_missing (const char *binary, const char *debug);
4e2e788
+
4e2e788
 /* From dwarf2read.c */
4e2e788
 
4e2e788
 extern int dwarf2_has_info (struct objfile *);
8c4c91e
Index: gdb-7.0.50.20100115/gdb/testsuite/lib/gdb.exp
eb11e3c
===================================================================
8c4c91e
--- gdb-7.0.50.20100115.orig/gdb/testsuite/lib/gdb.exp	2010-01-15 03:22:13.000000000 +0100
8c4c91e
+++ gdb-7.0.50.20100115/gdb/testsuite/lib/gdb.exp	2010-01-15 11:12:33.000000000 +0100
e5611bf
@@ -1248,6 +1248,16 @@ proc default_gdb_start { } {
c499105
 	    warning "Couldn't set the width to 0."
c499105
 	}
c499105
     }
09c22fd
+    # Turn off the missing warnings as the testsuite does not expect it.
c499105
+    send_gdb "set build-id-verbose 0\n"
c499105
+    gdb_expect 10 {
c499105
+	-re "$gdb_prompt $" {
c499105
+	    verbose "Disabled the missing debug infos warnings." 2
c499105
+	}
c499105
+	timeout {
c499105
+	    warning "Could not disable the missing debug infos warnings.."
c499105
+	}
c499105
+    }
c499105
     return 0;
c499105
 }
c499105
 
8c4c91e
Index: gdb-7.0.50.20100115/gdb/testsuite/lib/mi-support.exp
e5611bf
===================================================================
8c4c91e
--- gdb-7.0.50.20100115.orig/gdb/testsuite/lib/mi-support.exp	2010-01-12 22:40:25.000000000 +0100
8c4c91e
+++ gdb-7.0.50.20100115/gdb/testsuite/lib/mi-support.exp	2010-01-15 11:12:33.000000000 +0100
d5fb1cc
@@ -221,6 +221,16 @@ proc default_mi_gdb_start { args } {
d5fb1cc
 	    }
d5fb1cc
     	}
d5fb1cc
     }
d5fb1cc
+    # Turn off the missing warnings as the testsuite does not expect it.
d5fb1cc
+    send_gdb "190-gdb-set build-id-verbose 0\n"
d5fb1cc
+    gdb_expect 10 {
d5fb1cc
+	-re ".*190-gdb-set build-id-verbose 0\r\n190\\\^done\r\n$mi_gdb_prompt$" {
d5fb1cc
+	    verbose "Disabled the missing debug infos warnings." 2
d5fb1cc
+	}
d5fb1cc
+	timeout {
d5fb1cc
+	    warning "Could not disable the missing debug infos warnings.."
d5fb1cc
+	}
d5fb1cc
+    }
d5fb1cc
 
d5fb1cc
     detect_async
d5fb1cc
 
8c4c91e
Index: gdb-7.0.50.20100115/gdb/objfiles.h
580e056
===================================================================
8c4c91e
--- gdb-7.0.50.20100115.orig/gdb/objfiles.h	2010-01-15 03:22:13.000000000 +0100
8c4c91e
+++ gdb-7.0.50.20100115/gdb/objfiles.h	2010-01-15 11:14:42.000000000 +0100
8c4c91e
@@ -440,6 +440,10 @@ struct objfile
580e056
 
580e056
 #define OBJF_MAIN (1 << 7)
580e056
 
580e056
+/* This file was loaded according to the BUILD_ID_CORE_LOADS rules.  */
580e056
+
580e056
+#define OBJF_BUILD_ID_CORE_LOADED (1 << 12)
580e056
+
8c4c91e
 /* The object file that contains the runtime common minimal symbols
8c4c91e
    for SunOS4. Note that this objfile has no associated BFD.  */
580e056