February 18th, 2024
A collection of notes about making Assembly work more pleasurable with GDB debugging.
Read these before expanding to the next sections.
layout src
(or ctrl + x + a
).ni
and si
(next instruction / step instruction).i r rax
(info register rax) to inspect a register.i r eflags
set disassembly-flavor intel
so MOV instructions aren't in reverse.x 0x402000
to print value starting in memory block 0x402000x/xg 0x402000
to do the same but print 64bit in hex decimal.p
for printing .data (casting them in C first!)p /t $rax
to print contents of rax in binary.Layout allows you to have your code and the line being debugged side-by-side on the GDB terminal user interface.
You can have the following window configurations:
To change the layout you can type layout
followed by a configuration.
(gdb) layout src
Helpful shortcuts:
ctrl + x + 1: Use the TUI with only 1 window configuration. ctrl + x + 2: Use the TUI with at least 2 windows.
On the command terminal window, you can type focus
+ name of the window so
that your keyboard arrows work within the specified window:
(gdb) focus src
You can use p
followed by a C-casting command to find what the byte stored
in a memory address is. For example:
(gdb) p (char*)0x402000
Disassembles a specified section of memory. Can be useful for determining the assembly code in a routine.
(gdb) disassemble main // print all instructions of main.
(gdb) disassemble /s main // also adds the source code.