I'm seeing a strange crash in a virtual C++ method call. I tried looking this up in the mailing list archives to see if anyone else reported this problem but didn't find anything. So I thought I'd throw this out to the Xcode community.
The method crashes because an input parameter passed to it comes in as a bad pointer. Its pointer value is 4 less than the actual passed in value.
Unfortunately, I haven't been able to create a standalone test-case for this crash but here's something of what the code is like:
class Base1 { public: virtual void Method1( void ) = 0; };
class Base2 { public: virtual void Method2( Base1* inParam ) = 0; };
class Derived1 : public Base1 { public: void Method1( void ) { ... } };
class Derived2 : public Base2 { public: void Method2( Base1* inParam ) { inParam-> Method1(); } };
void Test( void ) { Base1* bp1 = new Derived1(); Base2* bp2 = new Derived2(); bp2->Method2( bp1 ); }
The implementations of Derived1, Derived2 and Test() are all in different shared libraries (Frameworks). Again, the above code doesn't exhibit the crash, but gives you a good idea of how my code is architected and what I'm doing.
As I step in the method call using the debugger I notice the following:
- In the course of stepping into the method that crashes, Xcode first calls "non-virtual thunk for <MyClass>:: <MyMethod>". It does this even though the method being called is a virtual method. It also displays the source of this call as a random header file in user includes.
- After I continue to step in I get to the actual source for the method I called. However, the input parameter is different than what I passed in originally. It is a pointer and the pointer value is 4 less than the real value. So, instead of being e.g. 0xbf08d0, the value I get in the called method is 0xbf08cc.
- When I try to dereference this pointer value I get a BAD_ACCESS exception.
As I haven't been able to create a standalone test-case for this crash I wanted to see if anyone has some idea why this might be happening. I'll continue trying to isolate the problem and come up with a real test case.
BTW, all optimizations are off and instruction scheduling is off for all my targets.
Thanks.
Doug Hill
|