ios - 间歇性 NSArray 索引异常

标签 ios xcode debugging

我每天至少发生一次崩溃,我似乎真的无法理解。它似乎在随机时刻发生在我身上,我无法追踪堆栈来理解它发生的原因。如果有人能为我指出正确的方向,甚至向我展示一些关于如何正确追踪值的在线文档和教程,那将是完美的。我最了解的是有些东西试图访问数组中的索引,但我无法弄清楚该数组可以是什么。我在下面的输出窗口中包含了信息:

2012-09-28 12:45:26.884 TestApp[1683:c07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x1bdd052 0x19ccd0a 0x1bc9db8 0x29522 0x23e76 0x22bed 0x21e36 0xdfee 0xdba8 0xd3cc 0x1bdee72 0x13339ef 0x1bb197f 0x1b14b73 0x1b14454 0x1b13db4 0x1b13ccb 0x2692879 0x269293e 0xa1ba9b 0x2ded 0x2d25)
terminate called throwing an exceptionCurrent language:  auto; currently objective-c
(gdb) bt
#0  0x98468a6a in __pthread_kill ()
#1  0x98554acf in pthread_kill ()
#2  0x9858b4f8 in abort ()
#3  0x021cbe78 in abort_message ()
#4  0x021c989e in default_terminate ()
#5  0x019ccf4b in _objc_terminate ()
#6  0x021c98de in safe_handler_caller ()
#7  0x021c9946 in std::terminate ()
#8  0x021cab3e in __cxa_rethrow ()
#9  0x019cce49 in objc_exception_rethrow ()
#10 0x01b13e10 in CFRunLoopRunSpecific ()
#11 0x01b13ccb in CFRunLoopRunInMode ()
#12 0x02692879 in GSEventRunModal ()
#13 0x0269293e in GSEventRun ()
#14 0x00a1ba9b in UIApplicationMain ()
#15 0x00002ded in main (argc=1, argv=0xbffff39c) at /Users/seb/Desktop/Development/main.m:14

最佳答案

您需要使用 Xcode 调试器:

  • 点击工具栏中的断点按钮:

Breakpoints button

  • 点击左 Pane 中的断点选项:

enter image description here

  • 点击左下角的“+”按钮,然后选择“添加异常断点”:

enter image description here

  • 在呈现的 View 中点击完成,您将看到类似这样的内容(顶部的已禁用):

enter image description here

  • 确保您的应用方案启用了 lldb:

enter image description here

关于ios - 间歇性 NSArray 索引异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12644212/

相关文章:

ios - 分析发现私有(private) API 使用,尽管我已经更改了该代码

ios - 将从 NIB 加载的 View 添加到自定义表格 View 单元格无法按预期工作

ios - 无法在 iOS 中设置启动图像

ios - 无法使用类型为 'CGFloat' 的参数列表调用类型为 '(CGFloat)' 的初始值设定项

visual-studio-2008 - Visual Studio 不再与应用程序崩溃相关联

ios - 使用一个 Storyboard和一个 Storyboard将 iPad 应用程序移植到 iPhone

ios - 带有 ReactiveCocoa 的 MVVM : limit the text length of a UITextField in view model

xcode - 快速将时间间隔存储到 nsuserdefaults

c++ - VS2013 遇到基类位于未命名命名空间中的问题

java - Android 有用的调试/发布宏(使用 gradle?)