1

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?

lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
  • Since you are debugging with gdb/ddd, consider using `-ggdb` instead; I generally go with `-ggdb3` (which implies -g, so you only need the one option). -g3 results in significantly larger executable sizes due to the large amount of additional detail. – kfsone Aug 07 '16 at 18:47
  • wait, so `g++ -ggdb -O0 program.cpp` ? That did not fix it. – lo tolmencre Aug 07 '16 at 19:33

2 Answers2

1

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)
kfsone
  • 23,617
  • 2
  • 42
  • 74
0

Have you tried to just remove -gdwarf-2 from compile flags? I had a similar problem when using a new compiler on a system with an old debugger. Then the default debug symbol format used by the compiler was too new for the debugger and I had to make the compiler use an old format. This could be similar if the debugger was recently updated.