
A List of few gdb commands that can help you during debugging using gdb debugger.
1) ๐ข๐ง๐๐จ ๐๐ฎ๐ง๐๐ญ๐ข๐จ๐ง๐ฌ:
List all the functions in the program or those matching a regular expression. Useful to see the functions provided by a library or module.
Syntax: info functions <regex>
Example: info functions _init
2) ๐ข๐ง๐๐จ ๐ซ๐๐ ๐ข๐ฌ๐ญ๐๐ซ๐ฌ:
Display the content of the CPU registers.
Example: info registers
3) ๐ฌ๐๐ญ:
Modify the value of variables or memory.
Syntax: set var <variable_name>=<value>
Example: To set a variable counter to 5: set var counter=5
Syntax for memory: set {<type>}<address> = <value>
Example: To set a word of memory at address 0x20000010 to 0xABCD1234: set {int}0x20000010 = 0xABCD1234
4) ๐ฐ๐๐ญ๐๐ก:
Set a watchpoint for a variable. The program will stop when the variable changes.
Syntax: watch <variable_name>
Example: watch myVariable
5) ๐ฌ๐ญ๐๐ฉ๐ข ๐จ๐ซ ๐ฌ๐ข:
Execute one machine instruction, stepping into functions.
Example: stepi
6) ๐ง๐๐ฑ๐ญ๐ข ๐จ๐ซ ๐ง๐ข:
Execute one machine instruction, stepping over functions.
Example: nexti
7) ๐ข๐ง๐๐จ ๐ฉ๐ซ๐จ๐:
Shows detailed information about the process being debugged. This can be helpful to inspect the memory map, which is essential in embedded systems.
Example: info proc
8) ๐ฌ๐ก๐จ๐ฐ ๐ฉ๐๐ญ๐ก๐ฌ:
Display the list of directories GDB searches for executables and source files. This is essential when you have an embedded system’s SDK or cross-compilation toolchain with its libraries.
Example: show paths
9) ๐๐๐-๐ฌ๐ฒ๐ฆ๐๐จ๐ฅ-๐๐ข๐ฅ๐:
Add symbols from an external file. This is useful when you have a stripped binary running on an embedded device but have a separate file with debugging symbols.
Syntax: add-symbol-file <file> <address>
Example: add-symbol-file my_symbols.elf 0x08000000
10) ๐๐ข๐ฌ๐๐ฌ๐ฌ๐๐ฆ๐๐ฅ๐:
View the assembly code of a function or a range of addresses.
Syntax: disassemble <function/range>
Example: disassemble main
Example: disassemble 0x08000000,+50
11) ๐ฆ๐๐ข๐ง๐ญ๐๐ง๐๐ง๐๐ ๐ข๐ง๐๐จ ๐ฌ๐๐๐ญ๐ข๐จ๐ง๐ฌ:
Display all the sections in the current binary. This is useful to inspect where each section (like .text, .data, .bss) is located in memory.
Example: maintenance info sections..
12) ๐ฌ๐๐ญ ๐ฉ๐ซ๐ข๐ง๐ญ ๐ฉ๐ซ๐๐ญ๐ญ๐ฒ ๐จ๐ง:
Print structures in a pretty format, making it easier to read complex data structures.
Example: set print pretty on
13) ๐ฌ๐๐ญ ๐๐จ๐ฅ๐ฅ๐จ๐ฐ-๐๐จ๐ซ๐ค-๐ฆ๐จ๐๐:
Decide how GDB should behave when the debugged process forks. It’s relevant in embedded systems where processes or tasks might spawn child processes.
Syntax: set follow-fork-mode <mode>
Example: set follow-fork-mode child (debug the child process after a fork)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An Article by: Yashwanth Naidu Tikkisetty
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
