Help: Unwinding the C++ stack...throw, longjmp & threads
Jason Merrill
jason@cygnus.com
Wed Aug 18 12:16:00 GMT 1999
>>>>> George T Talbot <george@moberg.com> writes:
> I'm working on a solution for deferred pthread_cancel() under Linux.
> What I want is to unwind the stack when the thread is cancelled so that
> C++ destructors for objects on the stack get called.
> If I recompile the C library with the -fexceptions flag, I can throw an
> exception in a cancellation handler, and this does what I want. My
> platform is Linux x86.
> However, after talking to Ulrich Drepper at LWCE, he says that
> recompiling the C library with -fexceptions slows it down by around 5%.
> So, obviously, he won't accept a patch to the main-line source to do
> this, with very good reason.
That doesn't make sense. Compiling C code with -fexceptions should not
affect the code at all; it just creates unwind tables in another section.
> I would like to write a function which unwinds the stack similarly to
> what happens at a throw in C++, but which wouldn't require recompiling
> existing libraries written in C.
> Is this possible?
Yes; gdb does it by looking at the code for the prologue and figuring out
from there how registers have been saved. See i386_frame_find_saved_regs
in gdb/i386-tdep.c. Adding generic unwind support would be most welcome.
> Can anyone point me to the source for how throw unwinds the stack?
See throw_helper in gcc/libgcc2.c.
> Alternatively, could someone put me in touch with the folks that work on
> C++ exceptions in gcc on the x86 processor?
That would be Andrew Macleod <amacleod@cygnus.com> and myself.
> Also, does setjmp()/longjmp() assure that C++ destructors for
> stack-based objects are called?
You mean, explicit calls to setjmp and longjmp in user code? No.
Jason
More information about the Libc-alpha
mailing list