2008-09-11 59 views
11

我想發送消息到gdb中的Objective-C對象。發送消息到對象,同時在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. 

我無法發送任何消息給它。我錯過了什麼嗎?我真的需要符號,還是其他什麼?

+0

注意:[reversing]標籤不能用於描述逆向工程主題;改用[反向工程] – user1354557 2016-06-22 15:59:02

回答

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 ] 
1

您可能需要投下$esi

p (NSUInteger)[(NSArray *)$esi count] 
0

@ [約翰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. 

我試圖加載符號基金會:

(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 

,所以我想有一個與我研究的對象......什麼的問題。

感謝您的幫助!