Questions about __cxa_throw and type_info

Brian Ellis
Fri Apr 6 17:29:00 GMT 2007

Hi list,

A brief forward to explain the context of these questions and establish my complete insanity to all -

I am in the proof of concepts stage of developing an extension language intended to interoperate natively with c++. The chief goal being the ability to derive new types at runtime, override virtuals, and have instances of these new types passed around to the engine of the extended application.

The primary concern that I am raising is RTTI and throw-catch compatibility. In the current design, I am using an interpreter which does not need it's own personality or to forge dynamic tables for the unwind process. I would, however, like to be able to forge type_info instances to put into the forged vtables and throw exceptions using __cxa_throw or some other (hopefully safer) semantic. Since these objects are intended to extend any explicitly exposed c++ class, I don't plan on having a common root that can be used in a regular throw statement.

My questions are -

1) I've not had much success poking and prodding at __cxa_throw using type_id and the likes, am I misusing that which I shouldn't be touching anyways... could somebody give me an example of how to make this work?

---- BEGIN CODE ----

class Base
 public: virtual ~Base();
class Derived : public Base
 public: virtual ~Derived();

int TestThrow()
 Derived d;
   __cxa_throw( &d, typeid( d ) ); // also tried typeid( &d )... don't think i had luck with either
 catch( Base * pBase )
    cout << "Caught a Base *";

---- END CODE ----

2) The c++ ABI is quite specific (afaik) about vtable structure and type_info pointers. I am a little bit stumped about the specification of functions within the type_info. __do_upcast's name is very suggestive about what it does, but I'm not so suer about __do_catch and would like a clear cut explanation of the in's and out's of each function. Also, if I were to forge a type_info object and vtable, would the runtime object be able to be thrown and caught properly (assuming the type_info object worked as expected)?

3) Assuming that the final design implemented a jit compiler, I would have to forge unwind tables and/or hook the lookup function (which I don't believe is within the scope of this library). If I were to use an incompatible or extended exception header, would there be any easy way to make it compatible with gcc's personality function? ("easy" is used very loosely here)

Thank you,
- Brian

Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.

More information about the Libstdc++ mailing list