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 Copyright (c) 2003 Hewlett-Packard Co.
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice shall be
18 included in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /* This test program checks whether proc_info lookup failures are
29 cached. They must NOT be cached because it could otherwise turn
30 temporary failures into permanent ones. Furthermore, we allow apps
31 to return -UNW_ESTOPUNWIND to terminate unwinding (though this
32 feature is deprecated and dynamic unwind info should be used
38 #include <libunwind.h>
43 #define panic(args...) \
44 { ++errors; fprintf (stderr, args); return -1; }
47 find_proc_info (unw_addr_space_t as UNUSED,
49 unw_proc_info_t *pip UNUSED,
50 int need_unwind_info UNUSED,
53 return -UNW_ESTOPUNWIND;
57 access_mem (unw_addr_space_t as UNUSED,
58 unw_word_t addr UNUSED,
59 unw_word_t *valp, int write,
68 access_reg (unw_addr_space_t as UNUSED,
69 unw_regnum_t regnum UNUSED,
70 unw_word_t *valp, int write,
79 access_fpreg (unw_addr_space_t as UNUSED,
80 unw_regnum_t regnum UNUSED,
81 unw_fpreg_t *valp, int write,
85 memset (valp, 0, sizeof (*valp));
90 get_dyn_info_list_addr (unw_addr_space_t as UNUSED,
91 unw_word_t *dilap UNUSED,
98 put_unwind_info (unw_addr_space_t as UNUSED,
99 unw_proc_info_t *pi UNUSED,
103 fprintf (stderr, "%s() got called!\n", __FUNCTION__);
107 resume (unw_addr_space_t as UNUSED,
108 unw_cursor_t *reg UNUSED,
111 panic ("%s() got called!\n", __FUNCTION__);
115 get_proc_name (unw_addr_space_t as UNUSED,
116 unw_word_t ip UNUSED,
118 size_t buf_len UNUSED,
119 unw_word_t *offp UNUSED,
122 panic ("%s() got called!\n", __FUNCTION__);
126 main (int argc, char **argv)
130 int ret, verbose = 0;
133 if (argc > 1 && strcmp (argv[1], "-v") == 0)
136 memset (&acc, 0, sizeof (acc));
137 acc.find_proc_info = find_proc_info;
138 acc.put_unwind_info = put_unwind_info;
139 acc.get_dyn_info_list_addr = get_dyn_info_list_addr;
140 acc.access_mem = access_mem;
141 acc.access_reg = access_reg;
142 acc.access_fpreg = access_fpreg;
144 acc.get_proc_name = get_proc_name;
146 as = unw_create_addr_space (&acc, 0);
148 panic ("unw_create_addr_space() failed\n");
150 unw_set_caching_policy (as, UNW_CACHE_GLOBAL);
152 ret = unw_init_remote (&c, as, NULL);
154 panic ("unw_init_remote() returned %d instead of 0\n", ret);
157 if (ret != -UNW_ESTOPUNWIND)
158 panic ("First call to unw_step() returned %d instead of %d\n",
159 ret, -UNW_ESTOPUNWIND);
162 if (ret != -UNW_ESTOPUNWIND)
163 panic ("Second call to unw_step() returned %d instead of %d\n",
164 ret, -UNW_ESTOPUNWIND);
166 unw_destroy_addr_space (as);
169 printf ("SUCCESS\n");