使用gdb进行调试 - 最佳实践 [英] Debugging using gdb - Best practices

查看:169
本文介绍了使用gdb进行调试 - 最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是GDB的初学者,我正确地工作。但是,我想知道这是如何用于大型项目。我有一个使用makefile和g ++完成构建的项目。为了GDB的工作,我们需要编译调试符号,正确的(g ++ -g文件)?



问题


  1. 是否需要创建makefile中的一个新目标,如debug,以便我可以进行调试构建,如 make debug 。这是最佳做法吗?

  2. 假设我只需要调试foo.cpp,是否可以为除了构建整个程序(包括main)之外的其他程序生成调试符号?

有什么想法?

解决方案


  1. 不需要,尽管您可能需要考虑始终使用-g进行构建(有时甚至可能需要尝试调试优化的(-O1,-O2等)代码;为什么不放弃-g on对于发行版,您始终可以在二进制文件上运行strip。



I am a beginner in GDB and I got it working correctly. However, I am wondering how this is used in big projects. I have a project where build is done using makefile and g++. For GDB to work, we need to compile with debug symbols on, right (g++ -g files)?

Question

  1. Do I need to create a new target in makefile something like "debug", so that I can make a debug build like make debug. Is this the best practice?
  2. Suppose, I need to debug only foo.cpp and is it possible to generate debug symbols only for that other than building whole program including main?

Any thoughts?

解决方案

  1. Not needed, although you may want to consider always building with -g (sometimes, you may even need to try and debug optimized (-O1, -O2, etc) code; why not leave -g on? For releases, you can always just run strip on the binary.

  2. Yes. Build just that file with -g .

这篇关于使用gdb进行调试 - 最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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