简体   繁体   中英

How to decode a debug_line section?

I'm trying to figure out how a DWARF 2 debug_line section is encoded. The standard paper ( http://www.dwarfstd.org/doc/dwarf-2.0.0.pdf ) isn't much helpful to me and I really don't understand how something like the following:

    .4byte  .debug_line
    .4byte  0x736e7502, 0x656e6769, 0x6e692064, 0x04070074

represents something. There's the "unsigned int" string encoded there but the 0x02 value before it.. what does that represent? I can't even find a standard enum/define header with the DWARF 2 constants.. can someone shed some light on how to parse a debug_line in DWARF 2?

I know, it's quite ancient question, but there might be someone who will be looking for a way to read .debug_line section. I found that readelf is able to parse it:

readelf --debug-dump=line <path/to/binary>

(or)

readelf --debug-dump=decodedline <path/to/binary>

First shows you interpreted .debug_line content as appears in Elf binary. Second composes all data into more structured view, in respect with references between different records given in particular .debug_line unit.

Also there is a tool dwarfdump (available in Ubuntu repos), but I did not have a chance to check it.

If the DWARF standard isn't helping then all I can really suggest is reading some source code that implements .debug_line parsing. Maybe that will be more clear; or maybe reading it in conjunction with the DWARF standard will help. There are plenty of readers for this information; a relatively simple one is in the GNU binutils; grab the source and look for .debug_line decoding in "bfd/dwarf2.c".

As for a standard header, binutils also includes a dwarf2.h. But you are right -- I don't think there is a standard header, rather various projects (binutils, elfutils, libdwarf, probably others) make their own headers, generally derived from the DWARF spec.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM