LLDB Debugger
Overview
Low Lever Debugger (LLDB) is a next-generation, high-performance debugger. For details, visit the LLDB official website.
LLDB used in OpenHarmony is developed on LLVM 15.0.4. It is the default debugger in DevEco Studio and supports debugging of C and C++ applications.
How to Obtain
Obtain the OpenHarmony SDK. Then find LLDB in the \ohos-sdk[system]\native\llvm directory of the SDK, where system can be windows, linux, or darwin.
For example, for Windows, lldb.exe is stored in \ohos-sdk\windows\native\llvm\bin after the SDK is decompressed.
Functions
The following lists some functions supported by LLDB. For more functions and related commands, see LLDB Usage Guide and LLDB official manual.
-
Logging
-
Breakpoint management
-
Watchpoint management
-
Expression processing
-
Viewing variables
-
Process/Thread management
-
Assembly processing
-
Obtaining source code information
-
Signal processing
-
Launching a process
-
Attaching to a process
When to Use
-
Local debugging
-
Local debugging in the Linux x86_64 environment
LLDB supports debugging of C and C++ applications in the Linux x86_64 environment.
-
Local debugging on the macOS desktop
LLDB supports debugging of C and C++ applications on the macOS desktop (including macOS x86_64 and M1).
-
-
Remote debugging
-
Remote debugging based on DevEco Studio
LLDB supports remote debugging of native C++ applications by connecting to OpenHarmony devices or emulators from the Windows and macOS desktops based on DevEco Studio.
-
Remote debugging through direct connection
LLDB supports remote debugging of C and C++ applications by directly connecting to OpenHarmony devices from Windows, macOS desktop, and Linux x86_64 environment.
-
Local Debugging
NOTE
The local debugging procedure for Linux x86_64 is the same as that for macOS.
Procedure
-
Using LLDB to start and debug an application
The following walks you through on how to debug an executable file named a.out in the Linux x86_64 environment. The file contains debugging information and is generated by the Clang compiler, which is of the same version as LLDB.
-
Obtain the executable file a.out.
-
Run LLDB and specify the file to debug as a.out.
./lldb a.out
-
Set breakpoints at the main function in the code.
(lldb) b main
-
Run the application, and it stops at the first breakpoint.
(lldb) run
-
Continue to run the application.
(lldb) continue
-
List all the breakpoints.
(lldb) breakpoint list
-
Show the arguments and local variables of the current frame.
(lldb) frame variable
-
Run debugging commands as required to continue debugging.
-
Exit debugging.
(lldb) quit
-
-
Using LLDB to debug a started application
The following walks you through on how to debug an executable file named a.out in the macOS environment. The file contains user input and debugging information and is generated by the Clang compiler.
-
Start the application on Command Line Interface (CLI) 1. (The message "Please input a number of type int" is displayed.)
./a.out
-
Run LLDB on CLI 2.
./lldb
-
Attach to the application.
(lldb) process attach --name a.out
-
Set a breakpoint in line 10 of hello.cpp.
(lldb) breakpoint set --file hello.cpp --line 10
-
On CLI 1, enter a number of the int type.
88
-
Continue to run the application on CLI 2. The application stops at the breakpoint.
(lldb) continue
-
Run debugging commands as required to continue debugging.
-
Detach from the application.
(lldb) detach
-
Exit debugging.
(lldb) quit
NOTE
You can also perform step 4 in prior to step 3.
-
Remote Debugging
NOTE
During remote debugging, lldb-server and lldb must be used together.
The remote debugging procedures for Windows, Linux x86_64, and macOS are the same.
Procedure
The following walks you through on how to remotely debug an executable file named a.out by connecting to an Arm-based OpenHarmony device (for example, RK3568 development board) from the Windows platform.
NOTE
In the command below, /data/local/tmp indicates the specified directory on the device.
8080 is the listening port, which can be customized.
You must have the execute permission on the lldb-server and a.out files of the device.
-
Open CLI 1 and push lldb-server and a.out to the device. (a.out is generated when you compile hello.cpp using the Clang compiler.)
hdc file send lldb-server /data/local/tmp hdc file send a.out /data/local/tmp
-
Run lldb-server.
hdc shell ./data/local/tmp/lldb-server p --server --listen "*:8080"
-
Open CLI 2 and run the binary file lldb.
./lldb
-
Select and connect to the remote device on the LLDB CLI.
(lldb) platform select remote-ohos (lldb) platform connect connect://localhost:8080
-
Specify the binary file a.out on the device to be debugged.
(lldb) target create /data/local/tmp/a.out
-
Set breakpoints at the main function in the code.
(lldb) b main
-
Start the application.
(lldb) run
-
Display source code for the current target process.
(lldb) source list
-
Run debugging commands as required to continue debugging.
-
Exit debugging.
(lldb) quit