1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/* libunwind - a platform-independent unwind library
Copyright (C) 2003 Hewlett-Packard Co
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of libunwind.
Copyright (c) 2003 Hewlett-Packard Co.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/* This test program checks whether proc_info lookup failures are
cached. They must NOT be cached because it could otherwise turn
temporary failures into permanent ones. Furthermore, we allow apps
to return -UNW_ESTOPUNWIND to terminate unwinding (though this
feature is deprecated and dynamic unwind info should be used
instead). */
#include <stdio.h>
#include <string.h>
#include <libunwind.h>
#include "compiler.h"
int errors;
#define panic(args...) \
{ ++errors; fprintf (stderr, args); return -1; }
static int
find_proc_info (unw_addr_space_t as UNUSED,
unw_word_t ip UNUSED,
unw_proc_info_t *pip UNUSED,
int need_unwind_info UNUSED,
void *arg UNUSED)
{
return -UNW_ESTOPUNWIND;
}
static int
access_mem (unw_addr_space_t as UNUSED,
unw_word_t addr UNUSED,
unw_word_t *valp, int write,
void *arg UNUSED)
{
if (!write)
*valp = 0;
return 0;
}
static int
access_reg (unw_addr_space_t as UNUSED,
unw_regnum_t regnum UNUSED,
unw_word_t *valp, int write,
void *arg UNUSED)
{
if (!write)
*valp = 32;
return 0;
}
static int
access_fpreg (unw_addr_space_t as UNUSED,
unw_regnum_t regnum UNUSED,
unw_fpreg_t *valp, int write,
void *arg UNUSED)
{
if (!write)
memset (valp, 0, sizeof (*valp));
return 0;
}
static int
get_dyn_info_list_addr (unw_addr_space_t as UNUSED,
unw_word_t *dilap UNUSED,
void *arg UNUSED)
{
return -UNW_ENOINFO;
}
static void
put_unwind_info (unw_addr_space_t as UNUSED,
unw_proc_info_t *pi UNUSED,
void *arg UNUSED)
{
++errors;
fprintf (stderr, "%s() got called!\n", __FUNCTION__);
}
static int
resume (unw_addr_space_t as UNUSED,
unw_cursor_t *reg UNUSED,
void *arg UNUSED)
{
panic ("%s() got called!\n", __FUNCTION__);
}
static int
get_proc_name (unw_addr_space_t as UNUSED,
unw_word_t ip UNUSED,
char *buf UNUSED,
size_t buf_len UNUSED,
unw_word_t *offp UNUSED,
void *arg UNUSED)
{
panic ("%s() got called!\n", __FUNCTION__);
}
int
main (int argc, char **argv)
{
unw_accessors_t acc;
unw_addr_space_t as;
int ret, verbose = 0;
unw_cursor_t c;
if (argc > 1 && strcmp (argv[1], "-v") == 0)
verbose = 1;
memset (&acc, 0, sizeof (acc));
acc.find_proc_info = find_proc_info;
acc.put_unwind_info = put_unwind_info;
acc.get_dyn_info_list_addr = get_dyn_info_list_addr;
acc.access_mem = access_mem;
acc.access_reg = access_reg;
acc.access_fpreg = access_fpreg;
acc.resume = resume;
acc.get_proc_name = get_proc_name;
as = unw_create_addr_space (&acc, 0);
if (!as)
panic ("unw_create_addr_space() failed\n");
unw_set_caching_policy (as, UNW_CACHE_GLOBAL);
ret = unw_init_remote (&c, as, NULL);
if (ret < 0)
panic ("unw_init_remote() returned %d instead of 0\n", ret);
ret = unw_step (&c);
if (ret != -UNW_ESTOPUNWIND)
panic ("First call to unw_step() returned %d instead of %d\n",
ret, -UNW_ESTOPUNWIND);
ret = unw_step (&c);
if (ret != -UNW_ESTOPUNWIND)
panic ("Second call to unw_step() returned %d instead of %d\n",
ret, -UNW_ESTOPUNWIND);
unw_destroy_addr_space (as);
if (verbose)
printf ("SUCCESS\n");
return 0;
}
|