diff options
| author | Mark Wielaard <[email protected]> | 2018-05-06 00:33:27 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2018-05-11 16:42:57 +0200 |
| commit | 982b6fe9e31683607d476d7f90d1b56cbb78aa21 (patch) | |
| tree | 7d19fa0c71053dcf39aa79ca68bf5cfe7dddb02a /tests | |
| parent | ce50fccb956238ed7a536397633edb2cc5294627 (diff) | |
libdw: Handle DWARF5 line tables in dwarf_getsrclines.
In DWARF5 the actual line number table format doesn't change, except for
not allowing DW_LNE_define_file (but we still just accept it). The
changes are the header having new fields for address and segment
selector sizes, and new formats for the directory and file names tables.
The directory and file name tables are much more flexible in DWARF5, but
we only interpret the actual names and file/dir index relationships,
skipping/ignoring any other information. There also is no new interface
yet to get at the new directory and file properties.
There is some small confusion about the file name table indexing. Older
DWARF versions explicitly called the first file name table 1. DWARF5
implies the first index is 0 (but for file attributes, zero means not
associated with a file). We get away with that by having an actual zero
index for older DWARF versions (the null_fill). It looks like gcc gets
around it by explicitly duplicating the first (0) and second (1) file
name entry in the table. This can also be seen in the new testcase.
The patch looks big because of moving a few initializations around
and because the code that is different for older/newer DWARF got moved
under if statements. But the original old DWARF code path didn't really
change.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ChangeLog | 10 | ||||
| -rw-r--r-- | tests/Makefile.am | 2 | ||||
| -rwxr-xr-x | tests/run-readelf-line.sh | 163 | ||||
| -rwxr-xr-x | tests/testfile-dwarf-4.bz2 | bin | 0 -> 4304 bytes | |||
| -rw-r--r-- | tests/testfile-dwarf-45.source | 81 | ||||
| -rwxr-xr-x | tests/testfile-dwarf-5.bz2 | bin | 0 -> 4318 bytes |
6 files changed, 256 insertions, 0 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 14159d80..8a098b4c 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,13 @@ +2018-05-05 Mark Wielaard <[email protected]> + + * testfile-dwarf-45.source: New file. + * testfile-dwarf-4.bz2: New test file. + * testfile-dwarf-5.bz2: Likewise. + * run-readelf-line.sh: Add testcases for testfile-dwarf-4 and + testfile-dwarf-5. + * Makefile (EXTRA_DIST): Add testfile-dwarf-45.source, + testfile-dwarf-4.bz2 and testfile-dwarf-5.bz2. + 2018-04-19 Andreas Schwab <[email protected]> * hello_riscv64.ko.bz2: New file. diff --git a/tests/Makefile.am b/tests/Makefile.am index 6b1356e9..2f9ae237 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -231,6 +231,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-readelf-loc.sh testfileloc.bz2 \ run-readelf-aranges.sh run-readelf-line.sh testfilefoobarbaz.bz2 \ testfile-ppc64-min-instr.bz2 \ + testfile-dwarf-45.source \ + testfile-dwarf-4.bz2 testfile-dwarf-5.bz2 \ run-readelf-z.sh \ run-readelf-dwz-multi.sh libtestfile_multi_shared.so.bz2 \ testfile_multi.dwz.bz2 testfile_multi_main.bz2 \ diff --git a/tests/run-readelf-line.sh b/tests/run-readelf-line.sh index f93bf47d..b08752ee 100755 --- a/tests/run-readelf-line.sh +++ b/tests/run-readelf-line.sh @@ -345,4 +345,167 @@ DWARF section [29] '.debug_line' at offset 0xdf6: 8:3 S * 0 0 0 0x00000000100005f7 <main+0x53> EOF + +# Two tests for the same code but encoded using DWARF4 or DWARF5. +# Output is identical except for the section offset and CU numbers. +# See tests/testfile-dwarf-45.source. + +testfiles testfile-dwarf-4 testfile-dwarf-5 + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=decodedline testfile-dwarf-4 << \EOF + +DWARF section [29] '.debug_line' at offset 0x1734: + + CU [b] hello.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /var/tmp/hello/hello.c (mtime: 0, length: 0) + 21:0 S 0 0 0 0x0000000000400510 <foo> + 22:1 S 0 0 0 0x0000000000400510 <foo> + 22:3 0 0 0 0x0000000000400510 <foo> + 25:6 0 0 0 0x0000000000400514 <foo+0x4> + 25:34 S 0 0 0 0x000000000040051a <foo+0xa> + 25:3 0 0 0 0x000000000040051a <foo+0xa> + 26:34 0 0 0 0x000000000040051e <foo+0xe> + 25:1 1 0 0 0x0000000000400528 <foo+0x18> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 7:18 S 0 0 0 0x000000000040052b <foo+0x1b> + 9:3 S 0 0 0 0x000000000040052b <foo+0x1b> + 9:3 0 0 0 0x000000000040052b <foo+0x1b> + 10:6 S 0 0 0 0x000000000040052f <foo+0x1f> + 10:5 0 0 0 0x000000000040052f <foo+0x1f> + 12:7 S 0 0 0 0x0000000000400531 <foo+0x21> + /var/tmp/hello/hello.c (mtime: 0, length: 0) + 10:3 S 0 0 0 0x0000000000400531 <foo+0x21> + 12:3 S 0 0 0 0x0000000000400531 <foo+0x21> + 12:3 0 0 0 0x0000000000400531 <foo+0x21> + 13:6 S 0 0 0 0x0000000000400535 <foo+0x25> + 13:5 0 0 0 0x0000000000400535 <foo+0x25> + 15:7 S 0 0 0 0x0000000000400539 <foo+0x29> + 22:3 S 0 0 0 0x0000000000400539 <foo+0x29> + 22:3 0 0 0 0x0000000000400539 <foo+0x29> + 23:6 S 0 0 0 0x000000000040053d <foo+0x2d> + 23:5 0 0 0 0x000000000040053d <foo+0x2d> + 9:12 S 0 0 0 0x0000000000400550 <baz> + 10:1 S 0 0 0 0x0000000000400550 <baz> + 12:3 S 0 0 0 0x0000000000400550 <baz> + 12:3 0 0 0 0x0000000000400550 <baz> + 13:9 0 0 0 0x0000000000400556 <baz+0x6> + 15:7 S 0 0 0 0x000000000040055f <baz+0xf> + 15:3 0 0 0 0x000000000040055f <baz+0xf> + 15:7 * 0 0 0 0x0000000000400560 <baz+0x10> + + CU [21c] world.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /var/tmp/hello/world.c (mtime: 0, length: 0) + 15:0 S 0 0 0 0x0000000000400410 <main> + 16:1 S 0 0 0 0x0000000000400410 <main> + 17:3 S 0 0 0 0x0000000000400410 <main> + 15:3 0 0 0 0x0000000000400410 <main> + 17:1 0 0 0 0x0000000000400419 <main+0x9> + 18:6 S 0 0 0 0x000000000040041e <main+0xe> + 18:5 0 0 0 0x000000000040041e <main+0xe> + 22:7 S 0 0 0 0x0000000000400421 <main+0x11> + 22:3 S * 0 0 0 0x000000000040042f <main+0x1f> + + 6:0 S 0 0 0 0x0000000000400570 <calc> + 7:1 S 0 0 0 0x0000000000400570 <calc> + 7:3 0 0 0 0x0000000000400570 <calc> + 7:6 1 0 0 0x0000000000400575 <calc+0x5> + 7:24 0 0 0 0x0000000000400578 <calc+0x8> + 10:17 S 0 0 0 0x000000000040057d <calc+0xd> + 10:3 0 0 0 0x000000000040057d <calc+0xd> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 10:10 0 0 0 0x0000000000400583 <calc+0x13> + /var/tmp/hello/world.c (mtime: 0, length: 0) + 10:7 0 0 0 0x0000000000400585 <calc+0x15> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 7:10 S 0 0 0 0x0000000000400588 <calc+0x18> + 9:3 S 0 0 0 0x0000000000400588 <calc+0x18> + 10:3 0 0 0 0x0000000000400588 <calc+0x18> + 12:7 S 0 0 0 0x000000000040058f <calc+0x1f> + 12:3 0 0 0 0x000000000040058f <calc+0x1f> + /var/tmp/hello/world.c (mtime: 0, length: 0) + 11:10 0 0 0 0x0000000000400598 <calc+0x28> + 11:1 * 0 0 0 0x000000000040059a <calc+0x2a> + +EOF + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=decodedline testfile-dwarf-5 << \EOF + +DWARF section [29] '.debug_line' at offset 0x171f: + + CU [c] hello.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /var/tmp/hello/hello.c (mtime: 0, length: 0) + 21:0 S 0 0 0 0x0000000000400510 <foo> + 22:1 S 0 0 0 0x0000000000400510 <foo> + 22:3 0 0 0 0x0000000000400510 <foo> + 25:6 0 0 0 0x0000000000400514 <foo+0x4> + 25:34 S 0 0 0 0x000000000040051a <foo+0xa> + 25:3 0 0 0 0x000000000040051a <foo+0xa> + 26:34 0 0 0 0x000000000040051e <foo+0xe> + 25:1 1 0 0 0x0000000000400528 <foo+0x18> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 7:18 S 0 0 0 0x000000000040052b <foo+0x1b> + 9:3 S 0 0 0 0x000000000040052b <foo+0x1b> + 9:3 0 0 0 0x000000000040052b <foo+0x1b> + 10:6 S 0 0 0 0x000000000040052f <foo+0x1f> + 10:5 0 0 0 0x000000000040052f <foo+0x1f> + 12:7 S 0 0 0 0x0000000000400531 <foo+0x21> + /var/tmp/hello/hello.c (mtime: 0, length: 0) + 10:3 S 0 0 0 0x0000000000400531 <foo+0x21> + 12:3 S 0 0 0 0x0000000000400531 <foo+0x21> + 12:3 0 0 0 0x0000000000400531 <foo+0x21> + 13:6 S 0 0 0 0x0000000000400535 <foo+0x25> + 13:5 0 0 0 0x0000000000400535 <foo+0x25> + 15:7 S 0 0 0 0x0000000000400539 <foo+0x29> + 22:3 S 0 0 0 0x0000000000400539 <foo+0x29> + 22:3 0 0 0 0x0000000000400539 <foo+0x29> + 23:6 S 0 0 0 0x000000000040053d <foo+0x2d> + 23:5 0 0 0 0x000000000040053d <foo+0x2d> + 9:12 S 0 0 0 0x0000000000400550 <baz> + 10:1 S 0 0 0 0x0000000000400550 <baz> + 12:3 S 0 0 0 0x0000000000400550 <baz> + 12:3 0 0 0 0x0000000000400550 <baz> + 13:9 0 0 0 0x0000000000400556 <baz+0x6> + 15:7 S 0 0 0 0x000000000040055f <baz+0xf> + 15:3 0 0 0 0x000000000040055f <baz+0xf> + 15:7 * 0 0 0 0x0000000000400560 <baz+0x10> + + CU [218] world.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /var/tmp/hello/world.c (mtime: 0, length: 0) + 15:0 S 0 0 0 0x0000000000400410 <main> + 16:1 S 0 0 0 0x0000000000400410 <main> + 17:3 S 0 0 0 0x0000000000400410 <main> + 15:3 0 0 0 0x0000000000400410 <main> + 17:1 0 0 0 0x0000000000400419 <main+0x9> + 18:6 S 0 0 0 0x000000000040041e <main+0xe> + 18:5 0 0 0 0x000000000040041e <main+0xe> + 22:7 S 0 0 0 0x0000000000400421 <main+0x11> + 22:3 S * 0 0 0 0x000000000040042f <main+0x1f> + + 6:0 S 0 0 0 0x0000000000400570 <calc> + 7:1 S 0 0 0 0x0000000000400570 <calc> + 7:3 0 0 0 0x0000000000400570 <calc> + 7:6 1 0 0 0x0000000000400575 <calc+0x5> + 7:24 0 0 0 0x0000000000400578 <calc+0x8> + 10:17 S 0 0 0 0x000000000040057d <calc+0xd> + 10:3 0 0 0 0x000000000040057d <calc+0xd> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 10:10 0 0 0 0x0000000000400583 <calc+0x13> + /var/tmp/hello/world.c (mtime: 0, length: 0) + 10:7 0 0 0 0x0000000000400585 <calc+0x15> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 7:10 S 0 0 0 0x0000000000400588 <calc+0x18> + 9:3 S 0 0 0 0x0000000000400588 <calc+0x18> + 10:3 0 0 0 0x0000000000400588 <calc+0x18> + 12:7 S 0 0 0 0x000000000040058f <calc+0x1f> + 12:3 0 0 0 0x000000000040058f <calc+0x1f> + /var/tmp/hello/world.c (mtime: 0, length: 0) + 11:10 0 0 0 0x0000000000400598 <calc+0x28> + 11:1 * 0 0 0 0x000000000040059a <calc+0x2a> + +EOF + exit 0 diff --git a/tests/testfile-dwarf-4.bz2 b/tests/testfile-dwarf-4.bz2 Binary files differnew file mode 100755 index 00000000..fd3aaea5 --- /dev/null +++ b/tests/testfile-dwarf-4.bz2 diff --git a/tests/testfile-dwarf-45.source b/tests/testfile-dwarf-45.source new file mode 100644 index 00000000..c9c44463 --- /dev/null +++ b/tests/testfile-dwarf-45.source @@ -0,0 +1,81 @@ +# Nonsensical program used to generate an example DWARF4 and DWARF5 file. +# The generated code is the same, but the DWARF representation is different. + +# = hello.h = + +extern int m; +extern int baz (int x); + +static inline int +frob (int a, int b) +{ + int c = a; + + if (a > b) + c -= b; + + return baz (c); +} + +# = hello.c = + +#include <stddef.h> +#include "hello.h" + +extern int main (int, char **); +int m = 2; + +wchar_t foo (wchar_t); +int baz (int x) +{ + int r = x; + + if (x > m) + r -= m; + + r = foo (r); + return r; +} + +wchar_t +foo (wchar_t f) +{ + if (f < 0) + return main (f, NULL); + + return f > 0 ? frob (f - 1, m) : 0; +} + +# = world.c = + +#include "hello.h" +#include <stdlib.h> + +int +calc (const char *word) +{ + if (word == 0 || word[0] == '\0') + return 0; + + return frob (word[0], m + 42); +} + +int +main (int argc, const char **argv) +{ + const char *n; + if (argc > 1) + n = argv[0]; + else + n = "world"; + + exit (calc (n)); +} + +$ gcc -gdwarf-4 -gno-as-loc-support -gno-variable-location-views -O2 -c world.c +$ gcc -gdwarf-4 -gno-as-loc-support -gno-variable-location-views -O2 -c hello.c +$ gcc -o testfile-dwarf-4 hello.o world.o + +$ gcc -gdwarf-5 -gno-as-loc-support -gno-variable-location-views -O2 -c world.c +$ gcc -gdwarf-5 -gno-as-loc-support -gno-variable-location-views -O2 -c hello.c +$ gcc -o testfile-dwarf-5 hello.o world.o diff --git a/tests/testfile-dwarf-5.bz2 b/tests/testfile-dwarf-5.bz2 Binary files differnew file mode 100755 index 00000000..689fa4fc --- /dev/null +++ b/tests/testfile-dwarf-5.bz2 |
