• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Crash in virtual method call
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Crash in virtual method call


  • Subject: Crash in virtual method call
  • From: Doug Hill <email@hidden>
  • Date: Wed, 11 Jun 2008 14:55:52 -0700

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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Crash in virtual method call
      • From: Brady Duga <email@hidden>
    • Re: Crash in virtual method call
      • From: Jens Alfke <email@hidden>
    • Re: Crash in virtual method call
      • From: Bill Royds <email@hidden>
  • Prev by Date: Re: Xcode next version feature request
  • Next by Date: Re: public release of Xcode 3.1?
  • Previous by thread: Re: Error on compile
  • Next by thread: Re: Crash in virtual method call
  • Index(es):
    • Date
    • Thread