summaryrefslogtreecommitdiff
path: root/libdw/dwarf_begin_elf.c
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-06-22 22:44:51 +0200
committerMark Wielaard <mark@klomp.org>2018-06-29 10:22:51 +0200
commit2ee84b2ca8b2da2bc4ad5663babfa25d97aa85b4 (patch)
tree4d0858c6896050b169d77d7211b8f4d94109a209 /libdw/dwarf_begin_elf.c
parente3b2060bb6a687587500c8d6c74145ef1d320c5c (diff)
downloadelfutils-2ee84b2ca8b2da2bc4ad5663babfa25d97aa85b4.tar.gz
libdw: Add dwarf_next_lines to read .debug_line tables without CUs.
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 <mark@klomp.org>
Diffstat (limited to 'libdw/dwarf_begin_elf.c')
-rw-r--r--libdw/dwarf_begin_elf.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index 513af2b1..e1542c75 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)
{
- /* If we failed to decompress the section and it's the
- debug_info section, then fail with specific error rather
- than the generic NO_DWARF. Without debug_info we can't do
- anything (see also valid_p()). */
- if (cnt == IDX_debug_info)
- {
- Dwarf_Sig8_Hash_free (&result->sig8_hash);
- __libdw_seterrno (DWARF_E_COMPRESSED_ERROR);
- free (result);
- return NULL;
- }
+ /* It would be nice if we could fail with a specific error.
+ But we don't know if this was an essential section or not.
+ So just continue for now. See also valid_p(). */
return result;
}
}
@@ -214,11 +206,10 @@ valid_p (Dwarf *result)
/* We looked at all the sections. Now determine whether all the
sections with debugging information we need are there.
- XXX Which sections are absolutely necessary? Add tests if
- necessary. For now we require only .debug_info. Hopefully this
- is correct. */
+ Require at least one section that can be read "standalone". */
if (likely (result != NULL)
- && unlikely (result->sectiondata[IDX_debug_info] == NULL))
+ && unlikely (result->sectiondata[IDX_debug_info] == NULL
+ && result->sectiondata[IDX_debug_line] == NULL))
{
Dwarf_Sig8_Hash_free (&result->sig8_hash);
__libdw_seterrno (DWARF_E_NO_DWARF);