Print stream value in gdb - C++

I got what I needed by recompiling everything (not just one or two translation units) with -D_GLIBCXX_DEBUG. Then I can just do

(gdb) p is.tellg()
$21 = {_M_off = 0, _M_state = {__count = 0, __value = {__wch = 0, __wchb = "\000\000\000"}}}
(gdb) 

where is is a std::istream&. Previously I was getting

(gdb) p is.tellg()
Couldn't find method std::istream::tellg
(gdb) p is

Also, when I only rebuilt one compilation unit, it ran but crashed with

...
305d85d000-305d85e000 r--p 0005d000 fd:01 1180082                        /lib64/libfreebl3.so
305d85e000-305d85f000 rw-p 0005e000 fd:01 118
Program received signal SIGABRT, Aborted.
0x0000003052e35215 in raise () from /lib64/libc.so.6
(gdb)

See also: http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode_using.html#debug_mode.using.mode


You have to make sure that you have the package with the libstdc++ library compiled with the debugging flags.

I have the libstdc++6-8-dbg package installed and now I can view all the stream object data in gdb.

Tags:

C++

Stream

Gdb