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 OverflowSwarthmore College
cs.swarthmore.edu βΊ ~newhall βΊ cs31 βΊ resources βΊ ia32_gdb.php
gdb assembly debuggin
ddd is a gui interface on top of a debugger (gdb in this case). It has a nicer interface for viewing assembly, registers, and stepping through IA32 instruction execution than command line gdb:
Top answer 1 of 9
427
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)
2 of 9
204
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
Ncona
ncona.com βΊ 2019 βΊ 12 βΊ debugging-assembly-with-gdb
Debugging assembly with GDB
This article shows how to use gdb to debug a simple assembly program. Most commands are similar to the ones used for debugging any other programming language, but we also go over how to access registers and memory addresses, which is more commonly needed when working at assembly level.
University of Maryland, Baltimore County
userpages.cs.umbc.edu βΊ chang βΊ cs313.f04 βΊ gdb_help.shtml
Using gdb for Assembly Language Debugging
Using a debugger is more important for assembly language programming than a high-level programming language because printing out values from an assembly language program is non-trivial, hence adding debugging code to an assembly language program might itself introduce new bugs, or at least make the bug behave differently. If your program contains portions written in C, those portions should be compiled using the -g option to retain debugging information in the a.out file. Although the NASM documentation describes a similar -g option for NASM, this option doesn't do anything when the output is in ELF format. The complete documentation for gdb is available on the Linux system using the "info" command:
Sonoma State University
bob.cs.sonoma.edu βΊ IntroCompOrg-x64 βΊ bookap3.html
C Using the gdb Debugger for Assembly Language
The gdb debugger allows you to load another program into memory and use gdb commands to control the execution of the other program β the target program β and to observe the states of its variables.
Diveintosystems
diveintosystems.org βΊ book βΊ C3-C_debug βΊ gdb_assembly.html
3.5. Debugging Assembly Code
Doing so enables GDB to list disassembled code sequences from functions, set breakpoints at the assembly instruction level, step through program execution one assembly instruction at a time, and examine the values stored in machine registers and in stack and heap memory addresses at runtime.
Kauffman77
kauffman77.github.io βΊ tutorials βΊ gdb.html
Quick Guide to gdb: The GNU Debugger
>> gcc -g collatz.s # compile assembly code with debug symbols >> gdb ./a.out # run gdb on executable (gdb) tui enable # enable text user interface mode (gdb) break main # set a break point at main (gdb) run # run to the break point (gdb) step # step a couple times to see position in assembly (gdb) s # shorthand for step (gdb) layout regs # start displaying registers (gdb) step # step to see changes in registers (gdb) break collatz.s:15 # break at another source line (gdb) continue # run to the source line (gdb) step # step (gdb) winheight regs +2 # show more of the register window for eflags (gdb) quit # exit the debugger
YouTube
youtube.com βΊ systempeeps
GDB Debugging - Displaying x86 Assembly from C program and stepping through instructions - YouTube
Create a simple program and debug in gdb. Exhibit how to show the x86 assembly, explain the output of the assembly language, show how to examine registers, m...
Published Β January 26, 2016 Views Β 52K
Swarthmore College
cs.swarthmore.edu βΊ ~zpalmer βΊ cs75 βΊ s23 βΊ guides βΊ gdb
CS75: Debugging x86-64 Assembly with GDB
The first line will ensure that GDB shows assembly in Intel syntax (which we are using in the class) rather than AT&T syntax (which we are not). The next line defines a layout mode which displays the contents of registers at the top, the disassembled program in the middle, and the command window at the bottom. When you are debugging, you can run layout asmreg to switch to this view mode.
Ruc
webhotel4.ruc.dk βΊ ~keld βΊ teaching βΊ CAN_e14 βΊ Readings βΊ gdb.pdf pdf
Debugging Assembly Code with gdb
To use gdb with high-level language programs, you should compile with the Β· -g option. This will include information in the object ο¬le to relate it back to Β· the source ο¬le. When assembling .s ο¬les to be debugged, the -g option is not Β· necessary, but it is harmless.
Infosec Institute
infosecinstitute.com βΊ resources βΊ secure-coding βΊ debugging-your-first-x86-program
Master Debugging x86 Assembly Programs with GDB | Infosec
Debugging the compiled programs ... written in the code is to debug the program using a debugger. GDB is one of the most popular debuggers available for debugging Linux-based executables....
Dbp-consulting
dbp-consulting.com βΊ tutorials βΊ debugging βΊ basicAsmDebuggingGDB.html
Asm Debugging With GDB
I step through the assembler with si (step instruction), and you'll see that gdb will tell you which line of the assembler will be executed next by marking it on the left with =>. Each time you tell gdb to step to the next instruction, the => will move down one, but the line of C won't change until you si off the bottom of the assembler lines that correspond to the line of C. When you start doing mixed assembler and C/C++ debugging there will be times you, by habit, type n (next) or s (step) and go to the next line of C when you meant to type ni (next instruction) or si (step instruction).
Mourtada
mourtada.se βΊ debug-x86-assembly-with-gdb
Debug x86 assembly with GDB | Mourtada.se
December 4, 2021 - Start gdb with gdb <your_assemlby_program> to enter its interactive shell. You can set breakpoints by writing break <function_name or line number>. By default gdb uses AT&T flavor to change to intel flavor type set dissambly-flavor intel. To start debugging the program type run.
Gerryyang
gerryyang.com βΊ debuggers βΊ 2020 βΊ 05 βΊ 04 βΊ debugging-assembly-code-with-gdb.html
Debugging Assembly Code with GDB | Gerryβs blog
May 4, 2020 - gdb is the GNU source-level debugger that is standard on linux (and many other unix) systems. It can be used both for programs written in high-level languages like C and C++ and for assembly code programs; this document concentrates on the latter.
Daniel Lemire's blog
lemire.me βΊ blog βΊ 2022 βΊ 06 βΊ 28 βΊ looking-at-assembly-code-with-gdb
Looking at assembly code with gdb β Daniel Lemire's blog
April 17, 2025 - The general lesson is that looking at the generated assembly is not so difficult and with little training, it can make you a better programmer. Tip: It helps sometimes to disable pagination (set pagination off). Useful script: I often write automated script in bash to locate addresses such as this one: ADDRESS=$(gdb -q ./tests/wpt_tests -ex "info functions parse_url[^]]*$" -ex quit | grep -o "0x[0-9a-fA-F]*") gdb -q ./tests/wpt_tests -ex "set pagination off" -ex "set print asm-demangle" -ex "disas "$ADDRESS -ex quit
Carnegie Mellon University
cs.cmu.edu βΊ afs βΊ cs βΊ academic βΊ class βΊ 15213-m19 βΊ www βΊ activities βΊ 213_lecture5-sol.pdf pdf
15213 Lecture 5: Intro to GDB & Assembly 1 Introduction
This handout introduces GDB (the GNU symbolic debugger), as well as the basics of assembly.
Chang Ge
www-users.cse.umn.edu βΊ ~kauffman βΊ tutorials βΊ gdb.html
CSCI 2021 Quick Guide to gdb: The GNU Debugger
> gcc -g collatz.s # compile assembly code with debug symbols > gdb ./a.out # run gdb on executable gdb> tui enable # enable text user interface mode gdb> break main # set a break point at main gdb> run # run to the break point gdb> step # step a couple times to see position in assembly gdb> s # shorthand for step gdb> layout regs # start displaying registers gdb> step # step to see changes in registers gdb> break collatz.s:15 # break at another source line gdb> continue # run to the source line gdb> step # step gdb> winheight regs +2 # show more of the register window for eflags gdb> quit # exit the debugger