1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2003 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of libunwind.
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
26 /* This file tests corner-cases of unwinding across multiple stacks.
27 In particular, it verifies that the extreme case with a frame of 96
28 stacked registers that are all backed up by separate stacks works
31 #include <libunwind.h>
35 #include "ia64-test-stack.h"
37 #define panic(args...) \
38 { printf (args); ++nerrors; }
40 /* The loadrs field in ar.rsc is 14 bits wide, which limits all ia64
41 implementations to at most 2048 physical stacked registers
42 (actually, slightly less than that, because loadrs also counts RNaT
43 slots). Since we can dirty 95 stacked registers per recursion, we
44 need to recurse RECURSION_DEPTH times to ensure all physical
45 stacked registers are in use. */
46 #define MAX_PHYS_STACKED 2048
47 #define RECURSION_DEPTH ((MAX_PHYS_STACKED + 94) / 95)
49 extern void touch_all (unsigned long recursion_depth);
50 extern void flushrs (void);
56 do_unwind_tests (void)
58 unw_word_t ip, sp, bsp, v0, v1, v2, v3, n0, n1, n2, n3, cfm, sof, sol, r32;
64 printf ("do_unwind_tests: here we go!\n");
66 /* do a full stack-dump: */
68 unw_init_local (&c, &uc);
74 if ((ret = unw_get_reg (&c, UNW_IA64_IP, &ip)) < 0
75 || (ret = unw_get_reg (&c, UNW_IA64_SP, &sp)) < 0
76 || (ret = unw_get_reg (&c, UNW_IA64_BSP, &bsp)) < 0)
78 printf ("ip=0x%16lx sp=0x%16lx bsp=0x%16lx\n", ip, sp, bsp);
80 for (reg = 32; reg < 128; reg += 4)
82 v0 = v1 = v2 = v3 = 0;
83 n0 = n1 = n2 = n3 = 0;
85 ((ret = unw_get_reg (&c, UNW_IA64_GR + reg, &v0)) < 0
86 || (ret = unw_get_reg (&c, UNW_IA64_NAT + reg, &n0)) < 0
87 || (ret = unw_get_reg (&c, UNW_IA64_GR + reg + 1, &v1)) < 0
88 || (ret = unw_get_reg (&c, UNW_IA64_NAT + reg + 1, &n1)) < 0
89 || (ret = unw_get_reg (&c, UNW_IA64_GR + reg + 2, &v2)) < 0
90 || (ret = unw_get_reg (&c, UNW_IA64_NAT + reg + 2, &n2)) < 0
91 || (ret = unw_get_reg (&c, UNW_IA64_GR + reg + 3, &v3)) < 0
92 || (ret = unw_get_reg (&c, UNW_IA64_NAT + reg + 3, &n3)) < 0);
97 printf (" %c%016lx %c%016lx %c%016lx %c%016lx\n",
98 n0 ? '*' : ' ', v0, n1 ? '*' : ' ', v1,
99 n2 ? '*' : ' ', v2, n3 ? '*' : ' ', v3);
105 if (i >= 1 && i <= NSTACKS)
107 if ((ret = unw_get_reg (&c, UNW_IA64_CFM, &cfm)) < 0)
110 if (sof != (unw_word_t) (i & 1))
111 panic ("\texpected sof=%d, found sof=%lu\n", i - 1, sof);
114 if ((ret = unw_get_reg (&c, UNW_IA64_GR + 32, &r32)) < 0)
116 if (r32 != (unw_word_t) (i - 1))
117 panic ("\texpected r32=%d, found r32=%lu\n", i - 1, r32);
120 else if (i > NSTACKS && i <= NSTACKS + RECURSION_DEPTH)
122 if ((ret = unw_get_reg (&c, UNW_IA64_CFM, &cfm)) < 0)
125 sol = (cfm >> 7) & 0x7f;
127 panic ("\texpected sof=96, found sof=%lu\n", sof);
129 panic ("\texpected sol=95, found sol=%lu\n", sol);
131 for (l = 2; l <= 93; ++l)
133 if ((ret = unw_get_reg (&c, UNW_IA64_GR + 33 + l, &v0)) < 0
134 || (ret = unw_get_reg (&c, UNW_IA64_NAT + 33 + l, &n0)) < 0)
138 case 2: case 31: case 73: case 93:
140 panic ("\texpected loc%d to be a NaT!\n", l);
145 panic ("\tloc%d is unexpectedly a NaT!\n", l);
146 v1 = ((unw_word_t) (i - NSTACKS) << 32) + l;
148 panic ("\tloc%d expected to be %lx, found to be %lx\n",
155 while ((ret = unw_step (&c)) > 0);
158 panic ("libunwind returned %d\n", ret);
162 main (int argc, char **argv)
167 touch_all (RECURSION_DEPTH);
170 printf ("FAILURE: detected %d errors\n", nerrors);
174 printf ("SUCCESS\n");