-Index: gdb-6.8.50.20090302/gdb/corelow.c
+Index: gdb-7.4.91.20120801/gdb/corelow.c
===================================================================
---- gdb-6.8.50.20090302.orig/gdb/corelow.c 2009-02-23 01:03:48.000000000 +0100
-+++ gdb-6.8.50.20090302/gdb/corelow.c 2009-03-07 17:04:57.000000000 +0100
-@@ -45,6 +45,10 @@
- #include "exceptions.h"
- #include "solib.h"
- #include "filenames.h"
+--- gdb-7.4.91.20120801.orig/gdb/corelow.c 2012-08-01 18:36:51.000000000 +0200
++++ gdb-7.4.91.20120801/gdb/corelow.c 2012-08-01 18:37:44.584925750 +0200
+@@ -47,6 +47,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
-@@ -267,6 +271,56 @@ add_to_thread_list (bfd *abfd, asection
- inferior_ptid = ptid; /* Yes, make it current */
+ #define O_LARGEFILE 0
+@@ -274,6 +277,52 @@ add_to_thread_list (bfd *abfd, asection
+ inferior_ptid = ptid; /* Yes, make it current. */
}
+static int build_id_core_loads = 1;
+ struct build_id *build_id;
+ char *exec_filename, *debug_filename;
+ char *build_id_filename;
++ struct cleanup *back_to;
+
-+ if (exec_bfd != NULL)
++ if (exec_bfd != NULL || symfile_objfile != NULL)
+ return;
+
+ if (target_auxv_search (¤t_target, AT_ENTRY, &at_entry) <= 0)
+ if (build_id == NULL)
+ return;
+
++ /* SYMFILE_OBJFILE should refer to the main executable (not only to its
++ separate debug info file). gcc44+ keeps .eh_frame only in the main
++ executable without its duplicate .debug_frame in the separate debug info
++ file - such .eh_frame would not be found if SYMFILE_OBJFILE would refer
++ directly to the separate debug info file. */
++
+ exec_filename = build_id_to_filename (build_id, &build_id_filename, 0);
-+ if (exec_filename != NULL)
-+ exec_file_attach (exec_filename, from_tty);
-+ else
-+ debug_print_missing (_("the main executable file"), build_id_filename);
-+ xfree (build_id_filename);
++ back_to = make_cleanup (xfree, build_id_filename);
+
-+ /* `.note.gnu.build-id' section exists even for files without a separate
-+ debuginfo. */
-+ debug_filename = build_id_to_filename (build_id, &build_id_filename, 1);
-+ if (debug_filename != NULL)
++ if (exec_filename != NULL)
+ {
-+ symbol_file_add_main (debug_filename, from_tty);
-+ xfree (debug_filename);
++ make_cleanup (xfree, exec_filename);
++ exec_file_attach (exec_filename, from_tty);
++ symbol_file_add_main (exec_filename, from_tty);
++ if (symfile_objfile != NULL)
++ symfile_objfile->flags |= OBJF_BUILD_ID_CORE_LOADED;
+ }
+ else
-+ {
-+ if (exec_filename != NULL)
-+ symbol_file_add_main (exec_filename, from_tty);
-+ /* For EXEC_FILENAME NULL we were already complaining above. */
-+ if (symfile_objfile == NULL && exec_filename != NULL)
-+ debug_print_missing (exec_filename, build_id_filename);
-+ }
-+ xfree (build_id_filename);
++ debug_print_missing (_("the main executable file"), build_id_filename);
+
-+ xfree (exec_filename);
++ do_cleanups (back_to);
+
+ /* No automatic SOLIB_ADD as the libraries would get read twice. */
+}
/* This routine opens and sets up the core file bfd. */
static void
-@@ -363,6 +417,12 @@ core_open (char *filename, int from_tty)
- push_target (&core_ops);
- discard_cleanups (old_chain);
+@@ -418,6 +467,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
-@@ -751,4 +811,11 @@ _initialize_corelow (void)
+ /* Now go through the target stack looking for threads since there
+@@ -939,4 +996,11 @@ _initialize_corelow (void)
init_core_ops ();
add_target (&core_ops);
+ 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.50.20090302/gdb/doc/gdb.texinfo
+Index: gdb-7.4.91.20120801/gdb/doc/gdb.texinfo
===================================================================
---- gdb-6.8.50.20090302.orig/gdb/doc/gdb.texinfo 2009-03-07 17:04:56.000000000 +0100
-+++ gdb-6.8.50.20090302/gdb/doc/gdb.texinfo 2009-03-07 17:04:57.000000000 +0100
-@@ -13294,6 +13294,27 @@ information files.
+--- gdb-7.4.91.20120801.orig/gdb/doc/gdb.texinfo 2012-08-01 18:36:51.000000000 +0200
++++ gdb-7.4.91.20120801/gdb/doc/gdb.texinfo 2012-08-01 18:37:44.598925672 +0200
+@@ -16530,6 +16530,27 @@ information files.
@end table
@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.50.20090302/gdb/solib-svr4.c
+Index: gdb-7.4.91.20120801/gdb/solib-svr4.c
===================================================================
---- gdb-6.8.50.20090302.orig/gdb/solib-svr4.c 2009-03-07 17:04:52.000000000 +0100
-+++ gdb-6.8.50.20090302/gdb/solib-svr4.c 2009-03-07 17:04:57.000000000 +0100
-@@ -1000,9 +1000,33 @@ 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);
-+
-+ xfree (build_id_filename);
-+ xfree (build_id);
-+ }
- }
- xfree (buffer);
-
-Index: gdb-6.8.50.20090302/gdb/symfile.c
+--- gdb-7.4.91.20120801.orig/gdb/solib-svr4.c 2012-08-01 18:36:51.000000000 +0200
++++ gdb-7.4.91.20120801/gdb/solib-svr4.c 2012-08-01 18:37:44.599925667 +0200
+@@ -1228,9 +1228,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 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);
+
+ /* If this entry has no name, or its name matches the name
+Index: gdb-7.4.91.20120801/gdb/elfread.c
===================================================================
---- gdb-6.8.50.20090302.orig/gdb/symfile.c 2009-03-07 17:04:53.000000000 +0100
-+++ gdb-6.8.50.20090302/gdb/symfile.c 2009-03-07 17:22:21.000000000 +0100
-@@ -54,6 +54,7 @@
- #include "elf-bfd.h"
- #include "solib.h"
- #include "remote.h"
+--- gdb-7.4.91.20120801.orig/gdb/elfread.c 2012-08-01 18:36:51.000000000 +0200
++++ gdb-7.4.91.20120801/gdb/elfread.c 2012-08-01 18:38:08.956790879 +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>
-@@ -1185,16 +1186,65 @@ symbol_file_clear (int from_tty)
- printf_unfiltered (_("No symbol file now.\n"));
+@@ -1074,16 +1079,65 @@ 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. */
-+
+#define BUILD_ID_VERBOSE_NONE 0
+#define BUILD_ID_VERBOSE_FILENAMES 1
+#define BUILD_ID_VERBOSE_BINARY_PARSE 2
};
-/* 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 build_id *
+-build_id_bfd_get (bfd *abfd)
+build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size)
+{
+ bfd_byte *p;
+
+/* 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 *
--build_id_bfd_get (bfd *abfd)
++
++static struct build_id *
+build_id_bfd_shdr_get (bfd *abfd)
{
struct build_id *retval;
-@@ -1210,6 +1260,348 @@ build_id_bfd_get (bfd *abfd)
+@@ -1099,6 +1153,348 @@ build_id_bfd_get (bfd *abfd)
return retval;
}
+/* 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)
/* Return if FILENAME has NT_GNU_BUILD_ID matching the CHECK value. */
static int
-@@ -1227,7 +1619,7 @@ build_id_verify (const char *filename, s
+@@ -1113,7 +1509,7 @@ build_id_verify (const char *filename, s
if (abfd == NULL)
return 0;
if (found == NULL)
warning (_("File \"%s\" has no build-id, file skipped"), filename);
-@@ -1246,8 +1638,9 @@ build_id_verify (const char *filename, s
+@@ -1131,17 +1527,18 @@ build_id_verify (const char *filename, s
return retval;
}
+build_id_to_filename (struct build_id *build_id, char **link_return,
+ int add_debug_suffix)
{
- char *link, *s, *retval = NULL;
- gdb_byte *data = build_id->data;
-@@ -1255,7 +1648,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)
- {
-@@ -1266,12 +1661,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. */
+@@ -1154,6 +1551,8 @@ build_id_to_debug_filename (struct build
+ size_t debugdir_len = strlen (debugdir);
+ gdb_byte *data = build_id->data;
+ size_t size = build_id->size;
++ unsigned seqno;
++ struct stat statbuf_trash;
+ char *s;
- if (retval != NULL && !build_id_verify (retval, build_id))
- {
-@@ -1279,9 +1676,142 @@ build_id_to_debug_filename (struct build
- retval = NULL;
- }
+ memcpy (link, debugdir, debugdir_len);
+@@ -1168,37 +1567,240 @@ build_id_to_debug_filename (struct build
+ *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;
+
-+ return retval;
-+}
++ 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 (retval != NULL && !build_id_verify (retval, build_id))
++ /* `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)
+ {
+- xfree (retval);
+- retval = NULL;
++ /* LINK_ALL is not used below in this non-NULL RETVAL case. */
++ break;
+ }
+
++ if (link_all == NULL)
++ link_all = xstrdup (link);
++ else
++ {
++ size_t len_orig = strlen (link_all);
++
++ link_all = xrealloc (link_all, len_orig + 1 + strlen (link) + 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], link);
++ }
++ }
++
++ 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;
+ }
+
+/* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
+ Try to install the hash file ...
+ avoidance. */
+
+ retval = obstack_alloc (&missing_filepair_obstack, size);
+ memset (retval, 0, size);
- return retval;
- }
-
++ return retval;
++}
++
+static hashval_t
+missing_filepair_hash_func (const struct missing_filepair *elem)
+{
+ const struct missing_filepair *elem2)
+{
+ return strcmp (elem1->binary, elem2->binary) == 0
-+ && ((elem1->debug == NULL && elem2->debug == NULL)
-+ || strcmp (elem1->debug, elem2->debug) == 0);
++ && ((elem1->debug == NULL) == (elem2->debug == NULL))
++ && (elem1->debug == NULL || strcmp (elem1->debug, elem2->debug) == 0);
+}
+
+static void
+{
+ size_t binary_len0 = strlen (binary) + 1;
+ size_t debug_len0 = debug ? strlen (debug) + 1 : 0;
++ struct missing_filepair missing_filepair_find;
+ struct missing_filepair *missing_filepair;
+ struct missing_filepair **slot;
+
+ missing_filepair_xcalloc, NULL);
+ }
+
++ /* Use MISSING_FILEPAIR_FIND first instead of calling obstack_alloc with
++ obstack_free in the case of a (rare) match. The problem is ALLOC_F for
++ MISSING_FILEPAIR_HASH allocates from MISSING_FILEPAIR_OBSTACK maintenance
++ structures for MISSING_FILEPAIR_HASH. Calling obstack_free would possibly
++ not to free only MISSING_FILEPAIR but also some such structures (allocated
++ during the htab_find_slot call). */
++
++ missing_filepair_find.binary = (char *) binary;
++ missing_filepair_find.debug = (char *) debug;
++ slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
++ &missing_filepair_find,
++ INSERT);
++
++ /* While it may be still printed duplicitely with the missing debuginfo file
++ * it is due to once printing about the binary file build-id link and once
++ * about the .debug file build-id link as both the build-id symlinks are
++ * located in the debuginfo package. */
++
++ if (*slot != NULL)
++ return;
++
+ missing_filepair = obstack_alloc (&missing_filepair_obstack,
+ sizeof (*missing_filepair) - 1
+ + binary_len0 + debug_len0);
+ else
+ missing_filepair->debug = NULL;
+
-+ slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
-+ missing_filepair,
-+ INSERT);
-+
-+ /* While it may be still printed duplicitely with the missing debuginfo file
-+ * it is due to once printing about the binary file build-id link and once
-+ * about the .debug file build-id link as both the build-id symlinks are
-+ * located in the debuginfo package. */
-+
-+ if (*slot != NULL)
-+ {
-+ obstack_free (&missing_filepair_obstack, missing_filepair);
-+ return;
-+ }
+ *slot = missing_filepair;
+
+ /* We do not collect and flush these messages as each such message
+}
+
static char *
- get_debug_link_info (struct objfile *objfile, unsigned long *crc32_out)
+-find_separate_debug_file_by_buildid (struct objfile *objfile)
++find_separate_debug_file_by_buildid (struct objfile *objfile,
++ char **build_id_filename_return)
{
-@@ -1364,32 +1894,36 @@ static char *
- find_separate_debug_file (struct objfile *objfile)
- {
- 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;
- 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);
++ build_id_name = build_id_to_filename (build_id, build_id_filename_return,
++ 1);
xfree (build_id);
/* 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
+@@ -1209,7 +1811,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;
+ }
+@@ -1436,9 +2038,10 @@ elf_symfile_read (struct objfile *objfil
+ `.note.gnu.build-id'. */
+ else if (!objfile_has_partial_symbols (objfile))
+ {
+- char *debugfile;
++ char *debugfile, *build_id_filename;
+
+- debugfile = find_separate_debug_file_by_buildid (objfile);
++ debugfile = find_separate_debug_file_by_buildid (objfile,
++ &build_id_filename);
- basename = get_debug_link_info (objfile, &crc32);
-@@ -1397,7 +1931,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);
-
-@@ -1413,23 +1947,19 @@ find_separate_debug_file (struct objfile
- gdb_assert (i >= 0 && IS_DIR_SEPARATOR (dir[i]));
- dir[i+1] = '\0';
-
-- debugfile = alloca (strlen (debug_file_directory) + 1
-- + strlen (dir)
-- + strlen (DEBUG_SUBDIRECTORY)
-- + strlen ("/")
-- + strlen (basename)
-- + 1);
-+ debugfile = xmalloc (strlen (debug_file_directory) + 1
-+ + strlen (dir)
-+ + 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);
-- return xstrdup (debugfile);
-- }
-+ goto cleanup_return_debugfile;
-
- /* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */
- strcpy (debugfile, dir);
-@@ -1438,11 +1968,7 @@ find_separate_debug_file (struct objfile
- strcat (debugfile, basename);
-
- if (separate_debug_file_exists (debugfile, crc32, objfile->name))
-- {
-- xfree (basename);
-- xfree (dir);
-- return xstrdup (debugfile);
-- }
-+ goto cleanup_return_debugfile;
-
- /* Then try in the global debugfile directory. */
- strcpy (debugfile, debug_file_directory);
-@@ -1451,11 +1977,7 @@ find_separate_debug_file (struct objfile
- strcat (debugfile, basename);
-
- if (separate_debug_file_exists (debugfile, crc32, objfile->name))
-- {
-- xfree (basename);
-- xfree (dir);
-- return xstrdup (debugfile);
-- }
-+ goto cleanup_return_debugfile;
-
- /* If the file is in the sysroot, try using its base path in the
- global debugfile directory. */
-@@ -1470,20 +1992,18 @@ find_separate_debug_file (struct objfile
- strcat (debugfile, basename);
-
- 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);
+@@ -1452,6 +2055,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;
- }
+ if (symtab_create_debug)
+@@ -1784,4 +2393,16 @@ _initialize_elfread (void)
-@@ -4216,4 +4736,16 @@ Show printing of symbol loading messages
- NULL,
- NULL,
- &setprintlist, &showprintlist);
+ 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,
+ _("\
+
+ observer_attach_executable_changed (debug_print_executable_changed);
}
-Index: gdb-6.8.50.20090302/gdb/symfile.h
+Index: gdb-7.4.91.20120801/gdb/symfile.h
===================================================================
---- gdb-6.8.50.20090302.orig/gdb/symfile.h 2009-03-07 17:04:52.000000000 +0100
-+++ gdb-6.8.50.20090302/gdb/symfile.h 2009-03-07 17:13:33.000000000 +0100
-@@ -372,6 +372,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.4.91.20120801.orig/gdb/symfile.h 2012-08-01 18:36:51.000000000 +0200
++++ gdb-7.4.91.20120801/gdb/symfile.h 2012-08-01 18:37:44.600925662 +0200
+@@ -615,6 +615,13 @@ void free_symfile_segment_data (struct s
+
+ extern struct cleanup *increment_reading_symtab (void);
+/* build-id support. */
+struct build_id;
+
/* From dwarf2read.c */
- extern int dwarf2_has_info (struct objfile *);
-Index: gdb-6.8.50.20090302/gdb/testsuite/lib/gdb.exp
+ /* Names for a dwarf2 debugging section. The field NORMAL is the normal
+Index: gdb-7.4.91.20120801/gdb/testsuite/lib/gdb.exp
===================================================================
---- gdb-6.8.50.20090302.orig/gdb/testsuite/lib/gdb.exp 2009-03-07 17:04:52.000000000 +0100
-+++ gdb-6.8.50.20090302/gdb/testsuite/lib/gdb.exp 2009-03-07 17:13:33.000000000 +0100
-@@ -1230,6 +1230,16 @@ proc default_gdb_start { } {
+--- gdb-7.4.91.20120801.orig/gdb/testsuite/lib/gdb.exp 2012-08-01 18:36:51.000000000 +0200
++++ gdb-7.4.91.20120801/gdb/testsuite/lib/gdb.exp 2012-08-01 18:37:44.601925656 +0200
+@@ -1388,6 +1388,16 @@ proc default_gdb_start { } {
warning "Couldn't set the width to 0."
}
}
return 0;
}
---- ./gdb/testsuite/lib/mi-support.exp 2009-03-21 21:09:09.000000000 +0100
-+++ ./gdb/testsuite/lib/mi-support.exp 2009-03-22 16:37:58.000000000 +0100
-@@ -221,6 +221,16 @@ proc default_mi_gdb_start { args } {
- }
- }
+Index: gdb-7.4.91.20120801/gdb/testsuite/lib/mi-support.exp
+===================================================================
+--- gdb-7.4.91.20120801.orig/gdb/testsuite/lib/mi-support.exp 2012-07-25 22:35:30.000000000 +0200
++++ gdb-7.4.91.20120801/gdb/testsuite/lib/mi-support.exp 2012-08-01 18:37:44.601925656 +0200
+@@ -213,6 +213,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"
+ warning "Could not disable the missing debug infos warnings.."
+ }
+ }
+ # 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.4.91.20120801/gdb/objfiles.h
+===================================================================
+--- gdb-7.4.91.20120801.orig/gdb/objfiles.h 2012-08-01 18:36:51.000000000 +0200
++++ gdb-7.4.91.20120801/gdb/objfiles.h 2012-08-01 18:37:44.601925656 +0200
+@@ -432,6 +432,10 @@ struct objfile
- detect_async
+ #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 contains the runtime common minimal symbols
+ for SunOS4. Note that this objfile has no associated BFD. */
+
+Index: gdb-7.4.91.20120801/gdb/testsuite/gdb.base/corefile.exp
+===================================================================
+--- gdb-7.4.91.20120801.orig/gdb/testsuite/gdb.base/corefile.exp 2012-06-21 22:46:21.000000000 +0200
++++ gdb-7.4.91.20120801/gdb/testsuite/gdb.base/corefile.exp 2012-08-01 18:37:44.602925650 +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
++}