Author Topic: Problem when "watching" std::string  (Read 5713 times)

Offline thamurath

  • Single posting newcomer
  • *
  • Posts: 9
Problem when "watching" std::string
« on: May 06, 2009, 02:35:26 pm »
Hi all .

First of all, i am not sure if this is the rightly forum so please sorry if not.

The question is: I am developing an application for an embedded system running debian etch over a powerpc. My pc runs debian etch also and i use codeblocks. Well, when i do remote debugging and try to watch a std::string programs start to receive SIGSEGV signals and evetually an SIGABRT.
At first i thought it was because i havent libstdc++-dbg pakage instaled but i have installed it ( both the "normal" and the cross ) and nothing changes.

Any help would be very appreciated!

Info:
S.O: debian etch
Codeblocks: svn5456
gcc 4.1.2
gdb 6.4.90
gdbserver 6.8
libstdc++6 4.1.21


Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Problem when "watching" std::string
« Reply #1 on: May 06, 2009, 03:18:13 pm »
This happens if you try to see the content of an unitialised std::string.

Offline thamurath

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem when "watching" std::string
« Reply #2 on: May 06, 2009, 03:56:12 pm »
Thanks for reply, but i dont think so.

The following code is an example. I usually put a breakpoint at the first if line and then SIGSEGV is raised ( in my watch window is msg).
The signal didnt raise if the breakpoint is disable.
Code: [Select]
void DiagnosticPutString(const unsigned short ai_sourceId,
                                                const unsigned short ai_diagCommIndex,
                                                const unsigned short ai_diagSessionIndex,
                                                const unsigned short ai_diagSectorIndex,
                                                const int ai_protocol,
                                                const int ai_errorCode,
                                                const std::string& ai_string)
            {
                static std::string msg ("");

                if ( !ai_string.empty() )
                {
                    msg = msg + ai_string;
                    if (
                            (ai_string.at(0) == '\n') ||
                            (ai_string.find("\r\n") != std::string::npos)
                        )
                    {
                        Log("DiagnosticPutString: "
                            << "\n sourceId: " << ai_sourceId
                            << "\n comIndex: " << ai_diagCommIndex
                            << "\n sessionIndex: " << ai_diagSessionIndex
                            << "\n sectorIndex: " << ai_diagSectorIndex
                            << "\n protocol: " << ai_protocol
                            << "\n errorCode: " << ai_errorCode
                            << "\n message: " << msg);
                        msg.clear();
                   }
                }

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Problem when "watching" std::string
« Reply #3 on: May 06, 2009, 04:06:30 pm »
gdb stops before the line where the breakpoint is set gets executed, that means msg is not initialised the first time you hit the breakpoint.

Offline thamurath

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem when "watching" std::string
« Reply #4 on: May 07, 2009, 10:38:33 am »
Thanks for your help.