~/.lldbinit type format add --format hex int type format add --format hex "char" type format add --format hex "unsigned char" set set stop-line-count-before 20 set set stop-line-count-after 15 settings set target.max-string-summary-length 16384 command alias brpos breakpoint set -f %1 -l %2 settings set target.process.thread.step-in-avoid-nodebug false settings set target.skip-prologue false settings set target.x86-disassembly-flavor intel settings set stop-disassembly-count 8
(lldb) process launch --stop-at-entry -- -program_arg value (lldb) process launch -- <args> (lldb) r <args>
附加在已经运行的程序
waitfor 参数,会在下次程序运行时自动附加上
(lldb) process attach --pid 123 (lldb) process attach --name Sketch (lldb) process attach --name Sketch --waitfor
继续运行
(lldb) thread continue // "c" (lldb) thread step-in // The same as gdb's "step" or "s" (lldb) thread step-over // The same as gdb's "next" or "n" (lldb) thread step-out // The same as gdb's "finish" or "f"
// 按指令步进 (lldb) thread step-inst // The same as gdb's "stepi" / "si" (lldb) thread step-over-inst // The same as gdb's "nexti" / "ni"
停止程序
Stop your process.
(lldb) exit
查看当前代码
(lldb) f //显示前 10 行 (lldb) l - list 1就回到第一行了。l 13就是从第13行开始往下看10行。 list 文件名看其他文件的代码 (lldb) list ArrayUtils.c 看某个函数的代码 (lldb) list main
-h --help Prints out the usage information for the LLDB debugger.
-v --version Prints out the current version number of the LLDB debugger.
-a <arch> --arch <arch> Tells the debugger to use the specified architecture when starting and running the program. <architecture> must be one of the architectures for which the program was compiled.
-f <filename> --file <filename> Tells the debugger to use the file <filename> as the program to be debugged.
-c <filename> --core <filename> Tells the debugger to use the fullpath to <path> as the core file.
-p <pid> --attach-pid <pid> Tells the debugger to attach to a process with the given pid.
-n <process-name> --attach-name <process-name> Tells the debugger to attach to a process with the given name.
-w --wait-for Tells the debugger to wait for a process with the given pid or name to launch before attaching.
-s <filename> --source <filename> Tells the debugger to read in and execute the lldb commands in the given file, after any file provided on the command line has been loaded.
-o --one-line Tells the debugger to execute this one-line lldb command after any file provided on the command line has been loaded.
-S <filename> --source-before-file <filename> Tells the debugger to read in and execute the lldb commands in the given file, before any file provided on the command line has been loaded.
-O --one-line-before-file Tells the debugger to execute this one-line lldb command before any file provided on the command line has been loaded.
-k --one-line-on-crash When in batch mode, tells the debugger to execute this one-line lldb command if the target crashes.
-K <filename> --source-on-crash <filename> When in batch mode, tells the debugger to source this file of lldb commands if the target crashes.
-Q --source-quietly Tells the debugger to execute this one-line lldb command before any file provided on the command line has been loaded.
-b --batch Tells the debugger to running the commands from -s, -S, -o & -O, and then quit. However if any run command stopped due to a signal or crash, the debugger will return to the interactive prompt at the place of the crash.
-e --editor Tells the debugger to open source files using the host's "external editor" mechanism.
-x --no-lldbinit Do not automatically parse any '.lldbinit' files.
-X --no-use-colors Do not use colors.
-P --python-path Prints out the path to the lldb.py file for this version of lldb.
-l <script-language> --script-language <script-language> Tells the debugger to use the specified scripting language for user-defined scripts, rather than the default. Valid scripting languages that can be specified include Python, Perl, Ruby and Tcl. Currently only the Python extensions have been implemented.
-d --debug Tells the debugger to print out extra information for debugging itself.
-r --repl Runs lldb in REPL mode with a stub process.
-R --repl-language Chooses the language for the REPL.
Notes:
Multiple "-s" and "-o" options can be provided. They will be processed from left to right in order, with the source files and commands interleaved. The same is true of the "-S" and "-O" options. The before file and after file sets can intermixed freely, the command parser will sort them out. The order of the file specifiers ("-c", "-f", etc.) is not significant in this regard.
If you don't provide -f then the first argument will be the file to be debugged which means that 'lldb -- <filename> [<ARG1> [<ARG2>]]' also works. But remember to end the options with "--" if any of your arguments have a "-" in them.