The basic format of LLDB instructions
<command> [<subcommand> [<subcommand>...]] <action> [-options [option- value]] [argument [argument...]]
Copy the code
Corresponds to the
Command subcommand Command Operation Command option Command parametersCopy the code
For example, to set a breakpoint for test:
breakpoint set -n test
Copy the code
The help command
The help directive can help us quickly find out how to use the LLDB directive
help breakpoint
help breakpoint set
Copy the code
Expression — instructions
The expression directive is used to execute an expression
Expression of self. The backgroundColor = [UIColor redColor] / / or expression -- self. The backgroundColor = [UIColor redColor]Copy the code
- Expression, expression — is equivalent to the print, p, call instructions
- Expression -O – is the same as the Po command
(lldb) expression -O -- self.view <UIView: 0x7f8f77c1dde0; frame = (0 0; 375, 667); autoresize = W+H; layer = <CALayer: 0x600002098d20>> (lldb) po self.view <UIView: 0x7f8f77c1dde0; frame = (0 0; 375, 667); autoresize = W+H; layer = <CALayer: 0x600002098d20>>Copy the code
Expression — indicates the end of command options. It indicates that all command options are set. If no command options are available, — can be omitted. If expression is followed by a command option, — cannot be omitted.
thread backtrace
The thread backtrace directive prints the stack information for a thread, which has the same effect as bt.
thread return []
Let the function return a value, not execute the following code. If the function returns a value, follow it with the return value. If the function does not return a value, simply use Thread return
frame variable []
Prints the variable of the current stack frame
(lldb) frame variable
(ViewController *) self = 0x00007f8f7b0091e0
(SEL) _cmd = "touchesBegan:withEvent:"
(__NSSetM *) touches = 0x00006000020c13e0 1 element
(UITouchesEvent *) event = 0x00006000011c43c0
(lldb) frame variable self
(ViewController *) self = 0x00007f8f7b0091e0
Copy the code
Thread related instruction
The following instructions are shown from left to right: full name of instruction, abbreviation of instruction, and minimalist instruction
- Process Continue, continue, c: Lets the program skip the breakpoint and continue running
- Thread step-over, next, n: Run in a single step, executing sub-functions as a whole in one step
- Thread step-in, step, s: Runs in a single step and enters a sub-function when it encounters a sub-function
- Thread step-out, finish: Executes all code of the current function and returns to the previous function
- Thread step-inst-over, Nexti, ni
- Thread step-inst, STEPI, and SI
Si and NI are similar to s and N instructions, but S and N are at the source level, while SI and NI are at the assembly level. Each line of OC code consists of one or more assembly instructions. S and N instructions represent the step by step execution of each line of OC code, while SI and NI represent the step by step execution of assembly instructions.
Breakpoint related instructions
breakpoint set
To set breakpoints
- Breakpoint set -a Function address
- Breakpoint set -n Specifies the function name
- breakpoint set -n test
- breakpoint set -n touchesBegan:withEvent:
- breakpoint set -n “-[ViewController touchesBegan:withEvent:]”
- Breakpoint set -r Regular expression
Following the regular expression, breakpoints are added to all matched methodsCopy the code
- Breakpoint set -s breakpoint set -n Breakpoint sets the breakpoint for the specified function in the specified dynamic library
breakpoint list
Lists all breakpoints, with each breakpoint individually numbered
Breakpoint Disable Indicates the breakpoint number
Disable breakpoints
Breakpoint Enable Indicates the breakpoint number
Enable the breakpoint
Breakpoint delete Indicates the breakpoint number
Remove breakpoints
Breakpoint Command add Breakpoint number
The breakpoint with the specified breakpoint number is preconfigured with commands to execute. When the breakpoint is triggered, the preconfigured commands are executed in sequence
(lldb) breakpoint command add 5 Enter your debugger command(s). Type 'DONE' to end. > po self.view > p self.view.backgroundColor = [UIColor yellowColor]; > DONE (lldb) c Process 76025 resuming po self.view <UIView: 0x7f8f77c1dde0; frame = (0 0; 375, 667); autoresize = W+H; layer = <CALayer: 0x600002098d20>> p self.view.backgroundColor = [UIColor yellowColor]; (UICachedDeviceRGBColor *) $5 = 0x00006000035b5cc0Copy the code
Breakpoint Command List Breakpoint number
View all preset commands for a breakpoint number
(lldb) breakpoint command list 5
Breakpoint 5:
Breakpoint commands:
po self.view
p self.view.backgroundColor = [UIColor yellowColor];
Copy the code
Breakpoint Command delete Number of a breakpoint
Deletes all default commands for breakpoints specified by number
Memory breakpoint Watchpoint
A breakpoint is triggered when data in memory changes
Watchpoint set variable
Sets a memory breakpoint on a specified variable. It is triggered when the value of the variable changes
Watchpoint set variable self->_age created: self. Age (LLDB) watchpoint set variable self->_age created: Watchpoint 1: addr = 0x7f9861205220 size = 8 state = enabled type = w watchpoint spec = 'self->_age' new value: 0 Watchpoint 1 hit: old value: 0 new value: 20Copy the code
Watchpoint set expression Memory address
Set a breakpoint on a specified memory address, as watchpoint set variable does
watchpoint list
List all memory breakpoints
(lldb) watchpoint list
Number of supported hardware watchpoints: 4
Current watchpoints:
Watchpoint 1: addr = 0x7f9861205220 size = 8 state = enabled type = w
watchpoint spec = 'self->_age'
old value: 0
new value: 20
Copy the code
Watchpoint Disable Breakpoint number
Disabling memory breakpoints
Watchpoint enable Number of a breakpoint
Enabling memory breakpoints
Watchpoint delete Breakpoint number
Delete memory breakpoints
Watchpoint Command add Breakpoint number
A memory breakpoint with a specified breakpoint number is preconfigured with commands to be executed. When a memory breakpoint is triggered, the preconfigured commands are executed in sequence
Watchpoint Command List Breakpoint number
View all preset commands for a specified memory breakpoint
Watchpoint Command delete Number of a breakpoint
Deletes all default commands for the specified number of memory breakpoints
Image module query instruction
image lookup
Module query instruction
- Image lookup -t type Searches for information of a certain type
(lldb) image lookup -t NSUInteger Best match found in /Users/pinba/Library/Developer/Xcode/DerivedData/LLDBDemo-dkmvkvkytmalsoensevrvixujugm/Build/Products/Debug-iphonesimula tor/LLDBDemo.app/LLDBDemo: id = {0x1000000ab}, name = "NSUInteger", byte-size = 8, decl = NSObjCRuntime.h:13, compiler_type = "typedef NSUInteger" typedef 'NSUInteger': id = {0x1000000b8}, name = "long unsigned int", qualified = "unsigned long", byte-size = 8, compiler_type = "unsigned long"Copy the code
- Image lookup -a Memory address Locate the memory address in the module
(lldb) image lookup -a 0x00000001088b7cdb
Address: LLDBDemo[0x0000000100000cdb] (LLDBDemo.__TEXT.__text + 187)
Summary: LLDBDemo`-[ViewController touchesBegan:withEvent:] + 123 at ViewController.m:26:15
Copy the code
- Image lookup -n Symbol or function name Finds the location of a symbol or function
(lldb) image lookup -n "-[ViewController touchesBegan:withEvent:]" 2 matches found in /Users/pinba/Library/Developer/Xcode/DerivedData/LLDBDemo-dkmvkvkytmalsoensevrvixujugm/Build/Products/Debug-iphonesimula tor/LLDBDemo.app/LLDBDemo: Address: LLDBDemo[0x0000000100000c60] (LLDBDemo.__TEXT.__text + 64) Summary: LLDBDemo`-[ViewController touchesBegan:withEvent:] at ViewController.m:22 Address: LLDBDemo[0x0000000100000c60] (LLDBDemo.__TEXT.__text + 64) Summary: LLDBDemo`-[ViewController touchesBegan:withEvent:] at ViewController.m:22Copy the code
image list
Lists all loaded modules
(lldb) image list [ 0] 927601BD-5A00-319C-B8AF-8D501BB5D849 0x0000000100c01000 /Users/pinba/Library/Developer/Xcode/DerivedData/LLDBDemo-dkmvkvkytmalsoensevrvixujugm/Build/Products/Debug-iphonesimula tor/LLDBDemo.app/LLDBDemo [ 1] EEA931D0-403E-3BC8-862A-CBA037DE4A74 0x000000010d352000 /usr/lib/dyld [ 2] 75369F31-702D-364A-95C3-8AFA9DD4B3A2 0x0000000100c0d000 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes /iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/dyld_sim ......Copy the code
- Image list -o -f Displays the offset address and full path of the module
lldb) image list -o -f [ 0] 0x0000000000c01000 /Users/pinba/Library/Developer/Xcode/DerivedData/LLDBDemo-dkmvkvkytmalsoensevrvixujugm/Build/Products/Debug-iphonesimula tor/LLDBDemo.app/LLDBDemo [ 1] 0x000000010d352000 /usr/lib/dyld [ 2] 0x0000000100c0d000 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes /iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/dyld_sim ......Copy the code
LLDB tip
- Each time you press Enter, the previous command is automatically executed
- Abbreviations can be used for most instructions
(lldb) breakpoint list
(lldb) br li
(lldb) br l
(lldb) breakpoint set -n test
(lldb) br s -n test
Copy the code