GDB - Assembly debugging

Here's a little GDB trick, if you want to debug your program using assembly output.

From a GDB session, type:

display /i $pc
break main

The first line will tell GCC to output the assembly code. The second one will create a breakpoint on the main function. You can of course choose another symbol for the breakpoint.

Once done, you can run your program:


In our example, to code will stop at the main function, showing the assembly code:

Breakpoint 1, main () at test.c:3
3	    return 0;
1: x/i $pc  0x100000f3c :	mov    $0x0,%eax

You can then step to each assembly instruction with the si command.