3

为什么stringsEclipse Mars CDT 中的值没有出现在表达式或variables窗口中?它出现{...}了,但我想在值选项卡下查看值本身。

我怎样才能做到这一点?

4

1 回答 1

6

这里发生的是 CDT 显示 GDB 提供给它的信息。

对于一个简单的程序,调试器停止在返回 0 的行上;

#include <string>
using namespace std;

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

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

变量的 cdt 视图

这与我在 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++ 的漂亮打印机,它使变量视图看起来像这样:

字符串打印得很漂亮

使用以下内容创建一个 ~/.gdbinit 文件(更新您机器的路径)

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 文件并开始调试。

于 2015-10-09T22:58:07.473 回答