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 |
| 46 | find_proc_info (unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pip, |
| 47 | int need_unwind_info, void *arg) |
| 48 | { |
| 49 | return -UNW_ESTOPUNWIND; |
| 50 | } |
| 51 | |
| 52 | static int |
| 53 | access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *valp, |
| 54 | int write, void *arg) |
| 55 | { |
| 56 | if (!write) |
| 57 | *valp = 0; |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static int |
| 62 | access_reg (unw_addr_space_t as, unw_regnum_t regnum, unw_word_t *valp, |
| 63 | int write, void *arg) |
| 64 | { |
| 65 | if (!write) |
| 66 | *valp = 32; |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static int |
| 71 | access_fpreg (unw_addr_space_t as, unw_regnum_t regnum, unw_fpreg_t *valp, |
| 72 | int write, void *arg) |
| 73 | { |
| 74 | if (!write) |
| 75 | memset (valp, 0, sizeof (valp)); |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | static int |
| 80 | get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dilap, void *arg) |
| 81 | { |
| 82 | return -UNW_ENOINFO; |
| 83 | } |
| 84 | |
| 85 | static int |
| 86 | nop (void) |
| 87 | { |
| 88 | panic ("nop() got called!\n"); |
| 89 | return -1; |
| 90 | } |
| 91 | |
| 92 | int |
| 93 | main (int argc, char **argv) |
| 94 | { |
| 95 | unw_accessors_t acc; |
| 96 | unw_addr_space_t as; |
| 97 | int ret, verbose = 0; |
| 98 | unw_cursor_t c; |
| 99 | |
| 100 | if (argc > 1 && strcmp (argv[0], "-v") == 0) |
| 101 | verbose = 1; |
| 102 | |
| 103 | memset (&acc, 0, sizeof (acc)); |
| 104 | acc.find_proc_info = find_proc_info; |
| 105 | acc.put_unwind_info = (void *) nop; |
| 106 | acc.get_dyn_info_list_addr = get_dyn_info_list_addr; |
| 107 | acc.access_mem = access_mem; |
| 108 | acc.access_reg = access_reg; |
| 109 | acc.access_fpreg = access_fpreg; |
| 110 | acc.resume = (void *) nop; |
| 111 | acc.get_proc_name = (void *) nop; |
| 112 | |
| 113 | as = unw_create_addr_space (&acc, 0); |
| 114 | if (!as) |
| 115 | panic ("unw_create_addr_space() failed\n"); |
| 116 | |
| 117 | unw_set_caching_policy (as, UNW_CACHE_GLOBAL); |
| 118 | |
| 119 | ret = unw_init_remote (&c, as, NULL); |
| 120 | if (ret < 0) |
| 121 | panic ("unw_init_remote() returned %d instead of 0\n", ret); |
| 122 | |
| 123 | ret = unw_step (&c); |
| 124 | if (ret != -UNW_ESTOPUNWIND) |
| 125 | panic ("First call to unw_step() returned %d instead of %d\n", |
| 126 | ret, -UNW_ESTOPUNWIND); |
| 127 | |
| 128 | ret = unw_step (&c); |
| 129 | if (ret != -UNW_ESTOPUNWIND) |
| 130 | panic ("Second call to unw_step() returned %d instead of %d\n", |
| 131 | ret, -UNW_ESTOPUNWIND); |
| 132 | |
| 133 | if (verbose) |
| 134 | printf ("SUCCESS\n"); |
| 135 | return 0; |
| 136 | } |