You can switch to assembly layout in GDB:
(gdb) layout asm
See here for more information. The current assembly instruction will be shown in assembler window.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β0x7ffff740d756 <__libc_start_main+214> mov 0x39670b(%rip),%rax #β
β0x7ffff740d75d <__libc_start_main+221> mov 0x8(%rsp),%rsi β
β0x7ffff740d762 <__libc_start_main+226> mov 0x14(%rsp),%edi β
β0x7ffff740d766 <__libc_start_main+230> mov (%rax),%rdx β
β0x7ffff740d769 <__libc_start_main+233> callq *0x18(%rsp) β
>β0x7ffff740d76d <__libc_start_main+237> mov %eax,%edi β
β0x7ffff740d76f <__libc_start_main+239> callq 0x7ffff7427970 <exit> β
β0x7ffff740d774 <__libc_start_main+244> xor %edx,%edx β
β0x7ffff740d776 <__libc_start_main+246> jmpq 0x7ffff740d6b9 <__libc_startβ
β0x7ffff740d77b <__libc_start_main+251> mov 0x39ca2e(%rip),%rax #β
β0x7ffff740d782 <__libc_start_main+258> ror $0x11,%rax β
β0x7ffff740d786 <__libc_start_main+262> xor %fs:0x30,%rax β
β0x7ffff740d78f <__libc_start_main+271> callq *%rax β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
multi-thre process 3718 In: __libc_start_main Line: ?? PC: 0x7ffff740d76d
#3 0x00007ffff7466eb5 in _IO_do_write () from /lib/x86_64-linux-gnu/libc.so.6
#4 0x00007ffff74671ff in _IO_file_overflow ()
from /lib/x86_64-linux-gnu/libc.so.6
#5 0x0000000000408756 in ?? ()
#6 0x0000000000403980 in ?? ()
#7 0x00007ffff740d76d in __libc_start_main ()
from /lib/x86_64-linux-gnu/libc.so.6
(gdb)
Answer from ks1322 on Stack OverflowYou can switch to assembly layout in GDB:
(gdb) layout asm
See here for more information. The current assembly instruction will be shown in assembler window.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β0x7ffff740d756 <__libc_start_main+214> mov 0x39670b(%rip),%rax #β
β0x7ffff740d75d <__libc_start_main+221> mov 0x8(%rsp),%rsi β
β0x7ffff740d762 <__libc_start_main+226> mov 0x14(%rsp),%edi β
β0x7ffff740d766 <__libc_start_main+230> mov (%rax),%rdx β
β0x7ffff740d769 <__libc_start_main+233> callq *0x18(%rsp) β
>β0x7ffff740d76d <__libc_start_main+237> mov %eax,%edi β
β0x7ffff740d76f <__libc_start_main+239> callq 0x7ffff7427970 <exit> β
β0x7ffff740d774 <__libc_start_main+244> xor %edx,%edx β
β0x7ffff740d776 <__libc_start_main+246> jmpq 0x7ffff740d6b9 <__libc_startβ
β0x7ffff740d77b <__libc_start_main+251> mov 0x39ca2e(%rip),%rax #β
β0x7ffff740d782 <__libc_start_main+258> ror $0x11,%rax β
β0x7ffff740d786 <__libc_start_main+262> xor %fs:0x30,%rax β
β0x7ffff740d78f <__libc_start_main+271> callq *%rax β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
multi-thre process 3718 In: __libc_start_main Line: ?? PC: 0x7ffff740d76d
#3 0x00007ffff7466eb5 in _IO_do_write () from /lib/x86_64-linux-gnu/libc.so.6
#4 0x00007ffff74671ff in _IO_file_overflow ()
from /lib/x86_64-linux-gnu/libc.so.6
#5 0x0000000000408756 in ?? ()
#6 0x0000000000403980 in ?? ()
#7 0x00007ffff740d76d in __libc_start_main ()
from /lib/x86_64-linux-gnu/libc.so.6
(gdb)
You can do
display/i $pc
and every time GDB stops, it will display the disassembly of the next instruction.
GDB-7.0 also supports set disassemble-next-line on, which will disassemble the entire next line, and give you more of the disassembly context.
Videos
Instead of gdb, run gdbtui. Or run gdb with the -tui switch. Or press C-x C-a after entering gdb. Now you're in GDB's TUI mode.
Enter layout asm to make the upper window display assembly -- this will automatically follow your instruction pointer, although you can also change frames or scroll around while debugging. Press C-x s to enter SingleKey mode, where run continue up down finish etc. are abbreviated to a single key, allowing you to walk through your program very quickly.
+---------------------------------------------------------------------------+ B+>|0x402670 <main> push %r15 | |0x402672 <main+2> mov %edi,%r15d | |0x402675 <main+5> push %r14 | |0x402677 <main+7> push %r13 | |0x402679 <main+9> mov %rsi,%r13 | |0x40267c <main+12> push %r12 | |0x40267e <main+14> push %rbp | |0x40267f <main+15> push %rbx | |0x402680 <main+16> sub $0x438,%rsp | |0x402687 <main+23> mov (%rsi),%rdi | |0x40268a <main+26> movq $0x402a10,0x400(%rsp) | |0x402696 <main+38> movq $0x0,0x408(%rsp) | |0x4026a2 <main+50> movq $0x402510,0x410(%rsp) | +---------------------------------------------------------------------------+ child process 21518 In: main Line: ?? PC: 0x402670 (gdb) file /opt/j64-602/bin/jconsole Reading symbols from /opt/j64-602/bin/jconsole...done. (no debugging symbols found)...done. (gdb) layout asm (gdb) start (gdb)
You can use stepi or nexti (which can be abbreviated to si or ni) to step through your machine code.