简体   繁体   English

Xcode 调试器 (lldb) 从内存地址获取对象描述

[英]Xcode debugger (lldb) get object description from memory address

Little-known fact: It is now possible, in Xcode, while paused in the debugger, to introspect the notification center to learn what objects are registered to receive what notifications:鲜为人知的事实:现在可以在 Xcode 中,在调试器中暂停时,内省通知中心以了解注册了哪些对象以接收哪些通知:

(lldb) po NotificationCenter.default

<NSNotificationCenter:0x6040000d40b0>
Name, Object, Observer, Options
com.apple.accessibility.reduce.motion.status, 0x10b126190, 0x7fc795700140, 1001
com.apple.accessibility.asst.scanner.status, 0x10b126190, 0x7fc795700140, 1001
// ... etc. ...

Very nice, but how do I get from the memory address 0x7fc795700140 to learning what object that is ?非常好,但是我如何从内存地址0x7fc795700140到它什么对象?

EDIT I'm leaving this question here, but I think the correct answer is the kind of thing shown at LLDB (Swift): Casting Raw Address into Usable Type编辑我把这个问题留在这里,但我认为正确的答案是LLDB (Swift): Casting Raw Address into Usable Type

The Swift equivalent of Phillip's answer is:菲利普的答案的斯威夫特等价物是:

(lldb) expr -l objc -O -- 0x7fc795700140
<UIApplication: 0x7fc795700140>

po works for addresses (In Objective-C/Mac context, at least) po适用于地址(至少在 Objective-C/Mac 上下文中)

eg:例如:

(lldb) po [NSNotificationCenter defaultCenter] (lldb) po [NSNotificationCenter defaultCenter]

NSWindowDidResizeNotification, 0x7fff9a0e98e0, 0x6100001246a0, 1400 NSWindowDidResizeNotification, 0x7fff9a0e98e0, 0x6100001246a0, 1​​400

(lldb) po 0x6100001246a0 (lldb) po 0x6100001246a0

ExpandOneView: 0x6100001246a0展开一个视图:0x6100001246a0

First, the LLDB commands I used.首先,我使用的 LLDB 命令。

(lldb) expr -l objc -O -- 0x600001582d00

<__NSArrayI 0x600001582d00>(
<UIStoryboardShowSegueTemplate: 0x600002c3e4c0>,
<UIStoryboardPresentationSegueTemplate: 0x600001582210>,
<UIStoryboardPresentationSegueTemplate: 0x600001582620>,
<UIStoryboardShowSegueTemplate: 0x600002c3f4c0>,
<UIStoryboardPresentationSegueTemplate: 0x6000015839d0>,
<UIStoryboardShowSegueTemplate: 0x600002c3d680>,
<UIStoryboardEmbedSegueTemplate: 0x600002c3dc40>
)

For an instance of a Swift class.对于 Swift 类的实例。

expr -l swift -O -- 

For an instance of an Objective-C class.对于 Objective-C 类的实例。

expr -l objc -O --

For an instance of a C class.对于 C 类的实例。

expr -l c -O --

Now, an explanation.现在,解释一下。 I had the joy of fixing over 1400 lemory leaks in our jr.我很高兴在我们的 jr 中修复了 1400 多个 lemory 泄漏。 iOS developers' code. iOS 开发人员的代码。 Often when in the Memory Graph Debugger, and I was inspecting leaked objects, all that I had was the object's address in memory.通常在内存图调试器中,当我检查泄漏的对象时,我所拥有的只是对象在内存中的地址。 This was in an Objective-C and Swift app, so we had to be able to inspect objects from both languages.这是在 Objective-C 和 Swift 应用程序中,所以我们必须能够检查来自两种语言的对象。 While in LLDB, I had to specify the language of the variable at the memory address being inspected.在 LLDB 中,我必须在被检查的内存地址处指定变量的语言。 This worked in Swift and Objective-C.这适用于 Swift 和 Objective-C。 What I provided above is sample output and examples of the command for Swift, Objective-C and C.我上面提供的是 Swift、Objective-C 和 C 的示例输出和命令示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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