Skip to content

Instantly share code, notes, and snippets.

@thornpig
Last active March 18, 2024 07:19
Show Gist options
  • Save thornpig/f1d1c06a13be052e9eb80c2f87839456 to your computer and use it in GitHub Desktop.
Save thornpig/f1d1c06a13be052e9eb80c2f87839456 to your computer and use it in GitHub Desktop.
Xcode lldb debugging tips
Make sure Product->Scheme->Edit Scheme->Run is using "Debug" mode
(lldb) p NSPointFromString(@"{10.0, 20.0}");
error: 'NSPointFromString' has unknown return type; cast the call to its declared return type
error: 1 errors parsing expression
(lldb) p (NSPoint)NSPointFromString(@"{10.0, 20.0}”);
(NSPoint) $0 = (x = 10, y = 20)
(lldb) e @import UIKit
(lldb) po self.view.bounds
(lldb) p @import Foundation
(lldb) p NSPointFromString(@"{10.0, 20.0}");
(NSPoint) $1 = (x = 10, y = 20)
(lldb) fr v //show arguments and local variables in current frame
(lldb) re r //show general purpose registers for current thread
(lldb) di -f //show disassemeble the current function for the current frame
...
0x10ff67f4e ; symbol stub for: objc_msgSend
...
(lldb) b 0x10ff67f4e
(lldb) po $rsi
4598742723
(lldb) x/s $rsi //read memory as string
0x1121b3ec3: "viewControllerForKey:"
(lldb)memory read -f s $rsi //same as above
(lldb) memory read --size 8 --format x 0x7fff5b5fe5c8 //read memory with 8-byte chunck
(lldb) disassemble --start-address 0x0000000104601bd0 //disassemble from address
(lldb)s //source level step in
(lldb)n //source level step over
(lldb)si //instruction level step in
(lldb)ni //instruction level step over
(lldb)br s -n '-[HelperClass doThing:]' -K 0 //set breakpoint at the beginning of a method call (without skipping prologue)
(lldb)po [NSMethodSignature signatureWithObjCTypes:"c24@?0@8q16"] //get method signature object with objc method type encoding
(lldb)dis -n '-[HelperClass doThing:]' //show disassembly for a method with its name. Very usefull when paired with 'br s -a'
(lldb)br s -a 0x10e2f5b10 //set breakpoint at an instruction with its address.
(lldb)br s -a `c-func` //set breakpoint at the beginning of a c function. cannot be used for objc method
(lldb)br s -a c-func //same as above
(lldb)po [[NSNotificationCenter defaultCenter] debugDescription] //debug notifications
(lldb)break set -r TIS|TSM.* //regex breakpoint
(lldb) break command add 5 //add commands to breakpoint 5. The commands will be automatically executed when the breakpoint is hit.
Enter your debugger command(s). Type 'DONE' to end.
> bt
> c
> DONE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment