开发者

How does objdump manage to display source code with the -S option?

Is there a reference to the source file in the binary? I tried running strings on the binar开发者_开发百科y and couldn't find any reference to the source file listed...


objdump uses the DWARF debugging information compiled into the binary, which references the source file name. objdump tries to open the named source file to load the source and display it in the output. If the binary isn't compiled with debugging information, or objdump can't find the source file, then you don't get source code in your output - only assembly.

You don't see the source file name when you use strings on the binary, because DWARF uses compression.


The dwarf information in a binary stores the mapping between instructions(the instruction pointer or IP actually) and the source file and line number. The source file is specified using the complete path so it can be found even if the binary is moved around. To see this information you can use objdump --dwarf=decodedline <binary> (the binary ofcourse has to be compiled with -g).

Once you say objdump -S <binary> it use this dwarf info to give you source code along with the disassembly.


My understanding is that for objdump to display source code from the binary code, there is a precondition: the DWARF debugging information must be compiled into the binary. (by gcc -g sourcefile or gcc -gdwarf-2 sourcefile) And by processing this DWARF information objdump is able to get the source code as @vlcekmi3 and @vkrnt answered

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜