Symbolic breakpoints in Xcode
Symbolic breakpoints are breakpoints based on symbols like functions or methods.
In Swift
You can set symbolic breakpoints on any free functions, instance and class methods, whether in your own classes or not.
Here is an example
1 |
func freeFunction() { |
You can have some breakpoints in Swift like
1 |
UIViewController.viewDidLoad |
- There seems no difference between instance and class methods !!
-
Robot.MyStruct.staticMethod
says that it must matchstaticMethod
inside Robot.MyStruct - With
instanceMethodWithArguments
, Xcode Breakpoint panel shows options for(Robot)(Swift.Int)(b: Swift.Int) -> Swift.Int
and(Robot)(Swift.Int)(b: Swift.Int)(c: Swift.Int) -> Swift.Int
. This may remind you of Instance Methods are Curried Functions in Swift - I thought that symbolic breakpoint must match
Selector
, likeinstanceMethodWithArguments:b:c
, but it is not - Objective-C style
-[UIViewController viewDidLoad]
or-[Robot instanceMethod]
does not work !!
And talking about Swift selector, you may want to take a look at this proposal Referencing the Objective-C selector of a method
In Objective-C
1 |
void freeFunction() { |
You can have some breakpoints in Objective-C like
1 |
-[UIViewController viewDidLoad] |
- We must specify the correct method with arguments like
-[Robot instanceMethod:b:]
- I use another Swift class into this Objective-C project
1 |
public class Animal: NSObject { |
but the symbolic breakpoint -[Animal hello]
does not work. Only Animal.hello
works !!
Syntax
- There are Swift syntax
Animal.hello
and Objective-C syntax-[Animal hello]
. It seems that Swift syntax must be used on Swift files. So in Swift project, we should use Swift syntax -
init
is instance method, see How to swizzle init in Swift
System symbols
Symbolic breakpoints are helpful in case you want to inspect system behaviours
Auto Layout
Breakpoints_v2.xcbkptlist
- Breakpoints_v2.xcbkptlist A list of common symbolic breakpoints and actions
swift_willThrow
- Breakpoint on all throws
objc_exception_throw
It is your Exception Breakpoint
with Break
set to Throw
There’s a Break
type Catch
also
Swizzle
Symbolic breakpoints help when you want to understand system call, like when you try to make Xcode plugin
See How To Create an Xcode Plugin: Part 1/3 on how to break in initWithIcon:message:parentWindow:duration
Assembly
Break on system classes and you want to understand the parameters there, so an understanding of assembly helps
- How to get parameters using symbolic breakpoints in Objective-C
- A Whirlwind Detour of Assembly
- Disassembling the Assembly, Part 1
- iOS Assembly Tutorial: Understanding ARM
Interesting
Some interesting questions
chisel
Facebook has chisel, which is a collection of lldb commands in Python
Specifically, bmessage
Set a symbolic breakpoint on the method of a class or the method of an instance without worrying which class in the hierarchy actually implements the method.