通过谷歌搜索,Xcode(在我的例子中是 3.1)应该至少尝试为我提供 STL 容器的合理调试视图 - 或者至少是向量。
然而,每当我在调试器中查看向量时,我只会看到 M_impl,以及 M_start 和 M_finish 成员(以及其他几个成员) - 但没有中间的东西! (顺便说一句,这是一个调试版本)。
我是否缺少某个设置或其他地方?
我还读到,有一些可用的宏可以进一步增强调试查看器以检查更复杂的容器 - 但一直找不到任何宏。
我还希望能够查看 std::wstrings,而不必转到内存查看器。 它显示 std::string 很好。 我可以做些什么来显示 std::wstring 吗?
我意识到这是一个有点复杂的问题 - 但它们实际上都是同一主题的一部分。
From googling around it looks like Xcode (3.1 in my case) should be at least trying to give me a sane debug view of STL containers - or at least vectors.
However, whenever I go to look at a vector in the debugger I just see M_impl, with M_start and M_finish members (and a couple of others) - but nothing in-between! (it's a debug build, btw).
Am I missing a setting or something somewhere?
I've also read that there are macros available that can augment the debug viewer even further to inspect more complex containers - but have been unable to find any.
I'd also like to be able to view std::wstrings, without having to drop to the memory viewer. It shows std::string fine. Is there anything I can do to show std::wstring?
I realise this is a bit of a composite question - but it's all really part of the same subject.
发布评论
评论(3)
您可以创建 针对不同变量类型的数据格式化程序,以便它们显示得更好:-)。
You can create Data formatters for different variable types so they show up nicer :-).
查看容器项目的能力可能依赖于模板化类型的复杂性。 对于像 int、bool 等这样的简单对象,甚至像
我这样的简单类模板,通常在调试器变量视图中查看向量项都没有问题。 我说“通常”是因为似乎偶尔会出现错误,导致某些东西(尤其是在调试时)不按我预期的方式运行。 其中之一是变量视图中的垃圾或完全无用的信息。 通常,目标的干净重建(或者有时甚至是更彻底地重新启动 XCode,然后进行干净重建)可以解决问题。
对于其他容器类型,很可能很难有效地查看这些信息。 例如,地图通常被实现为红黑树。 调试器必须提前知道这一点,才能正确遍历树并向您显示所有键和值。 这可能对 Xcode 或 GDB 提出了很多要求——特别是因为前者更关注 Objective-C 和普通 C 而不是 C++(因此,命名空间往往会杀死代码完成,尽管它们无处不在且很重要)。
The ability to view the container's items may rely on the complexity of the templated type. For trivial objects like int, bool, etc., and even simple class templates like
I normally have no problem viewing vector items in the debugger variable view. I say normally because there seem to be occasional bugs that cause stuff--particularly when debugging--not to behave the way I expected. One of those things is garbage or totally useless information in the variable view. Usually a clean rebuild of the target (or sometimes even a more drastic restarting of XCode followed by a clean rebuild) fixes the problem.
As for the other container types, it's most likely hard to efficiently view this information. For example a map is often implemented as a red-black tree. The debugger would have to know that in advance in order to properly walk the tree and show you all the keys and values. That's probably asking a lot from Xcode or GDB--especially since the former focuses more on Objective-C and plain C than C++ (hence the fact that namespaces tend to kill code completion despite their ubiquity and importance).
尝试在“项目”->“编辑方案...”中使用 GDB 调试器,并考虑在“项目构建设置”(在“构建选项”->“C/C++/Objective-C 编译器”下)中将编译器切换到 LLVM GCC 4.2。
在 XCode 4 中,我发现我需要这些设置来查看诸如 V3f 的 std::vector 之类的内容,其中 V3f 是模板化的浮点向量类型。
请注意,我认为您不能将 ARC(自动引用计数)与 LLVM GCC 4.2 一起使用。
Try using the GDB debugger in Project->Edit Scheme... and consider switching your compiler to LLVM GCC 4.2 in the Project Build Settings (under Build Options -> Compiler for C/C++/Objective-C).
In XCode 4, I found I needed these settings to view things like a std::vector of V3f where V3f is a templated float vector type.
Note that I think you can't use ARC (Automatic Reference Counting) with LLVM GCC 4.2.