如何确定此地址来自64位macOS应用程序的位置 [英] How to determine where this address comes from on 64-bit macOS application
问题描述
因此,我目前正在调试一个问题,并试图弄清楚这是怎么发生的.
So I'm currently debugging an issue, and trying to figure out how this could happen.
这是obj-c运行时中称为objc_msgsend()
Here is the assembly for a method in the obj-c runtime, called objc_msgsend()
libobjc.A.dylib`objc_msgSend:
0x7fff9084a0c0 <+0>: testq %rdi, %rdi
0x7fff9084a0c3 <+3>: je 0x7fff9084a140 ; <+128>
0x7fff9084a0c6 <+6>: testb $0x1, %dil
0x7fff9084a0ca <+10>: jne 0x7fff9084a14b ; <+139>
0x7fff9084a0cd <+13>: movabsq $0x7ffffffffff8, %r11
0x7fff9084a0d7 <+23>: andq (%rdi), %r11
0x7fff9084a0da <+26>: movq %rsi, %r10
0x7fff9084a0dd <+29>: andl 0x18(%r11), %r10d
我正在使用Xcode的lldb查看寄存器和地址.
I'm using Xcode's lldb to view the registers and addresses.
这是我第一次检出偏移量为+0(预期)的寄存器时得到的有趣输出:
Here is the interesting output I get, when I first check out the registers at offset +0 (expected):
(lldb) register read
r11 = 0x00007fff74a940f0 (void *)0x00007fff74a94118: NSObject
偏移+13后(预期):
(lldb) register read
r11 = 0x00007ffffffffff8
偏移+23后(未预期):
(lldb) register read
r11 = 0x0000000100761138 (void *)0x0000000100761160: GTMOAuth2WindowController
然后如果我po
此时的寄存器:
And then if I po
the registers at this point:
(lldb) po $rdi
<GTMOAuth2WindowController: 0x6100001c2850>
(lldb) po &$rdi
0x000000010bc2b3b8
(lldb) po $r11
GTMOAuth2WindowController
(lldb) po &$r11
0x000000010bc2b3b8
所以这是我迷路的地方;在偏移+23之后,当我register read
时该地址是什么?
0x0000000100761138
.我希望它具有0x6100001c2850
,即从+23
So here's where I'm lost; after offset +23, what is that address when I register read
?
0x0000000100761138
. I would've expected it to have 0x6100001c2850
, the location of the object from the dereference at +23
如果我po $r11
它打印出了类名(这是预期的,因为我们正在查看isa
属性),并且如果我为指针打印了内存中的位置,则它与地址不匹配在register read
中,它与%rdi
的地址匹配(预期).
If I po $r11
it prints out the class name (which is expected because we're looking at the isa
property), and if I print the location in memory for the pointer, it doesn't match the address in register read
, it matches the address of %rdi
(expected).
推荐答案
在%r11
之后的%r11
中的地址是表示您GTMOAuth2WindowController
类的类对象的地址.
That address in %r11
after <+23>
, 0x0000000100761138
, is the address of the class object that represents your GTMOAuth2WindowController
class.
在编译时(使用@interface
和@implementation
)定义类时,在运行时会有一个特殊的对象表示该类.实际上,它被称为类对象",就像您创建的所有对象一样,它是真实的对象.这意味着类对象本身可以响应消息.当您在<+23>
之后说po %r11
时,调试器将description
消息发送到类对象.类对象的description
方法以NSString
的形式返回类的名称,因此调试器将打印该类的名称.
When you define a class at compile time (with @interface
and @implementation
), there's a special object at runtime that represents the class. In fact it's called a "class object" and is a real object just like all the objects you created. This means that the class object can itself respond to messages. When you said po %r11
after <+23>
, the debugger sent the description
message to the class object. The class object's description
method returns the name of the class as an NSString
, so the debugger printed the name of the class.
您可以在此处了解有关类对象的更多信息.该页面上的图片链接在Chrome中已损坏,但您可以单击它以查看pdf.
You can learn more about class objects here. The image link on that page is broken in Chrome but you can click it to see a pdf.
这篇关于如何确定此地址来自64位macOS应用程序的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!