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

Christian Convey via lldb-dev lldb-dev at lists.llvm.org
Fri Aug 26 09:27:48 PDT 2016


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