I am debugging a crash and I noticed as a step through the debugger, this
pointer changes its value and after 3 steps it finally get the value 0x00000001 and application crashes.
Now the 0x00000001 value is obviously wrong but should I really expect this
value to change as I step through the debugger?
Below is the constructor I am debugging where it crashes. I have included the value of this
pointer in comments with each step and as you can see it jumps around quite a bit.
CADOCommand::CADOCommand(CADODatabase* pAdoDatabase, CString strCommandText, int nCommandType)
{
m_pCommand = NULL;
m_pCommand.CreateInstance(__uuidof(Command)); // this = 0x515f9d10
m_strCommandText = strCommandText; // this = 0x2c0c0ee8
m_pCommand->CommandText = m_strCommandText.AllocSysString(); // this = 0x515f9d20
m_nCommandType = nCommandType; // this = 0x70847a55
m_pCommand->CommandType = (CommandTypeEnum)m_nCommandType; // this = 0x00000001
m_pCommand->ActiveConnection = pAdoDatabase->GetActiveConnection();
m_nRecordsAffected = 0;
}
Is there any circumstances where value of this
could or should change as we step through the code in a given member function?
Update
I must add for record and in response to several comments, I was debugging release build but when I debugged the same function in debug build, the value of this
didn't change after all.
So what does that mean, is there a problem only in release build?
The comment by @drescherjm is upvoted which says in release mode the this pointer is not correct because of optimization
but what does that exactly mean by 'not correct'? That we can't trust this pointer in release build (is bogus) or that pointer value is correct but release build is broken because of optimizations?