blob: c4145bc374ec3858b5836c0ab17beef4ba4941d4 [file] [log] [blame]
mostang.com!davidm2eec1262003-09-19 06:56:39 +00001/* libunwind - a platform-independent unwind library
2 Copyright (C) 2003 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5This file is part of libunwind.
6
7Copyright (c) 2003 Hewlett-Packard Co.
8
9Permission is hereby granted, free of charge, to any person obtaining
10a copy of this software and associated documentation files (the
11"Software"), to deal in the Software without restriction, including
12without limitation the rights to use, copy, modify, merge, publish,
13distribute, sublicense, and/or sell copies of the Software, and to
14permit persons to whom the Software is furnished to do so, subject to
15the following conditions:
16
17The above copyright notice and this permission notice shall be
18included in all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
27
mostang.com!davidm9339de42003-09-18 06:09:22 +000028/* 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
33 instead). */
34
35#include <stdio.h>
36#include <string.h>
37
38#include <libunwind.h>
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030039#include "compiler.h"
mostang.com!davidm9339de42003-09-18 06:09:22 +000040
41int errors;
42
43#define panic(args...) \
44 { ++errors; fprintf (stderr, args); return -1; }
45
46static int
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030047find_proc_info (unw_addr_space_t as UNUSED,
48 unw_word_t ip UNUSED,
49 unw_proc_info_t *pip UNUSED,
50 int need_unwind_info UNUSED,
51 void *arg UNUSED)
mostang.com!davidm9339de42003-09-18 06:09:22 +000052{
53 return -UNW_ESTOPUNWIND;
54}
55
56static int
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030057access_mem (unw_addr_space_t as UNUSED,
58 unw_word_t addr UNUSED,
Tommi Rantalaf42a8de2012-08-02 09:42:21 +030059 unw_word_t *valp, int write,
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030060 void *arg UNUSED)
mostang.com!davidm9339de42003-09-18 06:09:22 +000061{
62 if (!write)
63 *valp = 0;
64 return 0;
65}
66
67static int
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030068access_reg (unw_addr_space_t as UNUSED,
69 unw_regnum_t regnum UNUSED,
Tommi Rantalaf42a8de2012-08-02 09:42:21 +030070 unw_word_t *valp, int write,
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030071 void *arg UNUSED)
mostang.com!davidm9339de42003-09-18 06:09:22 +000072{
73 if (!write)
74 *valp = 32;
75 return 0;
76}
77
78static int
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030079access_fpreg (unw_addr_space_t as UNUSED,
80 unw_regnum_t regnum UNUSED,
Tommi Rantalaf42a8de2012-08-02 09:42:21 +030081 unw_fpreg_t *valp, int write,
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030082 void *arg UNUSED)
mostang.com!davidm9339de42003-09-18 06:09:22 +000083{
84 if (!write)
Arunf89fb172011-10-02 22:43:28 -070085 memset (valp, 0, sizeof (*valp));
mostang.com!davidm9339de42003-09-18 06:09:22 +000086 return 0;
87}
88
89static int
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030090get_dyn_info_list_addr (unw_addr_space_t as UNUSED,
91 unw_word_t *dilap UNUSED,
92 void *arg UNUSED)
mostang.com!davidm9339de42003-09-18 06:09:22 +000093{
94 return -UNW_ENOINFO;
95}
96
hp.com!davidm3ff119a2004-04-23 00:12:51 +000097static void
Tommi Rantala6b55e0a2012-09-19 13:50:59 +030098put_unwind_info (unw_addr_space_t as UNUSED,
99 unw_proc_info_t *pi UNUSED,
100 void *arg UNUSED)
mostang.com!davidm9339de42003-09-18 06:09:22 +0000101{
hp.com!davidm3ff119a2004-04-23 00:12:51 +0000102 ++errors;
103 fprintf (stderr, "%s() got called!\n", __FUNCTION__);
104}
105
106static int
Tommi Rantala6b55e0a2012-09-19 13:50:59 +0300107resume (unw_addr_space_t as UNUSED,
108 unw_cursor_t *reg UNUSED,
109 void *arg UNUSED)
hp.com!davidm3ff119a2004-04-23 00:12:51 +0000110{
111 panic ("%s() got called!\n", __FUNCTION__);
112}
113
114static int
Tommi Rantala6b55e0a2012-09-19 13:50:59 +0300115get_proc_name (unw_addr_space_t as UNUSED,
116 unw_word_t ip UNUSED,
117 char *buf UNUSED,
118 size_t buf_len UNUSED,
119 unw_word_t *offp UNUSED,
120 void *arg UNUSED)
hp.com!davidm3ff119a2004-04-23 00:12:51 +0000121{
122 panic ("%s() got called!\n", __FUNCTION__);
mostang.com!davidm9339de42003-09-18 06:09:22 +0000123}
124
125int
126main (int argc, char **argv)
127{
128 unw_accessors_t acc;
129 unw_addr_space_t as;
130 int ret, verbose = 0;
131 unw_cursor_t c;
132
mostang.com!davidm6ef16402005-05-03 09:13:17 +0000133 if (argc > 1 && strcmp (argv[1], "-v") == 0)
mostang.com!davidm9339de42003-09-18 06:09:22 +0000134 verbose = 1;
135
136 memset (&acc, 0, sizeof (acc));
137 acc.find_proc_info = find_proc_info;
hp.com!davidm3ff119a2004-04-23 00:12:51 +0000138 acc.put_unwind_info = put_unwind_info;
mostang.com!davidm9339de42003-09-18 06:09:22 +0000139 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;
hp.com!davidm3ff119a2004-04-23 00:12:51 +0000143 acc.resume = resume;
144 acc.get_proc_name = get_proc_name;
mostang.com!davidm9339de42003-09-18 06:09:22 +0000145
146 as = unw_create_addr_space (&acc, 0);
147 if (!as)
148 panic ("unw_create_addr_space() failed\n");
149
150 unw_set_caching_policy (as, UNW_CACHE_GLOBAL);
151
152 ret = unw_init_remote (&c, as, NULL);
153 if (ret < 0)
154 panic ("unw_init_remote() returned %d instead of 0\n", ret);
155
156 ret = unw_step (&c);
157 if (ret != -UNW_ESTOPUNWIND)
158 panic ("First call to unw_step() returned %d instead of %d\n",
159 ret, -UNW_ESTOPUNWIND);
160
161 ret = unw_step (&c);
162 if (ret != -UNW_ESTOPUNWIND)
163 panic ("Second call to unw_step() returned %d instead of %d\n",
164 ret, -UNW_ESTOPUNWIND);
165
Tommi Rantala0d7738e2012-09-17 13:27:30 +0300166 unw_destroy_addr_space (as);
167
mostang.com!davidm9339de42003-09-18 06:09:22 +0000168 if (verbose)
169 printf ("SUCCESS\n");
170 return 0;
171}