Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the address of a stack trace in LLDB for iOS

Tags:

xcode

ios

lldb

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.

What is a good way to get the address of a method plus offset, as shown above, using 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.

like image 583
Skotch Avatar asked Aug 07 '13 20:08

Skotch


1 Answers

Here is something I found that worked:

First you need to find the address of the method itself.

image lookup -v -F "-[ViewController myMethod:]"

in the result you will see a lot of info, but the range part will give you want you want

... range = [0x000708c0-0x00070c6c) ...

(where 0x000708c0 is address of method)

Now to add the given offset of 47, just use LLDB to do that math for you:

(lldb) p/x 0x000708c0 + 47
(int) $0 = 0x000708ef

and you get your answer, the offending line is on 0x000708ef

Or better yet, based on Jason Molenda's answer, is to just go straight to the code listing, which will show the line number:

(lldb) source list -a `0x000708c0 + 47`

EDIT: improved based on the answer from Jason Molenda

like image 158
Skotch Avatar answered Nov 15 '22 17:11

Skotch