objdump 如何使用 -S 选项来显示源代码?
二进制文件中是否有对源文件的引用?我尝试在二进制文件上运行字符串,但找不到对列出的源文件的任何引用...
Is there a reference to the source file in the binary? I tried running strings on the binary and couldn't find any reference to the source file listed...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
objdump
使用编译到二进制文件中的 DWARF 调试信息,该信息引用源文件名。objdump
尝试打开指定的源文件以加载源并将其显示在输出中。如果二进制文件未使用调试信息进行编译,或者 objdump 找不到源文件,则您不会在仅输出的程序集中获得源代码。当您在二进制文件上使用
strings
时,您看不到源文件名,因为 DWARF 使用压缩。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, orobjdump
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.二进制文件中的矮信息存储了指令(指令指针或实际上的IP)与源文件和行号之间的映射。源文件是使用完整路径指定的,因此即使二进制文件被移动也可以找到它。要查看此信息,您可以使用 objdump --dwarf=decodedline(当然,二进制文件必须使用
-g
进行编译)。一旦你说 objdump -S它就会使用这个矮人信息为你提供源代码以及反汇编代码。
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.我的理解是,
objdump
要从二进制代码中显示源代码,有一个前提:DWARF调试信息必须编译到二进制文件中。 (通过gcc -g源文件
或gcc -gdwarf-2源文件
)通过处理这个 DWARF 信息,
objdump
能够获取 @vlcekmi3 和 @vkrnt 回答的源代码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. (bygcc -g sourcefile
orgcc -gdwarf-2 sourcefile
)And by processing this DWARF information
objdump
is able to get the source code as @vlcekmi3 and @vkrnt answered