From: Mark Wielaard Date: Wed, 29 Nov 2017 15:06:36 +0000 (+0100) Subject: readelf: Print actual file for decl_file and call_file attributes. X-Git-Tag: elfutils-0.171~101 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d5b99ee3b4a2fd0ca989fe42f3ab6b3ac328a414;p=thirdparty%2Felfutils.git 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 --- diff --git a/src/ChangeLog b/src/ChangeLog index e7e598d16..12cd5710d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2017-11-29 Mark Wielaard + + * 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 * readelf.c (print_debug_units): Print abbrev code after DIE tag. diff --git a/src/readelf.c b/src/readelf.c index e9887c457..8661ba83c 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 f522a69e3..c9fc53ab4 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2017-11-29 Mark Wielaard + + * run-readelf-dwz-multi.sh: Add expected file names. + * run-readelf-zdebug-rel.sh: Likewise. + 2017-11-29 Mark Wielaard * run-readelf-dwz-multi.sh: Add expected abbrev codes. diff --git a/tests/run-readelf-dwz-multi.sh b/tests/run-readelf-dwz-multi.sh index 21456fdf1..4f317ac9a 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 93201aee2..2b57d0581 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)