P
__PPS__
Hello all, i have a problem with some code written by other that I
need to fix.
This is windows specific, but I post it here anyways (simply I always
visit complangc++).
I have a class that has a reference member. The problem I'm facing
happens frequently on WinCE mobile phone. And the problem is that at
some point the reference becomes invalid. This reference actually
points to a singleton object and I can find out it's memory address.
The problem is that at some point address of referenced object changes
(basically memory cell that stores the reference is changed). So, I
have to put asserts all over the place to check that address of
referenced object is correct (equals to the address of the singleton)
and even if code asserts then it's of no use to me - I really need to
trap the code that actually modifies this memory cell and not the code
that tries to access modified reference. All the values of the object
are correct, except the reference itself. So... it's a bit weird why
it happens. I may remove that reference completely and use global
singleton, but still I really want to find out why reference gets
changed (even if I remove something else may get changed instead of
this reference)
I tried to use VirtualProtect win api to set PAGE_READONLYflag on
these 4 bytes to trap attempt to owerwrite memory but this doesn't
work, since it changes to readonly entire page and it code brakes
everywhere else.
Is there any other way I can find out how this reference becomes
corrupted
need to fix.
This is windows specific, but I post it here anyways (simply I always
visit complangc++).
I have a class that has a reference member. The problem I'm facing
happens frequently on WinCE mobile phone. And the problem is that at
some point the reference becomes invalid. This reference actually
points to a singleton object and I can find out it's memory address.
The problem is that at some point address of referenced object changes
(basically memory cell that stores the reference is changed). So, I
have to put asserts all over the place to check that address of
referenced object is correct (equals to the address of the singleton)
and even if code asserts then it's of no use to me - I really need to
trap the code that actually modifies this memory cell and not the code
that tries to access modified reference. All the values of the object
are correct, except the reference itself. So... it's a bit weird why
it happens. I may remove that reference completely and use global
singleton, but still I really want to find out why reference gets
changed (even if I remove something else may get changed instead of
this reference)
I tried to use VirtualProtect win api to set PAGE_READONLYflag on
these 4 bytes to trap attempt to owerwrite memory but this doesn't
work, since it changes to readonly entire page and it code brakes
everywhere else.
Is there any other way I can find out how this reference becomes
corrupted