From dccee2de163c22e9610e9103814d4b93768dd6aa Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 14 Mar 2013 20:26:19 +0000 Subject: [PATCH] * gdb_bfd.c (struct gdb_bfd_data) : New fields. (get_file_crc): Move from symfile.c. (gdb_bfd_crc): New function. * gdb_bfd.h (gdb_bfd_crc): Declare. * objfiles.h (struct objfile) : Remove. * symfile.c (get_file_crc): Move to gdb_bfd.c. (separate_debug_file_exists): Use gdb_bfd_crc. --- gdb/ChangeLog | 11 ++++++++++ gdb/gdb_bfd.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/gdb_bfd.h | 6 ++++++ gdb/objfiles.h | 5 ----- gdb/symfile.c | 49 ++++++------------------------------------ 5 files changed, 81 insertions(+), 48 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1404f25576..cf668375e2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2013-03-14 Tom Tromey + + * gdb_bfd.c (struct gdb_bfd_data) : + New fields. + (get_file_crc): Move from symfile.c. + (gdb_bfd_crc): New function. + * gdb_bfd.h (gdb_bfd_crc): Declare. + * objfiles.h (struct objfile) : Remove. + * symfile.c (get_file_crc): Move to gdb_bfd.c. + (separate_debug_file_exists): Use gdb_bfd_crc. + 2013-03-14 Tom Tromey * symfile.c (get_debug_link_info): Remove. diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index d4540b9e45..53c3a1244e 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -81,6 +81,12 @@ struct gdb_bfd_data /* The mtime of the BFD at the point the cache entry was made. */ time_t mtime; + /* This is true if we have successfully computed the file's CRC. */ + unsigned int crc_computed : 1; + + /* The file's CRC. */ + unsigned long crc; + /* If the BFD comes from an archive, this points to the archive's BFD. Otherwise, this is NULL. */ bfd *archive_bfd; @@ -413,6 +419,58 @@ gdb_bfd_map_section (asection *sectp, bfd_size_type *size) return descriptor->data; } +/* Return 32-bit CRC for ABFD. If successful store it to *FILE_CRC_RETURN and + return 1. Otherwise print a warning and return 0. ABFD seek position is + not preserved. */ + +static int +get_file_crc (bfd *abfd, unsigned long *file_crc_return) +{ + unsigned long file_crc = 0; + + if (bfd_seek (abfd, 0, SEEK_SET) != 0) + { + warning (_("Problem reading \"%s\" for CRC: %s"), + bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ())); + return 0; + } + + for (;;) + { + gdb_byte buffer[8 * 1024]; + bfd_size_type count; + + count = bfd_bread (buffer, sizeof (buffer), abfd); + if (count == (bfd_size_type) -1) + { + warning (_("Problem reading \"%s\" for CRC: %s"), + bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ())); + return 0; + } + if (count == 0) + break; + file_crc = bfd_calc_gnu_debuglink_crc32 (file_crc, buffer, count); + } + + *file_crc_return = file_crc; + return 1; +} + +/* See gdb_bfd.h. */ + +int +gdb_bfd_crc (struct bfd *abfd, unsigned long *crc_out) +{ + struct gdb_bfd_data *gdata = bfd_usrdata (abfd); + + if (!gdata->crc_computed) + gdata->crc_computed = get_file_crc (abfd, &gdata->crc); + + if (gdata->crc_computed) + *crc_out = gdata->crc; + return gdata->crc_computed; +} + /* See gdb_bfd.h. */ diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h index f3ee9ff4d6..1e74bfe608 100644 --- a/gdb/gdb_bfd.h +++ b/gdb/gdb_bfd.h @@ -70,6 +70,12 @@ void gdb_bfd_mark_parent (bfd *child, bfd *parent); const gdb_byte *gdb_bfd_map_section (asection *section, bfd_size_type *size); +/* Compute the CRC for ABFD. The CRC is used to find and verify + separate debug files. When successful, this fills in *CRC_OUT and + returns 1. Otherwise, this issues a warning and returns 0. */ + +int gdb_bfd_crc (struct bfd *abfd, unsigned long *crc_out); + /* A wrapper for bfd_fopen that initializes the gdb-specific reference diff --git a/gdb/objfiles.h b/gdb/objfiles.h index cbfbed222c..9646bbd360 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -259,11 +259,6 @@ struct objfile long mtime; - /* Cached 32-bit CRC as computed by gnu_debuglink_crc32. CRC32 is valid - iff CRC32_P. */ - unsigned long crc32; - int crc32_p; - /* Obstack to hold objects that should be freed when we load a new symbol table from this object file. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 925ca7b9c4..2abe3f8c7d 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1304,43 +1304,6 @@ symbol_file_clear (int from_tty) printf_unfiltered (_("No symbol file now.\n")); } -/* Return 32-bit CRC for ABFD. If successful store it to *FILE_CRC_RETURN and - return 1. Otherwise print a warning and return 0. ABFD seek position is - not preserved. */ - -static int -get_file_crc (bfd *abfd, unsigned long *file_crc_return) -{ - unsigned long file_crc = 0; - - if (bfd_seek (abfd, 0, SEEK_SET) != 0) - { - warning (_("Problem reading \"%s\" for CRC: %s"), - bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ())); - return 0; - } - - for (;;) - { - gdb_byte buffer[8 * 1024]; - bfd_size_type count; - - count = bfd_bread (buffer, sizeof (buffer), abfd); - if (count == (bfd_size_type) -1) - { - warning (_("Problem reading \"%s\" for CRC: %s"), - bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ())); - return 0; - } - if (count == 0) - break; - file_crc = bfd_calc_gnu_debuglink_crc32 (file_crc, buffer, count); - } - - *file_crc_return = file_crc; - return 1; -} - static int separate_debug_file_exists (const char *name, unsigned long crc, struct objfile *parent_objfile) @@ -1390,7 +1353,7 @@ separate_debug_file_exists (const char *name, unsigned long crc, else verified_as_different = 0; - file_crc_p = get_file_crc (abfd, &file_crc); + file_crc_p = gdb_bfd_crc (abfd, &file_crc); gdb_bfd_unref (abfd); @@ -1399,19 +1362,19 @@ separate_debug_file_exists (const char *name, unsigned long crc, if (crc != file_crc) { + unsigned long parent_crc; + /* If one (or both) the files are accessed for example the via "remote:" gdbserver way it does not support the bfd_stat operation. Verify whether those two files are not the same manually. */ - if (!verified_as_different && !parent_objfile->crc32_p) + if (!verified_as_different) { - parent_objfile->crc32_p = get_file_crc (parent_objfile->obfd, - &parent_objfile->crc32); - if (!parent_objfile->crc32_p) + if (!gdb_bfd_crc (parent_objfile->obfd, &parent_crc)) return 0; } - if (verified_as_different || parent_objfile->crc32 != file_crc) + if (verified_as_different || parent_crc != file_crc) warning (_("the debug information found in \"%s\"" " does not match \"%s\" (CRC mismatch).\n"), name, parent_objfile->name); -- 2.34.1