tags:

views:

60

answers:

2

I am using gcc 4.1.2 20080704 (Red Hat 4.1.2-48) GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5_5.1)

and I cannot watch variables declared inside for-loop. I tried to recreate this behavior on a smaller example but it worked fine. Seems like this problem shows up only inside complex class member functions. Please, advise.

EDIT: optimizations are turned off

+2  A: 

Sounds like you compiled with optimizations on. Try recompiling with with -O0 -g.

Tyler McHenry
+1, though code is usually still debuggable under `-O1`
Hasturkun
A: 

I agree that you probably need to turn off optimizations. The why is because the compiler likely eliminated the local variables during the optimization step and stored their values directly in a register.

You might also try declaring these variables as volatile while testing, if you don't wish to re-build everything with -O0.