-Index: gdb-7.2.90.20110429/gdb/corelow.c
+Index: gdb-7.4.91.20120801/gdb/corelow.c
===================================================================
---- gdb-7.2.90.20110429.orig/gdb/corelow.c 2011-02-26 03:07:07.000000000 +0100
-+++ gdb-7.2.90.20110429/gdb/corelow.c 2011-05-03 05:14:57.000000000 +0200
+--- 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 "filenames.h"
#include "progspace.h"
#include "objfiles.h"
+ #include "gdb_bfd.h"
+#include "auxv.h"
+#include "elf/common.h"
+#include "gdbcmd.h"
-
#ifndef O_LARGEFILE
-@@ -278,6 +281,52 @@ add_to_thread_list (bfd *abfd, asection
+ #define O_LARGEFILE 0
+@@ -274,6 +277,52 @@ add_to_thread_list (bfd *abfd, asection
inferior_ptid = ptid; /* Yes, make it current. */
}
/* This routine opens and sets up the core file bfd. */
static void
-@@ -379,6 +428,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);
+
- /* Do this before acknowledging the inferior, so if
- post_create_inferior throws (can happen easilly if you're loading
- a core file with the wrong exec), we aren't left with threads
-@@ -932,4 +987,11 @@ _initialize_corelow (void)
+ post_create_inferior (&core_ops, from_tty);
+
+ /* 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-7.2.90.20110429/gdb/doc/gdb.texinfo
+Index: gdb-7.4.91.20120801/gdb/doc/gdb.texinfo
===================================================================
---- gdb-7.2.90.20110429.orig/gdb/doc/gdb.texinfo 2011-05-03 05:14:56.000000000 +0200
-+++ gdb-7.2.90.20110429/gdb/doc/gdb.texinfo 2011-05-03 05:14:57.000000000 +0200
-@@ -15356,6 +15356,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-7.2.90.20110429/gdb/solib-svr4.c
+Index: gdb-7.4.91.20120801/gdb/solib-svr4.c
===================================================================
---- gdb-7.2.90.20110429.orig/gdb/solib-svr4.c 2011-05-03 05:14:56.000000000 +0200
-+++ gdb-7.2.90.20110429/gdb/solib-svr4.c 2011-05-03 05:14:57.000000000 +0200
-@@ -1179,9 +1179,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.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);
-Index: gdb-7.2.90.20110429/gdb/elfread.c
+ /* If this entry has no name, or its name matches the name
+Index: gdb-7.4.91.20120801/gdb/elfread.c
===================================================================
---- gdb-7.2.90.20110429.orig/gdb/elfread.c 2011-05-03 05:14:56.000000000 +0200
-+++ gdb-7.2.90.20110429/gdb/elfread.c 2011-05-03 05:19:27.000000000 +0200
-@@ -49,6 +49,11 @@
- #include "infcall.h"
- #include "gdbthread.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"
extern void _initialize_elfread (void);
-@@ -1077,16 +1082,65 @@ elf_gnu_ifunc_resolver_return_stop (stru
+@@ -1074,16 +1079,65 @@ elf_gnu_ifunc_resolver_return_stop (stru
update_breakpoint_locations (b, sals, sals_end);
}
-/* Locate NT_GNU_BUILD_ID from ABFD and return its content. */
+/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
+ FIXME: NOTE decoding should be unified with the BFD core notes decoding. */
-+
-+struct build_id *
+
+ 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;
-@@ -1102,6 +1156,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
-@@ -1116,7 +1512,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);
-@@ -1134,14 +1530,15 @@ build_id_verify (const char *filename, s
+@@ -1131,17 +1527,18 @@ build_id_verify (const char *filename, s
return retval;
}
{
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 = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
/* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
cause "/.build-id/..." lookups. */
-@@ -1152,6 +1549,8 @@ build_id_to_debug_filename (struct build
- char *s, *debugdir_end;
+@@ -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;
- while (*debugdir == DIRNAME_SEPARATOR)
- debugdir++;
-@@ -1172,39 +1571,242 @@ build_id_to_debug_filename (struct build
+ 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");
--
+
- /* lrealpath() is expensive even for the usually non-existent files. */
- if (access (link, F_OK) == 0)
- retval = lrealpath (link);
-
-- if (retval != NULL && !build_id_verify (retval, build_id))
+ for (seqno = 0;; seqno++)
- {
-- xfree (retval);
-- retval = NULL;
++ {
+ char *s2;
+
+ if (seqno)
+ 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)
+ {
+
+ if (retval)
+ break;
- }
-
- if (retval != NULL)
-- break;
-+ {
-+ /* LINK_ALL is not used below in this non-NULL RETVAL case. */
-+ 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
+
+ strcpy (&link_all[len_orig + 1], link);
+ }
-
- debugdir = debugdir_end;
- }
- while (*debugdir != 0);
-
++ }
++
+ if (link_return != NULL)
+ {
-+ if (retval != NULL)
+ if (retval != NULL)
+- break;
+ {
+ *link_return = link;
+ link = NULL;
+ *link_return = link_all;
+ link_all = NULL;
+ }
-+ }
+ }
+ xfree (link);
+ xfree (link_all);
-+
-+ return retval;
-+}
-+
+
+ 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)
+{
xfree (build_id);
/* Prevent looping on a stripped .debug file. */
if (build_id_name != NULL
-@@ -1215,7 +1817,7 @@ find_separate_debug_file_by_buildid (str
+@@ -1209,7 +1811,7 @@ find_separate_debug_file_by_buildid (str
xfree (build_id_name);
}
else if (build_id_name != NULL)
}
return NULL;
}
-@@ -1418,9 +2020,10 @@ elf_symfile_read (struct objfile *objfil
+@@ -1436,9 +2038,10 @@ elf_symfile_read (struct objfile *objfil
`.note.gnu.build-id'. */
else if (!objfile_has_partial_symbols (objfile))
{
if (debugfile == NULL)
debugfile = find_separate_debug_file_by_debuglink (objfile);
-@@ -1432,6 +2035,12 @@ elf_symfile_read (struct objfile *objfil
+@@ -1452,6 +2055,12 @@ elf_symfile_read (struct objfile *objfil
symbol_file_add_separate (abfd, symfile_flags, objfile);
- xfree (debugfile);
+ do_cleanups (cleanup);
}
+ /* Check if any separate debug info has been extracted out. */
+ else if (bfd_get_section_by_name (objfile->obfd, ".gnu_debuglink")
+
+ xfree (build_id_filename);
}
- }
-@@ -1911,4 +2520,16 @@ _initialize_elfread (void)
+ if (symtab_create_debug)
+@@ -1784,4 +2393,16 @@ _initialize_elfread (void)
elf_objfile_gnu_ifunc_cache_data = register_objfile_data ();
gnu_ifunc_fns_p = &elf_gnu_ifunc_fns;
+
+ observer_attach_executable_changed (debug_print_executable_changed);
}
-Index: gdb-7.2.90.20110429/gdb/symfile.h
+Index: gdb-7.4.91.20120801/gdb/symfile.h
===================================================================
---- gdb-7.2.90.20110429.orig/gdb/symfile.h 2011-05-03 05:14:56.000000000 +0200
-+++ gdb-7.2.90.20110429/gdb/symfile.h 2011-05-03 05:14:57.000000000 +0200
-@@ -605,6 +605,13 @@ void free_symfile_segment_data (struct s
+--- 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);
+
/* From dwarf2read.c */
- extern int dwarf2_has_info (struct objfile *);
-Index: gdb-7.2.90.20110429/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-7.2.90.20110429.orig/gdb/testsuite/lib/gdb.exp 2011-05-03 05:14:56.000000000 +0200
-+++ gdb-7.2.90.20110429/gdb/testsuite/lib/gdb.exp 2011-05-03 05:14:57.000000000 +0200
-@@ -1381,6 +1381,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;
}
-Index: gdb-7.2.90.20110429/gdb/testsuite/lib/mi-support.exp
+Index: gdb-7.4.91.20120801/gdb/testsuite/lib/mi-support.exp
===================================================================
---- gdb-7.2.90.20110429.orig/gdb/testsuite/lib/mi-support.exp 2011-03-07 17:03:04.000000000 +0100
-+++ gdb-7.2.90.20110429/gdb/testsuite/lib/mi-support.exp 2011-05-03 05:14:57.000000000 +0200
-@@ -221,6 +221,16 @@ proc default_mi_gdb_start { args } {
- }
- }
+--- 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.."
+ }
+ }
-
- detect_async
-
-Index: gdb-7.2.90.20110429/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.4.91.20120801/gdb/objfiles.h
===================================================================
---- gdb-7.2.90.20110429.orig/gdb/objfiles.h 2011-03-07 17:17:29.000000000 +0100
-+++ gdb-7.2.90.20110429/gdb/objfiles.h 2011-05-03 05:14:57.000000000 +0200
-@@ -441,6 +441,10 @@ struct objfile
+--- 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
- #define OBJF_PSYMTABS_READ (1 << 4)
+ #define OBJF_MAINLINE (1 << 5)
+/* This file was loaded according to the BUILD_ID_CORE_LOADS rules. */
+
/* 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
++}