
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
