summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2025-03-10 19:09:27 +0100
committerMark Wielaard <[email protected]>2025-03-11 10:54:22 +0100
commit66ae4b7ed9fd8dfd95c1276e752b279fc1aad996 (patch)
tree9fc4d41e0ca46d638bb98b1133443f3dc9fd9109 /tests
parentcbfa885f32a8e18a679f530a8a9910f6cb262273 (diff)
readelf: Add support for printing DW_AT_language_name DW_LNAMEs
Add a testfile using GCC 15 (experimental). * libdw/dwarf.h: Add DW_LNAME_lo_user and DW_LNAME_hi_user. * src/readelf.c (dwarf_lname_string): New function. (dwarf_lname_name): Likewise. (attr_callback): Handle DW_AT_language_name by calling dwarf_lname_name. * run-readelf-lnames.sh: New test. * testfile-lnames.bz2: New testfile. * tests/Makefile.am (TESTS): Add run-readelf-lnames.sh. (EXTRA_DIST): Add run-readelf-lnames.sh and testfile-lnames.bz2. Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rwxr-xr-xtests/run-readelf-lnames.sh92
-rwxr-xr-xtests/testfile-lnames.bz2bin0 -> 2717 bytes
3 files changed, 94 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bf5a9b22..f53fd926 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -165,6 +165,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
run-test-flag-nobits.sh run-prelink-addr-test.sh \
run-dwarf-getstring.sh run-rerequest_tag.sh run-typeiter.sh \
run-readelf-d.sh run-readelf-gdb_index.sh run-unstrip-n.sh \
+ run-readelf-lnames.sh \
run-low_high_pc.sh run-macro-test.sh run-elf_cntl_gelf_getshdr.sh \
run-test-archive64.sh run-readelf-vmcoreinfo.sh \
run-readelf-mixed-corenote.sh run-dwfllines.sh \
@@ -451,6 +452,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
run-typeiter.sh testfile59.bz2 \
run-readelf-d.sh testlib_dynseg.so.bz2 \
run-readelf-Dd.sh \
+ run-readelf-lnames.sh testfile-lnames.bz2 \
testfile-s390x-hash-both.bz2 \
run-readelf-gdb_index.sh testfilegdbindex5.bz2 \
testfilegdbindex7.bz2 testfilegdbindex9.bz2 \
diff --git a/tests/run-readelf-lnames.sh b/tests/run-readelf-lnames.sh
new file mode 100755
index 00000000..0f5d874d
--- /dev/null
+++ b/tests/run-readelf-lnames.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 2025 Mark J. Wielaard <[email protected]>
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# Using GCC 15.0.1 20250310 (experimental)
+#
+# echo "void foo () { }" | g++ -g -c -x c++ -std=c++20 - -o cpp.o
+# echo "int main () { }" | gcc -g -c -x c -std=c23 - -o c.o
+# gcc -g -o testfile-lnames cpp.o c.o
+#
+# Note this version outputs an older DW_AT_language you need to
+# see the DW_AT_language_version to see the real std used.
+
+testfiles testfile-lnames
+
+testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile-lnames <<\EOF
+
+DWARF section [28] '.debug_info' at offset 0x3314:
+ [Offset]
+ Compilation unit at offset 0:
+ Version: 5, Abbreviation section offset: 0, Address size: 8, Offset size: 4
+ Unit type: compile (1)
+ [ c] compile_unit abbrev: 1
+ producer (strp) "GNU C++20 15.0.1 20250310 (experimental) -mtune=generic -march=x86-64 -g -std=c++20"
+ language (data1) C_plus_plus_14 (33)
+ language_name (data1) C_plus_plus (4)
+ language_version (data4) 202002
+ name (line_strp) "<stdin>"
+ comp_dir (line_strp) "/tmp"
+ low_pc (addr) 0x0000000000401106 <_Z3foov>
+ high_pc (data8) 7 (0x000000000040110d <main>)
+ stmt_list (sec_offset) 0
+ [ 33] subprogram abbrev: 2
+ external (flag_present) yes
+ name (string) "foo"
+ decl_file (data1) <stdin> (1)
+ decl_line (data1) 1
+ decl_column (data1) 6
+ linkage_name (strp) "_Z3foov"
+ low_pc (addr) 0x0000000000401106 <_Z3foov>
+ high_pc (data8) 7 (0x000000000040110d <main>)
+ frame_base (exprloc)
+ [ 0] call_frame_cfa
+ call_all_calls (flag_present) yes
+ Compilation unit at offset 82:
+ Version: 5, Abbreviation section offset: 51, Address size: 8, Offset size: 4
+ Unit type: compile (1)
+ [ 5e] compile_unit abbrev: 1
+ producer (strp) "GNU C23 15.0.1 20250310 (experimental) -mtune=generic -march=x86-64 -g -std=c23"
+ language (data1) C11 (29)
+ language_name (data1) C (3)
+ language_version (data4) 202311
+ name (line_strp) "<stdin>"
+ comp_dir (line_strp) "/tmp"
+ low_pc (addr) 0x000000000040110d <main>
+ high_pc (data8) 11 (0x0000000000401118 <_fini>)
+ stmt_list (sec_offset) 76
+ [ 85] subprogram abbrev: 2
+ external (flag_present) yes
+ name (strp) "main"
+ decl_file (data1) <stdin> (1)
+ decl_line (data1) 1
+ decl_column (data1) 5
+ prototyped (flag_present) yes
+ type (ref4) [ a3]
+ low_pc (addr) 0x000000000040110d <main>
+ high_pc (data8) 11 (0x0000000000401118 <_fini>)
+ frame_base (exprloc)
+ [ 0] call_frame_cfa
+ call_all_calls (flag_present) yes
+ [ a3] base_type abbrev: 3
+ byte_size (data1) 4
+ encoding (data1) signed (5)
+ name (string) "int"
+EOF
+
+exit 0
diff --git a/tests/testfile-lnames.bz2 b/tests/testfile-lnames.bz2
new file mode 100755
index 00000000..4ce4d179
--- /dev/null
+++ b/tests/testfile-lnames.bz2
Binary files differ