如何在LLDB for iOS中找到堆栈跟踪的地址 [英] How can I find the address of a stack trace in LLDB for iOS

查看:636
本文介绍了如何在LLDB for iOS中找到堆栈跟踪的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我收到崩溃报告时,我的代码中有问题的部分有时看起来像这样,而不是向我显示实际的行号,即使崩溃报告是象征性的:

When I get a crash report, the offending part of my code will sometimes look like this, instead of showing me the actual line number, even though the crash report is symbolicated:

-[ViewController myMethod:] + 47  

为了调试这个,我需要知道我代码的代码行,以便我可以直观地检查它,设置一个断点等。

In order to debug this, I need to know what line of my code this represents so that I can visually inspect it, set a breakpoint, etc.

什么是好的获取方法地址加偏移量的方法,如上所示,使用LLDB?

What is a good way to get the address of a method plus offset, as shown above, using LLDB?

注意:这个问题不是如何阅读崩溃报告。我知道如何阅读崩溃报告。我非常具体地询问如何使用LLDB获取相应的行。其他答案中没有任何内容显示如何做到这一点。它们非常冗长,并且涉及到一般处理崩溃报告和调试的各种事情,但没有说明LLDB的具体步骤是什么。请不要复制此错误。

NOTE: this question is NOT a duplicate of how to read a crash report. I know how to read a crash report. I am asking very specifically how to get the corresponding line using LLDB. Nothing in the other answers shows how to do that. They are quite verbose and go into all kinds of things about dealing with crash reports and debugging in general, but don't show what the specific steps on LLDB are. Please do not duplicate this bug.

推荐答案

您的步骤(图像查询 + p / x addr + offset )会为您提供原始地址,如您所见。但原始崩溃报告可能包含方法+偏移之前的地址---使用目标模块加载将二进制文件滑动到正确的地址同样容易。在崩溃报告结束时,应该有一个程序中存在的二进制映像列表,包括加载地址和UUID。

Your steps (image lookup + p/x addr + offset) will give you the raw address, as you found. But the original crash report probably included an address before the method + offset --- it is just as easy to slide your binary to the correct address using target modules load. At the end of the crash report there should be a list of the binary images present in the program, including load address and UUID.

但更重要的是,虽然地址是很好,你真正追求的是源位置。在这种情况下,一旦确定了方法的正确地址(或通过目标模块加载将其滑动到匹配的地址),就可以使用来源清单

But more importantly, while the address is nice what you're really after is the source location. In that case, once you've determined the correct address for the method (or slid it to the matching address via target modules load), you can use source list

(lldb) so l -a `addr + offset`

我在这里使用反引号表示法进行内联表达式评估。大多数带有地址的命令有一个方便的快捷方式:如果省略空格,你可以编写没有反引号的表达式:

I'm using the backtick notation here which does an in-line expression evaluation. There's a handy shortcut for most commands that take an address: if you omit spaces, you can write the expression without backticks:

(lldb) so l -a addr+offset

您还可以使用图像查找带有地址。如果您有调试信息,这将告诉您此时变量的当前位置。为什么这有用?因为大多数崩溃报告都包含崩溃时的寄存器上下文,所以当前在寄存器中的任何变量都提供给您( -v 是获取所有寄存器位置信息所必需的)。

You can also use image lookup with an address. If you have debug information, this will tell you what the current location of variables are at this point. Why is this useful? Because most crash reports include the register context at crash and so any variables that are currently in a register are provided to you (-v is necessary to get all of the register location information).

(lldb) im loo -v -a addr+offset

最后 - 这不会起作用,因为你正在处理一个Objective-C方法名称 - 但是你可以使用简单的C函数名称只要将函数名转换为指针类型(在函数指针中添加偏移量不合法C),就可以在线进行偏移算术运算。例如

Finally -- this isn't going to work because you're dealing with an Objective-C method name -- but with a simple C function name you can do the offset arithmetic in-line as long as you cast the function name to a pointer type (it's not legal C to add an offset to a function pointer). e.g.

(lldb) so l -a (char*)main+10

这篇关于如何在LLDB for iOS中找到堆栈跟踪的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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