Author Topic: ostringstream in debugger  (Read 8636 times)

Offline mdblack98

  • Single posting newcomer
  • *
  • Posts: 3
ostringstream in debugger
« on: January 11, 2011, 09:42:06 pm »
I am using 10.05 and MinGW-w64.

When I compile a program using ostringstream the CodeBlocks debugger dies as soon as it enters a subroutine with a declaration of it.
It just dies with no message.  Running gdb outside of CodeBlocks works fine.

Example:
#include <iostream>
#include <sstream>

using namespace std;

void testme()
{
    ostringstream mystring;
    cout << "in testme" << endl;
}

int main()
{
    testme();
    return 0;
}

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: ostringstream in debugger
« Reply #1 on: January 11, 2011, 11:54:41 pm »
Probably some of the commands C::B is passing causes gdb to crash.

You can see the communication by enabling the debugger's debug log: Settings -> Compiler & Debugger -> Debugger -> Display debugger's log
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline mdblack98

  • Single posting newcomer
  • *
  • Posts: 3
Re: ostringstream in debugger
« Reply #2 on: January 12, 2011, 02:00:16 pm »
Under the 10.05 CodeBlocks MinGW compiler this is what happens...CodeBlocks handles the "incomplete type" and displays that message under the variable entry.
Breakpoint 1, main () at main.cpp:14
14      {
(gdb) n
15          testme();
(gdb) s
testme () at main.cpp:9
9           ostringstream mystring;
(gdb) p mystring
$1 = <incomplete type>

But under g++ (tdm64-1) 4.5.1 gdb tries to expand mystring but gets an "error reading variable" message which causes the script to bomb.

I don't see where "incomplete type" is handled in the scripts...but it seems like "error reading variable" is the same thing as "incomplete type" (at least in this case).
Apparently this is the behavior of the newer g++/gdb...and probably will occur in other classes too....

#0  main () at D:\Projects\stream\main.cpp:15
>>>>>>cb_gdb:
> step
testme () at D:\Projects\stream\main.cpp:9
D:\Projects\stream\main.cpp:9:87:beg:0x4015ed
>>>>>>cb_gdb:
> info locals
mystring = {
  <std::basic_ostream<char, std::char_traits<char> >> = {
    <std::basic_ios<char, std::char_traits<char> >> = <invalid address>,
    members of std::basic_ostream<char, std::char_traits<char> >:
    _vptr.basic_ostream = 0x49ac70
  },
  members of std::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >:
  _M_stringbuf = {
    <std::basic_streambuf<char, std::char_traits<char> >> = {
      _vptr.basic_streambuf = 0x6,
      _M_in_beg = 0x1000000006 <Address 0x1000000006 out of bounds>,
      _M_in_cur = 0x3e6880 '«' <repeats 16 times>,
      _M_in_end = 0x100 <Address 0x100 out of bounds>,
      _M_out_beg = 0x77f3d5a8 "Hƒø\020H‹ètleH‹\f%0",
      _M_out_cur = 0x0,
      _M_out_end = 0x22fe00 "",
      _M_buf_locale = {
        static none = 0,
        static ctype = 1,
        static numeric = 2,
        static collate = 4,
        static time = 8,
        static monetary = 16,
        static messages = 32,
        static all = 63,
        _M_impl = 0x3e3600,
        static _S_classic = 0x499ce0,
        static _S_global = 0x499ce0,
        static _S_categories = 0x49b440,
        static _S_once = {
          done = 1,
          started = 0
        }
      }
    },
    members of std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >:
    _M_mode = 4770432,
    _M_string = {
      static npos = <error reading variable>
  }
}
>>>>>>cb_gdb:

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6079
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: ostringstream in debugger
« Reply #3 on: January 12, 2011, 03:04:16 pm »
I test your code:
Quote
> p mystring
$1 = <incomplete type>
>>>>>>cb_gdb:
> info local
mystring = <incomplete type>
>>>>>>cb_gdb:
works OK.

Quote
But under g++ (tdm64-1) 4.5.1 gdb tries to expand mystring but gets an "error reading variable" message which causes the script to bomb.
you use a 64 bit compiler? and 32 bit gdb???

BTW: I use gdb with python enabled. not sure about your gdb version.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline mdblack98

  • Single posting newcomer
  • *
  • Posts: 3
Re: ostringstream in debugger
« Reply #4 on: January 12, 2011, 04:03:14 pm »
Not sure where you got 32/64-bit confused...I have both installed and tested with both.
Works fine under 4.4.1.

I installed the 4.4.5 32-bit version sezero_20101003 and it worked.  mystring gets displayed property.
g++ (GCC) 4.4.5 20101001 (release) [svn/rev.164871 - mingw-w64/oz]

I went back and downloaded the same MinGW 64-bit version (which matches the 32-bit version I just tested) and it works OK too.
g++ (GCC) 4.4.5 20101001 (release) [svn/rev.164871 - mingw-w64/oz]


mystring now displays its members correctly where in the 4.4.1 version it just said "incomplete type".

It's the 4.5.1 version that burps but it appears to have been fixed in 4.6.0
g++ (tdm64-1) 4.5.1

I went back and downloaded the latest tdm version and it's back to "incomplete type" now.  So all is well again.
g++ (GCC) 4.6.0 20100918 (experimental)
http://tdm-gcc.tdragon.net/download

I need the openmp libraries so that's why I'm using the TDM version.

We can close this now...not a CodeBlocks problem