Allow the find_abstract_instance_name() function in the BFD library to also return...
authorPaul Carroll <pcarroll@codesourcery.com>
Tue, 6 Feb 2018 15:45:31 +0000 (15:45 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 6 Feb 2018 15:45:31 +0000 (15:45 +0000)
The nm utility supports -l for using debug information to obtain file and line information for each symbol, if available.
We have a tool that consumes this information and displays it.
This identified a problem with the 'nm' utility.

When a source is compiled with -O2, functions can be inlined.  The compiler also produces an uninlined copy of the function, normally for linking to other object files.
In the case of DWARF2 debug information, the compiler generates debug information to describe a function.  If that function is inlined, the compiler then references that debug information from the inlined and uninlined copies of the routine through the use of the DW_AT_abstract_origin reference.
When nm is used on such a file, it is not able to find file and line information because that information is present in the common debug information and not at each actual implementation of the function.
The 'nm' utility only retrieves the name of the function from the abstract origin debug information and no more.

What I am proposing is to modify the find_abstract_instance_name() function (which I renamed to find_abstract_instance() ) to return the name of the function as well as any file and line information.  The routine is already parsing all of the debug information in the abstract instance, so it is easy to pick up the file and line information at that time. If, for some reason, the file and line information is not present, the routine behaves as before.

For example, if I have a simple test case:

int foo(int j)
{
        if (j < 15)
                j += j << 2;
        else
                j += j << 6;
        return j;
}

int main (int argc,char **argv)
{
        int i = argc;
        i += foo(i);
        return i;
}

If that test case is compiled with -O2 and then 'nm -l' reads that executable, it currently produces this symbol output (ignoring a lot of library symbols):

8048400 T foo
080482e0 T main /scratch/pcarroll/its254/test/mytest.c:12

If I modify 'nm' to return file and line information for abstract instances, it produces the following output:

08048400 T foo  /scratch/pcarroll/its254/test/mytest.c:1
080482e0 T main /scratch/pcarroll/its254/test/mytest.c:12
--------------------------------------------------------------------------
bfd * bfd/dwarf2.c (find_abstract_name): Modified to return file and
line information in addition to name, if they can be found.

bfd/ChangeLog
bfd/dwarf2.c

index f6c38443f01b75fe8eb5da65c31f10ccc5036374..72e937391daeefabfe2ac4d62226905b7f2a0618 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-06  Paul Carroll  <pcarroll@codesourcery.com>
+
+       * bfd/dwarf2.c (find_abstract_name): Modified to return file and
+       line information in addition to name, if they can be found.
+
 2018-02-05  Renlin Li  <renlin.li@arm.com>
 
        PR ld/22764
index a4a0dda209ecc1ee6a906b654185a9f8335f3ff1..c027542e50d798b799ff4a1beb14781c5d6b03b2 100644 (file)
@@ -2788,11 +2788,13 @@ lookup_symbol_in_variable_table (struct comp_unit *unit,
 }
 
 static bfd_boolean
-find_abstract_instance_name (struct comp_unit *unit,
-                            bfd_byte *orig_info_ptr,
-                            struct attribute *attr_ptr,
-                            const char **pname,
-                            bfd_boolean *is_linkage)
+find_abstract_instance (struct comp_unit *   unit,
+                       bfd_byte *           orig_info_ptr,
+                       struct attribute *   attr_ptr,
+                       const char **        pname,
+                       bfd_boolean *        is_linkage,
+                       char **              filename_ptr,
+                       int *                linenumber_ptr)
 {
   bfd *abfd = unit->abfd;
   bfd_byte *info_ptr;
@@ -2942,8 +2944,9 @@ find_abstract_instance_name (struct comp_unit *unit,
                    }
                  break;
                case DW_AT_specification:
-                 if (!find_abstract_instance_name (unit, info_ptr, &attr,
-                                                   pname, is_linkage))
+                 if (!find_abstract_instance (unit, info_ptr, &attr,
+                                              pname, is_linkage,
+                                              filename_ptr, linenumber_ptr))
                    return FALSE;
                  break;
                case DW_AT_linkage_name:
@@ -2956,6 +2959,13 @@ find_abstract_instance_name (struct comp_unit *unit,
                      *is_linkage = TRUE;
                    }
                  break;
+               case DW_AT_decl_file:
+                 *filename_ptr = concat_filename (unit->line_table,
+                                                  attr.u.val);
+                 break;
+               case DW_AT_decl_line:
+                 *linenumber_ptr = attr.u.val;
+                 break;
                default:
                  break;
                }
@@ -3148,9 +3158,11 @@ scan_unit_for_symbols (struct comp_unit *unit)
 
                case DW_AT_abstract_origin:
                case DW_AT_specification:
-                 if (!find_abstract_instance_name (unit, info_ptr, &attr,
-                                                   &func->name,
-                                                   &func->is_linkage))
+                 if (!find_abstract_instance (unit, info_ptr, &attr,
+                                              &func->name,
+                                              &func->is_linkage,
+                                              &func->file,
+                                              &func->line))
                    goto fail;
                  break;