Do we have a way to view assembly and c code both using gdb.
disassemble function_name shows only assembly, I was trying to find a way to easliy map c code to assembly. Thanks
You may add the -S tag to see the assembly code. clang also outputs the assembly code with a similar -S tag. After that just look for a file with a . S extension.
You can normally see assembly code while debugging C++ in visual studio (and eclipse too). For this in Visual Studio put a breakpoint on code in question and when debugger hits it rigth click and find "Go To Assembly" ( or press CTRL+ALT+D )
You can run gdb in Text User Interface (TUI) mode:
gdb -tui <your-binary> (gdb) b main (gdb) r (gdb) layout split
The layout split
command divides the window into two parts - one of them displaying the source code, the other one the corresponding assembly. A few others tricks:
If you do not want to use the TUI mode (e.g. your terminal does not like it), you can always do:
x /12i $pc
which means print 12 instructions from current program counter address - this also works with the tricks above (demangling, stepping instructions, etc.).
The "x /12i $pc" trick works in both gdb and cgdb, whereas "layout split" only works in gdb.
Enjoy :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With