本文介绍了调试的最佳实践C ++ STL /升压用gdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用GDB进行调试,使用STL /升压任何C ++ code仍然是一个噩梦。任何人谁用gdb用STL知道这一点。例如,见code 。

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.


  • 是使用和的的?是否有提升数据结构的一些这样的utils的?在上面的utils的似乎并不是可用递归,例如对于一个命令内打印出一张提振矢量:: shared_ptr的以易于辨认的方式。

  • 写您的.gdbinit文件。包括,例如,C ++相关的美化,在UCF GDB utils的底部列出。

  • 使用检查/调试STL / Boost库,如STLport的。

  • 使用日志记录(例如描述)

  • Is anyone using "Stanford GDB STL utils" and "UCF GDB utils"? Is there some such utils for boost data structures? The utils above do not seem to be usable recursively, for example for printing vector of a boost::shared_ptr in a legible manner within one command.
  • Write your .gdbinit file. Include, for example, C++ related beautifiers, listed at the bottom of UCF GDB utils.
  • Use checked/debug STL/Boost library, such as STLport.
  • Use logging (for example as described here)

更新的:GDB有一个。

Update: GDB has a new C++ branch.

推荐答案

也许不是那种小费你要找的人,但我不得不说,几年后从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:


  • 提高智能指针(特别是共同的指针,并需要性能时,指针容器)。我不记得上一次我不得不写一个明确的删除(删除是C的GOTO++恕我直言)。那还有很多GDB时间追踪无效的,泄漏的指针。

  • 提升充满了证明code的东西你可能会砍在一起,否则低劣的版本。例如的boost :: bimap的是伟大的LRU缓存逻辑的常见模式。有云的GDB时间的另一个堆。

  • 采用单元测试。 的boost ::测试的自动宏意味着它是一个绝对抄设立测试用例(的容易)。这捕获很多的东西不久,就被内置到任何东西你必须调试器附着在。

  • 相关人士认为,像工具的boost ::绑定更容易地设计出可测性。例如算法可以更为通用和更少的捆绑与它们操作的类型;这使得它们插入到测试垫片/代理/ mock对象等容易(即与事实暴露提高的模板tasticness会鼓励你敢模板你以前从未考虑的事情,产生类似的测试的好处)。

  • 的boost ::阵列。 C数组的表现,在调试范围检查的基础之上。

  • 提升充满了伟大的code,你不能不从学习

  • boost smart pointers (particularly "shared pointer", and the pointer containers when performance is needed). I can't remember the last time I had to write an explicit delete (delete is the "goto" of C++ IMHO). There goes a lot of GDB time tracking down invalid and leaking pointers.
  • boost is full of proven code for things you'd probably hack together an inferior version of otherwise. e.g boost::bimap is great for the common pattern of LRU caching logic. There goes another heap of GDB time.
  • Adopting unittesting. 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.
  • Related to that, tools like 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.
  • boost is full of great code you can't help but learn from

这篇关于调试的最佳实践C ++ STL /升压用gdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 07:23