Cristik
Cristik

Reputation: 32877

Set breakpoint on protocol method

Basically I need to set a breakpoint on a protocol method in order to catch all calls to objects conforming to that protocol. I have a custom framework with lots of classes conforming to the protocol, so manually setting a breakpoint on every class is not feasible.

I tried setting the breakpoint from the Xcode editor:

enter image description here

, however when setting the breakpoint I get only breakpoints for the allocation methods: allocation breakpoints

, and as expected the debugger doesn't stop when doSomething() is called.

I also tried adding symbolic breakpoints, no luck here too: enter image description here

Here's some demo code to illustrate this:

protocol TestProtocol {
    func doSomething()
    func doAnotherThing()
}

class TestConformingClass: TestProtocol {
    func doSomething() {
        print("Yay")
    }

    func doAnotherThing() {
        print("Hooray")
    }
}

Is there a way to intercept all calls to a method that is part of a protocol requirements list?

Upvotes: 2

Views: 986

Answers (1)

Mehul Parmar
Mehul Parmar

Reputation: 3699

Running the following command in lldb should do the trick:

breakpoint set --name doSomething
breakpoint set --name doAnotherThing

Possibly, even the following might work:

breakpoint set --name doSomething --name doAnotherThing

Upvotes: 6

Related Questions