When using gdb (via the debug console) to debug an iPad program in Xcode 4, I'm trying to print out the result of running a class method:
(gdb) po [MyClass foo:@"bar"]
gdb outputs the following:
No symbol "MyClass" in current context.
Is there some way to print the result of +(NSString *)foo:(NSString *)string
using gdb in Xcode 4?
I had the same problem here. The solution in my case was to use NSClassFromString
like this:
po [NSClassFromString(@"MyClass") foo:@"bar"]
The problem is you have not declared anything of type MyClass
in your targets source. If your MyClass
is only designed to have static methods you can try something like
#if DEBUG //gdb Static Method Fix
MyClass *mc = nil; //This makes the symbol available
[mc class]; //supress unused warning
#endif
My guess is that by not declaring a type of the class anywhere in your code it has been optimized out of the lookup symbols. From my testing that call above does not even have to be called for it to work. If you look at printcmd.c of gdb line # 1250 this is where the error is printed from and this occurs after a call to lookup_minimal_symbol. And although gdb is unable to find the symbol in context it is still fine to only use static methods of MyClass
in your source code without the fix above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With