This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: next/finish/etc -vs- exceptions


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]