lo tolmencre lo tolmencre - 4 months ago 24
C++ Question

GDB / DDD no symbol <var> in current context

I found an old solution to this problem that suggested compiling with

-gdwarf-2
, but this solution does not or no longer work for me.

So, running ddd on a compiled file and then double clicking variables always results in the error
no symbol <var> in current context


My program is this:

int main()
{
for (int i = 0; i < 10; ++i)
{

}
}


the commands I used are these:

g++ -g -O0 -gdwarf-2 test.cpp; ddd. ./a.out


Versions of the programs:

ddd: GNU DDD 3.3.12 (x86_64-pc-linux-gnu)
gdb: GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
gcc: gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)


How can I make this work?

Answer

In order to print/display variables, they have to be in scope, so for local variables/parameters that means you have to be at a breakpoint in that scope.

I can reproduce the error you are getting by starting ddd with your example program and immediately trying to print/display i.

Once I set a breakpoint on the for line and run the program, I am able to print/display them as expected.

I compiled with:

g++ -Wall -O0 -ggdb -o test.exe test.cpp

and ran ddd with

ddd ./test.exe

I have

GNU DDD 3.3.12 (x86_64-pc-linux-gnu)
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.1)