Debug C and C++ with LLDB
Debug C and C++ programs on Red Hat Enterprise Linux from the command line by using LLDB, the LLVM debugger in LLVM Toolset. Use LLDB 21.1.8 to inspect memory, control program execution, and set breakpoints when investigating application behavior.
Prerequisites Copy linkLink copied!
- LLVM Toolset is installed.
- Your compiler is configured to create debug information.
Start a debugging session Copy linkLink copied!
Use LLDB to start an interactive debugging session.
Procedure Copy linkLink copied!
Run the program in a debugging session Copy linkLink copied!
Use LLDB to run your program during your debugging session. The execution of your program stops when the first breakpoint is reached, when an error occurs, or when the program terminates.
Before you begin Copy linkLink copied!
- You started an interactive debugging session with LLDB.
Procedure Copy linkLink copied!
(lldb) run
Alternatively, run the program you are debugging by using a specific argument:
(lldb) run <argument>
Replace <argument> with the command-line argument you want to use.
Use breakpoints Copy linkLink copied!
Use breakpoints to pause the execution of your program at a set point in your source code.
Before you begin Copy linkLink copied!
- You started an interactive debugging session with LLDB.
Procedure Copy linkLink copied!
Step through code Copy linkLink copied!
You can use LLDB to step through the code of your program to run only one line of code after the line pointer.
Before you begin Copy linkLink copied!
- You started an interactive debugging session with LLDB.
Procedure Copy linkLink copied!
List source code Copy linkLink copied!
Before you run the program you are debugging, the LLDB debugger automatically displays the first 10 lines of source code. Each time execution stops, LLDB displays the line where it stopped and its surrounding lines. You can use LLDB to manually display source code during your debugging session.
Before you begin Copy linkLink copied!
- You started an interactive debugging session with LLDB.
Procedure Copy linkLink copied!
(lldb) list
(lldb) list <source_file_name>:<line_number>
Replace <source_file_name> with the name of your source file and <line_number> with the number of the line you want to display.
Display current program data Copy linkLink copied!
The LLDB debugger provides data on variables of any complexity, any valid expressions, and function call return values. You can use LLDB to display data relevant to the program state.
Before you begin Copy linkLink copied!
- You started an interactive debugging session with LLDB.
Procedure Copy linkLink copied!
(lldb) print <data_name>
Replace <data_name> with data you want to display.