Reputation: 736
I'm developing an iPhone application using mixed Obj-C and C++. It seems that sometimes the values of various fields are totally bogus as reported by gdb when stepping from an Obj-C file to a C++ file. For instance, in a method:
int count = 1;
for (int i = 0; i < count; ++i) {
int x = 0; // put a breakpoint here to see how many times it gets hit.
}
in this example, sometimes gdb will report a value for 'count' that is other than '1'. it might be 126346 for example. but, stepping through the code, the loop is only iterated once, indicating that the value of 'count' actually was the expected value.
I'm new to Xcode. I probably just missing something basic. But it sucks to doubt your tools. Has anyone else seen oddness in this area? Solved it?
Upvotes: 1
Views: 324
Reputation: 6475
Are you sure that you are getting the 'value' of count all the time, use NSLog and see the value in console. I think it will always show 1. Also,
int count = 1;// put a breakpoint here to see the value of count, before and after execution of the statement.
for (int i = 0; i < count; ++i) {
int x = 0;
}
When the breakpoint is hit, that particular line is not hit, and step throuogh to see the change in the value, initially the value given by the gdb will be some arbitrary values, as the variable is not initialised, and once it gets initialised, the value changes to the new value
Upvotes: 1
Reputation: 61351
Saw oddness, in this regard and in many others. Never solved.
Sometimes using the GDB console directly helps. The way Xcode wraps GDB is definitely flakey.
Upvotes: 0
Reputation: 75058
I have not seen gdb misprint variables as you say - however, if you compile in release instead of Debug, you can run into some wierd things with code being optimized away, or not being able to see some variables...
From what you describe, it almost seems more like you had an uninitialized value for "count". If your code looked like:
int count;
Then count could be pretty much anything and thus sometimes would be 0 - but other times some large random number.
Upvotes: 2