英文:
When debugging, how can I ask GDB to interpret the code directly from the binary, and not the source?
问题
我需要跟踪一些我拥有的二进制代码的执行。由于它是从我拥有的某个代码版本编译而来的(但是不完全相同),GDB警告我源代码比代码新,并且通常拒绝显示正在运行的汇编代码(甚至使用layout asm
命令)。但我猜想它可能可以简单地逐行读取并反汇编它正在读取的ELF文件。我该如何实现这一点?
背景信息:我需要获取已执行的二进制指令的跟踪信息(display/i $pc
),如果可能的话,显示当前指令的地址、内存中该指令的编码、它属于哪个函数(例如<main+0x8>
)以及指令的反汇编。如果我理解正确,所有这些信息都在ELF文件中可用,对吗?我该如何要求GDB打印这些信息,仅从调试的ELF文件开始,而不是从磁盘上的文件开始?
谢谢!
英文:
I need to follow the execution of some binary code I have. Since it is compiled from a version of some code I have (but which is not the same), GDB warns me that the source is newer than the code, and generally refuses to show me the assembly code it is running (even issuing layout asm
). But I guess it could simply read and disassemble line per line the ELF it is reading. How can I achieve that?
For context: I need to get a trace of the executed binary instructions (display/i $pc
), if possible showing the address of the current instruction, the encoding of that instruction in memory, in which function it is (like <main+0x8>
) and the disassembly of the instruction. IF I am correct, all this information is available in the ELF file, isn't it? How can I ask GDB to print this, starting only from the debugged ELF and not from the on-disk file?
Thanks!
答案1
得分: 1
GDB警告我源代码比代码新,并通常拒绝显示正在运行的汇编代码。
运行strip -g a.out -o a.stripped
并调试a.stripped
— 这将从二进制文件中删除所有调试信息,GDB将不知道源代码是什么,只会显示反汇编指令。
英文:
> GDB warns me that the source is newer than the code, and generally refuses to show me the assembly code it is running
Run strip -g a.out -o a.stripped
and debug a.stripped
-- this will remove all debug info from the binary, and GDB will have no idea what the source is (was), and will only show disassembled instructions.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论