This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/3] gdb: Use bfd size as another cache identification criteria.


Within gdb open bfd objects are reused where possible if an attempt is
made to reopen a file that is already being debugged.  To spot if the on
disc file has changed gdb currently examines the mtime of the file and
compares it to the mtime of the open bfd in the cache.

A problem exists when the on disc file is being rapidly regenerated, as
happens, for example, with automated testing.  In some cases the file is
generated so quickly that the mtime appears not to change, while the on
disc file has changed.

This patch extends the bfd cache to also hold the file size of the bfd,
something which can be cheaply acquired, gdb can then check the mtime
and the file size.  This is still not going to catch every on disc
change, but does increase the probability that a change will be spotted.

OK to apply?
Thanks,
Andrew

gdb/ChangeLog:

	* gdb_bfd.c (struct gdb_bfd_data): Add size field.
	(struct gdb_bfd_cache_search): Likewise.
	(eq_bfd): Compare the size fields.
	(gdb_bfd_open): Initialise the size field.
	(gdb_bfd_ref): Likewise.
	(gdb_bfd_unref): Likewise.
---
 gdb/ChangeLog |  9 +++++++++
 gdb/gdb_bfd.c | 14 +++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8a14194..d79d8e3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2015-04-13  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* gdb_bfd.c (struct gdb_bfd_data): Add size field.
+	(struct gdb_bfd_cache_search): Likewise.
+	(eq_bfd): Compare the size fields.
+	(gdb_bfd_open): Initialise the size field.
+	(gdb_bfd_ref): Likewise.
+	(gdb_bfd_unref): Likewise.
+
 2015-04-11  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	* NEWS (Changes since GDB 7.9): Add removed -xdb.
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 3d5d23f..35c068f 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -68,6 +68,9 @@ struct gdb_bfd_data
   /* The mtime of the BFD at the point the cache entry was made.  */
   time_t mtime;
 
+  /* The file size (in bytes) at the point the cache entry was made.  */
+  off_t size;
+
   /* This is true if we have determined whether this BFD has any
      sections requiring relocation.  */
   unsigned int relocation_computed : 1;
@@ -111,6 +114,8 @@ struct gdb_bfd_cache_search
   const char *filename;
   /* The mtime.  */
   time_t mtime;
+  /* The file size (in bytes).  */
+  off_t size;
 };
 
 /* A hash function for BFDs.  */
@@ -135,6 +140,7 @@ eq_bfd (const void *a, const void *b)
   struct gdb_bfd_data *gdata = bfd_usrdata (abfd);
 
   return (gdata->mtime == s->mtime
+	  && gdata->size == s->size
 	  && strcmp (bfd_get_filename (abfd), s->filename) == 0);
 }
 
@@ -369,9 +375,13 @@ gdb_bfd_open (const char *name, const char *target, int fd)
     {
       /* Weird situation here.  */
       search.mtime = 0;
+      search.size = 0;
     }
   else
-    search.mtime = st.st_mtime;
+    {
+      search.mtime = st.st_mtime;
+      search.size = st.st_size;
+    }
 
   /* Note that this must compute the same result as hash_bfd.  */
   hash = htab_hash_string (name);
@@ -466,6 +476,7 @@ gdb_bfd_ref (struct bfd *abfd)
   gdata = bfd_zalloc (abfd, sizeof (struct gdb_bfd_data));
   gdata->refc = 1;
   gdata->mtime = bfd_get_mtime (abfd);
+  gdata->size = bfd_get_size (abfd);
   gdata->archive_bfd = NULL;
   bfd_usrdata (abfd) = gdata;
 
@@ -506,6 +517,7 @@ gdb_bfd_unref (struct bfd *abfd)
       void **slot;
 
       search.mtime = gdata->mtime;
+      search.size = gdata->size;
       slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash,
 				       NO_INSERT);
 
-- 
2.2.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]