libunwind_i.h revision 6a671546741e8355dd9f821f171e4a3c895d28ec
1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2008 CodeSourcery 3 4This file is part of libunwind. 5 6Permission is hereby granted, free of charge, to any person obtaining 7a copy of this software and associated documentation files (the 8"Software"), to deal in the Software without restriction, including 9without limitation the rights to use, copy, modify, merge, publish, 10distribute, sublicense, and/or sell copies of the Software, and to 11permit persons to whom the Software is furnished to do so, subject to 12the following conditions: 13 14The above copyright notice and this permission notice shall be 15included in all copies or substantial portions of the Software. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 24 25#ifndef ARM_LIBUNWIND_I_H 26#define ARM_LIBUNWIND_I_H 27 28/* Target-dependent definitions that are internal to libunwind but need 29 to be shared with target-independent code. */ 30 31#include <stdlib.h> 32#include <libunwind.h> 33 34#include "elf32.h" 35#include "mempool.h" 36#include "dwarf.h" 37#include "ex_tables.h" 38 39struct unw_addr_space 40 { 41 struct unw_accessors acc; 42 int big_endian; 43 unw_caching_policy_t caching_policy; 44#ifdef HAVE_ATOMIC_OPS_H 45 AO_t cache_generation; 46#else 47 uint32_t cache_generation; 48#endif 49 unw_word_t dyn_generation; /* see dyn-common.h */ 50 unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */ 51 struct dwarf_rs_cache global_cache; 52 struct unw_debug_frame_list *debug_frames; 53 }; 54 55struct cursor 56 { 57 struct dwarf_cursor dwarf; /* must be first */ 58 struct arm_stackframe frame; 59 unw_word_t sigcontext_addr; 60 }; 61 62#define DWARF_GET_LOC(l) ((l).val) 63 64#ifdef UNW_LOCAL_ONLY 65# define DWARF_NULL_LOC DWARF_LOC (0, 0) 66# define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0) 67# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) }) 68# define DWARF_IS_REG_LOC(l) 0 69# define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 70 tdep_uc_addr((c)->as_arg, (r)), 0)) 71# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 72# define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 73 tdep_uc_addr((c)->as_arg, (r)), 0)) 74 75static inline int 76dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) 77{ 78 if (!DWARF_GET_LOC (loc)) 79 return -1; 80 *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc); 81 return 0; 82} 83 84static inline int 85dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 86{ 87 if (!DWARF_GET_LOC (loc)) 88 return -1; 89 *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val; 90 return 0; 91} 92 93static inline int 94dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) 95{ 96 if (!DWARF_GET_LOC (loc)) 97 return -1; 98 *val = *(unw_word_t *) DWARF_GET_LOC (loc); 99 return 0; 100} 101 102static inline int 103dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) 104{ 105 if (!DWARF_GET_LOC (loc)) 106 return -1; 107 *(unw_word_t *) DWARF_GET_LOC (loc) = val; 108 return 0; 109} 110 111#else /* !UNW_LOCAL_ONLY */ 112# define DWARF_LOC_TYPE_FP (1 << 0) 113# define DWARF_LOC_TYPE_REG (1 << 1) 114# define DWARF_NULL_LOC DWARF_LOC (0, 0) 115# define DWARF_IS_NULL_LOC(l) \ 116 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; }) 117# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) }) 118# define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0) 119# define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0) 120# define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG) 121# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 122# define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \ 123 | DWARF_LOC_TYPE_FP)) 124 125static inline int 126dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) 127{ 128 char *valp = (char *) &val; 129 unw_word_t addr; 130 int ret; 131 132 if (DWARF_IS_NULL_LOC (loc)) 133 return -UNW_EBADREG; 134 135 if (DWARF_IS_REG_LOC (loc)) 136 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 137 val, 0, c->as_arg); 138 139 addr = DWARF_GET_LOC (loc); 140 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp, 141 0, c->as_arg)) < 0) 142 return ret; 143 144 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 0, 145 c->as_arg); 146} 147 148static inline int 149dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 150{ 151 char *valp = (char *) &val; 152 unw_word_t addr; 153 int ret; 154 155 if (DWARF_IS_NULL_LOC (loc)) 156 return -UNW_EBADREG; 157 158 if (DWARF_IS_REG_LOC (loc)) 159 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 160 &val, 1, c->as_arg); 161 162 addr = DWARF_GET_LOC (loc); 163 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp, 164 1, c->as_arg)) < 0) 165 return ret; 166 167 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 168 1, c->as_arg); 169} 170 171static inline int 172dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) 173{ 174 if (DWARF_IS_NULL_LOC (loc)) 175 return -UNW_EBADREG; 176 177 /* If a code-generator were to save a value of type unw_word_t in a 178 floating-point register, we would have to support this case. I 179 suppose it could happen with MMX registers, but does it really 180 happen? */ 181 assert (!DWARF_IS_FP_LOC (loc)); 182 183 if (DWARF_IS_REG_LOC (loc)) 184 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val, 185 0, c->as_arg); 186 else 187 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val, 188 0, c->as_arg); 189} 190 191static inline int 192dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) 193{ 194 if (DWARF_IS_NULL_LOC (loc)) 195 return -UNW_EBADREG; 196 197 /* If a code-generator were to save a value of type unw_word_t in a 198 floating-point register, we would have to support this case. I 199 suppose it could happen with MMX registers, but does it really 200 happen? */ 201 assert (!DWARF_IS_FP_LOC (loc)); 202 203 if (DWARF_IS_REG_LOC (loc)) 204 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val, 205 1, c->as_arg); 206 else 207 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val, 208 1, c->as_arg); 209} 210 211#endif /* !UNW_LOCAL_ONLY */ 212 213#define tdep_needs_initialization UNW_OBJ(needs_initialization) 214#define tdep_init UNW_OBJ(init) 215/* Platforms that support UNW_INFO_FORMAT_TABLE need to define 216 tdep_search_unwind_table. */ 217#define tdep_search_unwind_table dwarf_search_unwind_table 218#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr) 219#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image) 220#define tdep_access_reg UNW_OBJ(access_reg) 221#define tdep_access_fpreg UNW_OBJ(access_fpreg) 222#define tdep_fetch_frame(c,ip,n) do {} while(0) 223#define tdep_cache_frame(c,rs) do {} while(0) 224#define tdep_reuse_frame(c,rs) do {} while(0) 225 226#ifdef UNW_LOCAL_ONLY 227# define tdep_find_proc_info(c,ip,n) \ 228 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \ 229 (c)->as_arg) 230# define tdep_put_unwind_info(as,pi,arg) \ 231 dwarf_put_unwind_info((as), (pi), (arg)) 232#else 233# define tdep_find_proc_info(c,ip,n) \ 234 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \ 235 (c)->as_arg) 236# define tdep_put_unwind_info(as,pi,arg) \ 237 (*(as)->acc.put_unwind_info)((as), (pi), (arg)) 238#endif 239 240#define tdep_get_as(c) ((c)->dwarf.as) 241#define tdep_get_as_arg(c) ((c)->dwarf.as_arg) 242#define tdep_get_ip(c) ((c)->dwarf.ip) 243#define tdep_big_endian(as) ((as)->big_endian) 244 245extern int tdep_needs_initialization; 246 247extern void tdep_init (void); 248extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, 249 unw_dyn_info_t *di, unw_proc_info_t *pi, 250 int need_unwind_info, void *arg); 251extern void *tdep_uc_addr (ucontext_t *uc, int reg); 252extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, 253 unsigned long *segbase, unsigned long *mapoff, 254 char *path, size_t pathlen); 255extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg, 256 unw_word_t *valp, int write); 257extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, 258 unw_fpreg_t *valp, int write); 259 260/* unwinding method selection support */ 261#define UNW_ARM_METHOD_ALL 0xFF 262#define UNW_ARM_METHOD_DWARF 0x01 263#define UNW_ARM_METHOD_FRAME 0x02 264#define UNW_ARM_METHOD_EXIDX 0x04 265 266#define unwi_unwind_method UNW_OBJ(unwind_method) 267extern int unwi_unwind_method; 268 269#define UNW_TRY_METHOD(x) (unwi_unwind_method & x) 270 271#endif /* ARM_LIBUNWIND_I_H */ 272