Xcode 3.2调试:查看数组中的内容? [英] Xcode 3.2 Debug: Seeing whats in an array?

查看:158
本文介绍了Xcode 3.2调试:查看数组中的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode_3.1.2中进行调试时,我很确定可以看到我的NSString数组的内容。然而升级到3.2后,我只看到以下内容。





我知道我可以使用po planetArray打印(gdb)中的对象,或者只需点击调试器并将其打印到控制台我只是好奇,因为我确信它在升级前工作。任何人都知道这一点吗?



欢呼加里



编辑:数据格式化程序已打开,它显示了您在上面看到的内容...


解决方案

这是因为GDB的作用就好像您正在查看的变量超出范围,而真正只是混淆了每个部分的功能或数据格式化程序的方法调用返回(数据格式化程序是您正在查看的{(unichar *)Xcode_CFStringSummary($ VAR,$ ID)}:s部分
调试时您正在您知道一个局部变量的方法现在必须在范围内,打开调试器窗口和可以看到变量,值和摘要列标题的区域双击变量的摘要行条目您有兴趣并输入以下内容(对于NSArray或NSCFArray的数组类型):



{(int)[$ VAR count]} objects {(NSString *) [(NSArray *)$ VAR description]}:s



然后按return。现在你已经覆盖了默认数据格式化程序由Xcode的GDB扩展(可以在/ Developer / Library / Xcode / CustomDataViews /)中找到,并附有您自己的数据格式化程序字符串。



您自己的覆盖保存在〜/ Library / Application Support / Developer / Shared / Xcode / CustomDataViews / CustomDataViews.plist中,如果您想拥有Apple默认数据格式化程序只需双击相同类型变量的行,并删除任何内容。



详细信息:在上面的自定义表达式中,{}结构告诉GDB执行一个命令(就像从GDB的调试器命令行执行它一样) ,这意味着适用相同的限制:您需要在返回某些东西的每个函数或方法前面指定cast中的返回类型)。关闭大括号后面的:s告诉Xcode和GDB引用摘要列。同样有效的是:v,它引用了大多数时间只是指针值的Value列。在大括号之外的一切都是逐字显示的。
不幸的是,花括号不能嵌套,这使得三元运算符条件无效。



所以使用上面的数据格式化程序,你应该看到一个空的NSArray的以下内容: / p>

0对象(\\\



如果要将自己的数据格式化程序写成GDB扩展名(相当于指定与上面的Xcode_CFStringSummary类似的函数),可以这样做。看看下面的标题:/Developer/Applications/Xcode.app/Contents/PlugIns/GDBMIDebugging.xcplugin/Contents/Headers/DataFormatterPlugin.h



它会告诉你所有你需要知道的。但是很难让它正确。它可能更容易,更容易出错,只需在类上定义另一种方法,并从数据格式化程序字符串而不是description中调用该方法。


Whilst debugging in Xcode_3.1.2 I am pretty sure I could see the contents of my NSString arrays. However after upgrading to 3.2 I only see the following ...

I know I can print the object in (gdb) using "po planetArray" or simply click in the debugger and "print description to console" I am just curious, as I am sure it worked prior to upgrading. Anyone know anything about this?

cheers gary

edit: data formatters is on and it shows what you see above ...

解决方案

This is because GDB acts as if the variable you are viewing is out of scope while it really just is confused about what each part function or method call of the data formatter is returning (the data formatter is the "{(unichar *)Xcode_CFStringSummary($VAR, $ID)}:s" part you are seeing. When you are debugging and you are in a method where you know a local variable must be in scope right now, open the debugger window and the area where you can see "Variable", "Value" and "Summary" column titles double click the "Summary" row entry for the variable you are interested in and enter the following (for array types like NSArray or NSCFArray):

"{(int)[$VAR count]} objects {(NSString *)[(NSArray *)$VAR description]}:s"

then press return. You have now overwritten the default data formatter provided by Xcode's GDB extension (to be found in various plists at "/Developer/Library/Xcode/CustomDataViews/") with your own data formatter string.

Your own overrides are saved at "~/Library/Application Support/Developer/Shared/Xcode/CustomDataViews/CustomDataViews.plist" and if you want to have the Apple default data formatter back just double click the row for a variable of the same type and delete whatever is there.

The nitty-gritty details: In the custom expression above the "{}" construct tells GDB to execute a command (as if you where executing it from GDB's debugger command line, which means the same restrictions apply: you need to specify the return type in cast parens in front of every function or method which returns something). The ":s" behind the closing curly brace tells Xcode and GDB to reference the "Summary" column. Also valid would be ":v" which references the "Value" column which most of the time is just the pointer value. Everything that is outside of the curly braces is shown verbatim. Unfortuntely curly braces can't be nested which invalidates ternary operator conditionals.

So with the above data formatter you should see the following for an empty NSArray:

"0 objects (\n)"

If you want to write your own data formatters as GDB extensions (equivalent to specifying a function akin to Xcode_CFStringSummary above) you can do so. Take a look at the following header: "/Developer/Applications/Xcode.app/Contents/PlugIns/GDBMIDebugging.xcplugin/Contents/Headers/DataFormatterPlugin.h"

it will tell you all you need to know. But it can be hard to get it right. It might be easier and less error prone to just define another method on your class and call that from the data formatter string instead of "description".

这篇关于Xcode 3.2调试:查看数组中的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆