xref: /freebsd-src/contrib/llvm-project/lldb/docs/man/lldb.rst (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
1480093f4SDimitry Andric:orphan:
2480093f4SDimitry Andric
3480093f4SDimitry Andriclldb -- The Debugger
4480093f4SDimitry Andric====================
5480093f4SDimitry Andric
6480093f4SDimitry Andric.. program:: lldb
7480093f4SDimitry Andric
8480093f4SDimitry AndricSYNOPSIS
9480093f4SDimitry Andric--------
10480093f4SDimitry Andric
11480093f4SDimitry Andric| :program:`lldb` [*options*] *executable*
12480093f4SDimitry Andric
13480093f4SDimitry AndricDESCRIPTION
14480093f4SDimitry Andric-----------
15480093f4SDimitry Andric
16480093f4SDimitry Andric:program:`lldb` is a next generation, high-performance debugger. It is built as
17480093f4SDimitry Andrica set of reusable components which highly leverage existing libraries in the
18480093f4SDimitry Andriclarger LLVM Project, such as the Clang expression parser and LLVM disassembler.
19480093f4SDimitry Andric
20480093f4SDimitry Andric:program:`lldb` is the default debugger in Xcode on macOS and supports
21480093f4SDimitry Andricdebugging C, Objective-C and C++ on the desktop and iOS devices and simulator.
22480093f4SDimitry Andric
23480093f4SDimitry AndricAll of the code in the LLDB project is available under the Apache 2.0 License
24480093f4SDimitry Andricwith LLVM exceptions.
25480093f4SDimitry Andric
26480093f4SDimitry AndricATTACHING
27480093f4SDimitry Andric---------
28480093f4SDimitry Andric
29480093f4SDimitry Andric.. option:: --attach-name <name>
30480093f4SDimitry Andric
31480093f4SDimitry Andric Tells the debugger to attach to a process with the given name.
32480093f4SDimitry Andric
33480093f4SDimitry Andric.. option:: --attach-pid <pid>
34480093f4SDimitry Andric
35480093f4SDimitry Andric Tells the debugger to attach to a process with the given pid.
36480093f4SDimitry Andric
37480093f4SDimitry Andric.. option:: -n <value>
38480093f4SDimitry Andric
39480093f4SDimitry Andric Alias for --attach-name
40480093f4SDimitry Andric
41480093f4SDimitry Andric.. option:: -p <value>
42480093f4SDimitry Andric
43480093f4SDimitry Andric Alias for --attach-pid
44480093f4SDimitry Andric
45480093f4SDimitry Andric.. option:: --wait-for
46480093f4SDimitry Andric
47480093f4SDimitry Andric Tells the debugger to wait for a process with the given pid or name to launch before attaching.
48480093f4SDimitry Andric
49480093f4SDimitry Andric.. option:: -w
50480093f4SDimitry Andric
51480093f4SDimitry Andric Alias for --wait-for
52480093f4SDimitry Andric
53480093f4SDimitry AndricCOMMANDS
54480093f4SDimitry Andric--------
55480093f4SDimitry Andric
56480093f4SDimitry Andric.. option:: --batch
57480093f4SDimitry Andric
58480093f4SDimitry Andric Tells the debugger to run the commands from -s, -S, -o & -O, and then quit.
59480093f4SDimitry Andric
60480093f4SDimitry Andric.. option:: -b
61480093f4SDimitry Andric
62480093f4SDimitry Andric Alias for --batch
63480093f4SDimitry Andric
64480093f4SDimitry Andric.. option:: -K <value>
65480093f4SDimitry Andric
66480093f4SDimitry Andric Alias for --source-on-crash
67480093f4SDimitry Andric
68480093f4SDimitry Andric.. option:: -k <value>
69480093f4SDimitry Andric
70480093f4SDimitry Andric Alias for --one-line-on-crash
71480093f4SDimitry Andric
72480093f4SDimitry Andric.. option:: --local-lldbinit
73480093f4SDimitry Andric
74480093f4SDimitry Andric Allow the debugger to parse the .lldbinit files in the current working directory, unless --no-lldbinit is passed.
75480093f4SDimitry Andric
76480093f4SDimitry Andric.. option:: --no-lldbinit
77480093f4SDimitry Andric
78480093f4SDimitry Andric Do not automatically parse any '.lldbinit' files.
79480093f4SDimitry Andric
80480093f4SDimitry Andric.. option:: --one-line-before-file <command>
81480093f4SDimitry Andric
82480093f4SDimitry Andric Tells the debugger to execute this one-line lldb command before any file provided on the command line has been loaded.
83480093f4SDimitry Andric
84480093f4SDimitry Andric.. option::  --one-line-on-crash <command>
85480093f4SDimitry Andric
86480093f4SDimitry Andric When in batch mode, tells the debugger to run this one-line lldb command if the target crashes.
87480093f4SDimitry Andric
88480093f4SDimitry Andric.. option:: --one-line <command>
89480093f4SDimitry Andric
90480093f4SDimitry Andric Tells the debugger to execute this one-line lldb command after any file provided on the command line has been loaded.
91480093f4SDimitry Andric
92480093f4SDimitry Andric.. option:: -O <value>
93480093f4SDimitry Andric
94480093f4SDimitry Andric Alias for --one-line-before-file
95480093f4SDimitry Andric
96480093f4SDimitry Andric.. option:: -o <value>
97480093f4SDimitry Andric
98480093f4SDimitry Andric Alias for --one-line
99480093f4SDimitry Andric
100480093f4SDimitry Andric.. option:: -Q
101480093f4SDimitry Andric
102480093f4SDimitry Andric Alias for --source-quietly
103480093f4SDimitry Andric
104480093f4SDimitry Andric.. option:: --source-before-file <file>
105480093f4SDimitry Andric
106480093f4SDimitry Andric Tells the debugger to read in and execute the lldb commands in the given file, before any file has been loaded.
107480093f4SDimitry Andric
108480093f4SDimitry Andric.. option:: --source-on-crash <file>
109480093f4SDimitry Andric
110480093f4SDimitry Andric When in batch mode, tells the debugger to source this file of lldb commands if the target crashes.
111480093f4SDimitry Andric
112480093f4SDimitry Andric.. option:: --source-quietly
113480093f4SDimitry Andric
114*349cc55cSDimitry Andric Tells the debugger not to echo commands while sourcing files or one-line commands provided on the command line.
115480093f4SDimitry Andric
116480093f4SDimitry Andric.. option:: --source <file>
117480093f4SDimitry Andric
118480093f4SDimitry Andric Tells the debugger to read in and execute the lldb commands in the given file, after any file has been loaded.
119480093f4SDimitry Andric
120480093f4SDimitry Andric.. option:: -S <value>
121480093f4SDimitry Andric
122480093f4SDimitry Andric Alias for --source-before-file
123480093f4SDimitry Andric
124480093f4SDimitry Andric.. option:: -s <value>
125480093f4SDimitry Andric
126480093f4SDimitry Andric Alias for --source
127480093f4SDimitry Andric
128480093f4SDimitry Andric.. option:: -x
129480093f4SDimitry Andric
130480093f4SDimitry Andric Alias for --no-lldbinit
131480093f4SDimitry Andric
132480093f4SDimitry AndricOPTIONS
133480093f4SDimitry Andric-------
134480093f4SDimitry Andric
135480093f4SDimitry Andric.. option:: --arch <architecture>
136480093f4SDimitry Andric
137480093f4SDimitry Andric Tells the debugger to use the specified architecture when starting and running the program.
138480093f4SDimitry Andric
139480093f4SDimitry Andric.. option:: -a <value>
140480093f4SDimitry Andric
141480093f4SDimitry Andric Alias for --arch
142480093f4SDimitry Andric
143480093f4SDimitry Andric.. option:: --capture-path <filename>
144480093f4SDimitry Andric
145480093f4SDimitry Andric Tells the debugger to use the given filename for the reproducer.
146480093f4SDimitry Andric
147480093f4SDimitry Andric.. option:: --capture
148480093f4SDimitry Andric
149480093f4SDimitry Andric Tells the debugger to capture a reproducer.
150480093f4SDimitry Andric
151480093f4SDimitry Andric.. option:: --core <filename>
152480093f4SDimitry Andric
153480093f4SDimitry Andric Tells the debugger to use the full path to <filename> as the core file.
154480093f4SDimitry Andric
155480093f4SDimitry Andric.. option:: -c <value>
156480093f4SDimitry Andric
157480093f4SDimitry Andric Alias for --core
158480093f4SDimitry Andric
159480093f4SDimitry Andric.. option:: --debug
160480093f4SDimitry Andric
161480093f4SDimitry Andric Tells the debugger to print out extra information for debugging itself.
162480093f4SDimitry Andric
163480093f4SDimitry Andric.. option:: -d
164480093f4SDimitry Andric
165480093f4SDimitry Andric Alias for --debug
166480093f4SDimitry Andric
167480093f4SDimitry Andric.. option:: --editor
168480093f4SDimitry Andric
169480093f4SDimitry Andric Tells the debugger to open source files using the host's "external editor" mechanism.
170480093f4SDimitry Andric
171480093f4SDimitry Andric.. option:: -e
172480093f4SDimitry Andric
173480093f4SDimitry Andric Alias for --editor
174480093f4SDimitry Andric
175480093f4SDimitry Andric.. option:: --file <filename>
176480093f4SDimitry Andric
177480093f4SDimitry Andric Tells the debugger to use the file <filename> as the program to be debugged.
178480093f4SDimitry Andric
179480093f4SDimitry Andric.. option:: -f <value>
180480093f4SDimitry Andric
181480093f4SDimitry Andric Alias for --file
182480093f4SDimitry Andric
183480093f4SDimitry Andric.. option:: --help
184480093f4SDimitry Andric
185480093f4SDimitry Andric Prints out the usage information for the LLDB debugger.
186480093f4SDimitry Andric
187480093f4SDimitry Andric.. option:: -h
188480093f4SDimitry Andric
189480093f4SDimitry Andric Alias for --help
190480093f4SDimitry Andric
191480093f4SDimitry Andric.. option:: --no-use-colors
192480093f4SDimitry Andric
193480093f4SDimitry Andric Do not use colors.
194480093f4SDimitry Andric
195480093f4SDimitry Andric.. option:: --replay <filename>
196480093f4SDimitry Andric
197480093f4SDimitry Andric Tells the debugger to replay a reproducer from <filename>.
198480093f4SDimitry Andric
199480093f4SDimitry Andric.. option:: --version
200480093f4SDimitry Andric
201480093f4SDimitry Andric Prints out the current version number of the LLDB debugger.
202480093f4SDimitry Andric
203480093f4SDimitry Andric.. option:: -v
204480093f4SDimitry Andric
205480093f4SDimitry Andric Alias for --version
206480093f4SDimitry Andric
207480093f4SDimitry Andric.. option:: -X
208480093f4SDimitry Andric
209480093f4SDimitry Andric Alias for --no-use-color
210480093f4SDimitry Andric
211480093f4SDimitry AndricREPL
212480093f4SDimitry Andric----
213480093f4SDimitry Andric
214480093f4SDimitry Andric.. option:: -r=<flags>
215480093f4SDimitry Andric
216480093f4SDimitry Andric Alias for --repl=<flags>
217480093f4SDimitry Andric
218480093f4SDimitry Andric.. option:: --repl-language <language>
219480093f4SDimitry Andric
220480093f4SDimitry Andric Chooses the language for the REPL.
221480093f4SDimitry Andric
222480093f4SDimitry Andric.. option:: --repl=<flags>
223480093f4SDimitry Andric
224480093f4SDimitry Andric Runs lldb in REPL mode with a stub process with the given flags.
225480093f4SDimitry Andric
226480093f4SDimitry Andric.. option:: -R <value>
227480093f4SDimitry Andric
228480093f4SDimitry Andric Alias for --repl-language
229480093f4SDimitry Andric
230480093f4SDimitry AndricSCRIPTING
231480093f4SDimitry Andric---------
232480093f4SDimitry Andric
233480093f4SDimitry Andric.. option:: -l <value>
234480093f4SDimitry Andric
235480093f4SDimitry Andric Alias for --script-language
236480093f4SDimitry Andric
237*349cc55cSDimitry Andric.. option:: --print-script-interpreter-info
238*349cc55cSDimitry Andric
239*349cc55cSDimitry Andric  Prints out a json dictionary with information about the scripting language interpreter.
240*349cc55cSDimitry Andric
241480093f4SDimitry Andric.. option:: --python-path
242480093f4SDimitry Andric
243480093f4SDimitry Andric Prints out the path to the lldb.py file for this version of lldb.
244480093f4SDimitry Andric
245480093f4SDimitry Andric.. option:: -P
246480093f4SDimitry Andric
247480093f4SDimitry Andric Alias for --python-path
248480093f4SDimitry Andric
249480093f4SDimitry Andric.. option:: --script-language <language>
250480093f4SDimitry Andric
251480093f4SDimitry Andric Tells the debugger to use the specified scripting language for user-defined scripts.
252480093f4SDimitry Andric
253480093f4SDimitry AndricEXAMPLES
254480093f4SDimitry Andric--------
255480093f4SDimitry Andric
256480093f4SDimitry AndricThe debugger can be started in several modes.
257480093f4SDimitry Andric
2585ffd83dbSDimitry AndricPassing an executable as a positional argument prepares lldb to debug the given
2595ffd83dbSDimitry Andricexecutable. To disambiguate between arguments passed to lldb and arguments
2605ffd83dbSDimitry Andricpassed to the debugged executable, arguments starting with a - must be passed
2615ffd83dbSDimitry Andricafter --.
262480093f4SDimitry Andric
26323408297SDimitry Andric  lldb --arch x86_64 /path/to/program program argument -- --arch armv7
2645ffd83dbSDimitry Andric
2655ffd83dbSDimitry AndricFor convenience, passing the executable after -- is also supported.
2665ffd83dbSDimitry Andric
26723408297SDimitry Andric  lldb --arch x86_64 -- /path/to/program program argument --arch armv7
268480093f4SDimitry Andric
269480093f4SDimitry AndricPassing one of the attach options causes :program:`lldb` to immediately attach
270480093f4SDimitry Andricto the given process.
271480093f4SDimitry Andric
272480093f4SDimitry Andric  lldb -p <pid>
273480093f4SDimitry Andric  lldb -n <process-name>
274480093f4SDimitry Andric
275480093f4SDimitry AndricPassing --repl starts :program:`lldb` in REPL mode.
276480093f4SDimitry Andric
277480093f4SDimitry Andric  lldb -r
278480093f4SDimitry Andric
279480093f4SDimitry AndricPassing --core causes :program:`lldb` to debug the core file.
280480093f4SDimitry Andric
281480093f4SDimitry Andric  lldb -c /path/to/core
282480093f4SDimitry Andric
283480093f4SDimitry AndricCommand options can be combined with these modes and cause :program:`lldb` to
284480093f4SDimitry Andricrun the specified commands before or after events, like loading the file or
285480093f4SDimitry Andriccrashing, in the order provided on the command line.
286480093f4SDimitry Andric
287480093f4SDimitry Andric  lldb -O 'settings set stop-disassembly-count 20' -o 'run' -o 'bt'
288480093f4SDimitry Andric  lldb -S /source/before/file -s /source/after/file
289480093f4SDimitry Andric  lldb -K /source/before/crash -k /source/after/crash
290480093f4SDimitry Andric
291480093f4SDimitry AndricNote: In REPL mode no file is loaded, so commands specified to run after
292480093f4SDimitry Andricloading the file (via -o or -s) will be ignored.
293480093f4SDimitry Andric
294480093f4SDimitry AndricUSING LLDB
295480093f4SDimitry Andric----------
296480093f4SDimitry Andric
297480093f4SDimitry AndricIn :program:`lldb` there is a help command which can be used to find
298480093f4SDimitry Andricdescriptions and examples of all :program:`lldb` commands.  To get help on
299480093f4SDimitry Andric"breakpoint set" you would type "help breakpoint set".
300480093f4SDimitry Andric
301480093f4SDimitry AndricThere is also an apropos command which will search the help text of all
302480093f4SDimitry Andriccommands for a given term ‐‐ this is useful for locating a command by topic.
303480093f4SDimitry AndricFor instance, "apropos breakpoint" will list any command that has the word
304480093f4SDimitry Andric"breakpoint" in its help text.
305480093f4SDimitry Andric
306480093f4SDimitry AndricCONFIGURATION FILES
307480093f4SDimitry Andric-------------------
308480093f4SDimitry Andric
309480093f4SDimitry Andric:program:`lldb` reads things like settings, aliases and commands from the
3105ffd83dbSDimitry Andric.lldbinit file.
3115ffd83dbSDimitry Andric
312e8d8bef9SDimitry AndricFirst, :program:`lldb` will try to read the application specific init file
313e8d8bef9SDimitry Andricwhose name is ~/.lldbinit followed by a "-" and the name of the current
314e8d8bef9SDimitry Andricprogram. This would be ~/.lldbinit-lldb for the command line :program:`lldb`
315e8d8bef9SDimitry Andricand ~/.lldbinit-Xcode for Xcode. If there is no application specific init
316e8d8bef9SDimitry Andricfile, :program:`lldb` will look for an init file in the home directory.
317e8d8bef9SDimitry AndricIf launched with a `REPL`_ option, it will first look for a REPL configuration
318e8d8bef9SDimitry Andricfile, specific to the REPL language. The init file should be named as follow:
319e8d8bef9SDimitry Andric``.lldbinit-<language>-repl`` (i.e. ``.lldbinit-swift-repl``). If this file doesn't
320e8d8bef9SDimitry Andricexist, or :program:`lldb` wasn't launch with `REPL`_, meaning there is neither
321e8d8bef9SDimitry Andrica REPL init file nor an application specific init file, ``lldb`` will fallback to
322e8d8bef9SDimitry Andricthe global ~/.lldbinit.
3235ffd83dbSDimitry Andric
324480093f4SDimitry AndricSecondly, it will look for an .lldbinit file in the current working directory.
325480093f4SDimitry AndricFor security reasons, :program:`lldb` will print a warning and not source this
326480093f4SDimitry Andricfile by default. This behavior can be changed by changing the
327480093f4SDimitry Andrictarget.load-cwd-lldbinit setting.
328480093f4SDimitry Andric
329480093f4SDimitry AndricTo always load the .lldbinit file in the current working directory, add the
330480093f4SDimitry Andricfollowing command to ~/.lldbinit:
331480093f4SDimitry Andric
332480093f4SDimitry Andric  settings set target.load-cwd-lldbinit true
333480093f4SDimitry Andric
334480093f4SDimitry AndricTo never load the .lldbinit file in the current working directory and silence
335480093f4SDimitry Andricthe warning, add the following command to ~/.lldbinit:
336480093f4SDimitry Andric
337480093f4SDimitry Andric  settings set target.load-cwd-lldbinit false
338480093f4SDimitry Andric
339480093f4SDimitry AndricSEE ALSO
340480093f4SDimitry Andric--------
341480093f4SDimitry Andric
342480093f4SDimitry AndricThe LLDB project page https://lldb.llvm.org has many different resources
343480093f4SDimitry Andricfor :program:`lldb` users ‐‐ the gdb/lldb command equivalence page
344480093f4SDimitry Andrichttps://lldb.llvm.org/use/map.html can be especially helpful for users
345480093f4SDimitry Andriccoming from gdb.
346