Table of Contents

IronForgeCyber

Courses

Resources

Blog

Log In



IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. asm-101
  3. debugging
4 min read

Debugging Assembly

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.

Launching Under gdb

Start 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:

gdb
gef➤ set disassembly-flavor intelgef➤ break _startBreakpoint 1 at 0x401000gef➤ runBreakpoint 1, 0x0000000000401000 in _start ()gef➤ x/3i $pc=> 0x401000 <_start>:   mov    eax,0x1   0x401005 <_start+5>: mov    edi,0x1   0x40100a <_start+10>:        movabs rsi,0x402000gef➤ si0x0000000000401005 in _start ()gef➤ info registers rax rdirax            0x1                 0x1rdi            0x0                 0x0gef➤ break *0x401019Breakpoint 2 at 0x401019gef➤ 

Everything below refers to that session.

Stepping: si and ni

Assembly 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.

Inspecting State

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.

Breakpoints on Addresses

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.

The TUI: layout asm and layout regs

For 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.

Best Practices

  • Step one instruction at a time. Resist the urge to run ahead — the bug is almost always in the instruction whose effect surprised you.
  • Watch the flags. After a cmp or arithmetic instruction, the flags register decides what the next jcc does. Check it before you step over a conditional jump.
  • Verify the stack. After 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.
For the full command reference see the GDB Guide and the radare2 resource — this lesson is about how to debug, not a keystroke cheat-sheet.
continue
Breakpoint 2, 0x0000000000401019 in _start ()
gef➤ x/8xb $rsi
0x402000: 0x48 0x65 0x6c 0x6c 0x6f 0x2c 0x20 0x77
gef➤ x/i $pc
=> 0x401019 <_start+25>: syscall