• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# LLDB
2## Overview
3Low Lever Debugger (LLDB) is a next-generation, high-performance debugger. For details, visit the [LLDB official website](https://lldb.llvm.org/).
4
5LLDB used in OpenHarmony is developed on [LLVM 15.0.4](https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.4). It is the default debugger in DevEco Studio and supports debugging of C and C++ applications.
6
7## How to Obtain
8Obtain the OpenHarmony SDK from the following website: http://ci.openharmony.cn/workbench/cicd/dailybuild
9
10Find LLDB in the **\ohos-sdk\[system]\native\llvm** directory of the SDK, where **system** can be **windows**, **linux**, or **darwin**.
11
12For example, for Windows, **lldb.exe** is stored in **\ohos-sdk\windows\native\llvm\bin** after the SDK is decompressed.
13
14## Functions
15
16The following lists some functions supported by LLDB. For more functions and related commands, see [LLDB Usage Guide](https://gitee.com/openharmony/third_party_llvm-project/blob/master/lldb/README.md) and [LLDB official manual](https://lldb.llvm.org/use/map.html#).
17
18- Logging
19
20- Breakpoint management
21
22- Watchpoint management
23
24- Expression processing
25
26- Viewing variables
27
28- Process/Thread management
29
30- Assembly processing
31
32- Obtaining source code information
33
34- Signal processing
35
36- Launching a process
37
38- Attaching to a process
39
40## Use Scenarios
41
42### Local Debugging
43
44- Linux x86_64 local debugging
45
46  LLDB supports debugging of C and C++ applications in the Linux x86_64 environment.
47
48- macOS local debugging on the macOS desktop
49
50  LLDB supports debugging of C and C++ applications on the macOS desktop (including macOS x86_64 and M1).
51
52### Remote Debugging
53
54- Remote debugging based on DevEco Studio
55
56  LLDB supports remote debugging of native C++ applications by connecting to OpenHarmony devices or emulators on the Windows and macOS desktops based on DevEco Studio.
57
58- Remote debugging through direct connection
59
60  LLDB supports remote debugging of C and C++ applications by directly connecting to OpenHarmony devices in Windows, macOS desktop, and Linux x86_64 environment.
61
62## How to Use
63
64### Local Debugging
65
66> **NOTE**
67>
68> The local debugging procedure for Linux x86_64 is the same as that for macOS.
69
70**Procedure**
71
72- Using LLDB to start and debug an application
73
74   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.
75
76   1. Obtain the executable file **a.out**.
77
78   2. Run LLDB and specify the file to debug as **a.out**.
79
80      ```lldb
81      ./lldb a.out
82      ```
83
84   3. Set breakpoints at the **main** function in the code.
85
86      ```lldb
87      (lldb) b main
88      ```
89
90   4. Run the application, and it stops at the first breakpoint.
91
92      ```lldb
93      (lldb) run
94      ```
95
96   5. Continue to run the application.
97
98      ```lldb
99      (lldb) continue
100      ```
101
102   6. List all the breakpoints.
103
104      ```lldb
105      (lldb) breakpoint list
106      ```
107
108   7. Show the arguments and local variables of the current frame.
109
110      ```lldb
111      (lldb) frame variable
112      ```
113
114   8. Run debugging commands as required to continue debugging.
115
116   9. Exit debugging.
117
118      ```lldb
119      (lldb) quit
120      ```
121
122- Using LLDB to debug a started application
123
124   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.
125
126   1. Start the application on Command Line Interface (CLI) 1. (The message "Please input a number of type int" is displayed.)
127      ```shell
128      ./a.out
129      ```
130
131   2. Run LLDB on CLI 2.
132      ```shell
133      ./lldb
134      ```
135
136   3. Attach to the application.
137
138      ```lldb
139      (lldb) process attach --name a.out
140      ```
141
142   4. Set a breakpoint in line 10 of **hello.cpp**.
143
144      ```lldb
145      (lldb) breakpoint set --file hello.cpp --line 12
146      ```
147
148   5. On CLI 1, enter a number of the int type.
149
150      ```shell
151      88
152      ```
153
154   6. Continue to run the application on CLI 2. The application stops at the breakpoint.
155
156      ````lldb
157      (lldb) continue
158      ````
159
160   7. Run debugging commands as required to continue debugging.
161
162   8. Detach from the application.
163
164      ```lldb
165      (lldb) detach
166      ```
167
168   9. Exit debugging.
169
170      ```lldb
171      (lldb) quit
172      ```
173
174   > **NOTE**
175   >
176   > You can also perform step 4 in prior to step 3.
177
178
179### Remote Debugging
180
181> **NOTE**
182>
183> - During remote debugging, **lldb-server** and **lldb** must be used together.
184> - The remote debugging procedures for Windows, Linux x86_64, and macOS are the same.
185>
186
187**Procedure**
188
189The 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) on the Windows platform.
190
191> **NOTE**
192>
193> In the command below, **/data/local/tmp** indicates the specified directory on the device.
194>
195> **8080** is the listening port, which can be customized.
196>
197> You must have the execute permission on the **lldb-server** and **a.out** files of the device.
198>
199
2001. 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.)
201
202   ```shell
203   hdc file send lldb-server /data/local/tmp
204   hdc file send a.out /data/local/tmp
205   ```
206
2072. Run **lldb-server**.
208
209   ```shell
210   hdc shell ./data/local/tmp/lldb-server p --server --listen "*:8080"
211   ```
212
2133. Open CLI 2 and run the binary file **lldb**.
214
215   ```shell
216   ./lldb
217   ```
218
2194. Select and connect to the remote device on the LLDB CLI.
220
221   ```lldb
222   (lldb) platform select remote-ohos
223   (lldb) platform connect connect://localhost:8080
224   ```
225
2265. Specify the binary file **a.out** on the device to be debugged.
227
228   ```lldb
229   (lldb) target create /data/local/tmp/a.out
230   ```
231
2326. Set breakpoints at the **main** function in the code.
233
234   ```lldb
235   (lldb) b main
236   ```
237
2387. Start the application.
239
240   ```lldb
241   (lldb) run
242   ```
243
2448. Display source code for the current target process.
245
246   ```lldb
247   (lldb) source list
248   ```
249
2509. Run debugging commands as required to continue debugging.
251
25210. Exit debugging.
253
254    ```lldb
255    (lldb) quit
256    ```
257