Low Level Debugger (LLDB) is a next-generation, high-performance debugger. For details, see the LLDB official document.
The LLDB tool in HarmonyOS is evolved from the llvm15.0.4 tool. It is the default debugger in HUAWEI DevEco Studio and supports debugging of C and C++ applications.
You can download the SDK from HUAWEI DevEco Studio to obtain the LLDB debugging tool.
Take Windows as an example. The path for storing lldb.exe is sdk\[HarmonyOS version]\base\native\llvm\bin. For example, sdk\HarmonyOS-NEXT-DP1\base\native\llvm\bin.
lldb-server is classified into the user tool and the root tool. lldb-server applicable to the user is a signed tool.
Path | Description |
|---|---|
Sdk\[HarmonyOS version] \openharmony\native\llvm\lib\clang\15.0.4\bin\aarch64-linux-ohos\lldb-server | lldb-server for root image aarch64-linux-ohos architecture |
Sdk\[HarmonyOS version] \openharmony\native\llvm\lib\clang\15.0.4\bin\arm-linux-ohos\lldb-server | lldb-server for root image arm-linux-ohos architecture |
Sdk\[HarmonyOS version] \openharmony\native\llvm\lib\clang\15.0.4\bin\arm-linux-ohos\lldb-server | lldb-server for root image x86_64-linux-ohos architecture |
Sdk\[HarmonyOS version] \hms\native\lldb\aarch64-linux-ohos\lldb-server | lldb-server for user image aarch64-linux-ohos architecture |
Sdk\[HarmonyOS version] \hms\native\lldb\arm-linux-ohos\lldb-server | lldb-server for user image aarch64-linux-ohos architecture |
Sdk\[HarmonyOS version] \hms\native\lldb\x86_64-linux-ohos\lldb-server | lldb-server for user image x86_64-linux-ohos architecture |
This section lists some functions supported by the LLDB debugger. For more commands, see LLDB Tool Usage Guide and LLDB official website manual. The LLDB tools may vary by platform, such as Windows, Linux x86_64, and macOS.
Record Logs
Breakpoint management
Watchpoint management
Expression Processing
Viewing variables
Process/Thread management
Assembly processing
Source code acquisition
Signal processing
Process startup
attaching process
Local debugging on Linux x86_64
LLDB supports debugging of C and C++ applications in the Linux x86_64 environment.
Local debugging on macOS desktops
LLDB supports debugging of C and C++ applications on macOS desktops (including Mac x86_64 and M1 systems).
Remote debugging based on HUAWEI DevEco Studio
LLDB supports remote debugging of native C++ applications by connecting to HarmonyOS devices or emulators from the Windows and macOS desktops based on HUAWEI DevEco Studio. That is, the debugging function of HUAWEI DevEco Studio is used.
Remote debugging by HarmonyOS devices connected to the desktop
If the HarmonyOS device is the root image and SELinux is disabled, LLDB supports remote debugging of C and C++ applications and executable binary files by the HarmonyOS devices directly connected to Windows, macOS desktop, and Linux x86_64 environments.
If the HarmonyOS device is the root image and SELinux is enabled, LLDB supports remote debugging of C and C++ applications and executable binary files by the HarmonyOS devices directly connected to Windows, macOS desktop, and Linux x86_64 environments. However, lldb-server, applications to be debugged, and executable binary files can be stored only in the /data/local/tmp/debugserver directory.
If the HarmonyOS device is the user image and SELinux is enabled, LLDB supports remote debugging of the signed debug-version HAP package compiled based on HUAWEI DevEco Studio by the HarmonyOS devices directly connected to Windows, macOS desktop, and Linux x86_64 environments. Currently, only this type of debugging is supported.
For root image: Run the hdc shell id command to query uid=0(root), or run the hdc shell command to enter the interactive command environment. The prompt is #.
For user image: Run the hdc shell id command to query uid=2000(shell), or run the hdc shell command to enter the interactive command environment. The prompt is $.
For SELinux-enabled mode: Run the hdc shell getenforce command to query Enforcing.
For SELinux-disabled mode: Run the hdc shell getenforce command to query Permissive.
The local debugging procedure for Linux x86_64 is the same as that for Mac.
Using the LLDB tool to start and debug the 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.
Source file: hello.cpp
#include <iostream>
using namespace std;
int main() {
cout << "hello world!" <<endl;
return 0;
} Compilation:
<clang distribution>/bin/clang++ -g hello.cpp -o a.out
./lldb a.out
(lldb) b main
(lldb) run
(lldb) continue
(lldb) breakpoint list
(lldb) frame variable
(lldb) quit
Using the LLDB tool 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.
Source file: hello.cpp
#include <iostream>
using namespace std;
int main() {
int i = 0, j = 5, sum = 0;
cout << "Please input a number of type int"" <<endl;
cin >> i;
cout << i;
sum = i + j;
cout << sum <<endl;
return 0;
} Compilation:
<clang distribution>/bin/clang++ -g hello.cpp -o a.out
./a.out
./lldb
(lldb) process attach --name a.out
(lldb) breakpoint set --file hello.cpp --line 10
88
(lldb) continue
(lldb) detach
(lldb) quit
Remote debugging by the root-image HarmonyOS device with SELinux disabled (aarch64-linux-ohos architecture)
Source file: hello.cpp
#include <iostream>
using namespace std;
int main() {
cout << "hello world!" <<endl;
return 0;
} Compilation:
<clang distribution>/bin/clang++ --target=aarch64-linux-ohos --sysroot=<sysroot distribution> -g hello.cpp -o a.out
hdc file send lldb-server /data/local/tmp hdc file send a.out /data/local/tmp hdc shell chmod 755 /data/local/tmp/lldb-server /data/local/tmp/a.out
hdc shell ./data/local/tmp/lldb-server p --server --listen "*:8080"
lldb
(lldb) platform select remote-ohos (lldb) platform connect connect://localhost:8080
(lldb) target create /data/local/tmp/a.out
(lldb) b main
(lldb) run
(lldb) source list
(lldb) quit