How do I set a symbolic breakpoint for only some of the overrides?

Consider the following code:

class Parent {
    func breakMethod() {
        println("p break")
    }
    func breakMethod(#variable: Int) {
        println("p breakpoint " + String(variable))
    }
}

class Child: Parent {
    override func breakMethod() {
        println("c break")
    }
    override func breakMethod(#variable: Int) {
        println("c breakpoint " + String(variable))
    }
}

let p = Parent()
let c = Child()

p.breakMethod()
c.breakMethod()
p.breakMethod(variable:0)
c.breakMethod(variable:1)

      

And obviously realistic, it could and would be much more difficult. Let's say I need to debug one of these methods in every class that implements it. One option is to go through each file and find each instance breakMethod

and manually add a breakpoint. But a much better option is to add a symbolic breakpoint to breakMethod

.

Xcode will then take care of adding a breakpoint at every appropriate place. Then I can manually select which breakpoints I want and disable some of them. But more importantly, with one click I can enable / disable all of them for that particular symbol. It's comfortable.

But what if I want to add a breakpoint for breakMethod(#variable: Int)

? It can be done?

I know, obviously, that I can set it for breakMethod

. This will trigger every override breakMethod

. And then I can just include only the ones I want. But it becomes a major pain in any scenario, much more difficult than that.

In Objective-C, we have a separate method that looks something like this:

- (void)breakMethod {
    NSLog("break");
}

- (void)breakMethodVariable:(int)variable {
    NSLog("break %i", variable);
}

      

In this case, adding a symbolic breakpoint for "breakMethod" will only stop at the first method, and we can add a separate symbolic breakpoint for "breakMethodVariable:" that will only stop at the second method.

But no matter what I do, I am unable to decouple the method override when setting symbolic breakpoints for Swift. Is there something I am missing?

For what it's worth, I tried setting up the following symbolic breakpoints, none of them worked for me:

  • breakMethod(variable:)

  • breakMethod(variable)

  • breakMethod(#variable:)

  • breakMethod(variable:)

  • breakMethod(variable)

  • breakMethod(#variable:)

  • breakMethodvariable:

  • breakMethodvariable:

  • breakMethodvariable

  • breakMethodvariable

  • breakMethodWithVariable:

  • breakMethodWithVariable

  • breakMethodWithVariable:

  • breakMethodWithVariable

It would be very annoying for me to know that it is not possible to set separate symbolic breakpoints in Swift, given that a user who is many different methods in Objective-C has turned into a complex set of overrides in many cases.

+3


source to share


1 answer


I don't know how to do this in Xcode Breakpoint navigator and so that they persist across execution.

But as a workaround, you can use the regex breakpoint for this:



(lldb) breakpoint set -r "\.breakMethod \(.+\(variable :"

      

+3


source







All Articles