I’ve been having this problem for while now, but always seem to put off asking this question because it seems like I am doing something wrong… but right now I feel otherwise… taken this code:
#include <string>
#include <iostream>
#include <algorithm>
int main(int argc, char** argv)
{
if(argc < 2)
{
std::cout << "usage: " << argv[0] << " <string>" << std::endl;
return 1;
}
std::string str = argv[1];
std::reverse(str.begin(), str.end());
std::cout << str << std::endl;
return 0;
}
Compiled with the command:
g++ -std=c++11 -Wall main.cpp -o main -O0 -ggdb3
I am using a very recent trunk version of gcc, I the trunk was taken around September 23rd ish… Also note that I am not compiling with optimization!
Now anyway, I start debugging, like this:
gdb --quiet --args ./main string
I set a break point at line 12 (the reverse algorithm)
b 12
then I run the program
run
then I try to print out the string, to see what it is
print str
And this, my dear friends, is what seems strange to me:
The output of that previous command is:
No symbol "str" in current context.
a quick check to the local variables doesn’t show the string either
info locals
all I get is
std::__ioinit = {static _S_refcount = 2, static _S_synced_with_stdio = true}
so I’m wondering, am I at fault, or is the compiler or debugger at fault… this has been a pretty pain in the ass problem for a long time for me… so thanks for even reading this question… 🙂
EDIT: now that it has become clear that there is something wrong with my gcc build, I’m wondering if anyone has come across a bug report or any other case where there seems to a be a problem similar to this… I will also try checking with a recent build of gdb to make sure that there is definitely not a problem with my current debugger (that comes with ubuntu)… does that make sense?
EDIT2: So after compiling gdb v7.5, I got relatively the same result except there were no locals present at all… I guess that means it’s a gcc issue, thanks everyone…
No, even with –quiet it works for me. Maybe there’s something wrong with your setup.