如何获得Crashlytics所做的崩溃和方法以及开源PLCrashReporter [英] How to get the line of the crash and the method as Crashlytics does and also the open source PLCrashReporter

查看:380
本文介绍了如何获得Crashlytics所做的崩溃和方法以及开源PLCrashReporter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我所提到的,我正在尝试恢复崩溃线以及它发生的功能。

As I mentioned I am trying to recover the line of a crash and also the function in wich it occurs.

我需要提醒我已尝试过下一次AppDelegate中的代码,我得到的堆栈没有符号化,类和错误抛出:

I need to metion that I have tried the next code in AppDelegate and I get the stack not symbolicated and the class and also the error throwed:

NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

void uncaughtExceptionHandler(NSException *exception) {

    NSLog(@"Exception description - %@",[exception description]);
    NSLog(@"Exception name - %@", [exception name]);
    NSLog(@"Reason - %@", [exception reason]);
    NSLog(@"\n\n - %@", [exception callStackSymbols]);
    NSLog(@"\n\n - %@", [exception callStackReturnAddresses]);
}

但是通过使用这些我没有得到崩溃的线,如我打算将它保存在CoreData中。

But by using these I don't get the line of the crash, as I intend to save it in CoreData.

此外,我对xcode aproaches不感兴趣:Add Exception Breakpoint或其他aproaces:XCode> Window> Devices> view崩溃登录设备,测试飞行aproaches或在应用程序中实现其他框架作为Crashlytics。

Also I am not interested in xcode aproaches as: "Add Exception Breakpoint" or other aproaces as: XCode > Window > Devices > view crash logs on a device, Test Flight aproaches or implementing other frameworks in the app as Crashlytics.

我提到这些是因为我对代码的处理方式非常感兴趣。

I mention these because I am very interested in the way it can be done by code.

也是能够在制作应用程序存档时获取应用程序存档的dsym并使用使用Bash编写的RunScript将其上载到服务器。所以我可以使用dsym来获得崩溃线。

Also am able to get dsym of the app archive it when an app archive is made and upload it to a server using a RunScript written using Bash. So I can use the dsym if it is needed to achive the crash line.

我也知道下一个aproach可以用来获取当前的代码行: LINE 和_FUNCTION__获取函数名称。

Also I know that the next aproach can be used to obtain the current code line: LINE and _FUNCTION__ to get the function name.

此外,如果您可以提供开源PLCrashReporter的代码示例,他们将如何做到这一点,我将非常赞赏。

Also if you can provide code examples from open source PLCrashReporter on how they do it I will much apreciate.

比你们所有人提前! :)

Than you all in advance! :)

推荐答案

基本上有两种类型的崩溃:

There are basically two types of crashes:


  1. 未捕获的异常,可以使用与您类似的代码捕获

  2. 基于信号的崩溃,可以使用信号处理程序(或Mach异常处理程序,但赢得了没有捕获所有信号)

然后捕获任何这些崩溃,你需要获得堆栈跟踪(所有线程)。 [NSException callStackSymbols] 将为您提供一些符号(仅用于异常崩溃),对于许多OS符号,它只显示编辑,对于您的应用,如果您不从二进制文件中删除它们,它将提供一些符号。建议从二进制文件中去除符号以使文件大小减少(很多),这些符号也绝不会提供文件名和行号。

Then catching any of these crashes, you need to get the stack trace (of all threads). [NSException callStackSymbols] will give you some symbols (only for an exception crash), for lots of OS symbols it will only show redacted, for your app it will provide some symbols if you don't strip them from your binary. It is recommended to strip the symbols from the binary to get the file size down (a lot), and these symbols would also never provide the filenames and line numbers anyway.

因此,您需要从堆栈帧中获取以下信息:二进制,二进制UUID,cpu体系结构和内存地址。 [NSException callStackReturnAddresses] 将为您提供内存地址,但仅限于基于异常的崩溃。另外它不提供对应于内存地址的二进制图像。

So instead you need to get the following information from the stack frames: binary, binary UUID, cpu architecture and memory address. [NSException callStackReturnAddresses] will give you the memory addresses, but again only for an exception based crash. In addition it doesn't provide the binary image corresponding to a memory address.

所以你需要获取内存中每个二进制图像的地址范围的二进制图像列表覆盖,以及获取线程的堆栈帧的内存地址的方法,也用于基于非异常的崩溃。如果想要了解这是怎么回事,你基本上可以看看所有的PLCrashReporters代码,因为这是开源项目的目的,解释这种复杂场景不是StackOverflow的范围。阅读代码,文档并学习:)为您提供简短的要点:不要自己动手,只需使用PLCrashReporter。

So you need to get the binary images list with the range of addresses in memory each binary image covers, and also a way to get the memory addresses of stack frames for threads also for non exception based crashes. If want to learn how that is that, you basically can take a look at ALL of PLCrashReporters code, since that is the purpose of the open source project and it is not the scope of StackOverflow to explain such complex scenarios. Read the code, the documentation and learn :) To give you the short gist: don't do it yourself, simply use PLCrashReporter.

现在获取包含文件名的符号和行号,您需要通过使用相应操作系统版本的操作系统符号以及发生崩溃报告的设备的相应CPU架构来表示崩溃报告。您还需要来自您的应用程序触发崩溃报告的确切二进制文件(和框架)中的符号(dSYM)包。每个二进制映像都有一个唯一的UUID和用于获取符号的符号文件,这些符号需要具有相同CPU架构的相同UUID。

Now to get the symbols including filenames and line numbers, you need to symbolicate the crash reports by using the OS symbols for the corresponding OS version and the corresponding CPU architecture from the device where the crash report happened. Also you need the symbols (dSYM) packages from the exact binary (and frameworks) that triggered the crash report from your app. Each binary image has a unique UUID and the symbol file your are using to get the symbols need to have the same UUID for the same CPU architecture.

现在需要运行工具 atos 从特定符号文件中获取特定内存地址的符号。以下堆栈溢出答案显示了如何执行此操作: https://stackoverflow.com/a/13576028/474794

Now you need to run the tool atos to get the symbols for a specific memory address from a specific symbol file. The following stack overflow answer shows how to do that: https://stackoverflow.com/a/13576028/474794

作为替代方案,您可以使用Xcode附带的 symbolicatecrash.pl 脚本并获取Apple标准格式的崩溃报告(PLCrashReporter有一个转换工具,可以通过更紧凑的报告创建此类报告)。

As an alternative, you can use the symbolicatecrash.pl script which comes with Xcode and takes a Apple standard formatted crash report (PLCrashReporter has a conversion tool to create such reports from its more compact reports).

这篇关于如何获得Crashlytics所做的崩溃和方法以及开源PLCrashReporter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆