mostang.com!davidm | 2eec126 | 2003-09-19 06:56:39 +0000 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
| 2 | Copyright (C) 2003 Hewlett-Packard Co |
| 3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
| 4 | |
| 5 | This file is part of libunwind. |
| 6 | |
| 7 | Copyright (c) 2003 Hewlett-Packard Co. |
| 8 | |
| 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: |
| 16 | |
| 17 | The above copyright notice and this permission notice shall be |
| 18 | included in all copies or substantial portions of the Software. |
| 19 | |
| 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. */ |
| 27 | |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 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 |
| 33 | instead). */ |
| 34 | |
| 35 | #include <stdio.h> |
| 36 | #include <string.h> |
| 37 | |
| 38 | #include <libunwind.h> |
| 39 | |
| 40 | int errors; |
| 41 | |
| 42 | #define panic(args...) \ |
| 43 | { ++errors; fprintf (stderr, args); return -1; } |
| 44 | |
| 45 | static int |
Tommi Rantala | f42a8de | 2012-08-02 09:42:21 +0300 | [diff] [blame] | 46 | find_proc_info (unw_addr_space_t as __attribute__((unused)), |
| 47 | unw_word_t ip __attribute__((unused)), |
| 48 | unw_proc_info_t *pip __attribute__((unused)), |
| 49 | int need_unwind_info __attribute__((unused)), |
| 50 | void *arg __attribute__((unused))) |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 51 | { |
| 52 | return -UNW_ESTOPUNWIND; |
| 53 | } |
| 54 | |
| 55 | static int |
Tommi Rantala | f42a8de | 2012-08-02 09:42:21 +0300 | [diff] [blame] | 56 | access_mem (unw_addr_space_t as __attribute__((unused)), |
| 57 | unw_word_t addr __attribute__((unused)), |
| 58 | unw_word_t *valp, int write, |
| 59 | void *arg __attribute__((unused))) |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 60 | { |
| 61 | if (!write) |
| 62 | *valp = 0; |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static int |
Tommi Rantala | f42a8de | 2012-08-02 09:42:21 +0300 | [diff] [blame] | 67 | access_reg (unw_addr_space_t as __attribute__((unused)), |
| 68 | unw_regnum_t regnum __attribute__((unused)), |
| 69 | unw_word_t *valp, int write, |
| 70 | void *arg __attribute__((unused))) |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 71 | { |
| 72 | if (!write) |
| 73 | *valp = 32; |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static int |
Tommi Rantala | f42a8de | 2012-08-02 09:42:21 +0300 | [diff] [blame] | 78 | access_fpreg (unw_addr_space_t as __attribute__((unused)), |
| 79 | unw_regnum_t regnum __attribute__((unused)), |
| 80 | unw_fpreg_t *valp, int write, |
| 81 | void *arg __attribute__((unused))) |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 82 | { |
| 83 | if (!write) |
Arun | f89fb17 | 2011-10-02 22:43:28 -0700 | [diff] [blame] | 84 | memset (valp, 0, sizeof (*valp)); |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static int |
Tommi Rantala | f42a8de | 2012-08-02 09:42:21 +0300 | [diff] [blame] | 89 | get_dyn_info_list_addr (unw_addr_space_t as __attribute__((unused)), |
| 90 | unw_word_t *dilap __attribute__((unused)), |
| 91 | void *arg __attribute__((unused))) |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 92 | { |
| 93 | return -UNW_ENOINFO; |
| 94 | } |
| 95 | |
hp.com!davidm | 3ff119a | 2004-04-23 00:12:51 +0000 | [diff] [blame] | 96 | static void |
Tommi Rantala | f42a8de | 2012-08-02 09:42:21 +0300 | [diff] [blame] | 97 | put_unwind_info (unw_addr_space_t as __attribute__((unused)), |
| 98 | unw_proc_info_t *pi __attribute__((unused)), |
| 99 | void *arg __attribute__((unused))) |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 100 | { |
hp.com!davidm | 3ff119a | 2004-04-23 00:12:51 +0000 | [diff] [blame] | 101 | ++errors; |
| 102 | fprintf (stderr, "%s() got called!\n", __FUNCTION__); |
| 103 | } |
| 104 | |
| 105 | static int |
Tommi Rantala | f42a8de | 2012-08-02 09:42:21 +0300 | [diff] [blame] | 106 | resume (unw_addr_space_t as __attribute__((unused)), |
| 107 | unw_cursor_t *reg __attribute__((unused)), |
| 108 | void *arg __attribute__((unused))) |
hp.com!davidm | 3ff119a | 2004-04-23 00:12:51 +0000 | [diff] [blame] | 109 | { |
| 110 | panic ("%s() got called!\n", __FUNCTION__); |
| 111 | } |
| 112 | |
| 113 | static int |
Tommi Rantala | f42a8de | 2012-08-02 09:42:21 +0300 | [diff] [blame] | 114 | get_proc_name (unw_addr_space_t as __attribute__((unused)), |
| 115 | unw_word_t ip __attribute__((unused)), |
| 116 | char *buf __attribute__((unused)), |
| 117 | size_t buf_len __attribute__((unused)), |
| 118 | unw_word_t *offp __attribute__((unused)), |
| 119 | void *arg __attribute__((unused))) |
hp.com!davidm | 3ff119a | 2004-04-23 00:12:51 +0000 | [diff] [blame] | 120 | { |
| 121 | panic ("%s() got called!\n", __FUNCTION__); |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | int |
| 125 | main (int argc, char **argv) |
| 126 | { |
| 127 | unw_accessors_t acc; |
| 128 | unw_addr_space_t as; |
| 129 | int ret, verbose = 0; |
| 130 | unw_cursor_t c; |
| 131 | |
mostang.com!davidm | 6ef1640 | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 132 | if (argc > 1 && strcmp (argv[1], "-v") == 0) |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 133 | verbose = 1; |
| 134 | |
| 135 | memset (&acc, 0, sizeof (acc)); |
| 136 | acc.find_proc_info = find_proc_info; |
hp.com!davidm | 3ff119a | 2004-04-23 00:12:51 +0000 | [diff] [blame] | 137 | acc.put_unwind_info = put_unwind_info; |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 138 | acc.get_dyn_info_list_addr = get_dyn_info_list_addr; |
| 139 | acc.access_mem = access_mem; |
| 140 | acc.access_reg = access_reg; |
| 141 | acc.access_fpreg = access_fpreg; |
hp.com!davidm | 3ff119a | 2004-04-23 00:12:51 +0000 | [diff] [blame] | 142 | acc.resume = resume; |
| 143 | acc.get_proc_name = get_proc_name; |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 144 | |
| 145 | as = unw_create_addr_space (&acc, 0); |
| 146 | if (!as) |
| 147 | panic ("unw_create_addr_space() failed\n"); |
| 148 | |
| 149 | unw_set_caching_policy (as, UNW_CACHE_GLOBAL); |
| 150 | |
| 151 | ret = unw_init_remote (&c, as, NULL); |
| 152 | if (ret < 0) |
| 153 | panic ("unw_init_remote() returned %d instead of 0\n", ret); |
| 154 | |
| 155 | ret = unw_step (&c); |
| 156 | if (ret != -UNW_ESTOPUNWIND) |
| 157 | panic ("First call to unw_step() returned %d instead of %d\n", |
| 158 | ret, -UNW_ESTOPUNWIND); |
| 159 | |
| 160 | ret = unw_step (&c); |
| 161 | if (ret != -UNW_ESTOPUNWIND) |
| 162 | panic ("Second call to unw_step() returned %d instead of %d\n", |
| 163 | ret, -UNW_ESTOPUNWIND); |
| 164 | |
Tommi Rantala | 0d7738e | 2012-09-17 13:27:30 +0300 | [diff] [blame^] | 165 | unw_destroy_addr_space (as); |
| 166 | |
mostang.com!davidm | 9339de4 | 2003-09-18 06:09:22 +0000 | [diff] [blame] | 167 | if (verbose) |
| 168 | printf ("SUCCESS\n"); |
| 169 | return 0; |
| 170 | } |