Bug 11233 - GDB fails to print value for ostringstream object
Summary: GDB fails to print value for ostringstream object
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.8
: P2 normal
Target Milestone: 7.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-28 18:30 UTC by James Kyle
Modified: 2015-03-24 17:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Kyle 2010-01-28 18:30:41 UTC
When attempting to print the value of an ostringstream object, gdb returns "could not find method" errors.

This behavior was observed in both v6.3 and v6.8 on Mac OSX 10.6 and on Fedora kernel 2.6.18-128. Both 64bit.

Below is an example program and gdb output when attempting to print the ostringsream methods:

#include <sstream>
#include <iostream>

using namespace std;

int main (int argc, char const *argv[])
{
  ostringstream os;
  
  os << "time be time";
  cout << os.str() << endl;
  cout << os.str().size() << endl;
  int foo = 24;
  cout << foo << endl;
  
  return 0;
}

/*
=======fedora=============
Starting program: ./bingcc/a.out 
Reading symbols for shared libraries ++. done

Breakpoint 1, main (argc=1, argv=0x7fff5fbfe850) at temp2.cpp:10
10        os << "time be time";
(gdb) n
12        int foo = 24;
(gdb) p os.str().size()
Cannot access memory at address 0x0
(gdb) p os.str()
Cannot access memory at address 0x0

=======osx 10.6============
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ... done

(gdb) b 10
Breakpoint 1 at 0x100000c15: file temp2.cpp, line 10.
(gdb) b 13
Breakpoint 2 at 0x100000c2f: file temp2.cpp, line 13.
(gdb) r
Starting program: /Volumes/Groups/Technical/Projects/jkyle/rtmrienv/src/bingcc/a.out
Reading symbols for shared libraries ++. done

Breakpoint 1, main (argc=1, argv=0x7fff5fbfe850) at temp2.cpp:10
10        os << "time be time";
(gdb) n
12        int foo = 24;
(gdb) p os.str().size()
Cannot access memory at address 0x0
(gdb) p os.str()
Cannot access memory at address 0x0
(gdb) p (std::string *)os.str()
A syntax error in expression, near `)os.str()'.
(gdb) p (string)os.str()
No symbol "string" in current context.
(gdb) p (std::string)os.str()
A syntax error in expression, near `os.str()'.
*/
Comment 1 Phil Armstrong 2015-03-24 17:42:30 UTC
Fixed by 7.9 by the looks of things:

phil@bill:~/Code$ g++ -ggdb gdbtest.cc -o gdbtest
phil@bill:~/Code$ gdb gdbtest
GNU gdb (Debian 7.9-1) 7.9
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from gdbtest...done.
(gdb) br main
Breakpoint 1 at 0x400cbf: file gdbtest.cc, line 9.
(gdb) run
Starting program: /home/phil/Code/gdbtest 

Breakpoint 1, main (argc=1, argv=0x7fffffffe2a8) at gdbtest.cc:9
9	  ostringstream os;
(gdb) n
11	  os << "time be time";
(gdb) n
12	  cout << os.str() << endl;
(gdb) p os.str().size()
$1 = 12
(gdb) p os.str()
$2 = "time be time"
(gdb)