How to setup a data breakpoint on a reference

2

I have a 64 bit reference to an object where the low order 32 bits of the reference are getting overwritten with 0xFFFFFFFF. I can't figure out how to set a data breakpoint on the bytes for the reference itself because the watch window gives me no way to acquire the address of the reference.

c++
visual-c++
asked on Stack Overflow Aug 9, 2018 by Joseph • edited Aug 10, 2018 by Matthias

2 Answers

1

I see two solutions (if I correctly understood the problem):

  • change the reference to a pointer;
  • add a dummy variable in front of your reference - see the code below - and set the break-point to its address.

class object_t
{
public:
  int i;
};

class test_t
{
public:
  int64_t dummy {};
  object_t& ro;
  test_t( object_t& aro ) : ro { aro } {}
};

int main()
{
  object_t obj;
  test_t c { obj };

  // without dummy
  int64_t* p = (int64_t*)&c;
  *(int32_t*)p = 0xffffffff; // simulates memory corruption
  c.ro.i = 0; // exception

  // with dummy
  int64_t* p = (int64_t*)&c;
  *(int32_t*)p = 0xffffffff; // will break 

  return 0;
}
answered on Stack Overflow Aug 10, 2018 by zdf • edited Aug 10, 2018 by zdf
0

I don't know any direct way to do this. But, here's a possible solution:

  • first, find where the variable is approximately: if you have a variable next to it, then get its address. If no variable nearby, then if the reference on the stack, then get the stack pointer (esp/rsp on x86). If the reference is in an object which is not on stack, then use the this pointer.
  • second, use the memory window, go to this approximate address, and search for the value of the reference, it will be somewhere nearby.
answered on Stack Overflow Aug 10, 2018 by geza

User contributions licensed under CC BY-SA 3.0