This page was already viewed 46times
GDB is a powerful command-line tool used for debugging programs written in languages like C and C++. It allows developers to inspect the internal workings of a running application, step through code line by line, analyze variables, set breakpoints, and even reverse-engineer binaries. Whether you're troubleshooting a crash or tracking down elusive bugs, GDB gives you full control over program execution and memory analysis—essential for deep diagnostics and performance tuning.
The following article presents various GDB commands for debugging binaries.
To explore GDB’s features and commands in detail, refer to the GDB manpage.
Run this command to launch the GDB shell.
*File selectionauditer@linux:#gdb
From within the GDB shell, execute the following command to specify the file to be analyzed (e.g., unknown.bin)
*Binary execution>(gdb)file unknown.bin
It’s recommended to execute the binary at least once before conducting further analysis, as this helps obtain accurate assembly addresses.
*Continue execution after a breakpoint>(gdb)run
When execution halts at a breakpoint, this command resumes the binary’s execution until either the next breakpoint or the program’s termination.
>(gdb)c
Display all defined functions in the loaded binary, including their memory addresses.
*Filter functions by Name>(gdb)info functions
Display only functions matching a Name Replace (Example: `info functions main` will show only functions matching "main".
*Inspect a function content (disas)>(gdb)info functions main
The following command disassembles a function to analyze its behavior (e.g., main).
>(gdb)disas main
The following command list the defined breakpoint.
*Add a breakpoint>(gdb)info b
This command sets a new breakpoint at a specified memory address (I.e 0x000055555555532f).
*Delete a breakpoint>(gdb)b *0x000055555555532f
This command delete a previously set breakpoint defined by its breakpoint number (I.e 1).
*Delete all breakpoints>(gdb)delete 1
This command delete all previously set breakpoints.
>(gdb)delete
View the contents of CPU registers.
*Extended Register Views>(gdb)info registers
To include floating-point and vector registers (like xmm, ymm, st0–st7), use:
*Show a variable>(gdb)info all-registers
Show a variable content. The variable should exist in the souce code when triggered (I.e variable str).
>(gdb)x/s str