[lldb-dev] Watching reads/writes on optimized variables?

Greg Clayton via lldb-dev lldb-dev at lists.llvm.org
Fri Aug 26 09:40:20 PDT 2016


Maybe the volatile keyword?

volatile int x = 10;

> On Aug 26, 2016, at 9:27 AM, Christian Convey <christian.convey at gmail.com> wrote:
> 
> Hi Greg,
> 
> 
>>> 
>>> Does anyone know of a way to minimize or eliminate this problem?
>> 
>> Just take the address of your variable at some point in your code and it will force it into memory.
> 
> Thanks for your idea.  I can see why taking the variable's address (in
> an expression that's not optimized away) would prompt llvm to allocate
> genuine stack space for it.
> 
> However, I'm still concerned about the following scenario:
> 
>   int foo() {
>      int x;
>      dummy_func(&x); // <-- your idea, AFAICT
>      x = 10;
>      f(x);
>      x = 20;
>      g(x);
>      return x;
>   }
> 
> I suspect it's still possible that the optimizer will (conceptually) replace:
>      x = 10;
>      f(x);
>      x = 20;
>      g(x);
>      return x;
> with:
>      f(10);
>      f(20);
>      return 20;
> 
> It's pretty important to me that at debug-time I detect the fact that
> "X=10" and "X=20" (conceptually) were executed and modified the value
> of "x".  (Whatever approach I use also needs to detect access to "x"
> which occur via aliasing.)
> 
> - Christian



More information about the lldb-dev mailing list