Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

beachdog

macrumors member
Original poster
Aug 10, 2008
86
0
Not sure if anyone else has seen this, but since a recent upgrade to 2.2 I am experiencing this weird problem in gdb when running my app in debug configuration in the simulator. As I step through code in gdb, local variables that I have declared are not showing in the variable display, and if I right mouse on them in the code window I get a message along the lines of "compiler optimized this variable out". What's worse, when I hit a line of code that tests the value of that variable, the comparison takes the incorrect path leading to various application errors. Maybe this is something I have got wrong in my code, but it's pretty basic (the piece of code where I have this problem, that is).
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
I've seen something like this using SDK 2.1 as well, twice maybe, but never narrowed it down enough to post a sufficiently detailed bug report. Changing a variable from a float to an Int32, and moving it's declaration from block local to local to instance to global seemed to seemed to change whether I could examine the variable, which way a conditional statement branched, and whether I could even assign another global from it. Might be a compiler code generation or optimization bug.

.
 

beachdog

macrumors member
Original poster
Aug 10, 2008
86
0
The strange thing is that it is doing any optimization at all, as this is a debug target. Is there some setting I can use to prevent any optimization? I checked the target settings and I don't see anything specific to the optimization level. It is definitely an optimization issue of some kind, because when I step through it in the debugger it jumps past whole lines at times, so it's clearly optimized the code from how it is written.
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
Yes, I think I've seen the same thing at -O0 level as well. I had to hoist the variables up into being volatile global variables, with maybe both float and int copies, to get something to appear in the debugger.

They were originally loop temporaries IIRC. So it might be some sort of code generation bug for register assignment of loop locals.

.
 

beachdog

macrumors member
Original poster
Aug 10, 2008
86
0
Hmm, you're right on. My problem also has to do with loop variables -- I tried both iterating an enumerator as well as a for loop in this specific location, and both showed the problem. I then moved by loop variables from local to instance variables of the class this instance method is in, and voila, no problem -- same experience as you.

I'm not exactly sure whether I can create a simple reusable test case to show this, since I have lots of similar looping constructs elsewhere in my code that work properly. I can't think of anything particularly noteworthy about this code, other than it is called from an IBAction callback hooked to a button click. If I have time I will try to see if I can recreate some sort of test case I could submit to Apple. For that matter, I have not had to submit a bug report before, does anyone have the url for that?

Of course, this is a pretty ugly workaround, but at least it gets me out of the mud for now. Many thanks!
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
If I have time I will try to see if I can recreate some sort of test case I could submit to Apple. For that matter, I have not had to submit a bug report before, does anyone have the url for that?

Please do! Start Here:
http://developer.apple.com/bugreporter/

Don't forget to read the documentation on recommended practices if you want your bug report more promptly reviewed (or even fixed!).

.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.