如何找出导致 iPhone 应用运行时错误的原因?
在 Xcode 中,假设您为 iPhone 编写了一个应用程序,并且它有一个运行时 其中的错误。我所看到的是它只是关闭了 模拟器中的程序但并没有真正突出显示或给我任何 关于哪条线导致崩溃的反馈...我错过了什么吗?
注意:我不认为控制台非常有效,因为 它只是吐出一个错误,但我仍然需要找到其中的位置 该错误到底源于代码中。
In Xcode, say you write an app for the iphone and it has a runtime
error in it. What I've been seeing is that it just closes out the
program in the simulator but doesn't really hilight or give me any
feedback as to what line caused the crash... am I missing something??
Note: I don't consider the console to be very effective since
it just spits out an error, but I still need to find where in
the heck that bug is stemming from in the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在控制台中,堆栈跟踪上方,应该显示类似“[ClassName 选择器名称] 无法识别的选择器已发送到实例”之类的内容。
确保您确实打算将该选择器发送到该类。如果您发布它是什么,我们也许能够提供更多帮助。
要访问 GDB,请启用断点,通过单击行号槽将断点添加到代码中,按构建和调试,最后打开调试器 (CMD+Shift+Y)。
In the console, above the stack trace, it should say something like "[ClassName selectorName] unrecognized selector sent to instance".
Make sure you really meant to send that selector to that class. If you post what it is, we might be able to help more.
To access GDB, enable breakpoints, add one to your code by clicking in the line number gutter, press build and debug and finally open the debugger (CMD+Shift+Y).
查看控制台(command-shift-R)。
Look in the console (command-shift-R).
您可以在异常上设置全局断点,这将让您跟踪异常发生的确切点。为此,请选择“运行”|“显示 | Xcode 中的断点菜单项可打开断点对话框。选择全局断点(以便为您的所有项目启用此功能)并在
libobjc.A.dylib
中的objc_exception_throw
上创建断点。现在,如果您通过选择 Run | 启动应用程序调试 - 断点打开,或者在运行之前在调试器窗口(运行 | 调试器)中手动启用断点,应用程序应在引发异常的位置停止。然后,您可以在调试器窗口中查看堆栈跟踪,其中它将突出显示导致异常的特定行。
You can set a global breakpoint on exceptions, which will let you trace the exact point at which they occurred. To do so, select the Run | Show | Breakpoints menu item in Xcode to bring up the breakpoints dialog. Select Global Breakpoints (so that this will be enabled for all of your projects) and create a breakpoint on
objc_exception_throw
inlibobjc.A.dylib
.Now if you start your application by choosing Run | Debug - Breakpoints On, or manually enable breakpoints in the debugger window (Run | Debugger) before running, the application should halt at the point where the exception is thrown. You can then look at the stack trace in the debugger window, where it will highlight the particular line that caused the exception.