aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdb_bfd.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2013-03-14 20:26:19 +0000
committerTom Tromey <tromey@redhat.com>2013-03-14 20:26:19 +0000
commitdccee2de163c22e9610e9103814d4b93768dd6aa (patch)
tree9ec350d17410647e56d95dd2da419d194e444cd1 /gdb/gdb_bfd.c
parentcc0ea93c7531fe59c4d7d2b01b01acb9bbe0b7fd (diff)
downloadgdb-dccee2de163c22e9610e9103814d4b93768dd6aa.zip
gdb-dccee2de163c22e9610e9103814d4b93768dd6aa.tar.gz
gdb-dccee2de163c22e9610e9103814d4b93768dd6aa.tar.bz2
* gdb_bfd.c (struct gdb_bfd_data) <crc_computed, crc>:
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) <crc32, crc32_p>: Remove. * symfile.c (get_file_crc): Move to gdb_bfd.c. (separate_debug_file_exists): Use gdb_bfd_crc.
Diffstat (limited to 'gdb/gdb_bfd.c')
-rw-r--r--gdb/gdb_bfd.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index d4540b9..53c3a12 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. */