在协议方法上设置断点

问题描述 投票:2回答:1

基本上我需要在协议方法上设置一个断点,以便捕获对符合该协议的对象的所有调用。我有一个自定义框架,其中包含许多符合协议的类,因此在每个类上手动设置断点是不可行的。

我尝试从Xcode编辑器设置断点:

enter image description here

但是,在设置断点时,我只得到分配方法的断点:allocation breakpoints

,正如预期的那样,调用doSomething()时调试器不会停止。

我也试过添加符号断点,这里也没有运气:enter image description here

这里有一些演示代码来说明这一点:

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

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

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

有没有办法拦截对作为协议要求列表一部分的方法的所有调用?

swift xcode debugging breakpoints lldb
1个回答
4
投票

在lldb中运行以下命令应该可以解决问题:

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

可能,甚至以下可能会起作用:

breakpoint set --name doSomething --name doAnotherThing
© www.soinside.com 2019 - 2024. All rights reserved.