Re: AW: [PATCH] eh_personality.cc: unwinding on ARM

2012-03-19 Thread Peter Waechtler

On 19.03.2012 18:32, Paul Brook wrote:

while I have your attention: what is an virtual unwind frame? ;)

No such thing exists.

Throwing an exception is a muti-stage process.  It requires unwinding the
stack frame twice, taking different actions in the process.  "Forced"
unwinding and backtracing add extra complications.  The _US_* flags tell the
PR which stage in the process we're at.

IIRC the ARM EABI doesn't officially include forced unwinding, it's something
we had to bolt on afterwards.  For added fun the ARM EABI defines the set of
states/actions somewhat differently to the DWARF unwinder.

Forced unwinding is one of the warts that come from interaction between C++
and POSIX.  Almost noone really understands how all these bits fit together.

Thanx Paul, that one gave me a good laugh. :))

I worked several months (not full-time, only every now and then) to nail 
this loop down.


It's definitely  a fix for upstream - saving the sanity of some souls.

Peter







Re: [PATCH] eh_personality.cc: unwinding on ARM

2012-03-29 Thread Peter Waechtler

On 19.03.2012 17:38, Daniel Jacobowitz wrote:

On Mon, Mar 19, 2012 at 12:12 PM, Andrew Stubbs  wrote:

On 16/03/12 13:29, EXTERNAL Waechtler Peter (Fa. TCP, CM-AI/PJ-CF31) wrote:

The CodeSourcery toolchain contains a "fix" like the following,
please consider for adding it.


Here's the full original patch with ChangeLog.

I don't know why Dan never submitted this one. Perhaps it's not suitable for
upstream or not considered the correct fix?

I think it was just a pain to write a test for.



Here's another version using siglongjmp to avoid VERIFY in signal handler:
Can someone (maybe you) put that at the appropriate place?
Please don't let the integration being a pain as well

Peter

seehttp://gcc.gnu.org/ml/gcc-patches/2012-03/msg01161.html


/*
author: Peter Waechtler (pwaechtler at mac.com)
Copyright FSF or whatever is needed

A simple test case to verify if backtrace(3) goes into
a loop while unwinding on ARM with cxx_personality routine.
*/
#include
#include
#include
#include
#include
#include

#include
#include
using namespace std;

//#include "testsuite.h"

#define WE_PASSED 42
#define WE_FAILED 0xff

sigjmp_buf env;

static void abort_handler(int n_signal, siginfo_t *siginfo, void *ptr)
{
void *address[20];
int depth;

depth = backtrace(address, sizeof(address)/sizeof(void*));

backtrace_symbols_fd(address, depth, 0);
/* this is a dumb check, better look for main */
if (depth == sizeof(address)/sizeof(void*))
siglongjmp(env, WE_FAILED);
else
siglongjmp(env, WE_PASSED);
}

static int tst_eh01(void)
{
int rc = 0;

std::vector   v(10);
rc = v.at(42);

return rc;
}

int main(int argc, char *argv[])
{
int c = 1;
struct sigaction sa;

memset(&sa, 0 , sizeof(sa));
sa.sa_sigaction = abort_handler;
sa.sa_flags = SA_SIGINFO;

sigaction(SIGABRT,&sa, NULL);

switch (sigsetjmp(env, 1)) {
case 0: /* the context was set */
c = tst_eh01();
break;
case WE_PASSED:
// VERIFY( true );
cerr<<  "PASSED"<<  endl;
break;
default:
// VERIFY( false );
cerr<<  "FAILED"<<  endl;
break;
}

return c;
}