Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb: No symbol "i" in current context

Tags:

c

debugging

gdb

While debugging a C program in gdb I have a breakpoint in a for loop. I cannot print the value of "i" ( I get : No symbol "i" in current context.). I can print the value of all the other variables. Is it normal?

Here is the loop:

for (i=0; i < datasize; i++){  
    if ( feature_mask[i] > 0 ){  
        k = feature_mask[i] - 1;  
        if (neighbors[k][nmax-1] != 0){
            neighbors[k][nmax-1] = bvalue;  
            feature_mask[i] = -feature_mask[i];
        }
    }
}
like image 851
Ben2209 Avatar asked Sep 21 '10 08:09

Ben2209


3 Answers

It has probably been optimised out of your compiled code as you only use feature_mask[i] within the loop.

Did you specify an optimization level when you called your compiler? If you were using gcc, then just omit any -O options and try again.

like image 101
a'r Avatar answered Sep 28 '22 11:09

a'r


I encountered this issue recently. I compiled GCC 5.1 and then used it to compile a C++11 codebase. And, although I could step through the program's code in gdb, I couldn't print the value of any variable, I kept getting “No symbol "xyz" in current context” errors, for every variable.

I was using gdb 7.4, but the latest version available at the time was 7.9. I downloaded the latest version of gdb and compiled it (using GCC 5.1) and when using gdb 7.9 I was able to successfully inspect variable values again.

I guess the debug information of GCC 5.1 is incompatible with gdb 7.4.

like image 42
dreamlax Avatar answered Sep 28 '22 13:09

dreamlax


Make sure the program is compiled without optimization, and with debugging information enabled. It's quite likely that the loop counter ends up in a register.

like image 36
unwind Avatar answered Sep 28 '22 11:09

unwind