目标C - 从调试器错误获取行号或完整的堆栈跟踪? [英] Objective C - getting line number or full stack trace from debugger error?

查看:161
本文介绍了目标C - 从调试器错误获取行号或完整的堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从调试器获取源代码的行号(或任何有助于调试问题所在的地方),以显示问题产生的原因。



我收到错误:

   -  [NSCFArray objectAtIndex:]:index(-1(或更大)超越边界(9)

这显然意味着我在某个点走出边界,我可能想得到一些更多的信息,以帮助我解决这个问题。



我放置一个断点,试图通过一行一行,但它是一个繁琐的过程。谢谢!

解决方案

当调试器停止时,转到调试导航器,确保底部的滑块是



从抛出异常的点开始扫描你的眼睛,你应该最终来到自己的代码。点击相应的方法/函数名,代码将在编辑器中打开。







如果在堆栈跟踪中没有看到自己的方法,那么异常可能已通过 performSelector - 样式调用,在这种情况下堆栈跟踪消失。如果是这种情况,您可以通过添加On Throw异常断点来获得更好的信息。首先切换到断点导航器:





然后点击加号并选择添加异常断点...



img src =https://i.stack.imgur.com/KeWGR.pngalt =enter image description here>



创建投掷断点:



p>

这将停止调试器在异常抛出的精确点,并且你得到更好的堆栈跟踪。这是一个好主意,有一个异常断点像这样启用所有的时间,虽然你偶尔会从苹果的代码(例如,当使用QLPreviewController,MPMoviePlayerController)。


Is it possible to get a line number for the source code (or anything that helps debug where the problem is) from the debugger, that shows where the problem is originating?

I am getting an error:

-[NSCFArray objectAtIndex:]: index (-1 (or possibly larger)) beyond bounds (9)

which obviously means that I am going out of bounds at some point, however if it possible I would like to get some more information to help me solve the problem.

I am placing a breakpoint and trying to go through the program line by line but it is a tedious process. Thanks!

解决方案

When the debugger stops, go to the "Debug Navigator" and make sure the slider on the bottom is all the way to the right.

Scan your eye down from the point at which the exception is thrown and you should eventually come to your own code. Click on the appropriate method/function name and the code will be opened in the editor.

If you don't see any of your own methods in the stack trace, the exception may have been passed through a performSelector-style call in which case the stack trace is gone. If this is the case, you may get better information by adding an "On Throw" exception break point. First switch to the "Breakpoint navigator":

Then click on the plus and choose "Add Exception breakpoint..."

Create an "On Throw" break point:

This will stop the debugger at the exact point the exception is thrown, and you get a better stack trace. It's a good idea to have an exception break point like this enabled all the time, although you will occasionally get internal exceptions from Apple code (e.g. when using QLPreviewController, MPMoviePlayerController).

这篇关于目标C - 从调试器错误获取行号或完整的堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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