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]

[PATCH v2] Precheck modification time between source and object file before showing source line


When running 'objdump -dlS',
if source file is more recent than object file,
line numbers can't match printed actual source code lines.
So print a warning message in the above case.

binutils/ChangeLog:

    * objdump.c (update_source_path): Check modification time between
    source and object file before opening source file.
    (show_line): Pass an argument for the bfd pointer into update_source_path()
---
 binutils/objdump.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 46b4417..1a3f22b 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1389,12 +1389,24 @@ try_print_file_open (const char *origname, const char *modname)
    If found, add location to print_files linked list.  */
 
 static struct print_file_list *
-update_source_path (const char *filename)
+update_source_path (const char *filename, bfd *abfd)
 {
   struct print_file_list *p;
   const char *fname;
+  struct stat fst, ost;
   int i;
 
+  if (stat (filename, &fst) < 0)
+    return NULL;
+  else
+  {
+    if (bfd_stat (abfd, &ost) < 0)
+      return NULL;
+    if (fst.st_mtime > ost.st_mtime)
+      warn (_("Source file is more recent than object file: %s, %s\n"),
+	    filename, bfd_get_filename (abfd));
+  }
+
   p = try_print_file_open (filename, filename);
   if (p != NULL)
     return p;
@@ -1551,7 +1563,7 @@ show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
 	{
 	  if (reloc)
 	    filename = xstrdup (filename);
-	  p = update_source_path (filename);
+	  p = update_source_path (filename, abfd);
 	}
 
       if (p != NULL && linenumber != p->last_line)
-- 
2.7.4


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