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

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

问题描述

好的,想象一下我在 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]

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

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

(请注意,在我测试的所有情况下,在断点命中时,eaxedx 寄存器中也存在异常对象.我不确定不过,情况总是如此.)

(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天全站免登陆