libunwind_i.h revision ec633a1911e365ba6016fa9fcbd81cad72f7afdb
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 38struct unw_addr_space 39 { 40 struct unw_accessors acc; 41 int big_endian; 42 unw_caching_policy_t caching_policy; 43#ifdef HAVE_ATOMIC_OPS_H 44 AO_t cache_generation; 45#else 46 uint32_t cache_generation; 47#endif 48 unw_word_t dyn_generation; /* see dyn-common.h */ 49 unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */ 50 struct dwarf_rs_cache global_cache; 51 struct unw_debug_frame_list *debug_frames; 52 }; 53 54struct cursor 55 { 56 struct dwarf_cursor dwarf; /* must be first */ 57 unw_word_t sigcontext_addr; 58 }; 59 60#define DWARF_GET_LOC(l) ((l).val) 61 62#ifdef UNW_LOCAL_ONLY 63# define DWARF_NULL_LOC DWARF_LOC (0, 0) 64# define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0) 65# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) }) 66# define DWARF_IS_REG_LOC(l) 0 67# define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 68 tdep_uc_addr((c)->as_arg, (r)), 0)) 69# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 70# define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 71 tdep_uc_addr((c)->as_arg, (r)), 0)) 72 73static inline int 74dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) 75{ 76 if (!DWARF_GET_LOC (loc)) 77 return -1; 78 *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc); 79 return 0; 80} 81 82static inline int 83dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 84{ 85 if (!DWARF_GET_LOC (loc)) 86 return -1; 87 *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val; 88 return 0; 89} 90 91static inline int 92dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) 93{ 94 if (!DWARF_GET_LOC (loc)) 95 return -1; 96 *val = *(unw_word_t *) DWARF_GET_LOC (loc); 97 return 0; 98} 99 100static inline int 101dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) 102{ 103 if (!DWARF_GET_LOC (loc)) 104 return -1; 105 *(unw_word_t *) DWARF_GET_LOC (loc) = val; 106 return 0; 107} 108 109#else /* !UNW_LOCAL_ONLY */ 110# define DWARF_LOC_TYPE_FP (1 << 0) 111# define DWARF_LOC_TYPE_REG (1 << 1) 112# define DWARF_NULL_LOC DWARF_LOC (0, 0) 113# define DWARF_IS_NULL_LOC(l) \ 114 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; }) 115# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) }) 116# define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0) 117# define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0) 118# define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG) 119# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 120# define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \ 121 | DWARF_LOC_TYPE_FP)) 122 123static inline int 124dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) 125{ 126 char *valp = (char *) &val; 127 unw_word_t addr; 128 int ret; 129 130 if (DWARF_IS_NULL_LOC (loc)) 131 return -UNW_EBADREG; 132 133 if (DWARF_IS_REG_LOC (loc)) 134 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 135 val, 0, c->as_arg); 136 137 addr = DWARF_GET_LOC (loc); 138 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp, 139 0, c->as_arg)) < 0) 140 return ret; 141 142 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 0, 143 c->as_arg); 144} 145 146static inline int 147dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 148{ 149 char *valp = (char *) &val; 150 unw_word_t addr; 151 int ret; 152 153 if (DWARF_IS_NULL_LOC (loc)) 154 return -UNW_EBADREG; 155 156 if (DWARF_IS_REG_LOC (loc)) 157 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 158 &val, 1, c->as_arg); 159 160 addr = DWARF_GET_LOC (loc); 161 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp, 162 1, c->as_arg)) < 0) 163 return ret; 164 165 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 166 1, c->as_arg); 167} 168 169static inline int 170dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) 171{ 172 if (DWARF_IS_NULL_LOC (loc)) 173 return -UNW_EBADREG; 174 175 /* If a code-generator were to save a value of type unw_word_t in a 176 floating-point register, we would have to support this case. I 177 suppose it could happen with MMX registers, but does it really 178 happen? */ 179 assert (!DWARF_IS_FP_LOC (loc)); 180 181 if (DWARF_IS_REG_LOC (loc)) 182 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val, 183 0, c->as_arg); 184 else 185 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val, 186 0, c->as_arg); 187} 188 189static inline int 190dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) 191{ 192 if (DWARF_IS_NULL_LOC (loc)) 193 return -UNW_EBADREG; 194 195 /* If a code-generator were to save a value of type unw_word_t in a 196 floating-point register, we would have to support this case. I 197 suppose it could happen with MMX registers, but does it really 198 happen? */ 199 assert (!DWARF_IS_FP_LOC (loc)); 200 201 if (DWARF_IS_REG_LOC (loc)) 202 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val, 203 1, c->as_arg); 204 else 205 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val, 206 1, c->as_arg); 207} 208 209#endif /* !UNW_LOCAL_ONLY */ 210 211#define tdep_needs_initialization UNW_OBJ(needs_initialization) 212#define tdep_init UNW_OBJ(init) 213/* Platforms that support UNW_INFO_FORMAT_TABLE need to define 214 tdep_search_unwind_table. */ 215#define tdep_search_unwind_table dwarf_search_unwind_table 216#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr) 217#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image) 218#define tdep_access_reg UNW_OBJ(access_reg) 219#define tdep_access_fpreg UNW_OBJ(access_fpreg) 220#define tdep_fetch_frame(c,ip,n) do {} while(0) 221#define tdep_cache_frame(c,rs) do {} while(0) 222#define tdep_reuse_frame(c,rs) do {} while(0) 223 224#ifdef UNW_LOCAL_ONLY 225# define tdep_find_proc_info(c,ip,n) \ 226 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \ 227 (c)->as_arg) 228# define tdep_put_unwind_info(as,pi,arg) \ 229 dwarf_put_unwind_info((as), (pi), (arg)) 230#else 231# define tdep_find_proc_info(c,ip,n) \ 232 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \ 233 (c)->as_arg) 234# define tdep_put_unwind_info(as,pi,arg) \ 235 (*(as)->acc.put_unwind_info)((as), (pi), (arg)) 236#endif 237 238#define tdep_get_as(c) ((c)->dwarf.as) 239#define tdep_get_as_arg(c) ((c)->dwarf.as_arg) 240#define tdep_get_ip(c) ((c)->dwarf.ip) 241#define tdep_big_endian(as) ((as)->big_endian) 242 243extern int tdep_needs_initialization; 244 245extern void tdep_init (void); 246extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, 247 unw_dyn_info_t *di, unw_proc_info_t *pi, 248 int need_unwind_info, void *arg); 249extern void *tdep_uc_addr (ucontext_t *uc, int reg); 250extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, 251 unsigned long *segbase, unsigned long *mapoff, 252 char *path, size_t pathlen); 253extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg, 254 unw_word_t *valp, int write); 255extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, 256 unw_fpreg_t *valp, int write); 257 258/* unwinding method selection support */ 259#define UNW_ARM_METHOD_ALL 0xFF 260#define UNW_ARM_METHOD_DWARF 0x01 261#define UNW_ARM_METHOD_FRAME 0x02 262 263#define unwi_unwind_method UNW_OBJ(unwind_method) 264extern int unwi_unwind_method; 265 266#define UNW_TRY_METHOD(x) (unwi_unwind_method & x) 267 268#endif /* ARM_LIBUNWIND_I_H */ 269