How to print the result of an objective-c class method in gdb?

When using gdb (via the debug console) to debug an iPad program in Xcode 4, I try to print the result of running the class method:

(gdb) po [MyClass foo:@"bar"] 

gdb displays the following:

In the current context, the MyClass character is missing.

Is there a way to print the result of +(NSString *)foo:(NSString *)string using gdb in Xcode 4?

+7
source share
2 answers

The problem is that you did not declare anything like MyClass in the target source. If your MyClass is only for 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 

I assume that without declaring the class type anywhere in your code, it was optimized from search characters. From my testing that the challenge is higher, you don’t even need to urge it to work. If you look at printcmd.c from gdb , line # 1250, an error will be printed here, and this will happen after calling lookup_minimal_symbol. Although gdb cannot find a character in context, it is still fine to use only the static MyClass methods in the source code without the correction above.

+6
source

I had the same problem here . The solution in my case was to use NSClassFromString as follows:

 po [NSClassFromString(@"MyClass") foo:@"bar"] 
+11
source

All Articles