Member_2_4548968
asked on
Values optimized Out GDB G++
I am using GDB in Kdevelop while trying to debug a C++ program compiled with g++.
Many times variables are optimized out by the compiler. However I am using the -O0 option to not optimize the code and have full debugging power. Are there other reasons why some variables are optimized out or switches maybe in Kdevelop???
Thanks.
p.s I have seen the other posts on the -O switch in experts exchange
Many times variables are optimized out by the compiler. However I am using the -O0 option to not optimize the code and have full debugging power. Are there other reasons why some variables are optimized out or switches maybe in Kdevelop???
Thanks.
p.s I have seen the other posts on the -O switch in experts exchange
ASKER
For example in the code below i cannot watch the NoClassObs variable or the Randomnumber. Another problem is that when I step through the code gdb (in kdevelop) seems to randomly jump and even stops and comment lines strangly enough.
while (CurrentClass != LastClass) {
NoClassObs = (unsigned int)((*CurrentClass).Ratio * PartitionSize);
for (unsigned int i=0; i < NoClassObs; i++) {
RandomNumber = GetRandomNumber((*CurrentC lass).Obse rvations.s ize()-1);
CurrentObservation += (RandomNumber);
(*CurrentPartition).AddObs ervation(* CurrentObs ervation);
(*CurrentClass).Observatio ns.erase(C urrentObse rvation);
}
CurrentClass++;
}
while (CurrentClass != LastClass) {
NoClassObs = (unsigned int)((*CurrentClass).Ratio
for (unsigned int i=0; i < NoClassObs; i++) {
RandomNumber = GetRandomNumber((*CurrentC
CurrentObservation += (RandomNumber);
(*CurrentPartition).AddObs
(*CurrentClass).Observatio
}
CurrentClass++;
}
Maybe you should try running gdb yourself (instead of using the one in kdevelop), and see if that works better.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just to add to what duncan_roe has said (and I've been caught out by this before so it can happen) are you sure your latest version of the code actually builds? Are you trying to debug an old version of the compiled code against a newer source. This sounds like such a daft thing to do but I promise, it can and does happen (I feel so silly admitting this :) ).
ASKER
thanks
The -O0 switch does indeed mean "no optimization". It is still possible that it performs certain basic optimizations (things like unreachable code for example - see below) however, but it tries to keep the resulting generated code as close as possible to the source code.
Can you give an example of what your compiler optimized at level -O0 ?
Open in new window