用gdb调试,任何使用STL/boost的c++代码仍然是一场噩梦.任何在 STL 中使用过 gdb 的人都知道这一点.例如,在此处中查看一些调试会话的示例运行.
Debugging with gdb, any c++ code that uses STL/boost is still a nightmare. Anyone who has used gdb with STL knows this. For example, see sample runs of some debugging sessions in code here.
我试图通过收集提示来减轻痛苦.您能否评论我在下面收集的技巧(特别是您一直在使用的技巧以及您建议对它们进行的任何更改)-我列出的技巧是按技术性递减顺序排列的.
I am trying to reduce the pain by collecting tips. Can you please comment on the tips I have collected below (particularly which ones you have been using and any changes you would recommend on them) - I have listed the tips is decreasing order of technicality.
更新:GDB 有一个新的 C++ 分支.
也许不是你要找的那种技巧",但我不得不说,我从 C++ 转向几年后的经验 &STL 到 C++ &提升 &STL 是我现在花在 GDB 上的时间比以前少了很多.我把这归结为以下几点:
Maybe not the sort of "tip" you were looking for, but I have to say that my experience after a few years of moving from C++ & STL to C++ & boost & STL is that I now spend a lot less time in GDB than I used to. I put this down to a number of things:
boost::bimap
非常适合 LRU 缓存逻辑的通用模式.还有一堆 GDB 时间.boost::test
的 AUTO 宏意味着设置测试用例绝对轻而易举(比 CppUnit 更容易).早在它被内置到您必须附加调试器的任何东西之前,它就会捕获很多东西.boost::bind
这样的工具可以更轻松地进行测试设计.例如,算法可以更通用,并且与它们所操作的类型的联系更少;这使得将它们插入到测试垫片/代理/模拟对象等中变得更加容易(而且事实上,接触 boost 的模板特性会鼓励你敢于模板化"你以前从未考虑过的东西,产生类似的测试好处).boost::array
.C 数组"性能,在调试版本中进行范围检查.boost::bimap
is great for the common pattern of LRU caching logic. There goes another heap of GDB time.boost::test
's AUTO macros mean it's an absolute doddle to set up test cases (easier than CppUnit). This catches lots of stuff long before it gets built into anything you'd have to attach a debugger to.boost::bind
make it easier to design-for-test. e.g algorithms can be more generic and less tied up with the types they operate on; this makes plugging them into test shims/proxies/mock objects etc easier (that and the fact that exposure to boost's template-tasticness will encourage you to "dare to template" things you'd never have considered before, yielding similar testing benefits).boost::array
. "C array" performance, with range checking in debug builds.这篇关于使用 gdb 调试 C++ STL/Boost 的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!