xcode 打印应用程序当前堆栈跟踪的简单方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1373858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:47:54  来源:igfitidea点击:

Easy way to print current stack trace of an app?

iphonecocoa-touchxcodedebugginguikit

提问by

Xcode / objective c does not really print a useful stack trace. My app crashes somewhere, and the damn thing gives me only numbers like 45353453, 34524323, 6745345353, 457634524234. Not useful at all.

Xcode/objective c 并没有真正打印有用的堆栈跟踪。我的应用程序在某处崩溃了,该死的东西只给了我 45353453、34524323、6745345353、457634524234 之类的数字。根本没有用。

So I want to make a NSLog(); on the beginning of EVERY method I have in my entire app. But maybe there's a simpler way to just find out the real stack trace, humanly readable? Not only on app launch or crash, but all the time, on every activity that happens? Would help debugging a lot.

所以我想做一个 NSLog(); 在我整个应用程序中的每个方法的开头。但也许有一种更简单的方法来找出真正的堆栈跟踪,人类可读的?不仅在应用程序启动或崩溃时,而且一直在发生的每个活动中?将有助于调试很多。

回答by Brian Westphal

Something like this might be helpful to you as well

像这样的事情也可能对你有帮助


@implementation UIApplication (MyCategory)

+ (void)logStackTrace {
    @try {
        [[NSException exceptionWithName:@"Stack Trace" reason:@"Testing" userInfo:nil] raise];
    }
    @catch (NSException *e) {
        NSLog(@"%@", [e callStackSymbols]);
    }
}

@end

回答by alex_c

Add a global breakpoint for objc_exception_throw, then you can get a useful stack trace in the debugger.

为 objc_exception_throw 添加全局断点,然后您可以在调试器中获得有用的堆栈跟踪。

How to add a breakpoint to objc_exception_throw?

如何向 objc_exception_throw 添加断点?

回答by bbum

There really isn't a way to do this reliably from within the app. If your app is crashing and not giving symbols, it sounds like your running a stripped release version and not the debug version?

确实没有办法从应用程序内可靠地做到这一点。如果您的应用程序崩溃并且没有给出符号,这听起来像是您运行的是剥离的发布版本而不是调试版本?

If you have the unstripped version sitting around, you can correlate between those numbers and the actual name of the stack frame using the atoscommand (see man atosin Terminal or search for atosin Xcode's documentation or Google).

如果您有未剥离的版本,您可以使用atos命令将这些数字与堆栈帧的实际名称相关联(请参阅man atos终端或atos在 Xcode 的文档或 Google 中搜索)。

You probably don't want to log the stack of every method call. The volume of information would quickly become overwhelming. And it shouldn't be a mystery as to why most of the methods in your app are being called (though it will take a while to understand why the interface between UIKit and your app works the way it does).

您可能不想记录每个方法调用的堆栈。信息量很快就会变得势不可挡。并且你的应用程序中的大多数方法为什么被调用应该不是一个谜(尽管需要一段时间才能理解为什么 UIKit 和你的应用程序之间的接口会以这种方式工作)。