This is the mail archive of the binutils@sources.redhat.com 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 for binutils bfd/dwarf2.c.


What follows is a patch for binutils bfd/dwarf2.c.
-Nathan Tallent


Description:
------------
lookup_address_in_line_info_table:
In the case that the function is found but a line number is not for a given
vma, this routine currently returns the line number and filename of the
most recently examined vma, if available.  (This is supposed to be tailored
for GCC 2.95.)  However, because the list is searched 'backwards', if the
vma is not found then at the end of the search the most recently examined
vma will be near the beginning of the function.  This behavior can result
in bogus line number reporting for non-GCC compiled binaries.  I have
changed the function to instead report the filename and linenumber of the
*nearest* vma in the case that an exact match is not found.


Testing and testcases: 
----------------------
I have tested this code on binaries compiled with GCC 2.95 and source line
reporting is unchanged.  In addition, the change improves source line
reporting on other binaries in the small number of cases that it is
executed.

I have run the binutils regression tests with and without my changes and
the results are the same.

Our tests: We are using bintuils as the binary reader for a program
that performs source code structure recovery on binaries from a number of
different platforms.  (We esp. focus on loop recovery for scientific
programs.) This program is also a cross-tool and we have successfully
tested these changes (and a number of others to follow eventually) on a
number of different binaries (from GNU and non-GNU compilers) and
platforms.

hosts (all of which are enabled on each platform)
  mips64-sgi-irix6
  alpha-*-linux-gnu, alpha-*-osf
  sparc32-*-elf, sparc64-*-solaris2
  i386-*-linux-gnu
  ia64-*-linux-gnu


ChangeLog:
----------
2002-09-25  Nathan Tallent  <eraxxon@alumni.rice.edu>

 * dwarf2.c (lookup_address_in_line_info_table): In the case
 that the function is found but a line number is not for a given
 vma, return the filename and linenumber of the *nearest* vma
 instead of most recently examined vma.


Patch: bfd/dwarf2.c
(created with 'cvs diff -c3p' against cvs repository on 9/25/02)
------

Index: dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.36
diff -c -3 -p -r1.36 dwarf2.c
*** dwarf2.c 24 Sep 2002 07:11:16 -0000 1.36
--- dwarf2.c 25 Sep 2002 12:13:30 -0000
*************** lookup_address_in_line_info_table (table
*** 1252,1262 ****
--- 1252,1268 ----
    struct line_info* next_line = table->last_line;
    struct line_info* each_line;
  
+   struct line_info* closest_line_by_vma;  /* eraxxon: see comments below. */
+   bfd_vma vma_min_delta, vma_delta;
+ 
    if (!next_line)
      return false;
  
    each_line = next_line->prev_line;
  
+   closest_line_by_vma = next_line;   /* eraxxon: see comments below. */
+   vma_min_delta = labs((long) (next_line->address - addr));
+   
    while (each_line && next_line)
      {
        if (!each_line->end_sequence
*************** lookup_address_in_line_info_table (table
*** 1280,1285 ****
--- 1286,1299 ----
       }
     return true;
   }
+       /* eraxxon: see comments below */
+       vma_delta = labs((long) (each_line->address - addr));
+       if (vma_delta < vma_min_delta)
+  {
+    vma_min_delta = vma_delta;
+    closest_line_by_vma = each_line;
+  }
+ 
        next_line = each_line;
        each_line = each_line->prev_line;
      }
*************** lookup_address_in_line_info_table (table
*** 1287,1296 ****
    /* At this point each_line is NULL but next_line is not.  If we found the
       containing function in this compilation unit, return the first line we
       have a number for.  This is also for compatibility with GCC 2.95.  */
    if (function != NULL)
      {
!       *filename_ptr = next_line->filename;
!       *linenumber_ptr = next_line->line;
        return true;
      }
  
--- 1301,1319 ----
    /* At this point each_line is NULL but next_line is not.  If we found the
       containing function in this compilation unit, return the first line we
       have a number for.  This is also for compatibility with GCC 2.95.  */
+ 
+   /* eraxxon@alumni.rice.edu: This can result in bogus line numbers for
+      non-GCC compiled binaries. If we must return a line number when the
+      function has been found, wouldn't it be better to return the line
+      number with the vma closest to 'addr'? */
+   
    if (function != NULL)
      {
!       /* *filename_ptr = next_line->filename; */
!       /* *linenumber_ptr = next_line->line; */
! 
!       *filename_ptr = closest_line_by_vma->filename;
!       *linenumber_ptr = closest_line_by_vma->line;
        return true;
      }
  



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