RE: Help needed in debugging the program

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Chandru,

I think this is the problem your are running into...

std::string typeinfo exists in both the main application, and in the shared library.

When the string object is created in the shared library, it's typeinfo pointer refers to the std::string typeinfo data structure that was compiled in the shared library.

The main application has its own compiled std::string typeinfo data structure.

When the main application processes the exception, it compares the typeinfo pointer of the exception object in hand to the typeinfo pointer of the std::string typeinfo data structure in the main application.

The pointers do not match.  Hence, the code does not consider the shared library's std::string to be the right type as attempting to be caught by the main application's std::string.

The pointers are being compared for equality, which is quick, but incorrect in this situation.  If the typeinfo objects were being compared as being equal (a heavier-weight / deeper "is equal" comparison), then the catch would work.

Solutions to the problem...

On many platforms, GCC uses vague linkage to implement the typeinfo structure.  For information...

http://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html

Does HP UX support COMDAT, or does it support weak linkage?

Is the shared library being compiled with early binding?

You should be able to use the nm tool to see what linkage the symbols have.

Also, if you change the visibility from default to hidden, you can inadverently affect the accessibility of the typeinfo structure.  On my project, we explicitly export the class using __attribute__((visibility("default"))) on our thrown classes, to avoid that problem.  But we don't proactively edit <string> or other standard header files to add such annotation!  For information...

http://gcc.gnu.org/wiki/Visibility

If you look in <typeinfo>, you'll see __GXX_MERGED_TYPEINFO_NAMES and the operator== ... that's where the fast pointer comparison happens.  I'm not sure what toggles __GXX_MERGED_TYPEINFO_NAMES being enabled or disabled (it's not a user -D__GXX_MERGED_TYPEINFO_NAMES specified kind of thing).  On one of my platforms, it's set the wrong way, so we wrote our own custom typeinfo comparison routine.

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux