This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

Eliminate bfd_get_mtime hack


This patch eliminates a nasty hack in BFD: when the open files cache
closes a file, it has to stat it and save the mtime.  GDB calls
bfd_get_mtime later to compare with the on-disk mtime.

I wrote this patch originally in November 2006, for Debian.  Alan
added the mtime hack to fix the same problem in 2005.  In hindsight I
can no longer figure out what test case I was fixing that Alan's patch
didn't already cover, but this is clearly the right way to do it: stat
the file when we open it, not later when we want to see if it's
changed.

Any comments on this patch?  Otherwise I'll check it in next week.
Tested on x86_64-linux, no GDB regressions.

-- 
Daniel Jacobowitz
CodeSourcery

2008-02-22  Daniel Jacobowitz  <dan@codesourcery.com>

	* cache.c (close_one): Remove mtime hack.

2008-02-22  Daniel Jacobowitz  <dan@codesourcery.com>

	* corefile.c (reopen_exec_file): Use exec_bfd_mtime.
	* exec.c (exec_bfd_mtime): Define.
	(exec_close): Clear it.
	(exec_file_attach): Set it.
	* gdbcore.h (exec_bfd_mtime): Declare.
	* source.c (find_source_lines): Do not use bfd_get_mtime.

Index: bfd/cache.c
===================================================================
RCS file: /cvs/src/src/bfd/cache.c,v
retrieving revision 1.31
diff -u -p -r1.31 cache.c
--- bfd/cache.c	11 Feb 2008 13:52:02 -0000	1.31
+++ bfd/cache.c	23 Feb 2008 03:05:27 -0000
@@ -166,22 +166,6 @@ close_one (void)
 
   kill->where = real_ftell ((FILE *) kill->iostream);
 
-  /* Save the file st_mtime.  This is a hack so that gdb can detect when
-     an executable has been deleted and recreated.  The only thing that
-     makes this reasonable is that st_mtime doesn't change when a file
-     is unlinked, so saving st_mtime makes BFD's file cache operation
-     a little more transparent for this particular usage pattern.  If we
-     hadn't closed the file then we would not have lost the original
-     contents, st_mtime etc.  Of course, if something is writing to an
-     existing file, then this is the wrong thing to do.
-     FIXME: gdb should save these times itself on first opening a file,
-     and this hack be removed.  */
-  if (kill->direction == no_direction || kill->direction == read_direction)
-    {
-      bfd_get_mtime (kill);
-      kill->mtime_set = TRUE;
-    }
-
   return bfd_cache_delete (kill);
 }
 
Index: gdb/corefile.c
===================================================================
RCS file: /cvs/src/src/gdb/corefile.c,v
retrieving revision 1.42
diff -u -p -r1.42 corefile.c
--- gdb/corefile.c	11 Jan 2008 13:34:14 -0000	1.42
+++ gdb/corefile.c	23 Feb 2008 03:05:28 -0000
@@ -160,10 +160,9 @@ reopen_exec_file (void)
   /* If the timestamp of the exec file has changed, reopen it. */
   filename = xstrdup (bfd_get_filename (exec_bfd));
   make_cleanup (xfree, filename);
-  mtime = bfd_get_mtime (exec_bfd);
   res = stat (filename, &st);
 
-  if (mtime && mtime != st.st_mtime)
+  if (exec_bfd_mtime && exec_bfd_mtime != st.st_mtime)
     exec_file_attach (filename, 0);
 #endif
 }
Index: gdb/exec.c
===================================================================
RCS file: /cvs/src/src/gdb/exec.c,v
retrieving revision 1.70
diff -u -p -r1.70 exec.c
--- gdb/exec.c	11 Jan 2008 13:34:14 -0000	1.70
+++ gdb/exec.c	23 Feb 2008 03:05:28 -0000
@@ -69,6 +69,7 @@ struct target_ops exec_ops;
 /* The Binary File Descriptor handle for the executable file.  */
 
 bfd *exec_bfd = NULL;
+long exec_bfd_mtime = 0;
 
 /* Whether to open exec and core files read-only or read-write.  */
 
@@ -136,6 +137,7 @@ exec_close (int quitting)
 		 name, bfd_errmsg (bfd_get_error ()));
       xfree (name);
       exec_bfd = NULL;
+      exec_bfd_mtime = 0;
     }
 
   if (exec_ops.to_sections)
@@ -260,6 +262,8 @@ exec_file_attach (char *filename, int fr
 		 scratch_pathname, bfd_errmsg (bfd_get_error ()));
 	}
 
+      exec_bfd_mtime = bfd_get_mtime (exec_bfd);
+
       validate_files ();
 
       set_gdbarch_from_file (exec_bfd);
Index: gdb/gdbcore.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbcore.h,v
retrieving revision 1.28
diff -u -p -r1.28 gdbcore.h
--- gdb/gdbcore.h	1 Jan 2008 22:53:10 -0000	1.28
+++ gdb/gdbcore.h	23 Feb 2008 03:05:28 -0000
@@ -116,6 +116,9 @@ extern void specify_exec_file_hook (void
 extern bfd *core_bfd;
 extern bfd *exec_bfd;
 
+/* The mtime when we last opened exec_bfd.  */
+extern long exec_bfd_mtime;
+
 /* Whether to open exec and core files read-only or read-write.  */
 
 extern int write_files;
Index: gdb/source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.84
diff -u -p -r1.84 source.c
--- gdb/source.c	8 Feb 2008 22:20:48 -0000	1.84
+++ gdb/source.c	23 Feb 2008 03:05:28 -0000
@@ -1127,9 +1127,9 @@ find_source_lines (struct symtab *s, int
     perror_with_name (s->filename);
 
   if (s->objfile && s->objfile->obfd)
-    mtime = bfd_get_mtime (s->objfile->obfd);
+    mtime = s->objfile->mtime;
   else if (exec_bfd)
-    mtime = bfd_get_mtime (exec_bfd);
+    mtime = exec_bfd_mtime;
 
   if (mtime && mtime < st.st_mtime)
     warning (_("Source file is more recent than executable."));


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