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