This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFC: next/finish/etc -vs- exceptions
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Daniel Jacobowitz <drow at false dot org>
- Cc: Pedro Alves <pedro at codesourcery dot com>, gdb-patches at sourceware dot org, tromey at redhat dot com, Joel Brobecker <brobecker at adacore dot com>
- Date: Thu, 25 Nov 2010 05:53:06 +0100
- Subject: Re: RFC: next/finish/etc -vs- exceptions
- References: <m37hzzzgk7.fsf@fleche.redhat.com> <20090610161204.GB25703@adacore.com> <m3hbyoghit.fsf@fleche.redhat.com> <200906101806.31977.pedro@codesourcery.com> <20090610171328.GA32661@caradoc.them.org>
On Wed, 10 Jun 2009 19:13:28 +0200, Daniel Jacobowitz wrote:
[...]
> exceptions can be thrown through
> signal handlers on many platforms; so yes, they might switch stack.
On Fedora 14 x86_64 getting instead of a caught exception-from-sighandler:
terminate called after throwing an instance of 'int'
from the testcase below and ISO C++ says:
The common subset of the C and C++ languages consists of all
declarations, definitions, and expressions that may appear in a well
formed C++ program and also in a conforming C program. A POF (“plain
old function”) is a function that uses only features from this common
subset, and that does not directly or indirectly use any function that
is not a POF, except that it may use functions defined in Clause 29
that are not member functions. All signal handlers shall have
C linkage. A POF that could be used as a signal handler in
a conforming C program does not produce undefined behavior when used
as a signal handler in a C++ program. The behavior of any other
function used as a signal handler in a C++ program is
implementation-defined.228
228) In particular, a signal handler using exception handling is very
-------------------------------------------------
likely to have problems. Also, invoking std::exit may cause
-----------------------
destruction of objects, including those of the standard library
implementation, which, in general, yields undefined behavior in
a signal handler (see 1.9).
If this really does not have to work it means for GDB the sigaltstack case is
unrelated to this "next/finish/etc -vs- exceptions" patch.
Thanks,
Jan
#include <signal.h>
#include <assert.h>
#include <iostream>
using namespace std;
static void
handler (int signo)
{
throw 1;
}
int
main (void)
{
sighandler_t sigvar;
sigvar = signal (SIGUSR1, handler);
assert (sigvar == SIG_DFL);
try
{
int i;
i = raise (SIGUSR1);
assert (i == 0);
}
catch (...)
{
cout << "caught" << endl;
}
cout << "done" << endl;
}