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

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

问题描述

是否可以从调试器中获取源代码(或任何有助于调试问题所在的任何内容)的行号,以显示问题的根源?

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?

我收到一个错误:

-[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.

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

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..."

创建一个On Throw"断点:

Create an "On Throw" break point:

这将在抛出异常的确切位置停止调试器,并且您将获得更好的堆栈跟踪.始终启用这样的异常断点是个好主意,尽管您偶尔会从 Apple 代码中获得内部异常(例如,在使用 QLPreviewController、MPMoviePlayerController 时).

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).

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

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