This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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 3/5] readelf: Print actual file for decl_file and call_file attributes.


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                   |  5 +++++
 src/readelf.c                   | 22 ++++++++++++++++++++++
 tests/ChangeLog                 |  5 +++++
 tests/run-readelf-dwz-multi.sh  | 32 ++++++++++++++++----------------
 tests/run-readelf-zdebug-rel.sh | 10 +++++-----
 5 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index e7e598d..12cd571 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
 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.
 
 2017-11-29  Mark Wielaard  <mark@klomp.org>
diff --git a/src/readelf.c b/src/readelf.c
index e9887c4..8661ba8 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -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;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index f522a69..c9fc53a 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,10 @@
 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.
 	* run-readelf-zdebug-rel.sh: Likewise.
 
diff --git a/tests/run-readelf-dwz-multi.sh b/tests/run-readelf-dwz-multi.sh
index 21456fd..4f317ac 100755
--- a/tests/run-readelf-dwz-multi.sh
+++ b/tests/run-readelf-dwz-multi.sh
@@ -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) 
diff --git a/tests/run-readelf-zdebug-rel.sh b/tests/run-readelf-zdebug-rel.sh
index 93201ae..2b57d05 100755
--- a/tests/run-readelf-zdebug-rel.sh
+++ b/tests/run-readelf-zdebug-rel.sh
@@ -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) 
-- 
1.8.3.1


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