gdbreverse-engineeringelfdisassemblybin

When debugging, how can I ask GDB to interpret the code directly from the binary, and not the source?


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!


Solution

  • 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.