<p>I'm trying to send messages to Objective-C objects in gdb.</p>

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

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

[{'answer_id': 57279, 'author': 'John Calsbeek', 'author_id': 5696, 'author_profile': 'https://Stackoverflow.com/users/5696', 'pm_score': 1, 'selected': False, 'text': '<p>Is it possible that you need to cast <code>$esi</code>?</p>\n\n<pre><code>p (NSUInteger)[(NSArray *)$esi count]\n</code></pre>\n'}, {'answer_id': 58687, 'author': 'asksol', 'author_id': 5577, 'author_profile': 'https://Stackoverflow.com/users/5577', 'pm_score': 0, 'selected': False, 'text': '<p>@[John Calsbeek]</p>\n\n<p>Then it complains about missing symbols.</p>\n\n<pre><code>(gdb) p (NSUInteger)[(NSObject*)$esi retainCount]\nNo symbol table is loaded.  Use the "file" command.\n(gdb) p [(NSArray *)$esi count]\nNo symbol "NSArray" in current context.\n</code></pre>\n\n<p>I tried to load the symbols for Foundation:</p>\n\n<pre><code>(gdb) add-symbol-file /System/Library/Frameworks/Foundation.framework/Foundation \nadd symbol table from file "/System/Library/Frameworks/Foundation.framework/Foundation"? (y or n) y\nReading symbols from /System/Library/Frameworks/Foundation.framework/Foundation...done.\n</code></pre>\n\n<p>but still no luck:</p>\n\n<pre><code>(gdb) p [(NSArray *)$esi count]\nNo symbol "NSArray" in current context.\n</code></pre>\n\n<p>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.\nThe weird thing is that I found an NSCFArray I have no problems sending messages to:</p>\n\n<pre><code>(gdb) p $eax\n$11 = 367589056\n(gdb) po $eax\n&lt;NSCFArray 0x15e8f6c0&gt;(\n    file://localhost/Users/ask/Documents/composing-fractals.pdf\n)\n\n(gdb) p (int)[$eax retainCount]\n$12 = 1\n</code></pre>\n\n<p>so I guess there was a problem with the object I was investigating... or something.</p>\n\n<p>Thanks for your help!</p>\n'}, {'answer_id': 61947, 'author': 'Kendall Helmstetter Gelner', 'author_id': 6330, 'author_profile': 'https://Stackoverflow.com/users/6330', 'pm_score': 4, 'selected': True, 'text': '<p>If you must override gdb and send a message to an object when it will not let you, you can use performSelector:</p>\n\n<pre><code>(gdb) print (int)[receivedData count]\nTarget does not respond to this message selector.\n\n(gdb) print (int)[receivedData performSelector:@selector(count) ]\n2008-09-15 00:46:35.854 Executable[1008:20b] *** -[NSConcreteMutableData count]:\nunrecognized selector sent to instance 0x105f2e0\n</code></pre>\n\n<p>If you need to pass an argument use withObject:</p>\n\n<pre><code>(gdb) print (int)[receivedData performSelector:@selector(count) withObject:myObject ]\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/56472', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5577/']