hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
mostang.com!davidm | 7343841 | 2003-02-27 09:58:57 +0000 | [diff] [blame] | 2 | Copyright (C) 2001-2003 Hewlett-Packard Co |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
| 4 | |
| 5 | This file is part of libunwind. |
| 6 | |
mostang.com!davidm | aca3843 | 2002-11-16 03:25:36 +0000 | [diff] [blame] | 7 | Permission is hereby granted, free of charge, to any person obtaining |
| 8 | a copy of this software and associated documentation files (the |
| 9 | "Software"), to deal in the Software without restriction, including |
| 10 | without limitation the rights to use, copy, modify, merge, publish, |
| 11 | distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | permit persons to whom the Software is furnished to do so, subject to |
| 13 | the following conditions: |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 14 | |
mostang.com!davidm | aca3843 | 2002-11-16 03:25:36 +0000 | [diff] [blame] | 15 | The above copyright notice and this permission notice shall be |
| 16 | included in all copies or substantial portions of the Software. |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 17 | |
mostang.com!davidm | aca3843 | 2002-11-16 03:25:36 +0000 | [diff] [blame] | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 22 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 25 | |
| 26 | #define UNW_PASTE2(x,y) x##y |
| 27 | #define UNW_PASTE(x,y) UNW_PASTE2(x,y) |
| 28 | #define UNW_OBJ(fn) UNW_PASTE(UNW_PREFIX, fn) |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 29 | #define UNW_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_), fn) |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 30 | |
| 31 | #ifdef UNW_LOCAL_ONLY |
| 32 | # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_UL,UNW_TARGET),_) |
| 33 | #else /* !UNW_LOCAL_ONLY */ |
| 34 | # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_) |
| 35 | #endif /* !UNW_LOCAL_ONLY */ |
| 36 | |
| 37 | typedef unw_tdep_word_t unw_word_t; |
| 38 | |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 39 | /* Error codes. The unwind routines return the *negated* values of |
| 40 | these error codes on error and a non-negative value on success. */ |
| 41 | typedef enum |
| 42 | { |
| 43 | UNW_ESUCCESS = 0, /* no error */ |
| 44 | UNW_EUNSPEC, /* unspecified (general) error */ |
| 45 | UNW_ENOMEM, /* out of memory */ |
| 46 | UNW_EBADREG, /* bad register number */ |
| 47 | UNW_EREADONLYREG, /* attempt to write read-only register */ |
| 48 | UNW_ESTOPUNWIND, /* stop unwinding */ |
| 49 | UNW_EINVALIDIP, /* invalid IP */ |
| 50 | UNW_EBADFRAME, /* bad frame */ |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 51 | UNW_EINVAL, /* unsupported operation or bad value */ |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 52 | UNW_EBADVERSION, /* unwind info has unsupported version */ |
| 53 | UNW_ENOINFO /* no unwind info found */ |
| 54 | } |
| 55 | unw_error_t; |
| 56 | |
| 57 | /* The following enum defines the indices for a couple of |
| 58 | (pseudo-)registers which have the same meaning across all |
| 59 | platforms. (RO) means read-only. (RW) means read-write. General |
| 60 | registers (aka "integer registers") are expected to start with |
| 61 | index 0. The number of such registers is architecture-dependent. |
| 62 | The remaining indices can be used as an architecture sees fit. The |
| 63 | last valid register index is given by UNW_REG_LAST. */ |
| 64 | typedef enum |
| 65 | { |
| 66 | UNW_REG_IP = UNW_TDEP_IP, /* (rw) instruction pointer (pc) */ |
| 67 | UNW_REG_SP = UNW_TDEP_SP, /* (ro) stack pointer */ |
mostang.com!davidm | c670abb | 2003-03-06 06:14:36 +0000 | [diff] [blame^] | 68 | UNW_REG_EH = UNW_TDEP_EH, /* (rw) exception-handling reg base */ |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 69 | UNW_REG_LAST = UNW_TDEP_LAST_REG |
| 70 | } |
| 71 | unw_frame_regnum_t; |
| 72 | |
mostang.com!davidm | c670abb | 2003-03-06 06:14:36 +0000 | [diff] [blame^] | 73 | /* Number of exception-handler argument registers: */ |
| 74 | #define UNW_NUM_EH_REGS UNW_TDEP_NUM_EH_REGS |
| 75 | |
mostang.com!davidm | 16f2189 | 2002-11-09 07:59:02 +0000 | [diff] [blame] | 76 | typedef enum |
| 77 | { |
| 78 | UNW_CACHE_NONE, /* no caching */ |
| 79 | UNW_CACHE_GLOBAL, /* shared global cache */ |
| 80 | UNW_CACHE_PER_THREAD /* per-thread caching */ |
| 81 | } |
| 82 | unw_caching_policy_t; |
| 83 | |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 84 | typedef int unw_regnum_t; |
| 85 | |
| 86 | /* The unwind cursor starts at the youngest (most deeply nested) frame |
| 87 | and is used to track the frame state as the unwinder steps from |
| 88 | frame to frame. It is safe to make (shallow) copies of variables |
| 89 | of this type. */ |
| 90 | typedef struct unw_cursor |
| 91 | { |
mostang.com!davidm | a4bea2c | 2003-01-21 08:08:32 +0000 | [diff] [blame] | 92 | unw_word_t opaque[UNW_TDEP_CURSOR_LEN]; |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 93 | } |
| 94 | unw_cursor_t; |
| 95 | |
| 96 | /* This type encapsulates the entire (preserved) machine-state. */ |
| 97 | typedef unw_tdep_context_t unw_context_t; |
| 98 | |
| 99 | /* unw_getcontext() fills the unw_context_t pointed to by UC with the |
| 100 | machine state as it exists at the call-site. For implementation |
| 101 | reasons, this needs to be a target-dependent macro. It's easiest |
| 102 | to think of unw_getcontext() as being identical to getcontext(). */ |
| 103 | #define unw_getcontext(uc) unw_tdep_getcontext(uc) |
| 104 | |
mostang.com!davidm | 981c8cc | 2003-02-08 10:10:59 +0000 | [diff] [blame] | 105 | typedef unw_tdep_fpreg_t unw_fpreg_t; |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 106 | |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 107 | typedef struct unw_addr_space *unw_addr_space_t; |
| 108 | |
mostang.com!davidm | a4bea2c | 2003-01-21 08:08:32 +0000 | [diff] [blame] | 109 | /* This bit is set to indicate */ |
| 110 | #define UNW_PI_FLAG_FIRST_TDEP_BIT 16 |
| 111 | |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 112 | typedef struct unw_proc_info |
| 113 | { |
| 114 | unw_word_t start_ip; /* first IP covered by this procedure */ |
| 115 | unw_word_t end_ip; /* first IP NOT covered by this procedure */ |
| 116 | unw_word_t lsda; /* address of lang.-spec. data area (if any) */ |
| 117 | unw_word_t handler; /* optional personality routine */ |
| 118 | unw_word_t gp; /* global-pointer value for this procedure */ |
| 119 | unw_word_t flags; /* misc. flags */ |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 120 | |
| 121 | int format; /* unwind-info format (arch-specific) */ |
mostang.com!davidm | b6251b0 | 2002-12-12 09:17:41 +0000 | [diff] [blame] | 122 | int unwind_info_size; /* size of the informat (if applicable) */ |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 123 | void *unwind_info; /* unwind-info (arch-specific) */ |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 124 | } |
| 125 | unw_proc_info_t; |
| 126 | |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 127 | /* These are backend callback routines that provide access to the |
| 128 | state of a "remote" process. This can be used, for example, to |
| 129 | unwind another process through the ptrace() interface. */ |
| 130 | typedef struct unw_accessors |
| 131 | { |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 132 | /* Look up the unwind info associated with instruction-pointer IP. |
| 133 | On success, the routine fills in the PROC_INFO structure. */ |
| 134 | int (*find_proc_info) (unw_addr_space_t as, unw_word_t ip, |
mostang.com!davidm | b6251b0 | 2002-12-12 09:17:41 +0000 | [diff] [blame] | 135 | unw_proc_info_t *proc_info, |
| 136 | int need_unwind_info, |
| 137 | void *arg); |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 138 | |
mostang.com!davidm | b6251b0 | 2002-12-12 09:17:41 +0000 | [diff] [blame] | 139 | /* Release any resources (e.g., memory) that were allocated for |
| 140 | the unwind info returned in by a previous call to |
| 141 | find_proc_info() with NEED_UNWIND_INFO set to 1. */ |
| 142 | void (*put_unwind_info) (unw_addr_space_t as, unw_proc_info_t *proc_info, |
| 143 | void *arg); |
| 144 | |
| 145 | /* Return the list-head of the dynamically registered unwind |
| 146 | info. */ |
| 147 | int (*get_dyn_info_list_addr) (unw_addr_space_t as, |
| 148 | unw_word_t *dyn_info_list_addr, |
| 149 | void *arg); |
| 150 | |
| 151 | /* Access aligned word at address ADDR. The value is returned |
| 152 | according to the endianness of the host (e.g., if the host is |
| 153 | little-endian and the target is big-endian, access_mem() needs |
| 154 | to byte-swap the value before returning it). */ |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 155 | int (*access_mem) (unw_addr_space_t as, unw_word_t addr, |
| 156 | unw_word_t *val, int write, void *arg); |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 157 | |
| 158 | /* Access register number REG at address ADDR. */ |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 159 | int (*access_reg) (unw_addr_space_t as, unw_regnum_t reg, |
| 160 | unw_word_t *val, int write, void *arg); |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 161 | |
| 162 | /* Access register number REG at address ADDR. */ |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 163 | int (*access_fpreg) (unw_addr_space_t as, unw_regnum_t reg, |
| 164 | unw_fpreg_t *val, int write, void *arg); |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 165 | |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 166 | int (*resume) (unw_addr_space_t as, unw_cursor_t *c, void *arg); |
mostang.com!davidm | 7343841 | 2003-02-27 09:58:57 +0000 | [diff] [blame] | 167 | |
| 168 | /* Optional call back to obtain the name of a (static) procedure. |
| 169 | Dynamically generated procedures are handled automatically by |
| 170 | libunwind. This callback is optional and may be set to |
| 171 | NULL. */ |
| 172 | int (*get_proc_name) (unw_addr_space_t as, unw_word_t addr, |
| 173 | char *buf, size_t buf_len, unw_word_t *offp, |
| 174 | void *arg); |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 175 | } |
| 176 | unw_accessors_t; |
| 177 | |
| 178 | typedef enum unw_save_loc_type |
| 179 | { |
| 180 | UNW_SLT_NONE, /* register is not saved ("not an l-value") */ |
| 181 | UNW_SLT_MEMORY, /* register has been saved in memory */ |
| 182 | UNW_SLT_REG /* register has been saved in (another) register */ |
| 183 | } |
| 184 | unw_save_loc_type_t; |
| 185 | |
| 186 | typedef struct unw_save_loc |
| 187 | { |
| 188 | unw_save_loc_type_t type; |
| 189 | union |
| 190 | { |
| 191 | unw_word_t addr; /* valid if type==UNW_SLT_MEMORY */ |
| 192 | unw_regnum_t regnum; /* valid if type==UNW_SLT_REG */ |
| 193 | } |
| 194 | u; |
| 195 | unw_tdep_save_loc_t extra; /* target-dependent additional information */ |
| 196 | } |
| 197 | unw_save_loc_t; |
| 198 | |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 199 | #include <libunwind-dynamic.h> |
| 200 | |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 201 | /* These routines work both for local and remote unwinding. */ |
| 202 | |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 203 | extern unw_addr_space_t UNW_OBJ(local_addr_space); |
| 204 | |
mostang.com!davidm | b6251b0 | 2002-12-12 09:17:41 +0000 | [diff] [blame] | 205 | extern unw_addr_space_t UNW_OBJ(create_addr_space) (unw_accessors_t *a, |
| 206 | int byte_order); |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 207 | extern void UNW_OBJ(destroy_addr_space) (unw_addr_space_t as); |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 208 | extern unw_accessors_t *UNW_ARCH_OBJ(get_accessors) (unw_addr_space_t as); |
| 209 | extern void UNW_ARCH_OBJ(flush_cache)(unw_addr_space_t as, |
| 210 | unw_word_t lo, unw_word_t hi); |
| 211 | extern int UNW_ARCH_OBJ(set_caching_policy)(unw_addr_space_t as, |
| 212 | unw_caching_policy_t policy); |
| 213 | extern const char *UNW_ARCH_OBJ(regname) (int regnum); |
| 214 | |
mostang.com!davidm | a38baad | 2003-01-17 07:48:52 +0000 | [diff] [blame] | 215 | extern int UNW_OBJ(init_local) (unw_cursor_t *c, unw_context_t *u); |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 216 | extern int UNW_OBJ(init_remote) (unw_cursor_t *c, unw_addr_space_t as, |
| 217 | void *as_arg); |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 218 | extern int UNW_OBJ(step) (unw_cursor_t *c); |
| 219 | extern int UNW_OBJ(resume) (unw_cursor_t *c); |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 220 | extern int UNW_OBJ(get_proc_info) (unw_cursor_t *c, unw_proc_info_t *pi); |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 221 | extern int UNW_OBJ(get_reg) (unw_cursor_t *c, int regnum, unw_word_t *valp); |
| 222 | extern int UNW_OBJ(set_reg) (unw_cursor_t *c, int regnum, unw_word_t val); |
| 223 | extern int UNW_OBJ(get_fpreg) (unw_cursor_t *c, int regnum, unw_fpreg_t *val); |
| 224 | extern int UNW_OBJ(set_fpreg) (unw_cursor_t *c, int regnum, unw_fpreg_t val); |
| 225 | extern int UNW_OBJ(get_save_loc) (unw_cursor_t *c, int regnum, |
| 226 | unw_save_loc_t *loc); |
| 227 | extern int UNW_OBJ(is_signal_frame) (unw_cursor_t *c); |
mostang.com!davidm | 981c8cc | 2003-02-08 10:10:59 +0000 | [diff] [blame] | 228 | extern int UNW_OBJ(get_proc_name) (unw_cursor_t *c, char *buf, size_t buf_len, |
| 229 | unw_word_t *offsetp); |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 230 | |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 231 | #define unw_local_addr_space UNW_OBJ(local_addr_space) |
| 232 | |
| 233 | /* Create a new address space (in addition to the default |
mostang.com!davidm | b6251b0 | 2002-12-12 09:17:41 +0000 | [diff] [blame] | 234 | local_addr_space). BYTE_ORDER can be 0 to select the default |
| 235 | byte-order or one of the byte-order values defined by <endian.h> |
mostang.com!davidm | a4bea2c | 2003-01-21 08:08:32 +0000 | [diff] [blame] | 236 | (e.g., __LITTLE_ENDIAN or __BIG_ENDIAN). The default byte-order is |
mostang.com!davidm | b6251b0 | 2002-12-12 09:17:41 +0000 | [diff] [blame] | 237 | either implied by the target architecture (e.g., x86 is always |
| 238 | little-endian) or is select based on the byte-order of the host. |
| 239 | |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 240 | This routine is NOT signal-safe. */ |
mostang.com!davidm | b6251b0 | 2002-12-12 09:17:41 +0000 | [diff] [blame] | 241 | #define unw_create_addr_space(a,b) UNW_OBJ(create_addr_space)(a,b) |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 242 | |
| 243 | /* Destroy an address space. |
| 244 | This routine is NOT signal-safe. */ |
| 245 | #define unw_destroy_addr_space(as) UNW_OBJ(destroy_addr_space)(as) |
| 246 | |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 247 | /* Retrieve a pointer to the accessors structure associated with |
| 248 | address space AS. |
| 249 | This routine is signal-safe. */ |
| 250 | #define unw_get_accessors(as) UNW_ARCH_OBJ(get_accessors)(as) |
| 251 | |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 252 | /* Initialize cursor C such that unwinding starts at the point |
| 253 | represented by the context U. Returns zero on success, negative |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 254 | value on failure. |
| 255 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 256 | #define unw_init_local(c,u) UNW_OBJ(init_local)(c, u) |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 257 | |
| 258 | /* Initialize cursor C such that it accesses the unwind target through |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 259 | accessors A. |
| 260 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 261 | #define unw_init_remote(c,a,arg) UNW_OBJ(init_remote)(c, a, arg) |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 262 | |
| 263 | /* Move cursor up by one step (up meaning toward earlier, less deeply |
| 264 | nested frames). Returns positive number if there are more frames |
| 265 | to unwind, 0 if last frame has been reached, negative number in |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 266 | case of an error. |
| 267 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 268 | #define unw_step(c) UNW_OBJ(step)(c) |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 269 | |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 270 | /* Resume execution at the point identified by the cursor. |
| 271 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 272 | #define unw_resume(c) UNW_OBJ(resume)(c) |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 273 | |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 274 | /* Return the proc-info associated with the cursor. |
| 275 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 276 | #define unw_get_proc_info(c,p) UNW_OBJ(get_proc_info)(c,p) |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 277 | |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 278 | /* Register accessor routines. Return zero on success, negative value |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 279 | on failure. |
| 280 | These routines are signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 281 | #define unw_get_reg(c,r,v) UNW_OBJ(get_reg)(c,r,v) |
| 282 | #define unw_set_reg(c,r,v) UNW_OBJ(set_reg)(c,r,v) |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 283 | |
| 284 | /* Floating-point accessor routines. Return zero on success, negative |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 285 | value on failure. |
| 286 | These routines are signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 287 | #define unw_get_fpreg(c,r,v) UNW_OBJ(get_fpreg)(c,r,v) |
| 288 | #define unw_set_fpreg(c,r,v) UNW_OBJ(set_fpreg)(c,r,v) |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 289 | |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 290 | /* Get the save-location of register R. |
| 291 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 292 | #define unw_get_save_loc(c,r,l) UNW_OBJ(get_save_loc)(c,r,l) |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 293 | |
| 294 | /* Return 1 if register number R is a floating-point register, zero |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 295 | otherwise. |
| 296 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 297 | #define unw_is_fpreg(r) unw_tdep_is_fpreg(r) |
hp.com!davidm | 76166fb | 2002-04-05 23:37:55 +0000 | [diff] [blame] | 298 | |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 299 | /* Returns non-zero value if the cursor points to a signal frame. |
| 300 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 301 | #define unw_is_signal_frame(c) UNW_OBJ(is_signal_frame)(c) |
mostang.com!davidm | 58142c0 | 2002-04-12 05:02:40 +0000 | [diff] [blame] | 302 | |
mostang.com!davidm | b6251b0 | 2002-12-12 09:17:41 +0000 | [diff] [blame] | 303 | /* Return the name of the procedure that created the frame identified |
| 304 | by the cursor. The returned string is ASCII NUL terminated. If the |
| 305 | string buffer is too small to store the entire name, the first |
| 306 | portion of the string that can fit is stored in the buffer (along |
| 307 | with a terminating NUL character) and -UNW_ENOMEM is returned. If |
mostang.com!davidm | 981c8cc | 2003-02-08 10:10:59 +0000 | [diff] [blame] | 308 | no name can be determined, -UNW_ENOINFO is returned. |
| 309 | This routine is NOT signal-safe. */ |
| 310 | #define unw_get_proc_name(c,s,l,o) UNW_OBJ(get_proc_name)(c, s, l, o) |
mostang.com!davidm | b6251b0 | 2002-12-12 09:17:41 +0000 | [diff] [blame] | 311 | |
mostang.com!davidm | 58142c0 | 2002-04-12 05:02:40 +0000 | [diff] [blame] | 312 | /* Returns the canonical register name of register R. R must be in |
| 313 | the range from 0 to UNW_REG_LAST. Like all other unwind routines, |
| 314 | this one is re-entrant (i.e., the returned string must be a string |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 315 | constant. |
| 316 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 317 | #define unw_regname(r) UNW_ARCH_OBJ(regname)(r) |
mostang.com!davidm | 16f2189 | 2002-11-09 07:59:02 +0000 | [diff] [blame] | 318 | |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 319 | /* Sets the caching policy of address space AS. Caching can be |
| 320 | disabled completely by setting the policy to UNW_CACHE_NONE. With |
| 321 | UNW_CACHE_GLOBAL, there is a single cache that is shared across all |
| 322 | threads. With UNW_CACHE_PER_THREAD, each thread gets its own |
| 323 | cache, which can improve performance thanks to less locking and |
| 324 | better locality. By default, UNW_CACHE_GLOBAL is in effect. |
| 325 | This routine is NOT signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 326 | #define unw_set_caching_policy(as, p) UNW_ARCH_OBJ(set_caching_policy)(as, p) |
mostang.com!davidm | 16f2189 | 2002-11-09 07:59:02 +0000 | [diff] [blame] | 327 | |
| 328 | /* Flush all caches (global, per-thread, or any other caches that |
mostang.com!davidm | 87bc2e3 | 2002-11-16 06:50:04 +0000 | [diff] [blame] | 329 | might exist) in address-space AS of information at least relating |
| 330 | to the address-range LO to HI (non-inclusive). LO and HI are only |
| 331 | a performance hint and the function is allowed to over-flush (i.e., |
| 332 | flush more than the requested address-range). Furthermore, if LO |
| 333 | and HI are both 0, the entire address-range is flushed. This |
| 334 | function must be called if any of unwind information might have |
| 335 | changed (e.g., because a library might have been removed via a call |
mostang.com!davidm | 50d7a15 | 2002-12-03 08:19:58 +0000 | [diff] [blame] | 336 | to dlclose()). |
| 337 | This routine is signal-safe. */ |
mostang.com!davidm | 20a6c1a | 2002-12-19 07:16:50 +0000 | [diff] [blame] | 338 | #define unw_flush_cache(as,lo,hi) UNW_ARCH_OBJ(flush_cache)(as, lo, hi) |
hp.com!davidm | 68bdac3 | 2003-01-28 03:40:06 +0000 | [diff] [blame] | 339 | |
| 340 | /* Helper routines which make it easy to use libunwind via ptrace(). |
| 341 | They're available only if UNW_REMOTE is _not_ defined and they |
| 342 | aren't really part of the libunwind API. They are simple enough |
| 343 | not to warrant creating a separate library for them. */ |
| 344 | |
| 345 | extern void *_UPT_create (pid_t); |
| 346 | extern void _UPT_destroy (void *upt); |
| 347 | extern int _UPT_find_proc_info (unw_addr_space_t as, unw_word_t ip, |
| 348 | unw_proc_info_t *pi, int need_unwind_info, |
| 349 | void *arg); |
| 350 | extern void _UPT_put_unwind_info (unw_addr_space_t as, unw_proc_info_t *pi, |
| 351 | void *arg); |
| 352 | extern int _UPT_get_dyn_info_list_addr (unw_addr_space_t as, |
| 353 | unw_word_t *dil_addr, void *arg); |
| 354 | extern int _UPT_access_mem (unw_addr_space_t as, unw_word_t addr, |
| 355 | unw_word_t *val, int write, void *arg); |
| 356 | extern int _UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, |
| 357 | unw_word_t *val, int write, void *arg); |
| 358 | extern int _UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, |
| 359 | unw_fpreg_t *val, int write, void *arg); |
mostang.com!davidm | 7343841 | 2003-02-27 09:58:57 +0000 | [diff] [blame] | 360 | extern int _UPT_get_proc_name (unw_addr_space_t as, unw_word_t addr, |
| 361 | char *buf, size_t len, unw_word_t *offp, |
| 362 | void *arg); |
mostang.com!davidm | c670abb | 2003-03-06 06:14:36 +0000 | [diff] [blame^] | 363 | extern int _UPT_resume (unw_addr_space_t as, unw_cursor_t *c, void *arg); |
hp.com!davidm | 68bdac3 | 2003-01-28 03:40:06 +0000 | [diff] [blame] | 364 | extern unw_accessors_t _UPT_accessors; |