Contents
  1. 1. In Swift
  2. 2. In Objective-C
  3. 3. Syntax
  4. 4. System symbols
    1. 4.1. Auto Layout
    2. 4.2. Breakpoints_v2.xcbkptlist
    3. 4.3. swift_willThrow
    4. 4.4. objc_exception_throw
    5. 4.5. Swizzle
    6. 4.6. Assembly
    7. 4.7. Interesting
  5. 5. chisel
  6. 6. Reference

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
func freeFunction() {
print("freeFunction")
}

class Robot {
init() {
print("init")
}

func instanceMethod() {
print("instanceMethod")
}

func instanceMethod(noise: Int) {
print("instanceMethod")
}

func instanceMethodWithArguments(a: Int, b: Int) -> Int {
print("instanceMethodWithArguments")
return a + b
}

func instanceMethodWithArguments(a: Int, b: Int, c: Int) -> Int {
print("instanceMethodWithArguments")
return a + b + c
}

class func classMethod() {
print("classMethod")
}

struct MyStruct {
static func staticMethod() {
print("staticMethod")
}
}
}

struct MyStruct {
static func staticMethod() {
print("staticMethod")
}
}

You can have some breakpoints in Swift like

1
2
3
4
5
6
7
UIViewController.viewDidLoad
freeFunction
Robot.instanceMethod
instanceMethodWithArguments
Robot.classMethod
Robot.init
Robot.MyStruct.staticMethod
  • There seems no difference between instance and class methods !!
  • Robot.MyStruct.staticMethod says that it must match staticMethod 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, like instanceMethodWithArguments: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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
void freeFunction() {
NSLog(@"freeFunction");
}


@interface Robot : NSObject

@property (nonatomic, copy) NSString *name;

- (void)instanceMethod;
- (void)instanceMethod:(NSInteger)a b:(NSInteger)b;
+ (void)classMethod;

@end

@implementation Robot

- (instancetype)initWithName:(NSString *)name {
self = [super init];
self.name = name;

return self;
}

- (void)instanceMethod {
NSLog(@"instanceMethod");
}

- (void)instanceMethod:(NSInteger)a b:(NSInteger)b {
NSLog(@"instanceMethod:b:");
}

+ (void)classMethod {
NSLog(@"classMethod");
}

@end

You can have some breakpoints in Objective-C like

1
2
3
4
5
6
-[UIViewController viewDidLoad]
freeFunction
-[Robot initWithName:]
-[Robot instanceMethod]
-[Robot instanceMethod:b:]
+[Robot classMethod]
  • We must specify the correct method with arguments like -[Robot instanceMethod:b:]
  • I use another Swift class into this Objective-C project
1
2
3
4
5
@objc public class Animal: NSObject {
@objc func hello() {
print("hello")
}
}

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

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

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.

Reference

Contents
  1. 1. In Swift
  2. 2. In Objective-C
  3. 3. Syntax
  4. 4. System symbols
    1. 4.1. Auto Layout
    2. 4.2. Breakpoints_v2.xcbkptlist
    3. 4.3. swift_willThrow
    4. 4.4. objc_exception_throw
    5. 4.5. Swizzle
    6. 4.6. Assembly
    7. 4.7. Interesting
  5. 5. chisel
  6. 6. Reference