Table of Contents
1- Key Functionalities of The GDB Debugger
![Basic GNU GDB Debugger Commands](https://www.ktpql.com/wp-content/uploads/2023/04/GDB-Debugger-Overview-jpeg.webp)
- Source code debugging
- GDB can debug programs at the source code level, allowing developers to step through their code line by line and examine variables and memory.
- Breakpoints
- GDB allows developers to set breakpoints in their code to stop the execution of the program at a specific point and examine the state of the program.
- Watchpoints
- GDB allows developer to watch memory locations for changes during program execution.
- Call Stack
- With GDB debugger, developers can examine the call stack to understand how the program reached a certain point in execution.
- Debugging multi-threaded and multi-process programs
- Dynamic tracing
- GDB can trace the execution of a program and generate a log of events that occurred during the execution.
- Remote debugging
- GDB can be used to debug programs running on remote systems.
- Core dump analysis
- GDB can analyze core dumps generated by crashing programs to help developers identify the cause of the crash.
- The GDB Agent Expression Mechanism
1.1- Breakpoint Management
![Advanced GNU GDB Debugger Commands](https://www.ktpql.com/wp-content/uploads/2023/04/Debugging-with-GDB-Debugger-jpeg.webp)
Breakpoint Types
There are 3 different types of breakpoints in GDB debugger.
Breakpoints
A breakpoint makes your program stop whenever a certain point in the program is reached. [10]
Watchpoints
A watchpoint is a special breakpoint that stops your program when the value of an expression changes. [10]
Catchpoints
A catchpoint is another special breakpoint that stops your program when a certain kind of event occurs, such as the throwing of a C++ exception or the loading of a library. [10]
Tracepoints
A tracepoint is a type of breakpoint that doesn’t stop the program’s execution when hit, but instead logs a message indicating that it has been hit. Tracepoints are useful for collecting information about the program’s execution without disrupting its flow.
Related Resources:
- [Official GDB Document] Tracepoints
- [Official GDB Document] Tracepoint Restrictions
- [Official GDB Document] Tracepoints support in
gdbserver
Breakpoint Operations
We can use a number of operations with breakpoints.
- The specific commands used for breakpoints, watchpoints, or catchpoints may change.
1- Set Breakpoints
You can set a breakpoint at a specific line number in the source code, or when a certain function is called. Once the program hits the breakpoint, it is temporarily suspended and you can inspect data/variables in the program.
Related Resources:
- [Official GDB Document] Setting Breakpoints
- [Official GDB Document] Setting Watchpoints
- [Official GDB Document] Setting Catchpoints
- [Official GDB Document] Create Tracepoints
2- Specify a condition
You can also specify a condition for a breakpoint. A conditional breakpoint allows you to specify a condition that must be met for the breakpoint to be triggered.
A special case of a breakpoint condition is to stop only when the breakpoint has been reached a certain number of times. If the ignore count value of the breakpoint is n, the breakpoint does not stop the next n times your program reaches it.
Related Resources:
- [Official GDB Document] Break Conditions
- [Official GDB Document] Tracepoint Conditions
3- Enable-Disable Breakpoints
In GDB, you can enable or disable breakpoints. When a breakpoint is enabled, it means that GDB will suspend the execution of your program when it reaches that breakpoint. When a breakpoint is disabled, it has no effect on your program until you enable it again.
Related Resources:
- [Official GDB Document] Enable and Disable Breakpoints
- [Official GDB Document] Enable and Disable Tracepoints
4- Delete Breakpoints
In GDB, you can delete breakpoints once they have done their job and you no longer want your program to stop there.
Related Resources:
- [Official GDB Document] Deleting Breakpoints
- [Official GDB Document] Delete Tracepoints
5- Save Breakpoints
In GDB, you can save all current breakpoint definitions to a file suitable for use in a later debugging session. This includes all types of breakpoints (breakpoints, watchpoints, catchpoints, tracepoints)
Related Resources:
- [Official GDB Document] Save Breakpoints
- [Official GDB Document] Save Tracepoints
6- Listing breakpoints
Related Resources:
- [Official GDB Document] Set Breakpoints
- Also includes information on listing breakpoints.
- [Official GDB Document] Listing Tracepoints
1.2- The GDB Agent Expression Mechanism
In some applications, it is not feasible for the debugger to interrupt the program’s execution long enough for the developer to learn anything helpful about its behavior. If the program’s correctness depends on its real-time behavior, delays introduced by a debugger might cause the program to fail, even when the code itself is correct.
Related Resources:
- Exploring The GNU GDB Agent Expressions: A Complete Overview – Ktpql
- [Official GDB Document] The GDB Agent Expression Mechanism
2- Key Features of The GDB Debugger
- Platform-independent
- GDB can be used on various platforms, including Linux, Windows, macOS, and more.
- Supports multiple programming languages
- GDB supports a wide range of programming languages such as C, C++, Ada, Fortran, and more.
- Command-line interface
- GDB has a command-line interface that allows developers to interact with the debugger using various commands.
- Extensible
- GDB is highly extensible, and developers can add their own commands and features to the debugger using the GDB Python API.
Further Exploring The GNU GDB Debugger
You can use the following resources for further research and understanding the GNU GDB in detail.
GDB Debugger Wikis
GDB Debugger Books:
GDB Debugger Documentation:
GDB Source Code:
- Official source code of the GNU GDB: sourceware.org Git
- Unofficial github mirror of sourceware binutils-gdb repository: bminor/binutils-gdb: . Updated daily. (github.com)
References
[10] Breakpoints (Debugging with GDB). Sourceware. https://sourceware.org/gdb/onlinedocs/gdb/Breakpoints.html
3 responses to “Exploring The GNU GDB Debugger: A Complete Overview”
[…] GDB allows the user to define tracepoints in their program, along with arbitrary expressions to evaluate when those tracepoints are reached. The user can later examine the values of these expressions at the tracepoints. When visiting a tracepoint, the user can inspect the recorded objects as if they were in memory at that moment. GDB collects this information unobtrusively and quickly, without disrupting the program’s behavior. […]
[…] communication between GDB server and GDB client is established using the GDB Remote Serial Protocol. Here’s an overview […]
[…] it comes to debugging on the GNU/Linux platform, understanding the essential GDB commands is crucial for software developers. Debugging is an indispensable part of software […]