11

I'm trying to send messages to Objective-C objects in gdb.

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

I can't send any message to it. Am I missing something? Do I really need the symbols, or something else?

1
  • Note: The [reversing] tag is not meant to be used to describe reverse engineering topics; use [reverse-engineering] instead Commented Jun 22, 2016 at 15:59

3 Answers 3

10

If you must override gdb and send a message to an object when it will not let you, you can use 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

If you need to pass an argument use withObject:

(gdb) print (int)[receivedData performSelector:@selector(count) withObject:myObject ]
Sign up to request clarification or add additional context in comments.

Comments

1

Is it possible that you need to cast $esi?

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

Comments

0

@[John Calsbeek]

Then it complains about missing symbols.

(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.

I tried to load the symbols for 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.

but still no luck:

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

Anyway, I don't think casting is the solution to this problem, you shouldn't have to know what kind of object it is, to be able to send messages to it. The weird thing is that I found an NSCFArray I have no problems sending messages to:

(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

so I guess there was a problem with the object I was investigating... or something.

Thanks for your help!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.