1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-26 17:17:39 +01:00

Test unwinding across signal delivered on alternate signal stack.

(Logical change 1.40)
This commit is contained in:
mostang.com!davidm 2003-01-21 17:41:20 +00:00
parent 6e7fb1619c
commit 51b47e4ecf

View file

@ -1,5 +1,5 @@
/* libunwind - a platform-independent unwind library /* libunwind - a platform-independent unwind library
Copyright (C) 2001-2002 Hewlett-Packard Co Copyright (C) 2001-2003 Hewlett-Packard Co
Contributed by David Mosberger-Tang <davidm@hpl.hp.com> Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of libunwind. This file is part of libunwind.
@ -25,10 +25,12 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <errno.h>
#include <execinfo.h> #include <execinfo.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <libunwind.h> #include <libunwind.h>
@ -88,8 +90,10 @@ foo (void)
void *buffer[20]; void *buffer[20];
int i, n; int i, n;
printf ("\texplicit backtrace:\n");
do_backtrace (); do_backtrace ();
printf ("\tvia backtrace():\n");
n = backtrace (buffer, 20); n = backtrace (buffer, 20);
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
printf ("[%d] ip=%p\n", i, buffer[i]); printf ("[%d] ip=%p\n", i, buffer[i]);
@ -102,7 +106,9 @@ sighandler (int signal, struct sigcontext sc)
sighandler (int signal, void *siginfo, struct sigcontext *sc) sighandler (int signal, void *siginfo, struct sigcontext *sc)
#endif #endif
{ {
printf ("sighandler: got signal %d", signal); int sp;
printf ("sighandler: got signal %d, sp=%p", signal, &sp);
#if UNW_TARGET_IA64 #if UNW_TARGET_IA64
printf (" @ %lx", sc->sc_ip); printf (" @ %lx", sc->sc_ip);
#elif UNW_TARGET_X86 #elif UNW_TARGET_X86
@ -116,9 +122,31 @@ sighandler (int signal, void *siginfo, struct sigcontext *sc)
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
struct sigaction act;
stack_t stk;
printf ("Normal backtrace:\n");
foo (); foo ();
printf ("\nBacktrace across signal handler:\n");
signal (SIGTERM, (sighandler_t) sighandler); signal (SIGTERM, (sighandler_t) sighandler);
kill (getpid (), SIGTERM); kill (getpid (), SIGTERM);
printf ("Backtrace across signal handler on alternate stack:\n");
stk.ss_sp = malloc (SIGSTKSZ);
if (!stk.ss_sp)
panic ("failed to allocate SIGSTKSZ (%u) bytes\n", SIGSTKSZ);
stk.ss_size = SIGSTKSZ;
stk.ss_flags = 0;
if (sigaltstack (&stk, NULL) < 0)
panic ("sigaltstack: %s\n", strerror (errno));
memset (&act, 0, sizeof (act));
act.sa_handler = (void (*)(int)) sighandler;
act.sa_flags = SA_ONSTACK;
if (sigaction (SIGTERM, &act, NULL) < 0)
panic ("sigaction: %s\n", strerror (errno));
kill (getpid (), SIGTERM);
return 0; return 0;
} }