2002-02-23 21:27:03 +01:00
|
|
|
/* libunwind - a platform-independent unwind library
|
|
|
|
Copyright (C) 2001-2002 Hewlett-Packard Co
|
|
|
|
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
|
|
|
|
|
|
|
This file is part of libunwind.
|
|
|
|
|
|
|
|
libunwind is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
libunwind is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details. */
|
|
|
|
|
|
|
|
/* This shows how to use the unwind interface to modify any ancestor
|
|
|
|
frame while still returning to the parent frame. */
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2002-04-25 08:47:29 +02:00
|
|
|
#include <libunwind-ia64.h>
|
2002-02-23 21:27:03 +01:00
|
|
|
|
|
|
|
#define panic(args...) \
|
|
|
|
{ fprintf (stderr, args); exit (-1); }
|
|
|
|
|
|
|
|
static void
|
|
|
|
sighandler (int signal)
|
|
|
|
{
|
|
|
|
unw_cursor_t cursor, cursor2;
|
2002-04-25 08:47:29 +02:00
|
|
|
unw_word_t ip;
|
2002-02-23 21:27:03 +01:00
|
|
|
unw_context_t uc;
|
|
|
|
|
|
|
|
printf ("caught signal %d\n", signal);
|
|
|
|
|
2002-04-25 08:47:29 +02:00
|
|
|
unw_getcontext (&uc);
|
|
|
|
if (unw_init_local (&cursor, &uc) < 0)
|
2002-02-23 21:27:03 +01:00
|
|
|
panic ("unw_init() failed!\n");
|
|
|
|
|
|
|
|
/* get cursor for caller of sighandler: */
|
|
|
|
if (unw_step (&cursor) < 0)
|
|
|
|
panic ("unw_step() failed!\n");
|
|
|
|
|
|
|
|
cursor2 = cursor;
|
|
|
|
while (!unw_is_signal_frame (&cursor2))
|
|
|
|
if (unw_step (&cursor2) < 0)
|
|
|
|
panic ("failed to find signal frame!\n");
|
|
|
|
|
2002-04-25 08:47:29 +02:00
|
|
|
if (unw_step (&cursor2) < 0)
|
|
|
|
panic ("unw_step() failed!\n");
|
|
|
|
|
|
|
|
if (unw_get_reg (&cursor2, UNW_REG_IP, &ip) < 0)
|
2002-02-23 21:27:03 +01:00
|
|
|
panic ("failed to get IP!\n");
|
|
|
|
|
|
|
|
/* skip faulting instruction (doesn't handle MLX template) */
|
2002-04-25 08:47:29 +02:00
|
|
|
++ip;
|
|
|
|
if (ip & 0x3 == 0x3)
|
|
|
|
ip += 13;
|
2002-02-23 21:27:03 +01:00
|
|
|
|
2002-04-25 08:47:29 +02:00
|
|
|
if (unw_set_reg (&cursor2, UNW_REG_IP, ip) < 0)
|
2002-02-23 21:27:03 +01:00
|
|
|
panic ("failed to set IP!\n");
|
|
|
|
|
|
|
|
unw_resume (&cursor); /* update context & return to caller of sighandler() */
|
|
|
|
|
|
|
|
panic ("unexpected return from unw_resume()!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-25 08:47:29 +02:00
|
|
|
doit (volatile char *p)
|
2002-02-23 21:27:03 +01:00
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
ch = *p; /* trigger SIGSEGV */
|
|
|
|
|
|
|
|
printf ("doit: finishing execution!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
signal (SIGSEGV, sighandler);
|
|
|
|
doit (0);
|
|
|
|
}
|