字符串的值不会出现在eclipse mars CDT中 [英] The value of strings doesn't appear in eclipse mars CDT

查看:164
本文介绍了字符串的值不会出现在eclipse mars CDT中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Eclipse Mars CDT中 string 的值不会出现在表达式或变量窗口中?
它出现 {...} 但我想在值选项卡下看到值本身。

Why does the value of strings in Eclipse Mars CDT not appear in the expression or variables windows? It appears {...} but i want to see the value itself under the value tab.

我该怎么做?

推荐答案

这里发生了什么是CDT显示GDB提供的信息。

What is going on here is CDT is showing the information that GDB is providing to it.

对于一个琐碎的程序,调试器停止在返回0的行;

For a trivial program, with the debugger stopped on the line with return 0;

#include <string>
using namespace std;

int main() {
    string mystring = "my string here";
    return 0;
}

这是我在CDT变量视图中看到的:

this is what I see in the CDT variable view:

这与我在GDB中看到的相符:

which matches what I see in GDB:

(gdb) p mystring 
$1 = {static npos = <optimised out>, 
  _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, 
    _M_p = 0x602028 "my string here"}}



漂亮的打印C ++



然而,我想你想要的是libstdc ++的漂亮打印机,这使得变量视图看起来像这样:

Pretty Printing C++

However, what I suspect you want is the pretty printers for libstdc++ which makes the variables view look like this:

创建〜/ .gdbinit文件以下内容(更新您的机器的路径)

Create a ~/.gdbinit file with the following contents (updating the path for your machine)

python
import sys
sys.path.insert(0, '/usr/share/gcc-4.8/python/')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

然后将启动配置指向该gdbinit文件并开始调试。

Then point your launch configuration at that gdbinit file and start debugging.

  • GDB wiki entry on the subject: https://sourceware.org/gdb/wiki/STLSupport
  • GCC manual entry: https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html

这篇关于字符串的值不会出现在eclipse mars CDT中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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