High-level debugging is about lines of code. Assembly debugging is about instructions, registers, and memory — you watch the machine change state one step at a time. gdb is the tool, and once you can step through a program and read the registers as you go, assembly stops being a wall of text and becomes something you can observe.
This lesson is about how to debug — the workflow. For the full command reference, see the GDB Guide.
gdbStart gdb on the hello program we built in Assembling & Linking, switch it to Intel syntax (the tools default to AT&T), break on our entry point _start, and run. Here is a complete session — step through it instruction by instruction, inspect state, then set a second breakpoint on a raw address:
set disassembly-flavor intelbreak _startBreakpoint 1 at 0x401000runBreakpoint 1, 0x0000000000401000 in _start ()x/3i $pc=> 0x401000 <_start>: mov eax,0x1 0x401005 <_start+5>: mov edi,0x1 0x40100a <_start+10>: movabs rsi,0x402000si0x0000000000401005 in _start ()info registers rax rdirax 0x1 0x1rdi 0x0 0x0break *0x401019Breakpoint 2 at 0x401019Everything below refers to that session.
si and niAssembly stepping works one instruction at a time, not one line:
si (step instruction) executes the next instruction and stops. If that instruction is a call, si steps into the called function.ni (next instruction) is the same, except it steps over a call — the whole function runs and you stop on the instruction after it.In the session, each si advances $rip by exactly one instruction. hello has no calls, so si and ni behave identically here, but the distinction matters the moment you hit a call: si to understand the callee, ni to skip past it.
Stepping is only useful if you can see what changed. Three commands cover almost everything:
info registers (or info registers rax rdi for specific ones) dumps the registers. After the first mov rax, 1 executes, you can watch rax hold 0x1.x/i $pc examines the instruction at the program counter — "what am I about to run?" x/3i $pc shows the next three.x/8xb $rsi examines memory: eight (8) bytes (b) in hex (x) at the address in $rsi. Since our code puts the message pointer in rsi, this prints the opening bytes of the message — 48 65 6c 6c 6f 2c 20 77, which is Hello, w — before the write syscall ever runs.The format letters (i instruction, x hex, b byte, plus s string, g 8-byte giant, w word) combine freely — x/s $rsi would print the string directly.
You will not always have a tidy label like _start. When you want to stop at a specific instruction, break on its address with the * prefix — break *0x401019. That address is exactly what objdump printed next to the syscall in the previous lesson, which is the usual workflow: disassemble to find the address, then break on it. In the session we stop right before the write syscall fires and inspect the buffer it is about to print.
layout asm and layout regsFor longer sessions, gdb's text UI shows the disassembly and registers live as you step. layout asm opens a pane that highlights the current instruction; layout regs adds a register pane that flashes changed values. Many people prefer a debugger plugin like pwndbg or gef, which show the same information — registers, stack, disassembly, flags — automatically after every step. Either way the commands above are identical; the UI just saves you from typing them.
cmp or arithmetic instruction, the flags register decides what the next jcc does. Check it before you step over a conditional jump.push, pop, call, and ret, confirm $rsp and the values around it are what you expect — stack mistakes are the most common and the most confusing.