简体   繁体   中英

Eclipse C++ debugger not displaying variable values

I have used Eclipse for Java coding without any problem. With C++ Eclipse (Indigo), my problem is that, I am not able to see the values of the variables when I put the mouse over them ! It just shows the definition of the variable.

In Java if we right click on a variable then we get an option like "Inspect value" . That option is also not visible in C++ eclipse. How to solve this issue ? Is there any plugin or configuration am I missing ?

Have freshly installed Ubuntu 11.10 in Virtual Box (Windows XP Host). Then installed g++ 4.6, Eclipse Indigo and Eclipse CDT. In "Debug Configurations" , it shows:

Debugger: gdb/mi
Advanced: Automatically track values of "Variables" and "Registers"
GDB Debugger: gdb
GDB command file: .gdbinit
GDB Command set: Standard(Linux)
Protocol: mi
(unchecked) Verbose console mode
(unchecked) Use full file path to set breakpoints

I am able to put break points and stop the execution there, the only problem is seeing values.

Most likely, due to optimizations those values don't exist at that point. For example, consider:

int foo(void)
{
    int i=SomeFunctions();
    if(i>3) Foo();
    else
    {
       Bar();
       Baz();
    }
    // breakpoint here
    return 8;
}

The compiler is free to keep i entirely in a register. By the time you hit the breakpoint, that register may have been re-used for some other purpose. It can be impossible for the debugger to tell you the value of i at that point.

As a general rule, unless the execution of a program depends on the value of a variable, there is no requirement that it be possible to determine that variable's value.

Turning off optimizations can help.

It seems possible that the compiler is optimizing it out. A quick trick to make sure a variable will never be optimized out is to declare it as volatile . This tells the compiler that the variable should be treated like it could changed at any time (such as a global being modified from an interrupt).

Example:

int main()
{
   // Even though we never read the value of test, it will not be optimized away
   volatile int test;

   test = foo();

   return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM