I found an old solution to this problem that suggested compiling with
no symbol <var> in current context
for (int i = 0; i < 10; ++i)
g++ -g -O0 -gdwarf-2 test.cpp; ddd. ./a.out
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)
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
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
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)