]> git.pld-linux.org Git - packages/gdb.git/blobdiff - gdb-6.6-buildid-locate.patch
- rel 1
[packages/gdb.git] / gdb-6.6-buildid-locate.patch
index edc52bd988b4754e48d8e43b67e62b5f257e5029..30b4375fce437b1c040748586cc849098c867060 100644 (file)
@@ -1,20 +1,19 @@
-Index: gdb-6.8.91.20090925/gdb/corelow.c
+Index: gdb-7.6/gdb/corelow.c
 ===================================================================
---- gdb-6.8.91.20090925.orig/gdb/corelow.c     2009-07-31 17:25:21.000000000 +0200
-+++ gdb-6.8.91.20090925/gdb/corelow.c  2009-09-25 09:39:09.000000000 +0200
-@@ -45,6 +45,10 @@
- #include "exceptions.h"
- #include "solib.h"
- #include "filenames.h"
+--- gdb-7.6.orig/gdb/corelow.c 2013-01-31 19:37:37.000000000 +0100
++++ gdb-7.6/gdb/corelow.c      2013-07-17 05:28:49.277203536 +0200
+@@ -46,6 +46,9 @@
+ #include "progspace.h"
+ #include "objfiles.h"
+ #include "gdb_bfd.h"
 +#include "auxv.h"
 +#include "elf/common.h"
-+#include "objfiles.h"
 +#include "gdbcmd.h"
  
  #ifndef O_LARGEFILE
-@@ -273,6 +277,52 @@ add_to_thread_list (bfd *abfd, asection 
-     inferior_ptid = ptid;                      /* Yes, make it current */
+ #define O_LARGEFILE 0
+@@ -271,6 +274,53 @@ add_to_thread_list (bfd *abfd, asection
+     inferior_ptid = ptid;                     /* Yes, make it current.  */
  }
  
 +static int build_id_core_loads = 1;
@@ -23,7 +22,7 @@ Index: gdb-6.8.91.20090925/gdb/corelow.c
 +build_id_locate_exec (int from_tty)
 +{
 +  CORE_ADDR at_entry;
-+  struct build_id *build_id;
++  struct elf_build_id *build_id;
 +  char *exec_filename, *debug_filename;
 +  char *build_id_filename;
 +  struct cleanup *back_to;
@@ -37,6 +36,7 @@ Index: gdb-6.8.91.20090925/gdb/corelow.c
 +  build_id = build_id_addr_get (at_entry);
 +  if (build_id == NULL)
 +    return;
++  back_to = make_cleanup (xfree, build_id);
 +
 +  /* SYMFILE_OBJFILE should refer to the main executable (not only to its
 +     separate debug info file).  gcc44+ keeps .eh_frame only in the main
@@ -45,7 +45,7 @@ Index: gdb-6.8.91.20090925/gdb/corelow.c
 +     directly to the separate debug info file.  */
 +
 +  exec_filename = build_id_to_filename (build_id, &build_id_filename, 0);
-+  back_to = make_cleanup (xfree, build_id_filename);
++  make_cleanup (xfree, build_id_filename);
 +
 +  if (exec_filename != NULL)
 +    {
@@ -66,20 +66,22 @@ Index: gdb-6.8.91.20090925/gdb/corelow.c
  /* This routine opens and sets up the core file bfd.  */
  
  static void
-@@ -371,6 +421,12 @@ core_open (char *filename, int from_tty)
-   push_target (&core_ops);
-   discard_cleanups (old_chain);
+@@ -409,6 +459,14 @@ core_open (char *filename, int from_tty)
+       switch_to_thread (thread->ptid);
+     }
  
 +  /* Find the build_id identifiers.  If it gets executed after
 +     POST_CREATE_INFERIOR we would clash with asking to discard the already
-+     loaded VDSO symbols.  */
++     loaded VDSO symbols.  If it gets executed before bfd_map_over_sections
++     INFERIOR_PTID is still not set and libthread_db initialization crashes on
++     PID == 0 in ps_pglobal_lookup.  */
 +  if (build_id_core_loads != 0)
 +    build_id_locate_exec (from_tty);
 +
-   add_inferior_silent (corelow_pid);
+   post_create_inferior (&core_ops, from_tty);
  
-   /* Do this before acknowledging the inferior, so if
-@@ -878,4 +934,11 @@ _initialize_corelow (void)
+   /* Now go through the target stack looking for threads since there
+@@ -978,4 +1036,11 @@ _initialize_corelow (void)
    init_core_ops ();
  
    add_target (&core_ops);
@@ -87,15 +89,15 @@ Index: gdb-6.8.91.20090925/gdb/corelow.c
 +  add_setshow_boolean_cmd ("build-id-core-loads", class_files,
 +                         &build_id_core_loads, _("\
 +Set whether CORE-FILE loads the build-id associated files automatically."), _("\
-+Show whether CORE-FILE loads the build-id associated files automatically.."),
++Show whether CORE-FILE loads the build-id associated files automatically."),
 +                         NULL, NULL, NULL,
 +                         &setlist, &showlist);
  }
-Index: gdb-6.8.91.20090925/gdb/doc/gdb.texinfo
+Index: gdb-7.6/gdb/doc/gdb.texinfo
 ===================================================================
---- gdb-6.8.91.20090925.orig/gdb/doc/gdb.texinfo       2009-09-25 09:29:58.000000000 +0200
-+++ gdb-6.8.91.20090925/gdb/doc/gdb.texinfo    2009-09-25 09:29:58.000000000 +0200
-@@ -13895,6 +13895,27 @@ information files.
+--- gdb-7.6.orig/gdb/doc/gdb.texinfo   2013-07-17 05:28:48.882203384 +0200
++++ gdb-7.6/gdb/doc/gdb.texinfo        2013-07-17 05:28:49.286203539 +0200
+@@ -16831,6 +16831,27 @@ information files.
  
  @end table
  
@@ -123,82 +125,87 @@ Index: gdb-6.8.91.20090925/gdb/doc/gdb.texinfo
  @cindex @code{.gnu_debuglink} sections
  @cindex debug link sections
  A debug link is a special section of the executable file named
-Index: gdb-6.8.91.20090925/gdb/solib-svr4.c
+Index: gdb-7.6/gdb/solib-svr4.c
 ===================================================================
---- gdb-6.8.91.20090925.orig/gdb/solib-svr4.c  2009-09-25 09:29:57.000000000 +0200
-+++ gdb-6.8.91.20090925/gdb/solib-svr4.c       2009-09-25 09:43:14.000000000 +0200
-@@ -1101,9 +1101,49 @@ svr4_current_sos (void)
-                    safe_strerror (errcode));
-         else
-           {
--            strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
--            new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
--            strcpy (new->so_original_name, new->so_name);
-+            struct build_id *build_id;
-+
-+            strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
-+            new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
-+            /* May get overwritten below.  */
-+            strcpy (new->so_name, new->so_original_name);
-+
-+            build_id = build_id_addr_get (LM_DYNAMIC_FROM_LINK_MAP (new));
-+            if (build_id != NULL)
-+              {
-+                char *name, *build_id_filename;
-+
-+                /* Missing the build-id matching separate debug info file
-+                   would be handled while SO_NAME gets loaded.  */
-+                name = build_id_to_filename (build_id, &build_id_filename, 0);
-+                if (name != NULL)
-+                  {
-+                    strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
-+                    new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
-+                    xfree (name);
-+                  }
-+                else
-+                  {
-+                    debug_print_missing (new->so_name, build_id_filename);
-+
-+                    /* In the case the main executable was found according to
-+                       its build-id (from a core file) prevent loading
-+                       a different build of a library with accidentally the
-+                       same SO_NAME.
-+
-+                       It suppresses bogus backtraces (and prints "??" there
-+                       instead) if the on-disk files no longer match the
-+                       running program version.  */
-+
-+                    if (symfile_objfile != NULL
-+                        && (symfile_objfile->flags
-+                            & OBJF_BUILD_ID_CORE_LOADED) != 0)
-+                      new->so_name[0] = 0;
-+                  }
-+
-+                xfree (build_id_filename);
-+                xfree (build_id);
-+              }
-           }
-         xfree (buffer);
+--- gdb-7.6.orig/gdb/solib-svr4.c      2013-01-31 14:52:52.000000000 +0100
++++ gdb-7.6/gdb/solib-svr4.c   2013-07-17 05:28:49.287203539 +0200
+@@ -1224,9 +1224,52 @@ svr4_read_so_list (CORE_ADDR lm, struct
+         continue;
+       }
+-      strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
+-      new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
+-      strcpy (new->so_original_name, new->so_name);
++      {
++      struct elf_build_id *build_id;
++
++      strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
++      new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
++      /* May get overwritten below.  */
++      strcpy (new->so_name, new->so_original_name);
++
++      build_id = build_id_addr_get (new->lm_info->l_ld);
++      if (build_id != NULL)
++        {
++          char *name, *build_id_filename;
++
++          /* Missing the build-id matching separate debug info file
++             would be handled while SO_NAME gets loaded.  */
++          name = build_id_to_filename (build_id, &build_id_filename, 0);
++          if (name != NULL)
++            {
++              strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
++              new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
++              xfree (name);
++            }
++          else
++            {
++              debug_print_missing (new->so_name, build_id_filename);
++
++              /* In the case the main executable was found according to
++                 its build-id (from a core file) prevent loading
++                 a different build of a library with accidentally the
++                 same SO_NAME.
++
++                 It suppresses bogus backtraces (and prints "??" there
++                 instead) if the on-disk files no longer match the
++                 running program version.  */
++
++              if (symfile_objfile != NULL
++                  && (symfile_objfile->flags
++                      & OBJF_BUILD_ID_CORE_LOADED) != 0)
++                new->so_name[0] = 0;
++            }
++
++          xfree (build_id_filename);
++          xfree (build_id);
++        }
++      }
++
+       xfree (buffer);
  
-Index: gdb-6.8.91.20090925/gdb/symfile.c
+       /* If this entry has no name, or its name matches the name
+Index: gdb-7.6/gdb/elfread.c
 ===================================================================
---- gdb-6.8.91.20090925.orig/gdb/symfile.c     2009-09-25 09:29:57.000000000 +0200
-+++ gdb-6.8.91.20090925/gdb/symfile.c  2009-09-25 09:29:58.000000000 +0200
-@@ -56,6 +56,7 @@
- #include "elf-bfd.h"
- #include "solib.h"
- #include "remote.h"
+--- gdb-7.6.orig/gdb/elfread.c 2013-03-18 10:20:02.000000000 +0100
++++ gdb-7.6/gdb/elfread.c      2013-07-17 05:31:21.242256141 +0200
+@@ -45,6 +45,11 @@
+ #include "regcache.h"
+ #include "bcache.h"
+ #include "gdb_bfd.h"
 +#include "libbfd.h"
++#include "gdbcore.h"
++#include "gdbcmd.h"
++#include "observer.h"
++#include <sys/stat.h>
+ extern void _initialize_elfread (void);
  
- #include <sys/types.h>
- #include <fcntl.h>
-@@ -1173,16 +1174,65 @@ symbol_file_clear (int from_tty)
-     printf_unfiltered (_("No symbol file now.\n"));
+@@ -1068,10 +1073,59 @@ elf_gnu_ifunc_resolver_return_stop (stru
+   update_breakpoint_locations (b, sals, sals_end);
  }
  
-+/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
-+   FIXME: NOTE decoding should be unified with the BFD core notes decoding.  */
-+
+-/* Locate NT_GNU_BUILD_ID from ABFD and return its content.  */
 +#define BUILD_ID_VERBOSE_NONE 0
 +#define BUILD_ID_VERBOSE_FILENAMES 1
 +#define BUILD_ID_VERBOSE_BINARY_PARSE 2
@@ -211,14 +218,10 @@ Index: gdb-6.8.91.20090925/gdb/symfile.c
 +                  value);
 +}
 +
- struct build_id
-   {
-     size_t size;
-     gdb_byte data[1];
-   };
--/* Locate NT_GNU_BUILD_ID from ABFD and return its content.  */
-+struct build_id *
++/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
++   FIXME: NOTE decoding should be unified with the BFD core notes decoding.  */
++
++static struct elf_build_id *
 +build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size)
 +{
 +  bfd_byte *p;
@@ -238,7 +241,7 @@ Index: gdb-6.8.91.20090925/gdb/symfile.c
 +      {
 +        size_t size = descsz;
 +        gdb_byte *data = (void *) descdata;
-+        struct build_id *retval;
++        struct elf_build_id *retval;
 +
 +        retval = xmalloc (sizeof *retval - 1 + size);
 +        retval->size = size;
@@ -254,26 +257,26 @@ Index: gdb-6.8.91.20090925/gdb/symfile.c
 +/* Separate debuginfo files have corrupted PHDR but SHDR is correct there.
 +   Locate NT_GNU_BUILD_ID from ABFD and return its content.  */
  
- static struct build_id *
+ static const struct elf_build_id *
 -build_id_bfd_get (bfd *abfd)
 +build_id_bfd_shdr_get (bfd *abfd)
  {
-   struct build_id *retval;
-@@ -1198,6 +1248,348 @@ build_id_bfd_get (bfd *abfd)
-   return retval;
+   if (!bfd_check_format (abfd, bfd_object)
+       || bfd_get_flavour (abfd) != bfd_target_elf_flavour
+@@ -1081,6 +1135,348 @@ build_id_bfd_get (bfd *abfd)
+   return elf_tdata (abfd)->build_id;
  }
  
 +/* Core files may have missing (corrupt) SHDR but PDHR is correct there.
 +   bfd_elf_bfd_from_remote_memory () has too much overhead by
 +   allocating/reading all the available ELF PT_LOADs.  */
 +
-+static struct build_id *
++static struct elf_build_id *
 +build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum,
 +                 Elf_Internal_Phdr *i_phdr)
 +{
 +  int i;
-+  struct build_id *retval = NULL;
++  struct elf_build_id *retval = NULL;
 +
 +  for (i = 0; i < e_phnum; i++)
 +    if (i_phdr[i].p_type == PT_NOTE && i_phdr[i].p_filesz > 0)
@@ -356,7 +359,7 @@ Index: gdb-6.8.91.20090925/gdb/symfile.c
 +/* Translate an ELF program header table entry in external format into an
 +   ELF program header table entry in internal format.  */
 +
-+void
++static void
 +elf_swap_phdr_in (bfd *abfd,
 +                const Elf64_External_Phdr *src64,
 +                Elf_Internal_Phdr *dst)
@@ -560,11 +563,11 @@ Index: gdb-6.8.91.20090925/gdb/symfile.c
 +    }
 +}
 +
-+struct build_id *
++struct elf_build_id *
 +build_id_addr_get (CORE_ADDR addr)
 +{
 +  struct build_id_addr_sect *candidate;
-+  struct build_id *retval = NULL;
++  struct elf_build_id *retval = NULL;
 +  Elf_Internal_Phdr *i_phdr = NULL;
 +  bfd_vma loadbase = 0;
 +  unsigned e_phnum = 0;
@@ -609,7 +612,7 @@ Index: gdb-6.8.91.20090925/gdb/symfile.c
  /* Return if FILENAME has NT_GNU_BUILD_ID matching the CHECK value.  */
  
  static int
-@@ -1215,7 +1607,7 @@ build_id_verify (const char *filename, s
+@@ -1095,7 +1491,7 @@ build_id_verify (const char *filename, c
    if (abfd == NULL)
      return 0;
  
@@ -618,55 +621,182 @@ Index: gdb-6.8.91.20090925/gdb/symfile.c
  
    if (found == NULL)
      warning (_("File \"%s\" has no build-id, file skipped"), filename);
-@@ -1234,8 +1626,9 @@ build_id_verify (const char *filename, s
-   return retval;
+@@ -1112,16 +1508,53 @@ build_id_verify (const char *filename, c
  }
  
--static char *
--build_id_to_debug_filename (struct build_id *build_id)
+ static char *
+-build_id_to_debug_filename (const struct elf_build_id *build_id)
++link_resolve (const char *symlink, int level)
++{
++  char buf[PATH_MAX + 1], *target, *retval;
++  ssize_t got;
++
++  if (level > 10)
++    return xstrdup (symlink);
++
++  got = readlink (symlink, buf, sizeof (buf));
++  if (got < 0 || got >= sizeof (buf))
++    return xstrdup (symlink);
++  buf[got] = '\0';
++
++  if (IS_ABSOLUTE_PATH (buf))
++    target = xstrdup (buf);
++  else
++    {
++      char *dir = ldirname (symlink);
++
++      if (dir == NULL)
++      return xstrdup (symlink);
++      target = xstrprintf ("%s"
++#ifndef HAVE_DOS_BASED_FILE_SYSTEM
++                         "/"
++#else /* HAVE_DOS_BASED_FILE_SYSTEM */
++                         "\\"
++#endif /* HAVE_DOS_BASED_FILE_SYSTEM */
++                         "%s", dir, buf);
++    }
++
++  retval = link_resolve (target, level + 1);
++  xfree (target);
++  return retval;
++}
++
 +char *
-+build_id_to_filename (struct build_id *build_id, char **link_return,
++build_id_to_filename (const struct elf_build_id *build_id, char **link_return,
 +                    int add_debug_suffix)
  {
-   char *link, *s, *retval = NULL;
-   gdb_byte *data = build_id->data;
-@@ -1243,7 +1636,9 @@ build_id_to_debug_filename (struct build
+   char *link, *debugdir, *retval = NULL;
++  char *link_all = NULL;
+   VEC (char_ptr) *debugdir_vec;
+   struct cleanup *back_to;
+   int ix;
  
    /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
-   link = xmalloc (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
--                + 2 * size + (sizeof ".debug" - 1) + 1);
-+                + 2 * size
-+                + (add_debug_suffix ? sizeof ".debug" - 1 : 0)
-+                + 1);
-   s = link + sprintf (link, "%s/.build-id/", debug_file_directory);
-   if (size > 0)
-     {
-@@ -1254,12 +1649,14 @@ build_id_to_debug_filename (struct build
-     *s++ = '/';
-   while (size-- > 0)
-     s += sprintf (s, "%02x", (unsigned) *data++);
--  strcpy (s, ".debug");
-+  if (add_debug_suffix)
-+    strcpy (s, ".debug");
-+  else
-+    *s = 0;
+-  link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
+-               + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
++  link = xmalloc (strlen (debug_file_directory) + 2 * build_id->size + 50);
  
-   /* lrealpath() is expensive even for the usually non-existent files.  */
-   if (access (link, F_OK) == 0)
-     retval = lrealpath (link);
--  xfree (link);
+   /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
+      cause "/.build-id/..." lookups.  */
+@@ -1134,7 +1567,10 @@ build_id_to_debug_filename (const struct
+       size_t debugdir_len = strlen (debugdir);
+       const gdb_byte *data = build_id->data;
+       size_t size = build_id->size;
+-      char *s;
++      unsigned seqno;
++      struct stat statbuf_trash;
++      /* Initialize it just to avoid a GCC false warning.  */
++      char *s, *link0 = NULL, *link0_resolved;
  
-   if (retval != NULL && !build_id_verify (retval, build_id))
-     {
-@@ -1267,9 +1664,150 @@ build_id_to_debug_filename (struct build
-       retval = NULL;
-     }
+       memcpy (link, debugdir, debugdir_len);
+       s = &link[debugdir_len];
+@@ -1148,37 +1584,256 @@ build_id_to_debug_filename (const struct
+       *s++ = '/';
+       while (size-- > 0)
+       s += sprintf (s, "%02x", (unsigned) *data++);
+-      strcpy (s, ".debug");
  
-+  if (link_return != NULL)
-+    *link_return = link;
-+  else
-+    xfree (link);
+-      /* lrealpath() is expensive even for the usually non-existent files.  */
+-      if (access (link, F_OK) == 0)
+-      retval = lrealpath (link);
++      for (seqno = 0;; seqno++)
++      {
++        char *s2;
++
++        if (seqno)
++          {
++            /* There can be multiple build-id symlinks pointing to real files
++               with the same build-id (such as hard links).  Some of the real
++               files may not be installed.  */
++
++            s2 = s + sprintf (s, ".%u", seqno);
++          }
++        else
++          s2 = s;
++
++        if (add_debug_suffix)
++          strcpy (s2, ".debug");
++        else
++          *s2 = 0;
++
++        if (!seqno)
++          {
++            /* If none of the real files is found report as missing file
++               always the non-.%u-suffixed file.  */
++            link0 = xstrdup (link);
++          }
++
++        /* `access' automatically dereferences LINK.  */
++        if (lstat (link, &statbuf_trash) != 0)
++          {
++            /* Stop increasing SEQNO.  */
++            break;
++          }
 +
++        retval = lrealpath (link);
++
++        if (retval != NULL && !build_id_verify (retval, build_id))
++          {
++            xfree (retval);
++            retval = NULL;
++          }
++
++        if (retval)
++          break;
++      }
++
++      if (retval != NULL)
++      {
++        /* LINK_ALL is not used below in this non-NULL RETVAL case.  */
++        xfree (link0);
++        break;
++      }
++
++      /* If the symlink has target request to install the target.
++         BASE-debuginfo.rpm contains the symlink but BASE.rpm may be missing.
++         https://bugzilla.redhat.com/show_bug.cgi?id=981154  */
++      link0_resolved = link_resolve (link0, 0);
++      xfree (link0);
+-      if (retval != NULL && !build_id_verify (retval, build_id))
++      if (link_all == NULL)
++      link_all = xstrdup (link0_resolved);
++      else
+       {
+-        xfree (retval);
+-        retval = NULL;
++        size_t len_orig = strlen (link_all);
++
++        link_all = xrealloc (link_all,
++                             len_orig + 1 + strlen (link0_resolved) + 1);
++
++        /* Use whitespace instead of DIRNAME_SEPARATOR to be compatible with
++           its possible use as an argument for installation command.  */
++        link_all[len_orig] = ' ';
++
++        strcpy (&link_all[len_orig + 1], link0_resolved);
+       }
++      xfree (link0_resolved);
++    }
++  if (link_return != NULL)
++    {
+       if (retval != NULL)
+-      break;
++      {
++        *link_return = link;
++        link = NULL;
++      }
++      else
++      {
++        *link_return = link_all;
++        link_all = NULL;
++      }
+     }
++  xfree (link);
++  xfree (link_all);
+   do_cleanups (back_to);
    return retval;
  }
  
@@ -807,190 +937,101 @@ Index: gdb-6.8.91.20090925/gdb/symfile.c
 +}
 +
  static char *
- get_debug_link_info (struct objfile *objfile, unsigned long *crc32_out)
- {
-@@ -1352,32 +1890,36 @@ static char *
- find_separate_debug_file (struct objfile *objfile)
+-find_separate_debug_file_by_buildid (struct objfile *objfile)
++find_separate_debug_file_by_buildid (struct objfile *objfile,
++                                   char **build_id_filename_return)
  {
-   asection *sect;
--  char *basename;
--  char *dir;
--  char *debugfile;
-+  char *basename = NULL;
-+  char *dir = NULL;
-+  char *debugfile = NULL;
-   char *name_copy;
--  char *canon_name;
-+  char *canon_name = NULL;
-   bfd_size_type debuglink_size;
-   unsigned long crc32;
-   int i;
-   struct build_id *build_id;
-+  char *build_id_filename = NULL;
+   const struct elf_build_id *build_id;
  
 -  build_id = build_id_bfd_get (objfile->obfd);
++  if (build_id_filename_return)
++    *build_id_filename_return = NULL;
++
 +  build_id = build_id_bfd_shdr_get (objfile->obfd);
    if (build_id != NULL)
      {
        char *build_id_name;
  
 -      build_id_name = build_id_to_debug_filename (build_id);
-+      build_id_name = build_id_to_filename (build_id, &build_id_filename, 1);
-       xfree (build_id);
++      build_id_name = build_id_to_filename (build_id, build_id_filename_return,
++                                          1);
        /* Prevent looping on a stripped .debug file.  */
-       if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
-         {
--        warning (_("\"%s\": separate debug info file has no debug info"),
-+        warning (_("\"%s\": The separate debug info file has no debug info"),
-                  build_id_name);
+       if (build_id_name != NULL
+         && filename_cmp (build_id_name, objfile->name) == 0)
+@@ -1188,7 +1843,7 @@ find_separate_debug_file_by_buildid (str
          xfree (build_id_name);
        }
        else if (build_id_name != NULL)
 -        return build_id_name;
-+        {
-+        xfree (build_id_filename);
-+        return build_id_name;
-+      }
++      return build_id_name;
      }
+   return NULL;
+ }
+@@ -1426,9 +2081,10 @@ elf_symfile_read (struct objfile *objfil
+          && objfile->separate_debug_objfile == NULL
+          && objfile->separate_debug_objfile_backlink == NULL)
+     {
+-      char *debugfile;
++      char *debugfile, *build_id_filename;
  
-   basename = get_debug_link_info (objfile, &crc32);
-@@ -1385,7 +1927,7 @@ find_separate_debug_file (struct objfile
-   if (basename == NULL)
-     /* There's no separate debug info, hence there's no way we could
-        load it => no warning.  */
--    return NULL;
-+    goto cleanup_return_debugfile;
-   dir = xstrdup (objfile->name);
-@@ -1407,24 +1949,19 @@ find_separate_debug_file (struct objfile
-   if (canon_name && strlen (canon_name) > i)
-     i = strlen (canon_name);
--  debugfile = alloca (strlen (debug_file_directory) + 1
--                      + i
--                      + strlen (DEBUG_SUBDIRECTORY)
--                      + strlen ("/")
--                      + strlen (basename)
--                      + 1);
-+  debugfile = xmalloc (strlen (debug_file_directory) + 1
-+                     + i
-+                     + strlen (DEBUG_SUBDIRECTORY)
-+                     + strlen ("/")
-+                     + strlen (basename)
-+                     + 1);
-   /* First try in the same directory as the original file.  */
-   strcpy (debugfile, dir);
-   strcat (debugfile, basename);
-   if (separate_debug_file_exists (debugfile, crc32, objfile->name))
--    {
--      xfree (basename);
--      xfree (dir);
--      xfree (canon_name);
--      return xstrdup (debugfile);
--    }
-+    goto cleanup_return_debugfile;
-   /* Then try in the subdirectory named DEBUG_SUBDIRECTORY.  */
-   strcpy (debugfile, dir);
-@@ -1433,12 +1970,7 @@ find_separate_debug_file (struct objfile
-   strcat (debugfile, basename);
-   if (separate_debug_file_exists (debugfile, crc32, objfile->name))
--    {
--      xfree (basename);
--      xfree (dir);
--      xfree (canon_name);
--      return xstrdup (debugfile);
--    }
-+    goto cleanup_return_debugfile;
-   /* Then try in the global debugfile directory.  */
-   strcpy (debugfile, debug_file_directory);
-@@ -1447,12 +1979,7 @@ find_separate_debug_file (struct objfile
-   strcat (debugfile, basename);
-   if (separate_debug_file_exists (debugfile, crc32, objfile->name))
--    {
--      xfree (basename);
--      xfree (dir);
--      xfree (canon_name);
--      return xstrdup (debugfile);
--    }
-+    goto cleanup_return_debugfile;
-   /* If the file is in the sysroot, try using its base path in the
-      global debugfile directory.  */
-@@ -1466,20 +1993,18 @@ find_separate_debug_file (struct objfile
-       strcat (debugfile, basename);
+-      debugfile = find_separate_debug_file_by_buildid (objfile);
++      debugfile = find_separate_debug_file_by_buildid (objfile,
++                                                     &build_id_filename);
  
-       if (separate_debug_file_exists (debugfile, crc32, objfile->name))
--      {
--        xfree (canon_name);
--        xfree (basename);
--        xfree (dir);
--        return xstrdup (debugfile);
--      }
-+      goto cleanup_return_debugfile;
+       if (debugfile == NULL)
+       debugfile = find_separate_debug_file_by_debuglink (objfile);
+@@ -1442,6 +2098,12 @@ elf_symfile_read (struct objfile *objfil
+         symbol_file_add_separate (abfd, symfile_flags, objfile);
+         do_cleanups (cleanup);
+       }
++      /* Check if any separate debug info has been extracted out.  */
++      else if (bfd_get_section_by_name (objfile->obfd, ".gnu_debuglink")
++             != NULL)
++      debug_print_missing (objfile->name, build_id_filename);
++
++      xfree (build_id_filename);
      }
-   
--  if (canon_name)
--    xfree (canon_name);
-+  debugfile = NULL;
-+  debug_print_missing (objfile->name, build_id_filename);
-+cleanup_return_debugfile:
-+  xfree (build_id_filename);
-+  xfree (canon_name);
-   xfree (basename);
-   xfree (dir);
--  return NULL;
-+  return debugfile;
  }
  
+@@ -1761,4 +2423,16 @@ _initialize_elfread (void)
  
-@@ -4229,4 +4754,16 @@ the global debug-file directory prepende
-                                    NULL,
-                                    show_debug_file_directory,
-                                    &setlist, &showlist);
-+ 
-+   add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
-+                          _("\
-+ Set debugging level of the build-id locator."), _("\
-+ Show debugging level of the build-id locator."), _("\
-+ Level 1 (default) enables printing the missing debug filenames,\n\
-+ level 2 also prints the parsing of binaries to find the identificators."),
-+                          NULL,
-+                          show_build_id_verbose,
-+                          &setlist, &showlist);
-+ 
-+   observer_attach_executable_changed (debug_print_executable_changed);
+   elf_objfile_gnu_ifunc_cache_data = register_objfile_data ();
+   gnu_ifunc_fns_p = &elf_gnu_ifunc_fns;
++
++  add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
++                          _("\
++Set debugging level of the build-id locator."), _("\
++Show debugging level of the build-id locator."), _("\
++Level 1 (default) enables printing the missing debug filenames,\n\
++level 2 also prints the parsing of binaries to find the identificators."),
++                          NULL,
++                          show_build_id_verbose,
++                          &setlist, &showlist);
++
++  observer_attach_executable_changed (debug_print_executable_changed);
  }
-Index: gdb-6.8.91.20090925/gdb/symfile.h
+Index: gdb-7.6/gdb/symfile.h
 ===================================================================
---- gdb-6.8.91.20090925.orig/gdb/symfile.h     2009-09-25 09:29:57.000000000 +0200
-+++ gdb-6.8.91.20090925/gdb/symfile.h  2009-09-25 09:29:58.000000000 +0200
-@@ -381,6 +381,13 @@ extern int symfile_map_offsets_to_segmen
- struct symfile_segment_data *get_symfile_segment_data (bfd *abfd);
void free_symfile_segment_data (struct symfile_segment_data *data);
+--- gdb-7.6.orig/gdb/symfile.h 2013-02-03 17:20:18.000000000 +0100
++++ gdb-7.6/gdb/symfile.h      2013-07-17 05:28:49.291203541 +0200
+@@ -593,6 +593,12 @@ void free_symfile_segment_data (struct s
extern struct cleanup *increment_reading_symtab (void);
  
 +/* build-id support.  */
-+struct build_id;
-+extern struct build_id *build_id_addr_get (CORE_ADDR addr);
-+extern char *build_id_to_filename (struct build_id *build_id,
++extern struct elf_build_id *build_id_addr_get (CORE_ADDR addr);
++extern char *build_id_to_filename (const struct elf_build_id *build_id,
 +                                 char **link_return, int add_debug_suffix);
 +extern void debug_print_missing (const char *binary, const char *debug);
 +
  /* From dwarf2read.c */
  
- extern int dwarf2_has_info (struct objfile *);
-Index: gdb-6.8.91.20090925/gdb/testsuite/lib/gdb.exp
+ /* Names for a dwarf2 debugging section.  The field NORMAL is the normal
+Index: gdb-7.6/gdb/testsuite/lib/gdb.exp
 ===================================================================
---- gdb-6.8.91.20090925.orig/gdb/testsuite/lib/gdb.exp 2009-09-25 09:29:57.000000000 +0200
-+++ gdb-6.8.91.20090925/gdb/testsuite/lib/gdb.exp      2009-09-25 09:29:58.000000000 +0200
-@@ -1248,6 +1248,16 @@ proc default_gdb_start { } {
+--- gdb-7.6.orig/gdb/testsuite/lib/gdb.exp     2013-07-17 05:28:48.334203172 +0200
++++ gdb-7.6/gdb/testsuite/lib/gdb.exp  2013-07-17 05:28:49.292203541 +0200
+@@ -1482,6 +1482,16 @@ proc default_gdb_start { } {
            warning "Couldn't set the width to 0."
        }
      }
@@ -1007,13 +1048,13 @@ Index: gdb-6.8.91.20090925/gdb/testsuite/lib/gdb.exp
      return 0;
  }
  
-Index: gdb-6.8.91.20090925/gdb/testsuite/lib/mi-support.exp
+Index: gdb-7.6/gdb/testsuite/lib/mi-support.exp
 ===================================================================
---- gdb-6.8.91.20090925.orig/gdb/testsuite/lib/mi-support.exp  2009-09-15 20:51:26.000000000 +0200
-+++ gdb-6.8.91.20090925/gdb/testsuite/lib/mi-support.exp       2009-09-25 09:29:58.000000000 +0200
-@@ -221,6 +221,16 @@ proc default_mi_gdb_start { args } {
-           }
-       }
+--- gdb-7.6.orig/gdb/testsuite/lib/mi-support.exp      2013-01-22 00:57:59.000000000 +0100
++++ gdb-7.6/gdb/testsuite/lib/mi-support.exp   2013-07-17 05:28:49.292203541 +0200
+@@ -212,6 +212,16 @@ proc default_mi_gdb_start { args } {
+           warning "Couldn't set the width to 0."
+       }
      }
 +    # Turn off the missing warnings as the testsuite does not expect it.
 +    send_gdb "190-gdb-set build-id-verbose 0\n"
@@ -1025,21 +1066,59 @@ Index: gdb-6.8.91.20090925/gdb/testsuite/lib/mi-support.exp
 +          warning "Could not disable the missing debug infos warnings.."
 +      }
 +    }
-     detect_async
-Index: gdb-6.8.91.20090925/gdb/objfiles.h
+     # If allowing the inferior to have its own PTY then assign the inferior
+     # its own terminal device here.
+     if { $separate_inferior_pty } {
+Index: gdb-7.6/gdb/objfiles.h
 ===================================================================
---- gdb-6.8.91.20090925.orig/gdb/objfiles.h    2009-09-25 09:29:57.000000000 +0200
-+++ gdb-6.8.91.20090925/gdb/objfiles.h 2009-09-25 09:38:27.000000000 +0200
-@@ -428,6 +428,10 @@ struct objfile
+--- gdb-7.6.orig/gdb/objfiles.h        2013-02-28 20:00:31.000000000 +0100
++++ gdb-7.6/gdb/objfiles.h     2013-07-17 05:28:49.293203542 +0200
+@@ -432,6 +432,10 @@ struct objfile
  
- #define OBJF_MAIN (1 << 7)
+ #define OBJF_MAINLINE (1 << 5)
  
 +/* This file was loaded according to the BUILD_ID_CORE_LOADS rules.  */
 +
 +#define OBJF_BUILD_ID_CORE_LOADED (1 << 12)
 +
- /* The object file that the main symbol table was loaded from (e.g. the
-    argument to the "symbol-file" or "file" command).  */
+ /* The object file that contains the runtime common minimal symbols
+    for SunOS4.  Note that this objfile has no associated BFD.  */
+Index: gdb-7.6/gdb/testsuite/gdb.base/corefile.exp
+===================================================================
+--- gdb-7.6.orig/gdb/testsuite/gdb.base/corefile.exp   2013-01-01 07:33:25.000000000 +0100
++++ gdb-7.6/gdb/testsuite/gdb.base/corefile.exp        2013-07-17 05:28:49.293203542 +0200
+@@ -256,3 +256,33 @@ if ![is_remote target] {
  
+     gdb_exit
+ }
++
++
++# Test auto-loading of binary files through build-id from the core file.
++set buildid [build_id_debug_filename_get $binfile]
++set wholetest "binfile found by build-id"
++if {$buildid == ""} {
++    untested "$wholetest (binary has no build-id)"
++} else {
++    gdb_exit
++    gdb_start
++
++    regsub {\.debug$} $buildid {} buildid
++    set debugdir ${objdir}/${subdir}/${testfile}-debugdir
++    file delete -force -- $debugdir
++    file mkdir $debugdir/[file dirname $buildid]
++    file copy $binfile $debugdir/$buildid
++
++    set test "show debug-file-directory"
++    gdb_test_multiple $test $test {
++      -re "The directory where separate debug symbols are searched for is \"(.*)\"\\.\r\n$gdb_prompt $" {
++          set debugdir_orig $expect_out(1,string)
++          pass $test
++      }
++    }
++    gdb_test_no_output "set debug-file-directory $debugdir:$debugdir_orig" "set debug-file-directory"
++    gdb_test "show build-id-core-loads" {Whether CORE-FILE loads the build-id associated files automatically is on\.}
++    gdb_test "core-file $corefile" "\r\nProgram terminated with .*" "core-file without executable"
++    gdb_test "info files" "Local exec file:\r\n\[ \t\]*`[string_to_regexp $debugdir/$buildid]', file type .*"
++    pass $wholetest
++}
This page took 0.067387 seconds and 4 git commands to generate.