Forrest logo
tool overview
On this page you find all important commands for the CLI tool gdb. If the command you are looking for is missing please ask our AI.

gdb

GDB (GNU Debugger) is a powerful and widely used command line tool for debugging and analyzing programs written in various programming languages such as C, C++, and Fortran. It allows developers to investigate and fix issues in their code by providing a comprehensive set of debugging features.

GDB supports various platforms and can be used for both local and remote debugging. It offers support for a wide range of architectures, making it versatile and flexible for different development environments.

One of GDB's main functionalities is the ability to set breakpoints in the code, allowing developers to pause the execution at specific points to examine the program's state. Users can also step through the code line by line, print the values of variables, and examine the contents of data structures.

GDB helps in identifying memory-related issues like buffer overflows and memory leaks. It provides memory access breakpoints, which can halt the execution when a certain memory region is accessed, allowing users to investigate potential memory-related errors.

Users can examine the stack frames to understand the call hierarchy and analyze the state of local and global variables at different levels. Backtraces can be generated to understand how the program arrived at a certain point in the code.

GDB allows for advanced features like conditional breakpoints, where the execution is paused only if specified conditions are met. It also supports watchpoints, enabling users to monitor changes to specific variables or memory locations.

GDB includes a command scripting language that allows users to automate common debugging tasks and create custom debugging commands. This scripting language enables the automation of repetitive tasks and enhances productivity.

The tool supports post-mortem debugging, which means it can analyze core dumps generated by crashed programs, helping developers understand the cause of the crash.

GDB can be used in conjunction with other tools, such as the GNU Profiler (gprof), to profile code performance and identify areas of improvement.

GDB is a vital tool in the development process, enabling developers to efficiently identify and resolve issues through its extensive set of debugging capabilities and scripting features.

List of commands for gdb:

  • gdb:tldr:0e1f2 gdb: Attach a process to gdb.
    $ gdb -p ${procID}
    try on your machine
    explain this command
  • gdb:tldr:543b8 gdb: Debug with a core file.
    $ gdb -c ${core} ${executable}
    try on your machine
    explain this command
  • gdb:tldr:9c1f1 gdb: Debug an executable.
    $ gdb ${executable}
    try on your machine
    explain this command
  • gdb:tldr:cb96a gdb: Execute given GDB commands upon start.
    $ gdb -ex "${commands}" ${executable}
    try on your machine
    explain this command
  • gdb:tldr:d7db6 gdb: Start gdb and pass arguments to the executable.
    $ gdb --args ${executable} ${argument1} ${argument2}
    try on your machine
    explain this command
tool overview