使用Eclipse / CDT调试C ++代码时,更好的变量探索 [英] Better variable exploring when debugging C++ code with Eclipse/CDT

查看:139
本文介绍了使用Eclipse / CDT调试C ++代码时,更好的变量探索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Eclipse和CDT调试C ++代码,变量窗口对于在标准模板库或boost(例如shared_ptr)中定义的类型来说,是非常繁琐且不是非常丰富的信息。



只是一个例子,这可能是一个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

即使关于这些类型内部的信息可能是有用的,在几乎任何情况下,我都希望在这里更清晰的介绍,即std :: vector的值列表。有没有工具,插件或其他修改可以做到这一点?



编辑



以下解决方案对于linux不起作用。我正在使用ubuntu 14.04,eclipse,g ++,gdb。



我找不到包gdb-python和linux不使用mingw

解决方案

您需要一个能够使用python来打印结构的GDB版本。我至少在Windows上使用mingw,这在默认安装中没有提供。



漂亮的打印机是python模块,告诉gdb如何显示给定的结构。您可以编写自己的,但是已经有可供下载的STL打印机。



获取漂亮的打印机在Windows上工作(说明应该与其他操作系统相似):



先决条件





安装:




  • 打开命令Shell并键入:

      mingw -get install gdb-python 


  • 当它的f将cd转到本地目录,然后键入以下命令安装打印机:

      svn co svn://gcc.gnu.org/svn / gcc / trunk / libstdc ++  -  v3 / python 


  • 打开.gdbinit一个文本编辑器,如果需要),并键入以下替换C:/目录与您检查打印机的文件夹。


    Python

    import sys

    sys.path.insert(0,'C:/ directory')

    from libstdcxx.v6.printers import register_libstdcxx_printers

    register_libstdcxx_printers(无)

    结束





Eclipse设置




  • 转到Windows>首选项> C / C ++>调试> GDB

  • 它在哪里说GDB Debugger将路径添加到启用了python的GDB中,它很可能在mingw / bin文件夹中,名称如gdb-python27.exe

  • 它在哪里说GDB命令文件把路径放到.gdb初始化文件,您之前制作。



就像这样,调试方式正常,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

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屋!

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