tags:

views:

207

answers:

3

I am examining a core dump, and noticed that in one frame the 'this' pointer is different than in the next frame (in the same thread). Not just a little different, it went from 0x8167428 to 0x200.

I am not that well-versed in using GDB, but this does not seem right to me. Is this problematic, and if so, what could be the cause?

+1  A: 

It's possible that an optimization in the code is confusing the debugger. This is a common issue when debugging retail code. Try disabling optimizations, re-running the scenario and see if you get the same problem.

JaredPar
Sorry, no optimization in that area of the code.
Hans
@Hans, i meant compiler optimizations, not user ones. Did you try disabling all compiler optimzations?
JaredPar
Sorry, that was what I meant as well. There are other shared objects used that are compiled with -O2
Hans
A: 

this pointer is local to frame.

Is the other frame belongs to 'C' function, you could see smth like 0x200

osgx
Both frames are for functions of the same class.
Hans
+3  A: 

The this pointer can change between frames in a gdb trace if the function in the next frame is called on a different object (even if the objects are the same type), since this is for the specific instance. This is probably not your problem.

0x200 is not a valid value for this, and almost certainly indicates memory corruption of some type. The this pointer is sometimes stored on the stack and passed as an invisible first argument to a function. So if you have corrupted the stack (by going out of bounds writing to another variable) you could see the this pointer corrupted.

The value 0x200 itself is interesting. Because it is so close to 0, but not actually 0, it indicates that the instance you're looking at is probably part of another object or array, located 0x200 bytes from the beginning of that object/array, and that the object/array's address is actually NULL. Looking at your code you should be able to pretty easily figure out which object has gotten set to NULL, which is causing this to report 0x200.

SoapBox
So, 0x200 is 512 in decimal. Does this mean I have to search for an object that is 512 bytes in size?
Hans
Not exactly. You're looking for an object that contains at least 512 bytes, because this is at offset 512 from the beginning. It could also be an array... if "this" is 128 bytes itself then it is the 4th index (5th element) of an array of these objects. Or it could be some combination of the two. but something, somewhere, is null.
SoapBox
This answer turned out to be close enough. There was a buffer close to the class for which the 'this' pointer changed that got zeroed out.
Hans