[PATCH] decoded output of .debug_line from readelf -wL

Nick Clifton nickc@redhat.com
Fri Apr 11 09:05:00 GMT 2008


Hi Torleif,

> So 0 means the compilation directory and directory indices start counting at 1.
> 
> I think I got it right this time

Close, but still no banana.  Cary was correct.  You need to subtract one 
from the directory index, once you have deduced that the index must be 
used.  (This is because although the directory indicies start counting 
from 1 in DWARF, in C they start counting from 0).  ie this:

       /* The directory index starts counting at 1 */
       printf (_("\n%s/%s:\n"),
               directory_table[file_table[
                   state_machine_regs.file - 1].directory_index],
               file_table[state_machine_regs.file - 1].name);

should actually be:

       /* The directory index starts counting at 1 */
       printf (_("\n%s/%s:\n"),
               directory_table[file_table[
                   state_machine_regs.file - 1].directory_index - 1],
               file_table[state_machine_regs.file - 1].name);


You can see this for yourself if you run the patched readelf.  I tried 
it (using the readelf executable as the test case) and your code was 
telling me that, for example, lines were coming from:

   /work/sources/binutils/current/binutils/ia64.h:

which does not exist, whereas the corrected version shows:

   /work/sources/binutils/current/binutils/../include/elf/ia64.h:

which is right.


Anyway to save you some time I have applied your patch, along with this 
correction, and another fix.  (You forgot to implement the long version 
of the command line switch, ie --debug-debug=decodedline).  I also 
created a ChangeLog entry for you and fixed up the formatting problems.

Thanks very much for working on this patch and submitting it.

Cheers
   Nick

PS. Some ideas for the future:

   * Add a testcase or two to check the behaviour of the new feature.

   * Find ways to reduce the verbosity of the output.  For example when 
the same line number appears twice in succession, you could only emit it 
once, followed by multiple addresses.  Or you could pre-scan the line 
number information and then only emit each line number once, along with 
the full set of address range(s) that it covers.

binutils/ChangeLog
2008-04-11  Torleif Sandnes  <torleif.sandnes@gmail.com>

	* dwarf.c (display_debug_lines): Rename to
	display_debug_lines_raw.
	(display_debug_lines_decoded): New function.  Displays the
	interpreted contents of a .debug_line section.
	(display_debug_lines): New function: Selects either a raw dump or
	a decoded dump (or both) as requested by the user.
	* dwarf.h (do_debug_lines_decoded): New extern.
	* readelf.c: Add support for -wL or --debug-dump=decodedline
	option to display the decoded contents of a .debug_line section.
	* doc/binutils.texi: Document the new option.
	* NEWS: Mention the new feature.



More information about the Binutils mailing list