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]

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


Andrew,

I modified this PATCH as you said like below.
For now, I'll send v2 with the changes.

If you want to change the warning message format again,
please tell me it! :)

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 6ec79b1..1a3f22b 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1389,7 +1389,7 @@ 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, char *objname)
+update_source_path (const char *filename, bfd *abfd)
 {
   struct print_file_list *p;
   const char *fname;
@@ -1398,11 +1398,13 @@ update_source_path (const char *filename, char *objname)

   if (stat (filename, &fst) < 0)
     return NULL;
-  else {
-    if (stat (objname, &ost) < 0)
+  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\n"));
+      warn (_("Source file is more recent than object file: %s, %s\n"),
+            filename, bfd_get_filename (abfd));
   }

   p = try_print_file_open (filename, filename);
@@ -1561,7 +1563,7 @@ show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
         {
           if (reloc)
             filename = xstrdup (filename);
-          p = update_source_path (filename, bfd_get_filename (abfd));
+          p = update_source_path (filename, abfd);
         }

       if (p != NULL && linenumber != p->last_line)


I tested the warning case after applied v2 as below.

    $ objdump -dlS /home/taeung/workspace/test/a.out
...
  400810:	5d                   	pop    %rbp
  400811:	e9 7a ff ff ff       	jmpq   400790 <register_tm_clones>

0000000000400816 <get_cond_maxprice>:
get_cond_maxprice():
/home/taeung/workspace/test/a.c:26
./objdump: Warning: Source file is more recent than object file: /home/taeung/workspace/test/a.c, /home/taeung/workspace/test/a.out
};

unsigned int limited_wgt;

unsigned int get_cond_maxprice(int wgt, struct jewelry *jewelry)
{
  400816:	55                   	push   %rbp
  400817:	48 89 e5             	mov    %rsp,%rbp
...


Thanks,
Taeung

On 03/12/2017 11:07 PM, Taeung Song wrote:
Hi Andrew,

Sorry for late reply.

On 03/10/2017 07:25 PM, Andrew Burgess wrote:
* Taeung Song <treeze.taeung@gmail.com> [2017-03-10 17:50:43 +0900]:

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 additional argument for object file name
    into update_source_path()
---
 binutils/objdump.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 4609858..237ec45 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1389,12 +1389,22 @@ 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, char *objname)

I wonder if it would be neater to pass the bfd* pointer in here and
then use bfd_stat below?


Okey, I'll use bfd_stat instead of just stat in v2 !

   struct print_file_list *p;
   const char *fname;
+  struct stat fst, ost;
   int i;

+  if (stat (filename, &fst) < 0)
+    return NULL;
+  else {

The '{' needs to move onto the next line, then re-indent the block below.

I got it.

+    if (stat (objname, &ost) < 0)
+      return NULL;
+    if (fst.st_mtime > ost.st_mtime)
+      warn (_("Source file is more recent than object file\n"));

Seems like a good thing to warn about.  How about adding the name of
the source file and object file to the warning?

Thanks,
Andrew


I understood!
What kind of this warning format do you prefer ?

For example, the source file is '/home/taeung/workspace/hello.c' and
the object file is '/home/taeung/workspace/a.out'

  1) just one line
objdump: Warning: Source file is more recent than object file:
'/home/taeung/workspace/hello.c', '/home/taeung/workspace/a.out'

  2) two lines
objdump: Warning: Source file is more recent than object file:
  ('/home/taeung/workspace/hello.c', '/home/taeung/workspace/a.out')

  3) show directly the name of source file and object file
objdump: Warning: '/home/taeung/workspace/hello.c' is more recent than
'/home/taeung/workspace/a.out'

Thanks,
Taeung

+  }
+
   p = try_print_file_open (filename, filename);
   if (p != NULL)
     return p;
@@ -1551,7 +1561,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, bfd_get_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]