用Eclipse / CDT调试C ++代码时更好的变量探索 [英] Better variable exploring when debugging C++ code with Eclipse/CDT
问题描述
使用Eclipse和CDT来调试C ++代码,变量窗口很繁琐,对于在标准模板库或boost(例如shared_ptr)中定义的类型来说并不是很有用。
bar {...}
std :: _ Vector_base< TSample< MyTraits> ;, std :: allocator< TSample< MyTraits> > >
_M_impl {...}
std :: allocator< TSample< MyTraits> > {...}
_M_start 0x00007ffff7fb5010
_M_finish 0x00007ffff7fd4410
_M_end_of_storage 0x00007ffff7fd5010
即使这些类型的内部信息可能是有用的,在几乎任何情况下,我希望这里有一个更清晰的表示,即std :: vector的值列表。是否有任何工具,插件或其他可以修改的修改?
EDIT
以下解决方案不适用于linux。我使用ubuntu 14.04,eclipse,g ++,gdb。
我找不到一个包gdb-python和linux不使用mingw
你需要一个版本的GDB能够使用python来打印结构。我知道至少在windows上使用mingw,这是默认安装中没有提供。
漂亮的打印机是python模块,告诉gdb如何显示给定的结构。您可以自己编写,但已经有可供下载的STL打印机。
To Pretty Pretty Printers在Windows上运行(说明与其他操作系统类似):
先决条件
-
确保您已安装Python 2.7并位于系统路径中。
http://www.python.org/download/
-
确保安装了MinGW-get
http://sourceforge.net/projects/mingw/files/ Installer / mingw-get-inst /
-
确保您已安装SVN客户端
安装:
-
打开命令Shell并键入:
mingw-get install gdb-python
-
当它完成cd到本地目录并通过键入以下命令安装打印机:
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
-
打开.gdbinit(如果需要,可在文本编辑器中创建),然后键入以下内容替换C:
Python
import sys
sys.path .insert(0,'C:/ directory')
从libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers(None)
end
Eclipse安装 b
- 转到Windows>首选项> C / C ++> Debug> GDB
- 其中GDB Debugger将路径放到python启动GDB,它很可能是在名为gdb-python27.exe的mingw / bin文件夹中。
- 在GDB命令文件中放置了你创建的.gdb init文件的路径
就像这样,正常调试,stl结构应该更容易阅读。
Using Eclipse and CDT to debug C++ code the variable windows is cumbersome and not very informative for types defined in the standard template library or in boost (e.g. shared_ptr).
Just an example how this may look like for an std::vector:
bar {...}
std::_Vector_base<TSample<MyTraits>, std::allocator<TSample<MyTraits> > >
_M_impl {...}
std::allocator<TSample<MyTraits> > {...}
_M_start 0x00007ffff7fb5010
_M_finish 0x00007ffff7fd4410
_M_end_of_storage 0x00007ffff7fd5010
Even if this information about the internals of those types may be useful, in almost any cases I would expect a clearer presentation here, i.e. a list of values for the std::vector. Are there any tools, plugins or other modifications around which can do this?
EDIT
The following solutions does not work for linux. I am using ubuntu 14.04, eclipse, g++, gdb.
I cant find a package gdb-python and linux does not use mingw
You need a version of GDB capable of using python to pretty print structures. I know at least on windows using mingw that this is not provided in the default install.
Pretty Printers are python modules which tell gdb how to display a given structure. You can write your own, but there are already printers for STL available for download.
To Get Pretty Printers working on Windows (instructions should be similiar for other OS's):
Prerequisites
Make sure you have you have Python 2.7 installed and in the system path.
Make sure MinGW-get is installed
http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/
Make sure you have an SVN client are installed
Installation:
Open a command Shell and type:
mingw-get install gdb-python
When its finished cd to a local directory and install the printers by typing:
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
Open the .gdbinit (create it in a text editor if need be) and type the following replaceing "C:/directory" with the folder that you checked the printers into.
Python
import sys
sys.path.insert(0, 'C:/directory')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
Eclipse Setup
- Go To Windows > Preferences > C/C++ > Debug > GDB
- Where it Says GDB Debugger put the path to the python enabled GDB it will most likely be in the mingw /bin folder with a name like gdb-python27.exe
- Where it says GDB Command File put the path to the .gdb init file you made earlier.
That's it, debug like normal, the stl structures should be much easier to read.
这篇关于用Eclipse / CDT调试C ++代码时更好的变量探索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!