Joseph
Joseph

Reputation: 308

How to setup a data breakpoint on a reference

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.

Upvotes: 2

Views: 318

Answers (2)

zdf
zdf

Reputation: 4808

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;
}

Upvotes: 1

geza
geza

Reputation: 29952

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.

Upvotes: 0

Related Questions