It is sometimes useful to read .debug_line tables on their own without
having an associated CU DIE. DWARF5 line tables are self-contained.
Adjust dwarf_begin_elf to accept ELF files with just a .debug_line.
Add a new function dwarf_next_lines that returns the Dwarf_Files and
Dwarf_Lines while iterating over just the .debug_lines section. Since
we parse and cache the information it also will try to match the CU
a table is associated with. This is only necessary for DWARF4 line
tables (we will need at least the compilation dir from the CU) and
won't be done for DWARF5 line tables. It also isn't an error if there
is no associated CU (but will mean for DWARF4 line tables the dir list
and the file paths might not be complete).
A typical way to call this new function is:
Dwarf_Off off, next_off = 0;
Dwarf_CU *cu = NULL;
Dwarf_Files *files;
size_t nfiles;
Dwarf_Lines *lines;
size_t nlines;
int res;
while ((res = dwarf_next_lines (dbg, off = next_off, &next_off, &cu,
&files, &nfiles, &lines, &nlines)) == 0)
{
/* ... handle files and lines ... */
}
if (res < 0)
printf ("BAD dwarf_next_lines: %s\n", dwarf_errmsg (-1));
See libdw.h for the full documentation. For more examples on how to use
the function see the new testcases next-files and next-lines.
Also adjust the file paths for line tables missing a comp_dir.
They are no longer made "absolute" by prepending a slash '/' in front
of them. This really was not useful and didn't happen in any of the
testcases. They are now just kept relative.
Make eu-readelf --debug-dump=decodedline use dwarf_next_lines instead
of iterating over the CUs to show the (decoded) line tables. This allows
it to show decoded line tables even if there is no .debug_info section.
New tests have been added that mimic the get-files and get-lines tests
but use dwarf_next_lines instead of iterating over all CUs. They produce
identical output (modulo the CU information). Also add a new test file
that contains only a .debug_line section.
Signed-off-by: Mark Wielaard
---
libdw/ChangeLog| 12 +++
libdw/Makefile.am | 3 +-
libdw/dwarf_begin_elf.c| 21 ++--
libdw/dwarf_getsrclines.c | 16 +--
libdw/dwarf_next_lines.c | 197 +
libdw/libdw.h | 18
libdw/libdw.map| 5 +
src/ChangeLog | 6 ++
src/readelf.c | 78 ---
tests/ChangeLog| 14 +++
tests/Makefile.am | 7 +-
tests/next-files.c | 93 +
tests/next-lines.c | 144 +++
tests/run-next-files.sh| 165 +++
tests/run-next-lines.sh| 116 ++
tests/testfile-only-debug-line.bz2 | Bin 0 -> 2514 bytes
16 files changed, 833 insertions(+), 62 deletions(-)
create mode 100644 libdw/dwarf_next_lines.c
create mode 100644 tests/next-files.c
create mode 100644 tests/next-lines.c
create mode 100755 tests/run-next-files.sh
create mode 100755 tests/run-next-lines.sh
create mode 100644 tests/testfile-only-debug-line.bz2
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 4280c55..4148a44 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,15 @@
+2018-06-25 Mark Wielaard
+
+ * Makefile.am (libdw_a_SOURCES): Add dwarf_next_lines.c.
+ * libdw.h (dwarf_next_lines): New function declaration.
+ * libdw.map (ELFUTILS_0.173): New section.
+ * dwarf_next_lines.c: New files.
+ * dwarf_begin_elf.c (check_section): Don't error out when elf
+ decompression fails.
+ (valid_p): Allow just a single .debug_line section.
+ * dwarf_getsrclines.c (read_srclines): Keep files relative if comp_dir
+ is missing.
+
2018-06-18 Mark Wielaard
* dwarf_aggregate_size.c (array_size): New depth argument. Use
diff --git a/libdw/Makefile.am b/libdw/Makefile.am
index 41df4f3..7a3d532 100644
--- a/libdw/Makefile.am
+++ b/libdw/Makefile.am
@@ -91,7 +91,8 @@ libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c
dwarf_getelf.c \
dwarf_getalt.c dwarf_setalt.c dwarf_cu_getdwarf.c \
dwarf_cu_die.c dwarf_peel_type.c dwarf_default_lower_bound.c \
dwarf_die_addr_die.c dwarf_get_units.c \
- libdw_find_split_unit.c dwarf_cu_info.c
+ libdw_find_split_unit.c dwarf_cu_info.c \
+ dwarf_next_lines.c
if MAINTAINER_MODE
BUILT_SOURCES = $(srcdir)/known-dwarf.h
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index 513af2b..e1542c7 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -156,17 +156,9 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn
*scn, bool inscngrp)
{
if (elf_compress (scn, 0, 0) < 0)