Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

xcode - How can I find the address of a stack trace in 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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...