Xcode / LLDB:如何获取有关刚被抛出的异常的信息? [英] Xcode/LLDB: How to get information about an exception that was just thrown?

查看:118
本文介绍了Xcode / LLDB:如何获取有关刚被抛出的异常的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OK,所以假设我的断点在 objc_exception_throw 刚刚触发。我正在调试器提示符下,我想获取有关异常对象的更多信息。我在哪里找到?

OK, so imagine that my breakpoint in objc_exception_throw has just triggered. I'm sitting at the debugger prompt, and I want to get some more information about the exception object. Where do I find it?

推荐答案

异常对象作为第一个参数传入 objc_exception_throw 。 LLDB提供 $ arg1 .. $ argn 变量指向正确调用约定中的参数,使其简单打印例外细节:

The exception object is passed in as the first argument to objc_exception_throw. LLDB provides $arg1..$argn variables to refer to arguments in the correct calling convention, making it simple to print the exception details:

(lldb) po $arg1
(lldb) po [$arg1 name]
(lldb) po [$arg1 reason]

确保选择执行这些命令之前调用堆栈中的objc_exception_throw 帧。请参阅WWDC15会议视频中的高级调试和地址消毒器,以查看在舞台上执行的操作。

Make sure to select the objc_exception_throw frame in the call stack before executing these commands. See the "Advanced Debugging and the Address Sanitizer" in the WWDC15 session videos to see this performed on stage.

过期信息

如果您使用GDB,则引用第一个参数的语法取决于您正在运行的体系结构的调用约定。如果您在实际的iOS设备上进行调试,则指向该对象的指针位于注册表 r0 中。要打印或发送消息,请使用以下简单语法:

If you're on GDB, the syntax to refer to the first argument depends on the calling conventions of the architecture you're running on. If you're debugging on an actual iOS device, the pointer to the object is in register r0. To print it or send messages to it, use the following simple syntax:

(gdb) po $r0
(gdb) po [$r0 name]
(gdb) po [$r0 reason]

在iPhone模拟器上,所有的函数参数都传递给堆栈,所以语法比较可怕。我可以构造的最短的表达式是 *(id *)($ ebp + 8)。为了使事情变得不那么痛苦,我建议使用一个方便的变量:

On the iPhone Simulator, all function arguments are passed on the stack, so the syntax is considerably more horrible. The shortest expression I could construct that gets to it is *(id *)($ebp + 8). To make things less painful, I suggest using a convenience variable:

(gdb) set $exception = *(id *)($ebp + 8)
(gdb) po $exception
(gdb) po [$exception name]
(gdb) po [$exception reason]

您还可以通过添加命令列表触发断点,自动设置 $ exception objc_exception_throw 断点。

You can also set $exception automatically whenever the breakpoint is triggered by adding a command list to the objc_exception_throw breakpoint.

(请注意,在所有情况下,我测试过,异常对象也存在于 eax 和$ code> edx 在断点打到时注册,我不知道会是这样,

(Note that in all cases I tested, the exception object was also present in the eax and edx registers at the time the breakpoint hit. I'm not sure that'll always be the case, though.)

从以下评论中添加:

lldb ,选择 objc_exception_throw 的堆栈框,然后输入以下命令:

In lldb, select the stack frame for objc_exception_throw and then enter this command:

(lldb) po *(id *)($esp + 4)

这篇关于Xcode / LLDB:如何获取有关刚被抛出的异常的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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