This is a list of common LLDB commands, including all debugging commands, helping you locate and Debug bugs faster

Getting help

(lldb) help
Copy the code

Lists all commands and aliases

(lldb) help po
Copy the code

Get the help documentation for the Po command

(lldb) help break set
Copy the code

Get the help documentation for the break set subcommand

(lldb) apropos step-in
Copy the code

Step-in commands are included in the search help documentation

Finding Code

(lldb) image lookup -rn UIAlertController
Copy the code

See all the compiled or run code that contains UIAlertController

(lldb) image lookup -rn (? i)hosturlCopy the code

View all code that contains the hostURL and is case insensitive

(lldb) image lookup -rn 'UIViewController\ set\w+:\]'
Copy the code

Look at the setter methods that are implemented or overwritten for all the properties in UIViewController

(lldb) image lookup -rn . Security
Copy the code

View all the code in the Security module

(lldb) image lookup -s mmap
Copy the code

View the code identified as MMAP

Breakpoints

(lldb) b viewDidLoad
Copy the code

Create a breakpoint in all viewDidLoad methods (Swift/ Objective-C)

(lldb) b setAlpha:
Copy the code

Create a breakpoint in oc’s setAlpha: method or in setter methods for oc’s alpha property

(lldb) b -[CustomeViewControllerSubclass viewDidLoad]
Copy the code

In the OC [CustomeViewControllerSubclass viewDidLoad] set a breakpoint

(lldb) rbreak CustomViewControllerSubclass.viewDidLoad
Copy the code

Create a regular breakpoints, matching OC and Swift CustomViewControllerSubclass viewDidLoad method in the class, including the OC [CustomeViewControllerSubclass. ViewDidLoad] or Swfit The ModuleName. CustomeViewControllerSubclass. ViewDidLoad () – > ().

(lldb) breakpoint delete
Copy the code

Delete all breakpoints

(lldb) breakpoint delete 2
Copy the code

Example Delete breakpoint 2

(lldb) breakpoint list
Copy the code

Lists all breakpoints and their ids

(lldb) rbreak viewDid
Copy the code

Create a regular breakpoint match.*viewDid.*

(lldb) rbreak viewDid -s SwiftRadio
Copy the code

Create a regular breakpoint match in the SwfitRadio module.

(lldb) rbreak viewDid(Appear|Disappear) -s SwiftHN
Copy the code

Create a breakpoint in viewDidAppear and viewDidDisappera of the Swift module

(lldb) rb "\-\[UIViewController\ set" -s UIKit
Copy the code

Create a breakpoint in UIKit module to break all methods in OC that contain [UIViewController set]

(lldb) rb . -s SwiftHN -o
Copy the code

Breakpoints are created in all methods in the SwiftHN module, but as soon as one breakpoint is triggered, all breakpoints are removed

(lldb) rb . -f ViewController.m
Copy the code

Create a breakpoint on all methods in viewController.m

Expressions(Expressions)

(lldb) po "hello, debugger"
Copy the code

Print the hello, the debugger

(lldb) expression -lobjc -O -- [UIApplication sharedApplication]
Copy the code

Print UIApplication instances in OC

(lldb) expression -lswift -O -- UIApplication.shared
Copy the code

Prints an instance of UIApplication in Swift

(lldb) b getenv
(lldb) expression -i0 -- getenv("HOME")
Copy the code

Create a breakpoint in getenv and execute the getenv method. The program will break where the getenv method is executed

(lldb) expression -u0 -O -- [UIApplication test]
Copy the code

Execute method [UIApplication test], do not expand the call stack if this method causes the application to crash

(lldb) expression -p -- NSString *globalString = [NSString stringWithUTF8String: "Hello, Debugger"];
(lldb) po globalString
Hello, Debugger
Copy the code

Declare a globalString variable globalString

(lldb) expression -g -O -lobjc -- [NSObject new]
Copy the code

Parse the representation of [NSObject new] in OC

Stepping (step)

(lldb) thread return false
Copy the code

Returns false ahead of time in the current code

(lldb) thread step-in
Copy the code

Execute the next line of code

(lldb) thread step-over
Copy the code

Execute the next method

(lldb) thread step-out
Copy the code

Step out of the current method

(lldb) thread step-inst
Copy the code

Step if you execute a method, otherwise enter the command set

GDB formatting

(lldb) p/x 128
Copy the code

Output data in hexadecimal format

(lldb) p/d 128
Copy the code

Output data in base 10 format

(lldb) p/t 128
Copy the code

Output data in base 2 format

(lldb) p/a 128
Copy the code

Output data as an address

(lldb) x/gx 0x000000010fff6c40
Copy the code

Get the data from address 0x000000010FFF6c40 and display it in 8 bytes

(lldb) x/wx 0x000000010fff6c40
Copy the code

Get the data from address 0x000000010FFF6c40 and display it in 4 bytes

Memory

(lldb) memory read 0x000000010fff6c40
Copy the code

Read memory at address 0x000000010FFF6c40

(lldb) po id $d = [NSData dataWithContentsOfFile:@"..."]
(lldb) mem read `(uintptr_t)[$d bytes]` `(uintptr_t)[$d bytes] +
(uintptr_t)[$d length]` -r -b -o /tmp/file
Copy the code

Get an instance from a remote file and write it to/TMP /file on your computer

Registers & Assemblies

(lldb)  register read -a
Copy the code

Displays all registers in the system

(lldb) register read rdi rsi
Copy the code

Read data from registers RDI and RSI

(lldb) register write rsi 0x0
Copy the code

Set register RSI data to 0x0

(lldb) disassemble
Copy the code

Assembler instruction that displays your current pause method

(lldb) disassemble -n '-[UIViewController setTitle:]'
Copy the code

Parse the [UIViewController setTitle:] method in OC

(lldb) disassemble -a 0x000000010b8d972d
Copy the code

Resolves a method that contains the address 0x000000010b8d972D

Modules (Modules)

(lldb) image list
Copy the code

Lists information about all modules loaded in the current process

(lldb) image list -b
Copy the code

Lists the names of all modules loaded in the current process

(lldb) process load /Path/To/Module.framework/Module
Copy the code

Loads a local module in the current process