Eclipse/CDT漂亮打印错误 [英] Eclipse/CDT Pretty Print Errors

查看:100
本文介绍了Eclipse/CDT漂亮打印错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我首先说,我在这里已经搜索了其他一些令人难以置信的密切相关的问题,但还没有解决这个问题.

Let me start by saying that I've scoured other questions on here that are incredibly closely related, but haven't lent themselves to resolving my issue.

设置:

  • Win7笔记本电脑,SSH/X11至CentOS 6.4最终运行带CDT 8.3的Eclipse Kepler SR2
  • GDB 7.2
  • 没有Internet访问权限的受管理公司服务器(因此没有 svn co ... )

我不熟悉Eclipse/CDT,但熟悉GDB.当我尝试调试使用STL的应用程序时,第一次出现STL对象时,出现以下错误.在具有许多STL对象的程序中,我遇到了很多错误,以至于无法单步执行.我这里有一个用于示例目的的小示例程序.

I am new to using Eclipse/CDT, but familiar with GDB. When I try to debug an application that uses STL, upon the first occurrence of an STL object, I get the below error(s). On programs with many, many STL objects, I get so many errors, that it makes single-stepping impossible. I have here a small sample program for illustration purposes.

这是我的示例程序:

#include <iostream>
using namespace std;

int main() {
    string sComplex;
    sComplex = "!!!Hello World!!!";
    cout << sComplex << endl; // prints !!!Hello World!!!
    //cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    cout << "This is a new string that writes out a numeric..." << endl;
    int i = 1000;
    cout << "Value for integer 'i' is : '" << i << "'." << endl;
    cout << "  In HEX: '";
    cout << std::hex << std::showbase << i;
    cout << "'." <<endl;
    return 0;
}

以下是到达第一行时立即打印出的错误(STL字符串实例化):

Here are the errors that print out as soon as it hits the first line (STL string instantiation):

回溯(最近通话最近):文件"/usr/lib64/../share/gdb/python/libstdcxx/v6/printers.py",行558,位于to_string中返回self.val ['_ M_dataplus'] ['_ M_p'].lazy_string(长度= len)RuntimeError:无法访问地址0xffffffffffffffffe8处的内存

Traceback (most recent call last): File "/usr/lib64/../share/gdb/python/libstdcxx/v6/printers.py", line 558, in to_string return self.val['_M_dataplus']['_M_p'].lazy_string (length = len) RuntimeError: Cannot access memory at address 0xffffffffffffffe8

回溯(最近通话最近):文件"/usr/lib64/../share/gdb/python/libstdcxx/v6/printers.py",行558,位于to_string中返回self.val ['_ M_dataplus'] ['_ M_p'].lazy_string(长度= len)RuntimeError:无法访问地址0xffffffffffffffffe8处的内存

Traceback (most recent call last): File "/usr/lib64/../share/gdb/python/libstdcxx/v6/printers.py", line 558, in to_string return self.val['_M_dataplus']['_M_p'].lazy_string (length = len) RuntimeError: Cannot access memory at address 0xffffffffffffffe8

回溯(最近通话最近):文件"/usr/lib64/../share/gdb/python/libstdcxx/v6/printers.py",行558,位于to_string中返回self.val ['_ M_dataplus'] ['_ M_p'].lazy_string(长度= len)RuntimeError:无法访问地址0xffffffffffffffffe8处的内存

Traceback (most recent call last): File "/usr/lib64/../share/gdb/python/libstdcxx/v6/printers.py", line 558, in to_string return self.val['_M_dataplus']['_M_p'].lazy_string (length = len) RuntimeError: Cannot access memory at address 0xffffffffffffffe8

首先,请注意此对象有3个单独的错误.我已验证已安装python漂亮打印模块,并且尝试过尝试限制 to_string 中的长度的建议,但无济于事.如果我跳过字符串实例化,一切都会正常工作,并且我可以看到该变量的简单字符串值.鼠标悬停看起来也不错.当我直接在命令行上使用gdb调试同一应用程序时,我看不到任何此类错误,并且变量值显示 pretty .

First, notice that there are 3 separate errors for this one object. I have verified that the python pretty print module is installed and I have tried suggestions to limit the length in to_string, but to no avail. If I step past the string instantiation, everything works fine and I can see the simple string value of the variable. Mouse-over looks good too. When I debug this same application using gdb straight on the command-line, I don't see any such errors and variable values print pretty.

(gdb) p sComplex
$1 = "!!!Hello World!!!"
(gdb) p sComplex.c_str()
$2 = 0x602028 "!!!Hello World!!!"

我已经使用.gdbinit文件和Eclipse的Window-> Preferences-> C/C ++-> Debug-> GDB设置尝试了各种建议,甚至禁用了漂亮的打印,但是仍然会发生.我不知道接下来还要尝试什么.

I've tried various suggestions with my .gdbinit file and Eclipse's Window->Preferences->C/C++->Debug->GDB settings, even disabling pretty print, but it still happens. I don't know what else to try next.

推荐答案

我最终决定重温此问题,并通过遵循类似于

I finally decided to revisit this issue and finally resolved it by following solutions similar to this one, and by additional editing of my custom printers.py. Hopefully this helps someone else who's hit this.

  1. 结帐漂亮打印机( svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python )到 $ HOME/gdb/gdb_printers/.
    • 如果您无法结帐(如果您的组织像我的组织一样阻止外部svn),请查看是否可以从系统位置(例如/usr/share/gdb/)进行复制.完成后,您应该具有这样的目录结构:
  1. Checkout pretty printers (svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python) to $HOME/gdb/gdb_printers/.
    • If you cannot checkout (if your organization blocks external svn like mine does), see if you can copy it from a system location (such as /usr/share/gdb/). You should have a directory structure like this when you're done:

此结构必须是精确的,否则将不会使用您的printers.py/v6/.

This structure has to be EXACT or it won't use your printers.py down in /v6/.

  1. 按以下方式编辑printers.py,特别是 StdStringPrinter :: to_string (添加try/except/else):

  1. Edit printers.py, specifically StdStringPrinter::to_string as follows (adding try/except/else):

def to_string(self):
    # Make sure &string works, too.
    type = self.val.type
    if type.code == gdb.TYPE_CODE_REF:
        type = type.target ()

    # Calculate the length of the string so that to_string returns
    # the string according to length, not according to first null
    # encountered.
    # I wrapped this section in a try/except/else block so that uninitialized
    # strings don't cause massive RuntimeError exception reporting during debugging
    # with or without pretty printers enabled. -jkw
    try:
         ptr = self.val ['_M_dataplus']['_M_p']
         realtype = type.unqualified ().strip_typedefs ()
         reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
         header = ptr.cast(reptype) - 1
         len = header.dereference ()['_M_length']
    except RuntimeError:
         #print 'Caught exception'
         return ''
    else:
         return self.val['_M_dataplus']['_M_p'].lazy_string (length = len)

  • 创建/编辑$ code/$ HOME/gdb/.gdbinit 文件,并将以下内容放入其中.请注意,该路径必须与上述图像/树视图中的"python"目录的路径匹配.

  • Create/edit $HOME/gdb/.gdbinit file and put the following in it. Note the path must match the path to the 'python' directory in the above image/tree view.

     python
    import sys
    sys.path.insert(0, '/home/(user_id)/gdb/gdb_printers/python')
    from libstdcxx.v6.printers import register_libstdcxx_printers
    register_libstdcxx_printers (None)
    end
    

  • 在Eclipse中,在 Window->下;偏好->C/C ++->调试->GDB ,将路径设置为 gdb 和您的 .gdbinit 文件.您可能还需要在要使用printers.py的任何现有调试配置上进行设置.

  • In Eclipse, under Window -> preferences -> C/C++ -> Debug -> GDB, set the path to gdb and your .gdbinit file. You may also need to set this on any existing debug configurations that you want to use your printers.py.

    GDB debugger: /usr/bin/gdb
    GDB command file: /home/(user_id)/gdb/.gdbinit
    

  • 从那里开始,调试功能将按照您的预期进行.

    From there, debugging functions just as you think it should.

    这篇关于Eclipse/CDT漂亮打印错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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