lldb - the llvm debugger

C++ debugging basics

A debugger allows to intervene in a program, to continue or to examine variables at a breakpoint or watchpoint. For example, to fix a seqfault of the program. The program must be compiled with debug symbols.

Start lldb program-name or run lldb and create a target create program-name.

to start the program in lldb:

  • process launch or alias run, r
  • or connect it to a process by process id or process name.

When it is running:

  1. s step into
  2. n next
  3. f finish
  • help
  • bt backtrace

Interactive debugging

Example using lldb for a program called sdl-beatbox with CMake. CMake ensures that the program is built with -g for lldb or gdb.

  1. mkdir Debug && cd Debug
  2. cmake -DCMAKE_BUILD_TYPE=Debug ..
  3. make
  4. lldb sdl-beatbox
  5. breakpoint example b main
    • on symbol: b Au<tab>
    • or on line: set breakpoint -f <filename> -l <line number> or b sequencer.cpp : 43
  6. r to launch.

lldb-run

lldb gui

In the lldb session, gui leads to the graphical user interface.
In the gui, a diamond shows the current line and allows navigation with arrow keys and checking the status.

lldb-run

  1. lldb tutorial
  2. lldb for gdb users
Written on June 3, 2023
[ debugging  c++  ]