feg@clyde.ATT.COM (Forrest Gehrke) (01/12/88)
When compiling with the -Ox flag on, the optimzer ALWAYS tries to registerize loop variables. i.e. program(ptr) char *ptr; { while(*ptr){ ...... ...... ptr++; } } Will load ptr into the SI register and go merrily on its way using SI to access the data. However, the actual memory variable for ptr will not be updated until the loop terminates. This is great for speed, but it outsmarts Codeview. i.e. if you put a watch statement on *ptr and try to single step through the loop, Codeview doesn't know enough to watch the register instead of the memory variable and ptr, never changes. The moral here is don't use -Ox if you want to trace with Codeview or the QC in-memory debugger. Forrest Gehrke
tim@doug.UUCP (Tim J Ihde) (01/14/88)
In article <20028@clyde.ATT.COM>, feg@clyde.ATT.COM (Forrest Gehrke) writes: > updated until the loop terminates. This is great for speed, but it outsmarts > Codeview. i.e. if you put a watch statement on *ptr and try to single step > through the loop, Codeview doesn't know enough to watch the register > instead of the memory variable and ptr, never changes. The moral here is don't > use -Ox if you want to trace with Codeview or the QC in-memory debugger. I would add another word here: don't use the optimizer at all if you are going to be using the debugger. Sometimes you will see blocks of code executing in very different places than they were in your original source code, and it's just not worth the trouble (especially if you are looking at the assembly code). Besides, the extra information needed by codeview will probably be more that the optimizer is saving you anyway. I always use -Od to turn off all optimization (I hope that's the right command, I don't have my manual handy) while debugging, and don't bother with it except for final testing versions. By the way, you can get a real good idea of the kind of things the optimizer does by breaking this rule just to use codeview to look that the generated assembly language and comparing it with the same program with optimization off. Some of the optimizations they do are pretty impressive. -- Tim J. Ihde ihnp4!ctsmain!doug!tim (201) 535-9897 Ok, we can all agree that this is my fault.