From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8218 invoked by alias); 11 Dec 2009 10:41:02 -0000 Received: (qmail 8208 invoked by uid 22791); 11 Dec 2009 10:41:01 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Dec 2009 10:40:56 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 9427729000D for ; Fri, 11 Dec 2009 11:40:54 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IvzXTv6J2Ylu for ; Fri, 11 Dec 2009 11:40:53 +0100 (CET) Received: from ulanbator.act-europe.fr (ulanbator.act-europe.fr [10.10.1.67]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id BD02A29001E for ; Fri, 11 Dec 2009 11:40:53 +0100 (CET) From: Tristan Gingold Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: [RFA] Move buildid stuff from symfile.c to elfread.c Date: Fri, 11 Dec 2009 10:41:00 -0000 Message-Id: <81FAA351-3C2E-4023-B373-5078D9D66A4A@adacore.com> To: gdb-patches ml Mime-Version: 1.0 (Apple Message framework v1077) 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: 2009-12/txt/msg00161.txt.bz2 Hi, the build-id feature is only available on ELF platforms and only used by elfread.c. As previously discussed, this patch moves the associated functi= ons from symfile.c to elfread.c I have also added a new function, protocol_bfd_open to make common an idiom used 3 times. I haven't found a better name but suggrestions are very welcome. No sepdebug.exp regressions on i386/linux. Tristan. 2009-12-11 Tristan Gingold * symfile.h (find_separate_debug_file_by_buildid): Remove prototype. (protocol_bfd_open): New prototype. * symfile.c (protocol_bfd_open): New function. (separate_debug_file_exists, reread_symbols): Use it. (struct build_id, build_id_bfd_get, build_id_verify) (build_id_to_debug_filename) (find_separate_debug_file_by_buildid): Move these ... * elfread.c (struct build_id) (build_id_bfd_get, build_id_verify, build_id_to_debug_filename) (find_separate_debug_file_by_buildid): ... here. --- gdb/elfread.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++ gdb/symfile.c | 177 +++++------------------------------------------------= ---- gdb/symfile.h | 4 +- 3 files changed, 168 insertions(+), 164 deletions(-) diff --git a/gdb/elfread.c b/gdb/elfread.c index a47e687..a00ac6e 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -568,6 +568,157 @@ elf_symtab_read (struct objfile *objfile, int type, } } =20 +struct build_id + { + size_t size; + gdb_byte data[1]; + }; + +/* Locate NT_GNU_BUILD_ID from ABFD and return its content. */ + +static struct build_id * +build_id_bfd_get (bfd *abfd) +{ + struct build_id *retval; + + if (!bfd_check_format (abfd, bfd_object) + || bfd_get_flavour (abfd) !=3D bfd_target_elf_flavour + || elf_tdata (abfd)->build_id =3D=3D NULL) + return NULL; + + retval =3D xmalloc (sizeof *retval - 1 + elf_tdata (abfd)->build_id_size= ); + retval->size =3D elf_tdata (abfd)->build_id_size; + memcpy (retval->data, elf_tdata (abfd)->build_id, retval->size); + + return retval; +} + +/* Return if FILENAME has NT_GNU_BUILD_ID matching the CHECK value. */ + +static int +build_id_verify (const char *filename, struct build_id *check) +{ + bfd *abfd; + struct build_id *found =3D NULL; + int retval =3D 0; + + /* We expect to be silent on the non-existing files. */ + abfd =3D protocol_bfd_open (filename); + if (abfd =3D=3D NULL) + return 0; + + found =3D build_id_bfd_get (abfd); + + if (found =3D=3D NULL) + warning (_("File \"%s\" has no build-id, file skipped"), filename); + else if (found->size !=3D check->size + || memcmp (found->data, check->data, found->size) !=3D 0) + warning (_("File \"%s\" has a different build-id, file skipped"), file= name); + else + retval =3D 1; + + if (!bfd_close (abfd)) + warning (_("cannot close \"%s\": %s"), filename, + bfd_errmsg (bfd_get_error ())); + + xfree (found); + + return retval; +} + +static char * +build_id_to_debug_filename (struct build_id *build_id) +{ + char *link, *debugdir, *retval =3D NULL; + + /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */ + link =3D alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" -= 1) + 1 + + 2 * build_id->size + (sizeof ".debug" - 1) + 1); + + /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will + cause "/.build-id/..." lookups. */ + + debugdir =3D debug_file_directory; + do + { + char *s, *debugdir_end; + gdb_byte *data =3D build_id->data; + size_t size =3D build_id->size; + + while (*debugdir =3D=3D DIRNAME_SEPARATOR) + debugdir++; + + debugdir_end =3D strchr (debugdir, DIRNAME_SEPARATOR); + if (debugdir_end =3D=3D NULL) + debugdir_end =3D &debugdir[strlen (debugdir)]; + + memcpy (link, debugdir, debugdir_end - debugdir); + s =3D &link[debugdir_end - debugdir]; + s +=3D sprintf (s, "/.build-id/"); + if (size > 0) + { + size--; + s +=3D sprintf (s, "%02x", (unsigned) *data++); + } + if (size > 0) + *s++ =3D '/'; + while (size-- > 0) + s +=3D sprintf (s, "%02x", (unsigned) *data++); + strcpy (s, ".debug"); + + /* lrealpath() is expensive even for the usually non-existent files.= */ + if (access (link, F_OK) =3D=3D 0) + retval =3D lrealpath (link); + + if (retval !=3D NULL && !build_id_verify (retval, build_id)) + { + xfree (retval); + retval =3D NULL; + } + + if (retval !=3D NULL) + break; + + debugdir =3D debugdir_end; + } + while (*debugdir !=3D 0); + + return retval; +} + +static char * +find_separate_debug_file_by_buildid (struct objfile *objfile) +{ + asection *sect; + char *basename, *name_copy, *debugdir; + char *dir =3D NULL; + char *debugfile =3D NULL; + char *canon_name =3D NULL; + bfd_size_type debuglink_size; + unsigned long crc32; + int i; + struct build_id *build_id; + + build_id =3D build_id_bfd_get (objfile->obfd); + if (build_id !=3D NULL) + { + char *build_id_name; + + build_id_name =3D build_id_to_debug_filename (build_id); + xfree (build_id); + /* Prevent looping on a stripped .debug file. */ + if (build_id_name !=3D NULL && strcmp (build_id_name, objfile->name)= =3D=3D 0) + { + warning (_("\"%s\": separate debug info file has no debug info"), + build_id_name); + xfree (build_id_name); + } + else if (build_id_name !=3D NULL) + return build_id_name; + } + return NULL; +} + /* Scan and build partial symbols for a symbol file. We have been initialized by a call to elf_symfile_init, which=20 currently does nothing. diff --git a/gdb/symfile.c b/gdb/symfile.c index 10733d7..e81802a 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1137,127 +1137,6 @@ symbol_file_clear (int from_tty) printf_unfiltered (_("No symbol file now.\n")); } =20 -struct build_id - { - size_t size; - gdb_byte data[1]; - }; - -/* Locate NT_GNU_BUILD_ID from ABFD and return its content. */ - -static struct build_id * -build_id_bfd_get (bfd *abfd) -{ - struct build_id *retval; - - if (!bfd_check_format (abfd, bfd_object) - || bfd_get_flavour (abfd) !=3D bfd_target_elf_flavour - || elf_tdata (abfd)->build_id =3D=3D NULL) - return NULL; - - retval =3D xmalloc (sizeof *retval - 1 + elf_tdata (abfd)->build_id_size= ); - retval->size =3D elf_tdata (abfd)->build_id_size; - memcpy (retval->data, elf_tdata (abfd)->build_id, retval->size); - - return retval; -} - -/* Return if FILENAME has NT_GNU_BUILD_ID matching the CHECK value. */ - -static int -build_id_verify (const char *filename, struct build_id *check) -{ - bfd *abfd; - struct build_id *found =3D NULL; - int retval =3D 0; - - /* We expect to be silent on the non-existing files. */ - if (remote_filename_p (filename)) - abfd =3D remote_bfd_open (filename, gnutarget); - else - abfd =3D bfd_openr (filename, gnutarget); - if (abfd =3D=3D NULL) - return 0; - - found =3D build_id_bfd_get (abfd); - - if (found =3D=3D NULL) - warning (_("File \"%s\" has no build-id, file skipped"), filename); - else if (found->size !=3D check->size - || memcmp (found->data, check->data, found->size) !=3D 0) - warning (_("File \"%s\" has a different build-id, file skipped"), file= name); - else - retval =3D 1; - - if (!bfd_close (abfd)) - warning (_("cannot close \"%s\": %s"), filename, - bfd_errmsg (bfd_get_error ())); - - xfree (found); - - return retval; -} - -static char * -build_id_to_debug_filename (struct build_id *build_id) -{ - char *link, *debugdir, *retval =3D NULL; - - /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */ - link =3D alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" -= 1) + 1 - + 2 * build_id->size + (sizeof ".debug" - 1) + 1); - - /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will - cause "/.build-id/..." lookups. */ - - debugdir =3D debug_file_directory; - do - { - char *s, *debugdir_end; - gdb_byte *data =3D build_id->data; - size_t size =3D build_id->size; - - while (*debugdir =3D=3D DIRNAME_SEPARATOR) - debugdir++; - - debugdir_end =3D strchr (debugdir, DIRNAME_SEPARATOR); - if (debugdir_end =3D=3D NULL) - debugdir_end =3D &debugdir[strlen (debugdir)]; - - memcpy (link, debugdir, debugdir_end - debugdir); - s =3D &link[debugdir_end - debugdir]; - s +=3D sprintf (s, "/.build-id/"); - if (size > 0) - { - size--; - s +=3D sprintf (s, "%02x", (unsigned) *data++); - } - if (size > 0) - *s++ =3D '/'; - while (size-- > 0) - s +=3D sprintf (s, "%02x", (unsigned) *data++); - strcpy (s, ".debug"); - - /* lrealpath() is expensive even for the usually non-existent files.= */ - if (access (link, F_OK) =3D=3D 0) - retval =3D lrealpath (link); - - if (retval !=3D NULL && !build_id_verify (retval, build_id)) - { - xfree (retval); - retval =3D NULL; - } - - if (retval !=3D NULL) - break; - - debugdir =3D debugdir_end; - } - while (*debugdir !=3D 0); - - return retval; -} - static char * get_debug_link_info (struct objfile *objfile, unsigned long *crc32_out) { @@ -1308,10 +1187,7 @@ separate_debug_file_exists (const char *name, unsign= ed long crc, if (strcmp (name, parent_objfile->name) =3D=3D 0) return 0; =20 - if (remote_filename_p (name)) - abfd =3D remote_bfd_open (name, gnutarget); - else - abfd =3D bfd_openr (name, gnutarget); + abfd =3D protocol_bfd_open (name); =20 if (!abfd) return 0; @@ -1367,39 +1243,6 @@ The directory where separate debug symbols are searc= hed for is \"%s\".\n"), #endif =20 char * -find_separate_debug_file_by_buildid (struct objfile *objfile) -{ - asection *sect; - char *basename, *name_copy, *debugdir; - char *dir =3D NULL; - char *debugfile =3D NULL; - char *canon_name =3D NULL; - bfd_size_type debuglink_size; - unsigned long crc32; - int i; - struct build_id *build_id; - - build_id =3D build_id_bfd_get (objfile->obfd); - if (build_id !=3D NULL) - { - char *build_id_name; - - build_id_name =3D build_id_to_debug_filename (build_id); - xfree (build_id); - /* Prevent looping on a stripped .debug file. */ - if (build_id_name !=3D NULL && strcmp (build_id_name, objfile->name)= =3D=3D 0) - { - warning (_("\"%s\": separate debug info file has no debug info"), - build_id_name); - xfree (build_id_name); - } - else if (build_id_name !=3D NULL) - return build_id_name; - } - return NULL; -} - -char * find_separate_debug_file_by_debuglink (struct objfile *objfile) { asection *sect; @@ -1605,6 +1448,19 @@ set_initial_language (void) } } =20 +/* If NAME is a remote name open the file using remote protocol, otherwise + open it normaly. */ + +bfd * +protocol_bfd_open (const char *name) +{ + if (remote_filename_p (name)) + return remote_bfd_open (name, gnutarget); + else + return bfd_openr (name, gnutarget); +} + + /* Open the file specified by NAME and hand it off to BFD for preliminary analysis. Return a newly initialized bfd *, which includes a newly malloc'd` copy of NAME (tilde-expanded and made @@ -2381,10 +2237,7 @@ reread_symbols (void) if (!bfd_close (objfile->obfd)) error (_("Can't close BFD for %s: %s"), objfile->name, bfd_errmsg (bfd_get_error ())); - if (remote_filename_p (obfd_filename)) - objfile->obfd =3D remote_bfd_open (obfd_filename, gnutarget); - else - objfile->obfd =3D bfd_openr (obfd_filename, gnutarget); + objfile->obfd =3D protocol_bfd_open (obfd_filename); if (objfile->obfd =3D=3D NULL) error (_("Can't open %s to read symbols."), objfile->name); else diff --git a/gdb/symfile.h b/gdb/symfile.h index a9c5608..6445298 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -241,8 +241,6 @@ extern struct objfile *symbol_file_add_from_bfd (bfd *,= int, extern void symbol_file_add_separate (bfd *bfd, int symfile_flags, struct objfile *objfile); =20 -extern char *find_separate_debug_file_by_buildid (struct objfile *objfile); - extern char *find_separate_debug_file_by_debuglink (struct objfile *objfil= e); =20 /* Create a new section_addr_info, with room for NUM_SECTIONS. */ @@ -324,6 +322,8 @@ extern void find_lowest_section (bfd *, asection *, voi= d *); =20 extern bfd *symfile_bfd_open (char *); =20 +extern bfd *protocol_bfd_open (const char *); + extern int get_section_index (struct objfile *, char *); =20 /* Utility functions for overlay sections: */ --=20 1.6.4