summaryrefslogtreecommitdiff
path: root/tests/ia64-test-sig.c
diff options
context:
space:
mode:
authormostang.com!davidm <mostang.com!davidm>2003-01-23 10:04:09 +0000
committermostang.com!davidm <mostang.com!davidm>2003-01-23 10:04:09 +0000
commite5b4f8a40dc15be7943b3a1996c33e1887e5735e (patch)
tree0e0f679aabe4a84a6b20940269c9d1294a7a9d12 /tests/ia64-test-sig.c
parent7ec3afd8db47ccb4957432fed8ba38d27c1c8230 (diff)
downloadlibunwind-e5b4f8a40dc15be7943b3a1996c33e1887e5735e.tar.gz
Rename: tests/sig.c -> tests/ia64-test-sig.c
(Logical change 1.41)
Diffstat (limited to 'tests/ia64-test-sig.c')
-rw-r--r--tests/ia64-test-sig.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/ia64-test-sig.c b/tests/ia64-test-sig.c
index e69de29b..95b3d5f0 100644
--- a/tests/ia64-test-sig.c
+++ b/tests/ia64-test-sig.c
@@ -0,0 +1,93 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2001-2003 Hewlett-Packard Co
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+/* 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>
+#include <stdlib.h>
+
+#include <libunwind-ia64.h>
+
+#define panic(args...) \
+ { fprintf (stderr, args); exit (-1); }
+
+static void
+sighandler (int signal)
+{
+ unw_cursor_t cursor, cursor2;
+ unw_word_t ip;
+ unw_context_t uc;
+
+ printf ("caught signal %d\n", signal);
+
+ unw_getcontext (&uc);
+ if (unw_init_local (&cursor, &uc) < 0)
+ 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");
+
+ if (unw_step (&cursor2) < 0)
+ panic ("unw_step() failed!\n");
+
+ if (unw_get_reg (&cursor2, UNW_REG_IP, &ip) < 0)
+ panic ("failed to get IP!\n");
+
+ /* skip faulting instruction (doesn't handle MLX template) */
+ ++ip;
+ if ((ip & 0x3) == 0x3)
+ ip += 13;
+
+ if (unw_set_reg (&cursor2, UNW_REG_IP, ip) < 0)
+ 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
+doit (volatile char *p)
+{
+ int ch;
+
+ ch = *p; /* trigger SIGSEGV */
+
+ printf ("doit: finishing execution!\n");
+}
+
+int
+main (int argc, char **argv)
+{
+ signal (SIGSEGV, sighandler);
+ doit (0);
+ return 0;
+}