On Saturday 20 of August 2011 14:51:44 sudhakar govindavajhala wrote:
> Hi there,
> 
> I am writing C++ code in Linux (2.6.18) using pthreads. glibc 2.5. gcc 4.1.2
> 
 
> 2) I would like to translate SIGSEGV or SIGFPE to an exception in the
> program so that it can be caught at higher levels. Is there a default
> option to convert a SIGSEGV to an exception?  For my tests, I provided
> a signal handler for SIGSEGV/SIGFPE that throws an int exception and
> it works.

1).
for proper exception throwing from signal handler you need to have a quite
new gcc (so called enterprise linux distros may have an old one) with unwinder
that can properly walk through signal frame.

2).
during e.g. sigsegv handling (broken program stack, broken glibc heap, etc.)
you should throw c++ exception in the safe way, that means you should setup
custom stack for signal handler with sigaction() and exception object should
be constructible/copyable without heap usage (probably damaged).
classic std::*_error exceptions use std::string with dynamic buffer :/

> 3) Could someone point me to  a sample to print the stack trace when
> an exception occurred?

feel free to use and improve the http://svn.pld-linux.org/svn/backtracexx

ps).
use gcc-help mailinglist next time.

BR,
Paweł.

Reply via email to