轻松打印应用程序的当前堆栈跟踪?

时间:2021-12-08 19:14:10

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();在我的整个应用程序中的每个方法的开头。但也许有一种更简单的方法来找出真正的堆栈跟踪,人性可读?不仅在应用程序启动或崩溃时,而且在所有发生的活动中始终如此?会帮助调试很多。

3 个解决方案

#1


5  

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

#2


3  

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中添加断点?

#3


1  

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 atos command (see man atos in Terminal or search for atos in Xcode's documentation or Google).

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

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和你的应用程序之间的界面以它的方式工作)。

#1


5  

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

#2


3  

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中添加断点?

#3


1  

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 atos command (see man atos in Terminal or search for atos in Xcode's documentation or Google).

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

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和你的应用程序之间的界面以它的方式工作)。