On Aug 9, 2011, at 11:29 , Gordon Apple wrote: Why can I not set a breakpoint on an unused variable _expression_ so I can step into it? Is there a setting I need to change? (Diagnostic purpose.)
Answering "why?" questions when it comes to gdb is probably quixotic, but …
It's a somewhat unfortunate fact that the compilers Apple uses are *very* aggressive about shortening the effective lifetime of variables. I happen to think it has lousy usability in the Debug configuration, but you can probably file that opinion in the same place as "Snowballs, Chance in Hell".
The compiler has likely optimized your variable's lifetime away completely, which means there isn't anywhere you can set a breakpoint. It may additionally have optimized away the _expression_ itself. (However, if the _expression_ contains a function/method call, the compiler isn't allowed to discard that, because it might have side effects you're depending on.)
In order to preserve the ability to step into the _expression_, you'll have to use the variable in a subsequent _expression_ that the compiler doesn't also optimize away. In practical terms, this means you'll need to use the variable (or another variable that depends on it) as a parameter to a function/method call. The simplest approach might be to write your own dummy function:
static void WhatHo (…) {}
… int myUnusedVariable = … some _expression_ … WhatHo (myUnusedVariable);
|