Xcode 3.2 调试:查看数组中的内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1427871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 3.2 Debug: Seeing whats in an array?
提问by fuzzygoat
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 ...
在 Xcode_3.1.2 中调试时,我很确定我可以看到 NSString 数组的内容。但是升级到 3.2 后,我只看到以下内容......
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?
我知道我可以使用“po PlanetArray”在(gdb)中打印对象,或者只需单击调试器并“将描述打印到控制台”我只是好奇,因为我确定它在升级之前有效。有人知道这是什么一回事吗?
cheers gary
干杯加里
edit: data formatters is on and it shows what you see above ...
编辑:数据格式化程序已打开,它显示了您在上面看到的内容...
回答by andreb
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):
这是因为 GDB 就好像您正在查看的变量超出范围一样,而它实际上只是对数据格式化程序的每个部分函数或方法调用返回的内容感到困惑(数据格式化程序是“{(unichar *)Xcode_CFStringSummary( $VAR, $ID)}:s" 你看到的部分。当你在调试并且你在一个方法中你知道局部变量现在必须在范围内时,打开调试器窗口和你可以看到的区域“ Variable”、“Value”和“Summary”列标题双击您感兴趣的变量的“Summary”行条目并输入以下内容(对于像 NSArray 或 NSCFArray 这样的数组类型):
"{(int)[$VAR count]} objects {(NSString *)[(NSArray *)$VAR description]}:s"
"{(int)[$VAR count]} 个对象 {(NSString *)[(NSArray *)$VAR 描述]}: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.
然后按回车。您现在已经用您自己的数据格式化程序字符串覆盖了 Xcode 的 GDB 扩展提供的默认数据格式化程序(可在“/Developer/Library/Xcode/CustomDataViews/”的各种 plist 中找到)。
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.
您自己的覆盖保存在“~/Library/Application Support/Developer/Shared/Xcode/CustomDataViews/CustomDataViews.plist”,如果您想恢复 Apple 默认数据格式化程序,只需双击相同类型变量的行并删除那里的任何内容。
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.
细节:在上面的自定义表达式中,“{}”构造告诉 GDB 执行一个命令(就像你从 GDB 的调试器命令行执行它一样,这意味着同样的限制适用:你需要指定返回类型在每个返回某些内容的函数或方法前面的强制转换中)。右花括号后面的“:s”告诉 Xcode 和 GDB 引用“Summary”列。同样有效的是“:v”,它引用“Value”列,大多数时候它只是指针值。大括号之外的所有内容都逐字显示。不幸的是,大括号不能嵌套,这会使三元运算符条件无效。
So with the above data formatter you should see the following for an empty NSArray:
因此,使用上面的数据格式化程序,您应该看到以下空 NSArray:
"0 objects (\n)"
"0 个对象 (\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"
如果您想将自己的数据格式化程序编写为 GDB 扩展(相当于指定一个类似于上面的 Xcode_CFStringSummary 的函数),您可以这样做。看看下面的标题:“/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".
它会告诉你所有你需要知道的。但是很难做到正确。仅在您的类上定义另一个方法并从数据格式化程序字符串而不是“描述”中调用它可能更容易且不易出错。
回答by Rob Keniger
In the Run > Variables View menu in Xcode, is "Use Data Formatters" enabled?
在 Xcode 的 Run > Variables View 菜单中,是否启用了“Use Data Formatters”?
回答by Kevin Horgan
I am not sure if this helps but if you select the array value to wish to see in the debugger window and the go to the Menu : Run > Variables View > View Variable As you can change it from "NSCFString *" to "NSString *". You then see the value so "Planet_1" for example.
我不确定这是否有帮助,但是如果您选择希望在调试器窗口中查看的数组值并转到菜单:运行 > 变量视图 > 查看变量,因为您可以将其从“NSCFString *”更改为“NSString * ”。然后您会看到值,例如“Planet_1”。
Cheers,
干杯,
Kevin
凯文