【问题标题】:How to make symbolic breakpoint for all push segues?如何为所有推送序列创建符号断点?
【发布时间】:2016-01-04 15:02:33
【问题描述】:

我目前正在调试我的应用程序,并且遇到了正在执行 segue 的问题,但我终其一生都无法弄清楚它是从哪里调用的。

我想知道是否可以添加一个断点,以便应用程序暂停并显示调用它的行?

我尝试添加一个符号断点,但无法正常工作。

【问题讨论】:

  • 您可以使用方法调配或 UIViewController 的简单类别来实现 prepareForSegue:.
  • 试试- [UIStoryboardSegue perform]
  • @Cy-4AH 好的,这让它崩溃了,但我有那个奇怪的难以理解的调试屏幕。像这样:UIKit - [UIStoryboardSegue perform]: -> 0x10a1f8bfa <+0>: pushq %rbp 0x10a1f8bfb <+1>: movq %rsp, %rbp 0x10a1f8bfe <+4>: pushq %r15 是否可以看到从哪里调用该行?
  • @Cy-4AH 从侧面板查看堆栈,它说它是从 UIApplicationMain 调用的...为什么会这样?另一个 segue 显示了调用它的视图控制器。
  • 调试导航器中应该有调用栈。您也可以通过在调试控制台中输入bt 来打印堆栈。

标签: ios objective-c xcode debugging segue


【解决方案1】:

为 UIViewController 创建类别并将其添加到其中:

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];

        SEL originalSelector = @selector(prepareForSegue:sender:);
        SEL swizzledSelector = @selector(yd_prepareForSegue:sender:);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

        BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    });
}

- (void)yd_prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    [self yd_prepareForSegue:segue sender:sender];
    NSLog(@"prepareForSegue From: %@", self);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    相关资源
    最近更新 更多