Exception handling mechanism on Solaris
I'm building an error handling mechanism for a C++ application. Right now, I got the windows part done using VectoredExceptionHand开发者_Go百科ling and I wanted to know if there is a similar concept on Solaris. Basically, whenever an exception is thrown from anywhere in the program, I want to have a callback called. Under windows, you can register a callback using AddVectoredExceptionHandler()
. How do I do this for Solaris?
Not 100% if this will work, but you can try to mimic the way gdb's catchpoints work: see http://www.delorie.com/gnu/docs/gdb/gdb_31.html The key piece of info is this:
"To stop just before an exception handler is called, you need some knowledge of the implementation. In the case of GNU C++, exceptions are raised by calling a library function named __raise_exception which has the following ANSI C interface:
/* addr is where the exception identifier is stored.
id is the exception identifier. */
void __raise_exception (void **addr, void *id);
To make the debugger catch all exceptions before any stack unwinding takes place, set a breakpoint on __raise_exception"
So, my guess is that you could install your own __raise_exception via LD_PRELOAD trick, for example.
精彩评论