tags:

views:

65

answers:

4

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];
        }
    }
}

Thanks

A: 

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.

unwind
A: 

Check your optimization options. It's possible the GCC could replace the variable with a pointer into feature_mask.

Aaron Digulla
+2  A: 

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.

ar
A: 

You can try declaring i as volatile. That will prevent some compiler optimizations (and hopefully make i visible inside the debugger).

pmg
This is daft. Don’t work round the optimisations – always compile without optimisations for debugging (except in the rare case that a bug only manifests with optimisations – but that’s another story).
Daniel Cassidy
I agree with Daniel. +1 for his comment
pmg