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

Christian Convey via lldb-dev lldb-dev at lists.llvm.org
Fri Aug 26 07:25:14 PDT 2016


Hi guys,

I'm trying to use watchpoints to detect user-space reads/writes of an
arbitrary C/C++ program variable.

For example:
   void foo() {
      int x;   // <-- I'm interested in 'x'
      x = 10;  // <-- I want to detect this

      for (int i = 0; i < 4; ++i) {
         x = i;  // <-- And this
         bar(x);
      }

      x = 20;  // <-- and this
      bar(x);
      baz( &x ); // <-- and any updates to 'x' during this call
   }

My concern is that the clang+LLVM will sometimes model "x" using a
register or constant, rather than with memory.  And so a watchpoint
might miss some reads/writes to "x".

Does anyone know of a way to minimize or eliminate this problem?

Ideas I've considered so far:

* Compiling the whole program with "-O0".  This might be enough, but
I'm not sure.

* Add the "volatile" qualifier to "x".  This might solve the problem,
but could require countless additions of "volatile" elsewhere as well.

* Adding a statement of the form "my_dummy_func( &x )".  Assuming this
reliably causes a memory allocation for "x", this might help.  But I
wouldn't expect it to reliably preclude "x"'s value from being modeled
with a register or constant at certain locations in the object code.

I don't mind modifying compiler/linker flags, but I'd prefer to not
modify the source code.  I should be able to use most versions of GCC
and/or Clang/LLVM/LLDB.

Thanks,
Christian


More information about the lldb-dev mailing list