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