11

我正在尝试向 gdb 中的 Objective-C 对象发送消息。

(gdb) p $esi
$2 = (void *) 0x1268160
(gdb) po $esi
<NSArray: 0x1359c0>
(gdb) po [$esi count]
Target does not respond to this message selector.

我无法向它发送任何消息。我错过了什么吗?我真的需要符号或其他东西吗?

4

3 回答 3

10

如果您必须覆盖 gdb 并在对象不允许您的情况下向它发送消息,您可以使用 performSelector:

(gdb) print (int)[receivedData count]
Target does not respond to this message selector.

(gdb) print (int)[receivedData performSelector:@selector(count) ]
2008-09-15 00:46:35.854 Executable[1008:20b] *** -[NSConcreteMutableData count]:
unrecognized selector sent to instance 0x105f2e0

如果需要传递参数,请使用 withObject:

(gdb) print (int)[receivedData performSelector:@selector(count) withObject:myObject ]
于 2008-09-15T06:54:05.183 回答
1

你有可能需要投$esi吗?

p (NSUInteger)[(NSArray *)$esi count]
于 2008-09-11T18:27:46.937 回答
0

@[约翰·卡尔斯贝克]

然后它抱怨缺少符号。

(gdb) p (NSUInteger)[(NSObject*)$esi retainCount]
No symbol table is loaded.  Use the "file" command.
(gdb) p [(NSArray *)$esi count]
No symbol "NSArray" in current context.

我尝试为 Foundation 加载符号:

(gdb) add-symbol-file /System/Library/Frameworks/Foundation.framework/Foundation 
add symbol table from file "/System/Library/Frameworks/Foundation.framework/Foundation"? (y or n) y
Reading symbols from /System/Library/Frameworks/Foundation.framework/Foundation...done.

但仍然没有运气:

(gdb) p [(NSArray *)$esi count]
No symbol "NSArray" in current context.

无论如何,我不认为强制转换是解决这个问题的方法,你不应该知道它是什么类型的对象,就可以向它发送消息。奇怪的是,我发现了一个 NSCFArray,我可以毫无问题地将消息发送到:

(gdb) p $eax
$11 = 367589056
(gdb) po $eax
<NSCFArray 0x15e8f6c0>(
    file://localhost/Users/ask/Documents/composing-fractals.pdf
)

(gdb) p (int)[$eax retainCount]
$12 = 1

所以我想我正在调查的对象有问题……或者什么。

谢谢你的帮助!

于 2008-09-12T11:02:27.933 回答