简体   繁体   中英

XCode LLDB - Get self from a given frame

I want to get "self" from a given frame. Is there a way to do this?

I tried "frame info" and a few other options.

(lldb) frame info frame #11: 0x0000000102767ab8 UIKit`-[UIImageView _resolveImageForTrait:] + 463 (lldb)

For instance in the following example I want the button object from the 11th frame.

在此输入图像描述

It's fairly easy to get the parameters to optimized functions w/o debug information if you are stopped when the function is invoked, since then they will still be in the ABI specified argument passing registers. So if the problem you are investigating is one you can reproduce, putting an auto-continue breakpoint on -[UIImageView _resolveImageForTrait:] and printing or po'ing $arg1 in its commands will help you figure it out.

But if you're trying to figure the value out starting from this stack, your life is considerably harder. Since the frame you are interested in has called another function, you are guaranteed that your self no longer lives in the argument passing register, it has been reused. And there is no required place where arguments are put within the body of the function. In optimized code the compiler is expected to do with self whatever makes the code run the fastest.

Indeed, if self is not referenced in the frame in question after the call you are stopped at, the information may not exist at all anymore.

If self is still alive in that frame, it was most likely pushed on the stack somewhere in the function before calling into imageWithTraitCollection:. The debug information would tell you where that was, but without that your only choice is to read the assembly code and follow the propagation of self from the first argument register at the beginning of the function to the point where you are stopped. This might not be too bad for a small function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM