Skip to content

Debugging Your Program

Debugging

Debugging is the process of identifying and resolving errors (also known as "bugs") within the software or the hardware. This article is about software debugging only.

Debugging Techniques

  • Enabling compiler warnings (-Wall -Wextra -Wpedantic -Wconversion ...)
  • Enabling sanitizers (-fsanitize=address)
  • Print debugging - logging the state of your program
  • Systematic elimination - enabling/disabling parts of your code
  • Using static code analysis tools
  • Unit Testing - testing individual components of a software application
  • Interactive debugging - using a debugger

What is a Debugger

Debugger is a software application that is used for inspecting other programs. It allows you to observe and control the execution of the program and display the current state. Some debuggers allow the change of the state of the program to test for different scenarios. Main features of a debugger are:

  • Setting breakpoints to suspend the execution
  • Examining the suspended program
  • Examining the call stack
  • Inspecting memory
  • Stepping trough the program
  • Examine core dump files
  • Modifying the state of the program

What is a Debug Adapter Protocol

Debug Adapter Protocol (DAP) is a communication protocol between debuggers and other development tools (e.g., IDEs, editors). Official Documentation

Debuggers

  • GNU Debugger (GDB) - often used with GCC compiler
  • LLVM Debugger (LLDB) - often used with Clang compiler
  • Visual Studio Debugger - often used with MSVC compiler

Debugging with Visual Studio Code

Debugging in Visual Studio Code can be done with the use of a microsoft extension. This extension uses GDB as it's backend. See tutorial for more information.

Debugging with Visual Studio

Visual studio provides a debugger out of the box. See tutorial for more information.

Debugging with Clion

Clion debugger uses GDB or LLDB as it's backend. See tutorial for more information.