ios中的堆栈跟踪获取源代码行

ios中的堆栈跟踪获取源代码行

本文介绍了如何从obj-c / ios中的堆栈跟踪获取源代码行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NSSetUncaughtExceptionHandler 将堆栈跟踪打印到iPhone中的本地文件,下次应用程序启动时将发送到我们的服务器。然后我可以检查异常数据并修复错误。
在某些崩溃中,我有模块名称和抛出异常的功能,这些都很简单。
但是大部分我都是这样的:

 4 libc ++ abi.dylib 0x35bba3c5 _ZL19safe_handler_callerPFvvE + 76 
5 libc ++ abi.dylib 0x35bba451 _ZdlPv + 0,
6 libc ++ abi.dylib 0x35bbb825 __cxa_current_exception_type + 0,
7 libobjc.A.dylib 0x37bab2a9 objc_exception_rethrow + 12,
8 CoreFoundation 0x3575a50d CFRunLoopRunSpecific + 404

,例如原因:



*** - [__ NSArrayI objectAtIndex:]:index 0超出空数组的界限



但我的应用程序中有数十个数组,所以我需要帮助找到抛出异常的特定行,使用从堆栈跟踪得到的数据。有没有人知道Apple或其他的好的文章/教程,我可以在这里学习解码堆栈跟踪中的数字,以便在源代码中找到有问题的行。
提前感谢!

解决方案

我强烈建议在Xcode中启用异常断点。它将在您的应用程序崩溃的确切行上停止执行代码。所以你不需要担心阵列中的哪一个导致崩溃。
*** - [__ NSArrayI objectAtIndex:]:index 0超出空数组的范围



添加异常断点


  1. 转到Xcode上的Breakpoints部分

  2. 点击
  3. 底部的加号
  4. 选择添加例外断点


I use NSSetUncaughtExceptionHandler to print the stack trace to local file in iPhone, which will be sent to our server next time the app launches. Then I can examine the exception data and fix the bug.In some crashes I have the module name and the function that threw the exception, these are easy.But mostly I have something like this:

"4   libc++abi.dylib 0x35bba3c5 _ZL19safe_handler_callerPFvvE + 76",
"5   libc++abi.dylib 0x35bba451 _ZdlPv + 0",
"6   libc++abi.dylib 0x35bbb825 __cxa_current_exception_type + 0",
"7   libobjc.A.dylib 0x37bab2a9 objc_exception_rethrow + 12",
"8   CoreFoundation  0x3575a50d CFRunLoopRunSpecific + 404"

and for example the reason:

*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array

but I have dozens of arrays in my app, so I need help to find the specific line that threw the exception, using the data I get from the stack trace.

Does anyone know a good article/tutorial from Apple or other, where I can learn to decode the numbers in the stack trace to find the problematic line in the source code.Thanks in advance!

解决方案

I strongly recommend enabling Exception Breakpoint in Xcode. It will stop execution of your code on the exact line which crashes your application. So you do not need to worry about which of the array cause of the crash.*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array

Adding exception breakpoint

  1. Go to Breakpoints section on Xcode
  2. Click on plus sing at bottom of the section
  3. Select Add Exception Breakpoint

这篇关于如何从obj-c / ios中的堆栈跟踪获取源代码行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 03:40