From 30dec34c3a0bf851cdf41153528659ad347c0ccb Mon Sep 17 00:00:00 2001 From: "hp.com!davidm" Date: Tue, 3 May 2005 09:13:17 +0000 Subject: [PATCH] Include "config.h" and if we have them. 2004/10/19 23:11:07-07:00 mostang.com!davidm (got_here): New global variable. (raise_exception): Fix off-by-2 error so that we _really_ step to the outermost a() frame. (get_bsp): New function. (__builtin_ia64_bsp): Remove. (a): Print stack and bsp addresses as we recurse. When resuming execution in outermost a() frame (n==depth), clear "result" and set "got_here" so we know we landed in the right place. (main): Don't accept arguments that cause "depth" to be < 1. When returning from a(), also check "got_here". If the check failed, print result, got_here, and nerrors for diagnostic purposes. (Logical change 1.290) --- tests/Gtest-exc.c | 79 ++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/tests/Gtest-exc.c b/tests/Gtest-exc.c index 18d49907..44b837d1 100644 --- a/tests/Gtest-exc.c +++ b/tests/Gtest-exc.c @@ -1,5 +1,5 @@ /* libunwind - a platform-independent unwind library - Copyright (C) 2001-2003 Hewlett-Packard Co + Copyright (C) 2001-2004 Hewlett-Packard Co Contributed by David Mosberger-Tang Permission is hereby granted, free of charge, to any person obtaining @@ -24,18 +24,27 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* This illustrates the basics of using the unwind interface for exception handling. */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include #include +#ifdef HAVE_IA64INTRIN_H +# include +#endif + #define panic(args...) \ { ++nerrors; fprintf (stderr, args); } int nerrors = 0; int verbose = 0; int depth = 13; +volatile int got_here = 0; extern void b (int); @@ -53,15 +62,8 @@ raise_exception (void) return; } - /* unwind to frame b(): */ - if (unw_step (&cursor) < 0) - { - panic ("unw_step() failed!\n"); - return; - } - - /* unwind to top-most frame a(): */ - for (i = 0; i < depth - 1; ++i) + /* unwind to top-most frame a(), skipping over b() and raise_exception(): */ + for (i = 0; i < depth + 2; ++i) if (unw_step (&cursor) < 0) { panic ("unw_step() failed!\n"); @@ -70,42 +72,50 @@ raise_exception (void) unw_resume (&cursor); /* transfer control to exception handler */ } -#if !UNW_TARGET_IA64 || defined(__INTEL_COMPILER) - -void * -__builtin_ia64_bsp (void) +uintptr_t +get_bsp (void) { - return NULL; -} - +#if UNW_TARGET_IA64 +# ifdef __INTEL_COMPILER + return __getReg (_IA64_REG_AR_BSP); +# else + return (uintptr_t) __builtin_ia64_bsp (); +# endif +#else + return 0; #endif +} int a (int n) { long stack; + int result = 99; if (verbose) - printf ("a(n=%d)\n", n); + printf ("a(n=%d): sp=%p bsp=0x%lx\n", + n, &stack, (unsigned long) get_bsp ()); if (n > 0) - return a (n - 1); - - if (verbose) - printf ("a: sp=%p bsp=%p\n", &stack, __builtin_ia64_bsp ()); - - b (16); + a (n - 1) + 1; + else + b (16); if (verbose) { - printf ("exception handler: here we go (sp=%p, bsp=%p)...\n", - &stack, __builtin_ia64_bsp ()); + printf ("exception handler: here we go (sp=%p, bsp=0x%lx)...\n", + &stack, (unsigned long) get_bsp ()); /* This call works around a bug in gcc (up-to pre3.4) which causes invalid assembly code to be generated when __builtin_ia64_bsp() gets predicated. */ getpid (); } - return 0; + if (n == depth) + { + result = 0; + got_here = 1; + } + return result; } void @@ -123,15 +133,26 @@ b (int n) int main (int argc, char **argv) { + int result; + if (argc > 1) { ++verbose; depth = atol (argv[1]); + if (depth < 1) + { + fprintf (stderr, "Usage: %s depth\n" + " depth must be >= 1\n", argv[0]); + exit (-1); + } } - if (a (depth) != 0 || nerrors > 0) + result = a (depth); + if (result != 0 || !got_here || nerrors > 0) { - fprintf (stderr, "FAILURE: test failed; try again?\n"); + fprintf (stderr, + "FAILURE: test failed: result=%d got_here=%d nerrors=%d\n", + result, got_here, nerrors); exit (-1); }