From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32470 invoked by alias); 23 Nov 2010 16:28:58 -0000 Received: (qmail 32460 invoked by uid 22791); 23 Nov 2010 16:28:56 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 23 Nov 2010 16:28:40 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oANGSdFR011850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Nov 2010 11:28:39 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oANGSc6M006850 for ; Tue, 23 Nov 2010 11:28:38 -0500 Received: from [10.15.16.129] (dhcp-10-15-16-129.yyz.redhat.com [10.15.16.129]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id oANGSc9V006245 for ; Tue, 23 Nov 2010 11:28:38 -0500 Message-ID: <4CEBEBB6.7050502@redhat.com> Date: Tue, 23 Nov 2010 16:28:00 -0000 From: sami wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100806 Fedora/3.1.2-1.fc13 Lightning/1.0b2pre Thunderbird/3.1.2 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [patch 2/2] build id Content-Type: multipart/mixed; boundary="------------020604010502090301060409" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-11/txt/msg00354.txt.bz2 This is a multi-part message in MIME format. --------------020604010502090301060409 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 19 My modifications: --------------020604010502090301060409 Content-Type: text/x-patch; name="build-id-locate-corrections.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="build-id-locate-corrections.patch" Content-length: 8992 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); --------------020604010502090301060409--