如何在 gdb 中打印objective-c 类方法的结果?

How do I print the result of an objective-c class method in gdb?(如何在 gdb 中打印objective-c 类方法的结果?)

本文介绍了如何在 gdb 中打印objective-c 类方法的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xcode 4 中使用 gdb(通过调试控制台)调试 iPad 程序时,我试图打印出运行类方法的结果:

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

gdb 输出以下内容:

<块引用><块引用>

当前上下文中没有符号MyClass".

有没有办法在 Xcode 4 中使用 gdb 打印 +(NSString *)foo:(NSString *)string 的结果?

解决方案

问题是您没有在目标源中声明任何 MyClass 类型的内容.如果您的 MyClass 仅设计为具有静态方法,您可以尝试类似

#if DEBUG//gdb 静态方法修复我的班级 *mc = nil;//这使得符号可用[mc类];//抑制未使用的警告#万一

我的猜测是,通过不在代码中的任何位置声明类的类型,它已从查找符号中优化.根据我的测试,甚至不需要调用上面的调用就可以工作.如果您查看 printcmd.c of gdb 第 1250 行,这是从哪里打印错误,这发生在调用 lookup_minimal_symbol 之后.尽管 gdb 无法在上下文中找到该符号,但在您的源代码中仅使用 MyClass 的静态方法而不进行上述修复仍然可以.

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?

解决方案

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.

这篇关于如何在 gdb 中打印objective-c 类方法的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 gdb 中打印objective-c 类方法的结果?

基础教程推荐