]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Print actual file for decl_file and call_file attributes.
authorMark Wielaard <mark@klomp.org>
Wed, 29 Nov 2017 15:06:36 +0000 (16:06 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 29 Nov 2017 15:45:18 +0000 (16:45 +0100)
When we see a DW_AT_decl_file or DW_AT_call_file attribute print the
actual file name. The current interface gives us a full (absolute) patch,
but we only want to show the file name for now to not clutter the output
too much. This helps a lot when trying to determine where something was
declared if you are just looking at the DIE tree. Otherwise you'll have
to cross match the number by hand with the corresponding line table entry.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c
tests/ChangeLog
tests/run-readelf-dwz-multi.sh
tests/run-readelf-zdebug-rel.sh

index e7e598d16fb1c126e810a9d2d128362ddf1c8aa0..12cd5710d2d82dfc9be5b474bfe65b3ab0b24aa6 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
+       * readelf.c (attr_callback): Set valuestr to resolved file name
+       for DW_AT_decl_file and DW_AT_call_file.
+
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (print_debug_units): Print abbrev code after DIE tag.
index e9887c457b7b4649370f3c3d71682081725a7c97..8661ba83c62ccaeb3a775934b9f4bce2a60a72b0 100644 (file)
@@ -6126,6 +6126,28 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
        case DW_AT_discr_list:
          valuestr = dwarf_discr_list_name (num);
          break;
+       case DW_AT_decl_file:
+       case DW_AT_call_file:
+         {
+           /* Try to get the actual file, the current interface only
+              gives us full paths, but we only want to show the file
+              name for now.  */
+           Dwarf_Die cudie;
+           if (dwarf_cu_die (cbargs->cu, &cudie,
+                             NULL, NULL, NULL, NULL, NULL, NULL) != NULL)
+             {
+               Dwarf_Files *files;
+               size_t nfiles;
+               if (dwarf_getsrcfiles (&cudie, &files, &nfiles) == 0)
+                 {
+                   valuestr = dwarf_filesrc (files, num, NULL, NULL);
+                   char *filename = strrchr (valuestr, '/');
+                   if (filename != NULL)
+                     valuestr = filename + 1;
+                 }
+             }
+         }
+         break;
        default:
          /* Nothing.  */
          break;
index f522a69e358d4986f5c94d1537e840828775d2ab..c9fc53ab4c10f55d6243273e86e8d90cf085ba0d 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
+       * run-readelf-dwz-multi.sh: Add expected file names.
+       * run-readelf-zdebug-rel.sh: Likewise.
+
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
        * run-readelf-dwz-multi.sh: Add expected abbrev codes.
index 21456fdf1f5b40d94f0613631ddbb63bbfecebf0..4f317ac9ab111d1234f2f1cf927f0041be4de8cb 100755 (executable)
@@ -100,7 +100,7 @@ DWARF section [28] '.debug_info' at offset 0x1078:
  [    31]    subprogram           abbrev: 3
              external             (flag_present) yes
              name                 (strp) "main"
-             decl_file            (data1) 1
+             decl_file            (data1) main.c (1)
              decl_line            (data1) 3
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    3e]
@@ -112,21 +112,21 @@ DWARF section [28] '.debug_info' at offset 0x1078:
              sibling              (ref_udata) [    6e]
  [    48]      formal_parameter     abbrev: 8
                name                 (strp) "argc"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    3e]
                location             (exprloc) 
                 [ 0] fbreg -36
  [    56]      formal_parameter     abbrev: 4
                name                 (strp) "argv"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 3
                type                 (ref_udata) [    6e]
                location             (exprloc) 
                 [ 0] fbreg -48
  [    61]      variable             abbrev: 7
                name                 (string) "b"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 5
                type                 (GNU_ref_alt) [    5a]
                location             (exprloc) 
@@ -161,7 +161,7 @@ DWARF section [28] '.debug_info' at offset 0x1078:
  [    31]    subprogram           abbrev: 3
              external             (flag_present) yes
              name                 (strp) "main"
-             decl_file            (data1) 1
+             decl_file            (data1) main.c (1)
              decl_line            (data1) 3
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    3e]
@@ -173,21 +173,21 @@ DWARF section [28] '.debug_info' at offset 0x1078:
              sibling              (ref_udata) [    6e]
  [    48]      formal_parameter     abbrev: 8
                name                 (strp) "argc"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    3e]
                location             (exprloc) 
                 [ 0] fbreg -36
  [    56]      formal_parameter     abbrev: 4
                name                 (strp) "argv"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 3
                type                 (ref_udata) [    6e]
                location             (exprloc) 
                 [ 0] fbreg -48
  [    61]      variable             abbrev: 7
                name                 (string) "b"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 5
                type                 (GNU_ref_alt) [    5a]
                location             (exprloc) 
@@ -218,7 +218,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
  [    2b]    subprogram           abbrev: 1
              external             (flag_present) yes
              name                 (strp) "call_foo"
-             decl_file            (data1) 1
+             decl_file            (data1) shared.c (1)
              decl_line            (data1) 3
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    3e]
@@ -229,7 +229,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
              GNU_all_call_sites   (flag_present) yes
  [    41]      formal_parameter     abbrev: 4
                name                 (string) "fb"
-               decl_file            (data1) 1
+               decl_file            (data1) shared.c (1)
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    76]
                location             (exprloc) 
@@ -258,7 +258,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
  [    2b]    subprogram           abbrev: 1
              external             (flag_present) yes
              name                 (strp) "call_foo"
-             decl_file            (data1) 1
+             decl_file            (data1) shared.c (1)
              decl_line            (data1) 3
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    3e]
@@ -269,7 +269,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
              GNU_all_call_sites   (flag_present) yes
  [    41]      formal_parameter     abbrev: 4
                name                 (string) "fb"
-               decl_file            (data1) 1
+               decl_file            (data1) shared.c (1)
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    76]
                location             (exprloc) 
@@ -297,7 +297,7 @@ DWARF section [28] '.debug_info' at offset 0x1088:
  [    2b]    subprogram           abbrev: 4
              external             (flag_present) yes
              name                 (GNU_strp_alt) "main"
-             decl_file            (data1) 1
+             decl_file            (data1) main.c (1)
              decl_line            (data1) 8
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    30]
@@ -308,21 +308,21 @@ DWARF section [28] '.debug_info' at offset 0x1088:
              GNU_all_call_sites   (flag_present) yes
  [    41]      formal_parameter     abbrev: 1
                name                 (GNU_strp_alt) "argc"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 8
                type                 (GNU_ref_alt) [    30]
                location             (exprloc) 
                 [ 0] fbreg -36
  [    4f]      formal_parameter     abbrev: 1
                name                 (GNU_strp_alt) "argv"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 8
                type                 (GNU_ref_alt) [    41]
                location             (exprloc) 
                 [ 0] fbreg -48
  [    5d]      variable             abbrev: 3
                name                 (string) "fbb"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 10
                type                 (GNU_ref_alt) [    14]
                location             (exprloc) 
index 93201aee2c4ae1c2f2759b88b79bdb9f0de59b94..2b57d05817bdb484b558d4475122e91d79952b0a 100755 (executable)
@@ -62,7 +62,7 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
  [    2d]    subprogram           abbrev: 2
              external             (flag_present) yes
              name                 (strp) "main"
-             decl_file            (data1) 1
+             decl_file            (data1) testfile-zdebug-rel.c (1)
              decl_line            (data1) 4
              prototyped           (flag_present) yes
              type                 (ref4) [    80]
@@ -74,26 +74,26 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
              sibling              (ref4) [    80]
  [    4e]      formal_parameter     abbrev: 3
                name                 (strp) "argc"
-               decl_file            (data1) 1
+               decl_file            (data1) testfile-zdebug-rel.c (1)
                decl_line            (data1) 4
                type                 (ref4) [    80]
                location             (sec_offset) location list [     0]
  [    5d]      formal_parameter     abbrev: 4
                name                 (strp) "argv"
-               decl_file            (data1) 1
+               decl_file            (data1) testfile-zdebug-rel.c (1)
                decl_line            (data1) 4
                type                 (ref4) [    87]
                location             (exprloc) 
                 [ 0] reg4
  [    6a]      variable             abbrev: 5
                name                 (string) "a"
-               decl_file            (data1) 1
+               decl_file            (data1) testfile-zdebug-rel.c (1)
                decl_line            (data1) 6
                type                 (ref4) [    9a]
                const_value          (sdata) -9
  [    74]      variable             abbrev: 6
                name                 (string) "b"
-               decl_file            (data1) 1
+               decl_file            (data1) testfile-zdebug-rel.c (1)
                decl_line            (data1) 7
                type                 (ref4) [    9a]
                location             (exprloc)