Use build id to locate debuginfo and executable files. 2010-11-22 Sami Wagiaalla * solib-svr4.c (svr4_current_sos): Use buildid to set soname. * corelow.c (build_id_locate_exec): New function. (core_open): Use build id to find executable file. (_initialize_corelow): Add build-id-core-loads to show/set list. * elfread.c (build_id_addr_get): New function. (show_build_id_verbose): New funciton. (build_id_buf_get): New function. (build_id_phdr_get): New function. (build_id_bfd_get): Rename this... (build_id_bfd_shdr_get): ...to this. (elf_file_p): New function. (build_id_verify): Updated (find_separate_debug_file_by_buildid): Update. (H_GET_WORD): New. (H_GET_SIGNED_WORD): New. (build_id_to_debug_filename): Rename this to... (build_id_to_filename): ... this. Add and handel add_debug_suffix boolean. (struct missing_filepair): New. (missing_filepair_xcalloc): New. (missing_filepair_hash_func): New. (missing_filepair_eq): New. (missing_filepair_changed): New. (debug_print_executable_changed): New. (debug_print_missing): New. (find_separate_debug_file_by_buildid): Add parameter 'char **build_id_filename_return' (_initialize_elfread): Add build-id-verbose to sho/set list. 2010-11-22 Sami Wagiaalla * gdb.texinfo: Document build-id-verbose. Document build-id-core-loads. 2010-11-22 Sami Wagiaalla * lib/gdb.exp: Test set/show build-id-verbose. * lib/mi-support.exp: Ditto. diff --git a/gdb/corelow.c b/gdb/corelow.c index 9948809..c82dd13 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -278,8 +278,13 @@ add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg) inferior_ptid = ptid; /* Yes, make it current */ } +/* Boolean which indicates whether files associated through build id + with the current core file should be loaded. */ static int build_id_core_loads = 1; +/* Using build_id of the current target find the corresponding executable file, + and set it as the current executable file. */ + static void build_id_locate_exec (int from_tty) { diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index cb19edd..9c05e39 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -15258,6 +15258,27 @@ Show the current verbosity value for the @dfn{build id} content locating. @end table +For corefiles the @dfn{build id} can be used to load the corresponding +executable. This feature can be turned on or off through the following +options: + +@table @code + +@kindex set build-id-core-loads on +@item set build-id-core-loads on +Automatically load files associated with a corefile's build id. + +@kindex set build-id-core-loads off +@item set build-id-core-loads off +Do not load files associated with a corefile's build id. + +@kindex show build-id-core-loads +@item show build-id-core-loads +Show whether @dfn{build id} will be used to load files asscociated with the +corefile being inspected. + +@end table + @cindex @code{.gnu_debuglink} sections @cindex debug link sections A debug link is a special section of the executable file named diff --git a/gdb/elfread.c b/gdb/elfread.c index 903612b..db217dd 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -597,6 +597,9 @@ struct build_id gdb_byte data[1]; }; +/* Scan the given buffer for NT_GNU_BUILD_ID return it its content if found + otherwise return NULL. */ + struct build_id * build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size) { @@ -650,7 +653,10 @@ build_id_bfd_shdr_get (bfd *abfd) return retval; } -/* Core files may have missing (corrupt) SHDR but PDHR is correct there. +/* Starting at program header I_PHDR search each program header for + the one containing build-id. Return it if found otherwise return + NULL. + 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. */ @@ -682,7 +688,7 @@ build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum, return retval; } -/* First we validate the file by reading in the ELF header and checking +/* Validate the file by reading in the ELF header and checking the magic number. */ static inline bfd_boolean @@ -708,6 +714,9 @@ elf_file_p (Elf64_External_Ehdr *x_ehdrp64) #define H_GET_SIGNED_WORD(bfd, ptr) (is64 ? H_GET_S64 (bfd, (ptr)) \ : H_GET_S32 (bfd, (ptr))) +/* Translate an ELF header table entry in external format into an ELF header + table entry in internal format. */ + static void elf_swap_ehdr_in (bfd *abfd, const Elf64_External_Ehdr *src64, @@ -776,6 +785,9 @@ elf_swap_phdr_in (bfd *abfd, #undef H_GET_SIGNED_WORD #undef H_GET_WORD +/* Get an array of program file headers of TEMPL. Store the number of + headers in address pointed to by E_PHNUM_POINTER. */ + static Elf_Internal_Phdr * elf_get_phdr (bfd *templ, bfd_vma ehdr_vma, unsigned *e_phnum_pointer, bfd_vma *loadbase_pointer) @@ -933,6 +945,8 @@ struct build_id_addr_sect }; static struct build_id_addr_sect *build_id_addr_sect; +/* Construct a list of candidate sections which can contain build-id. */ + static void build_id_addr_candidate (bfd *abfd, asection *sect, void *obj) { if (build_id_addr >= bfd_section_vma (abfd, sect)) @@ -946,6 +960,8 @@ static void build_id_addr_candidate (bfd *abfd, asection *sect, void *obj) } } +/* Find and return the build_id for the object file containing ADDR. */ + struct build_id * build_id_addr_get (CORE_ADDR addr) { @@ -1023,6 +1039,9 @@ build_id_verify (const char *filename, struct build_id *check) return retval; } +/* Return the file name of the debug info file or executable associated with + BUILD_ID. If ADD_DEBUG_SUFFIX is false do not append the .debug suffix. */ + char * build_id_to_filename (struct build_id *build_id, char **link_return, int add_debug_suffix) @@ -1136,6 +1155,8 @@ struct missing_filepair static struct htab *missing_filepair_hash; static struct obstack missing_filepair_obstack; +/* Allocate a missing_filepair entry. */ + static void * missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size) { @@ -1147,6 +1168,8 @@ missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size) return retval; } +/* Hash function for missing_filepair. */ + static hashval_t missing_filepair_hash_func (const struct missing_filepair *elem) { @@ -1159,6 +1182,8 @@ missing_filepair_hash_func (const struct missing_filepair *elem) return retval; } +/* Comparison function for missing_filepair. */ + static int missing_filepair_eq (const struct missing_filepair *elem1, const struct missing_filepair *elem2) @@ -1168,8 +1193,10 @@ missing_filepair_eq (const struct missing_filepair *elem1, && (elem1->debug == NULL || strcmp (elem1->debug, elem2->debug) == 0); } +/* Free missing_filepair obstack. */ + static void -missing_filepair_change (void) +missing_filepair_changed (void) { if (missing_filepair_hash != NULL) { @@ -1182,7 +1209,7 @@ missing_filepair_change (void) static void debug_print_executable_changed (void) { - missing_filepair_change (); + missing_filepair_changed (); } /* Notify user the file BINARY with (possibly NULL) associated separate debug @@ -1258,6 +1285,8 @@ debug_print_missing (const char *binary, const char *debug) debug); } +/* Using the build id of OBJFILE find its separate debug info file. */ + static char * find_separate_debug_file_by_buildid (struct objfile *objfile, char **build_id_filename_return) diff --git a/gdb/exec.c b/gdb/exec.c index de0c459..1dfa253 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -177,15 +177,16 @@ exec_file_clear (int from_tty) printf_unfiltered (_("No executable file now.\n")); } -/* Set FILENAME as the new exec file. +/* Set FILENAME as the new exec file. Open and process the give + executable file. - This function is intended to be behave essentially the same + This function is intended to behave essentially the same as exec_file_command, except that the latter will detect when a target is being debugged, and will ask the user whether it should be shut down first. (If the answer is "no", then the new file is ignored.) - This file is used by exec_file_command, to do the work of opening + This function is used by exec_file_command, to do the work of opening and processing the exec file after any prompting has happened. And, it is used by child_attach, when the attach command was diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 1f40d25..df60943 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1179,6 +1179,8 @@ svr4_current_sos (void) safe_strerror (errcode)); else { + /* Set so_name using build_id. */ + struct build_id *build_id; strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);