> On Aug 26, 2016, at 7:25 AM, Christian Convey via lldb-dev > <lldb-dev@lists.llvm.org> wrote: > > 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?
Just take the address of your variable at some point in your code and it will force it into memory. > > 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 > _______________________________________________ > lldb-dev mailing list > lldb-dev@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev _______________________________________________ lldb-dev mailing list lldb-dev@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev