mostang.com!davidm | 5109550 | 2003-03-11 01:11:18 +0000 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
hp.com!davidm | 25b8795 | 2004-01-22 08:36:15 +0000 | [diff] [blame^] | 2 | Copyright (C) 2002-2004 Hewlett-Packard Co |
mostang.com!davidm | 5109550 | 2003-03-11 01:11:18 +0000 | [diff] [blame] | 3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
| 4 | |
| 5 | This file is part of libunwind. |
| 6 | |
| 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: |
| 14 | |
| 15 | The above copyright notice and this permission notice shall be |
| 16 | included in all copies or substantial portions of the Software. |
| 17 | |
| 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. */ |
| 25 | |
| 26 | #ifndef TDEP_X86_H |
| 27 | #define TDEP_X86_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 | |
hp.com!davidm | 497018e | 2003-11-27 06:52:54 +0000 | [diff] [blame] | 35 | #include "elf32.h" |
hp.com!davidm | 468aacc | 2003-12-20 11:50:00 +0000 | [diff] [blame] | 36 | #include "dwarf.h" |
mostang.com!davidm | 5109550 | 2003-03-11 01:11:18 +0000 | [diff] [blame] | 37 | |
| 38 | struct unw_addr_space |
| 39 | { |
| 40 | struct unw_accessors acc; |
| 41 | unw_caching_policy_t caching_policy; |
| 42 | uint32_t cache_generation; |
| 43 | unw_word_t dyn_generation; /* see dyn-common.h */ |
| 44 | unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */ |
| 45 | }; |
| 46 | |
| 47 | struct cursor |
| 48 | { |
hp.com!davidm | 468aacc | 2003-12-20 11:50:00 +0000 | [diff] [blame] | 49 | struct dwarf_cursor dwarf; /* must be first */ |
mostang.com!davidm | 5109550 | 2003-03-11 01:11:18 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
hp.com!davidm | 468aacc | 2003-12-20 11:50:00 +0000 | [diff] [blame] | 52 | #define DWARF_GET_LOC(l) ((l).val) |
| 53 | |
| 54 | #ifdef UNW_LOCAL_ONLY |
| 55 | # define DWARF_NULL_LOC DWARF_LOC (0, 0) |
| 56 | # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0) |
| 57 | # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) }) |
| 58 | # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \ |
| 59 | tdep_uc_addr((c)->as_arg, (r)), 0)) |
| 60 | # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) |
| 61 | # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \ |
| 62 | tdep_uc_addr((c)->as_arg, (r)), 0)) |
| 63 | |
| 64 | static inline int |
| 65 | dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) |
| 66 | { |
| 67 | if (!DWARF_GET_LOC (loc)) |
| 68 | return -1; |
| 69 | *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc); |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static inline int |
| 74 | dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) |
| 75 | { |
| 76 | if (!DWARF_GET_LOC (loc)) |
| 77 | return -1; |
| 78 | *(unw_fpreg_t *) DWARF_GET_LOC (loc) = *val; |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static inline int |
| 83 | dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) |
| 84 | { |
| 85 | if (!DWARF_GET_LOC (loc)) |
| 86 | return -1; |
| 87 | *val = *(unw_word_t *) DWARF_GET_LOC (loc); |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static inline int |
| 92 | dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) |
| 93 | { |
| 94 | if (!DWARF_GET_LOC (loc)) |
| 95 | return -1; |
| 96 | *(unw_word_t *) DWARF_GET_LOC (loc) = val; |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | #else /* !UNW_LOCAL_ONLY */ |
| 101 | # define DWARF_LOC_TYPE_FP (1 << 0) |
| 102 | # define DWARF_LOC_TYPE_REG (1 << 1) |
| 103 | # define DWARF_NULL_LOC DWARF_LOC (0, 0) |
| 104 | # define DWARF_IS_NULL_LOC(l) \ |
| 105 | ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; }) |
| 106 | # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) }) |
| 107 | # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0) |
| 108 | # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0) |
| 109 | # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG) |
| 110 | # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) |
| 111 | # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \ |
| 112 | | DWARF_LOC_TYPE_FP)) |
| 113 | |
| 114 | static inline int |
| 115 | dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) |
| 116 | { |
| 117 | abort (); |
| 118 | } |
| 119 | |
| 120 | static inline int |
| 121 | dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) |
| 122 | { |
| 123 | abort (); |
| 124 | } |
| 125 | |
| 126 | static inline int |
| 127 | dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) |
| 128 | { |
| 129 | if (DWARF_IS_FP_LOC (loc)) |
| 130 | abort (); |
| 131 | |
| 132 | if (DWARF_IS_REG_LOC (loc)) |
| 133 | return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val, |
| 134 | 0, c->as_arg); |
| 135 | else |
| 136 | return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val, |
| 137 | 0, c->as_arg); |
| 138 | } |
| 139 | |
| 140 | static inline int |
| 141 | dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) |
| 142 | { |
| 143 | if (DWARF_IS_FP_LOC (loc)) |
| 144 | abort (); |
| 145 | |
| 146 | if (DWARF_IS_REG_LOC (loc)) |
| 147 | return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val, |
| 148 | 1, c->as_arg); |
| 149 | else |
| 150 | return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val, |
| 151 | 1, c->as_arg); |
| 152 | } |
| 153 | |
| 154 | #endif /* !UNW_LOCAL_ONLY */ |
| 155 | |
mostang.com!davidm | 5109550 | 2003-03-11 01:11:18 +0000 | [diff] [blame] | 156 | /* Platforms that support UNW_INFO_FORMAT_TABLE need to define |
| 157 | tdep_search_unwind_table. */ |
hp.com!davidm | 468aacc | 2003-12-20 11:50:00 +0000 | [diff] [blame] | 158 | #define tdep_search_unwind_table dwarf_search_unwind_table |
| 159 | #define tdep_find_proc_info dwarf_find_proc_info |
| 160 | #define tdep_put_unwind_info dwarf_put_unwind_info |
mostang.com!davidm | 5109550 | 2003-03-11 01:11:18 +0000 | [diff] [blame] | 161 | #define tdep_uc_addr(uc,reg) UNW_ARCH_OBJ(uc_addr)(uc,reg) |
hp.com!davidm | f9cc1e4 | 2003-03-29 07:32:50 +0000 | [diff] [blame] | 162 | #define tdep_get_elf_image(a,b,c,d,e) UNW_ARCH_OBJ(get_elf_image) (a, b, c, \ |
| 163 | d, e) |
mostang.com!davidm | 5109550 | 2003-03-11 01:11:18 +0000 | [diff] [blame] | 164 | extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, |
| 165 | unw_dyn_info_t *di, unw_proc_info_t *pi, |
| 166 | int need_unwind_info, void *arg); |
mostang.com!davidm | 5109550 | 2003-03-11 01:11:18 +0000 | [diff] [blame] | 167 | extern void tdep_put_unwind_info (unw_addr_space_t as, |
| 168 | unw_proc_info_t *pi, void *arg); |
| 169 | extern void *tdep_uc_addr (ucontext_t *uc, int reg); |
hp.com!davidm | f9cc1e4 | 2003-03-29 07:32:50 +0000 | [diff] [blame] | 170 | extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, |
| 171 | unsigned long *segbase, unsigned long *mapoff); |
mostang.com!davidm | 5109550 | 2003-03-11 01:11:18 +0000 | [diff] [blame] | 172 | |
| 173 | #endif /* TDEP_X86_H */ |