了解Xcode调试器var显示 [英] understanding Xcode debugger var display

查看:26
本文介绍了了解Xcode调试器var显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新手问题:谁能告诉我如何理解/解释调试器 var 窗格中显示的内容?

newbie question: can anyone tip me to how to understand/interpret what is displayed in the debugger var pane?

例如:我将 NSDictionary 作为方法参数传递.我设置了一个断点,以便我可以检查字典中的值.下图(如果它通过..)显示了调试器中这个 var 的扩展视图.它正确地报告它包含 3 个名称/值对,但是当我展开所有部分时,我根本找不到它们的存储位置.

Ex: I am passing an NSDictionary as a method param. I set a breakpoint so I can examine the values in the dictionary. The image below (if it comes through..) shows the expanded view of this var in the debugger. It correctly reports that it contains 3 name/value pairs but as I expand all the sections, I simply can not find where these are stored.

我是否必须创建这些名称/值对的本地变量才能在我要检查时查看它们?我知道我可以使用 NSLog 或 printf,但有时我只想快速浏览一下.

Do I have to create local vars of these name/value pairs in order to view them when I want to check? I know I can use NSLog or printf but sometimes I just want a quick peek.

推荐答案

右键单击变量,单击编辑摘要格式"并键入以下内容:

Right click the variable, click "Edit Summary Format" and type the following:

{(NSString*)[$VAR description]}:s

这通过调用更昂贵的描述方法替换了 NSDictionary 的 GDB 格式化程序.
也就是说,您将看到由 -[NSDictionary description] 生成的字典内容,而不是x 键/值对".

This replaces the GDB formatter for NSDictionary with a call to the more expensive description method.
That is, instead "x key/value pairs", you'll see the contents of the dictionary as produced by -[NSDictionary description].

这与在控制台窗口中键入 po dictionary 相同.或右键单击变量并选择打印说明".两者都调用了对象的描述方法.

This is the same as typing po dictionary in the console window. Or right clicking the variable and choosing "Print Description". Both of them call the description method of the object.

如果你很好奇,你可以在 /Developer/Library/Xcode/CustomDataViews/Foundation.plist 键 NSDictionary 下找到这个格式化程序.您键入的替换内容保存在 /Users/USERNAME/Library/Developer/Xcode/UserData/Debugger/CustomDataFormatters 中,并且在您删除该文件之前会一直存在.

If you are curious, you can find this formatter at /Developer/Library/Xcode/CustomDataViews/Foundation.plist under the key NSDictionary. What you type as replacement is saved in /Users/USERNAME/Library/Developer/Xcode/UserData/Debugger/CustomDataFormatters and will persist across runs until you delete that file.

NSDictionary 实际上是一个类簇,很少有人知道其内部结构.此时,您不会发现该调试器树有多大用处.

A NSDictionary is really a class cluster and few people know the inside structure. At this point you ain't going to find much use for that debugger tree.

这篇关于了解Xcode调试器var显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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