在gdb中调试Objective-C时向对象发送消息,不带符号
时间:2020-03-05 18:51:25 来源:igfitidea点击:
我正在尝试向gdb中的Objective-C对象发送消息。
(gdb) p $esi = (void *) 0x1268160 (gdb) po $esi <NSArray: 0x1359c0> (gdb) po [$esi count] Target does not respond to this message selector.
我无法向它发送任何消息。我想念什么吗?我真的需要符号,还是其他?
解决方案
回答
我们是否可能需要转换$ esi
?
p (NSUInteger)[(NSArray *)$esi count]
回答
@ [John Calsbeek]
然后,它抱怨缺少符号。
(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 = 367589056 (gdb) po $eax <NSCFArray 0x15e8f6c0>( file://localhost/Users/ask/Documents/composing-fractals.pdf ) (gdb) p (int)[$eax retainCount] = 1
所以我想我正在调查的对象有问题...
谢谢你的帮助!
回答
如果必须重写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 ]