Problems outputting a string
jacques
jacqueslenormand@sympatico.ca
Thu Feb 27 18:04:00 GMT 2003
Hello
I'm having problems with my program. I've always been able to see
strings with gdb, but now I can't!
Here's my source:
#include <iostream>
#include <string>
using namespace std;
string foo(){
string ret;
ret = "lal";
return ret; //<ssbreak here
}
int main(){
cout << foo();
}
Here's the output:
lal
Here's gdb:
Breakpoint 1, firstAlpha() () at /home/palomer/tetete.cpp:7
7 return ret;
(gdb) p ret
$1 = {static npos = 4294967295,
_M_dataplus = {<allocator<char>> = {<No data fields>},
_M_p = 0xbffff7a0
"l\234\004\ba"+$@?¡Ãy"??\205\004\bT_\022@a"+$@?¡Ãy"?d\n\023@\001"}, static
_S_empty_rep_storage = {0, 0, 0, 0}}
(gdb) p ret.c_str()
Program received signal SIGSEGV, Segmentation fault.
0x400acf3c in std::char_traits<char>::assign(char&, char const&) ()
from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.1/libstdc++.so.5
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function
(std::string::c_str() const) will be abandoned.
(gdb)
Here are my compiler flags:
-ggdb -O0 -fno-inline
g++ version:
bash-2.05b$ g++ --version
g++ (GCC) 3.2.1 20021207 (Gentoo Linux 3.2.1-20021207)
gdb version:
bash-2.05b$ gdb --version
GNU gdb 5.3
any suggestions?
--Jacques
More information about the Gdb
mailing list