The value of strings doesn't appear in eclipse mars CDT

廉价感情. 提交于 2019-11-26 23:26:41

问题


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.

How can i do this?


回答1:


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

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;
}

this is what I see in the CDT variable view:

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"}}

Pretty Printing C++

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

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

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


来源:https://stackoverflow.com/questions/32411117/the-value-of-strings-doesnt-appear-in-eclipse-mars-cdt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!