On Mon, 2018-06-25 at 15:12 +0200, Mark Wielaard wrote: > 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.
Initial testing seems to indicate that it works as expected. Pushed to git master. Cheers, Mark