blob: 68c8ffe2ea4ba58910ee6c35d1393d207ca861ca [file] [log] [blame]
hp.com!davidm76166fb2002-04-05 23:37:55 +00001/* libunwind - a platform-independent unwind library
2 Copyright (C) 2001-2002 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5This file is part of libunwind.
6
7libunwind is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12libunwind is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
mostang.com!davidm35699692002-07-18 03:58:34 +000017You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA.
21
hp.com!davidm76166fb2002-04-05 23:37:55 +000022As a special exception, if you link this library with other files to
23produce an executable, this library does not by itself cause the
24resulting executable to be covered by the GNU General Public License.
25This exception does not however invalidate any other reasons why the
26executable file might be covered by the GNU General Public
27License. */
28
29#define UNW_PASTE2(x,y) x##y
30#define UNW_PASTE(x,y) UNW_PASTE2(x,y)
31#define UNW_OBJ(fn) UNW_PASTE(UNW_PREFIX, fn)
32
33#ifdef UNW_LOCAL_ONLY
34# define UNW_PREFIX UNW_PASTE(UNW_PASTE(_UL,UNW_TARGET),_)
35#else /* !UNW_LOCAL_ONLY */
36# define UNW_PREFIX UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_)
37#endif /* !UNW_LOCAL_ONLY */
38
39typedef unw_tdep_word_t unw_word_t;
40
41/* This needs to be big enough to accommodate the unwind state of any
42 architecture, while leaving some slack for future expansion.
43 Changing this value will require recompiling all users of this
44 library. */
45#define UNW_STATE_LEN 127
46
47/* Error codes. The unwind routines return the *negated* values of
48 these error codes on error and a non-negative value on success. */
49typedef enum
50 {
51 UNW_ESUCCESS = 0, /* no error */
52 UNW_EUNSPEC, /* unspecified (general) error */
53 UNW_ENOMEM, /* out of memory */
54 UNW_EBADREG, /* bad register number */
55 UNW_EREADONLYREG, /* attempt to write read-only register */
56 UNW_ESTOPUNWIND, /* stop unwinding */
57 UNW_EINVALIDIP, /* invalid IP */
58 UNW_EBADFRAME, /* bad frame */
59 UNW_EINVAL, /* unsupported operation */
60 UNW_EBADVERSION, /* unwind info has unsupported version */
61 UNW_ENOINFO /* no unwind info found */
62 }
63unw_error_t;
64
65/* The following enum defines the indices for a couple of
66 (pseudo-)registers which have the same meaning across all
67 platforms. (RO) means read-only. (RW) means read-write. General
68 registers (aka "integer registers") are expected to start with
69 index 0. The number of such registers is architecture-dependent.
70 The remaining indices can be used as an architecture sees fit. The
71 last valid register index is given by UNW_REG_LAST. */
72typedef enum
73 {
74 UNW_REG_IP = UNW_TDEP_IP, /* (rw) instruction pointer (pc) */
75 UNW_REG_SP = UNW_TDEP_SP, /* (ro) stack pointer */
76 UNW_REG_PROC_START = UNW_TDEP_PROC_START, /* (ro) proc startaddr */
77 UNW_REG_HANDLER = UNW_TDEP_HANDLER, /* (ro) addr. of personality routine */
78 UNW_REG_LSDA = UNW_TDEP_LSDA, /* (ro) addr. of lang.-specific data */
79 UNW_REG_LAST = UNW_TDEP_LAST_REG
80 }
81unw_frame_regnum_t;
82
mostang.com!davidm16f21892002-11-09 07:59:02 +000083typedef enum
84 {
85 UNW_CACHE_NONE, /* no caching */
86 UNW_CACHE_GLOBAL, /* shared global cache */
87 UNW_CACHE_PER_THREAD /* per-thread caching */
88 }
89unw_caching_policy_t;
90
hp.com!davidm76166fb2002-04-05 23:37:55 +000091typedef int unw_regnum_t;
92
93/* The unwind cursor starts at the youngest (most deeply nested) frame
94 and is used to track the frame state as the unwinder steps from
95 frame to frame. It is safe to make (shallow) copies of variables
96 of this type. */
97typedef struct unw_cursor
98 {
99 unw_word_t opaque[UNW_STATE_LEN];
100 }
101unw_cursor_t;
102
103/* This type encapsulates the entire (preserved) machine-state. */
104typedef unw_tdep_context_t unw_context_t;
105
106/* unw_getcontext() fills the unw_context_t pointed to by UC with the
107 machine state as it exists at the call-site. For implementation
108 reasons, this needs to be a target-dependent macro. It's easiest
109 to think of unw_getcontext() as being identical to getcontext(). */
110#define unw_getcontext(uc) unw_tdep_getcontext(uc)
111
112/* We will assume that "long double" is sufficiently large and aligned
113 to hold the contents of a floating-point register. Note that the
114 fp register format is not usually the same format as a "long
115 double". Instead, the content of unw_fpreg_t should be manipulated
116 only through the "raw.bits" member. */
117typedef union
118 {
119 struct { unw_word_t bits[1]; } raw;
120 long double dummy; /* dummy to force 16-byte alignment */
121 }
122unw_fpreg_t;
123
124/* These are backend callback routines that provide access to the
125 state of a "remote" process. This can be used, for example, to
126 unwind another process through the ptrace() interface. */
127typedef struct unw_accessors
128 {
129 /* Lock for unwind info for address IP. The architecture specific
130 UNWIND_INFO is updated as necessary. */
131 int (*acquire_unwind_info) (unw_word_t ip, void *unwind_info, void *arg);
132 int (*release_unwind_info) (void *unwind_info, void *arg);
133
134 /* Access aligned word at address ADDR. */
135 int (*access_mem) (unw_word_t addr, unw_word_t *val, int write, void *arg);
136
137 /* Access register number REG at address ADDR. */
138 int (*access_reg) (unw_regnum_t reg, unw_word_t *val, int write,
139 void *arg);
140
141 /* Access register number REG at address ADDR. */
142 int (*access_fpreg) (unw_regnum_t reg, unw_fpreg_t *val, int write,
143 void *arg);
144
145 int (*resume) (unw_cursor_t *c, void *arg);
146
147 void *arg; /* application-specific data */
148 }
149unw_accessors_t;
150
151typedef enum unw_save_loc_type
152 {
153 UNW_SLT_NONE, /* register is not saved ("not an l-value") */
154 UNW_SLT_MEMORY, /* register has been saved in memory */
155 UNW_SLT_REG /* register has been saved in (another) register */
156 }
157unw_save_loc_type_t;
158
159typedef struct unw_save_loc
160 {
161 unw_save_loc_type_t type;
162 union
163 {
164 unw_word_t addr; /* valid if type==UNW_SLT_MEMORY */
165 unw_regnum_t regnum; /* valid if type==UNW_SLT_REG */
166 }
167 u;
168 unw_tdep_save_loc_t extra; /* target-dependent additional information */
169 }
170unw_save_loc_t;
171
172/* These routines work both for local and remote unwinding. */
173
174extern int UNW_OBJ(init_local) (unw_cursor_t *c, ucontext_t *u);
175extern int UNW_OBJ(init_remote) (unw_cursor_t *c, unw_accessors_t *a);
176extern int UNW_OBJ(step) (unw_cursor_t *c);
177extern int UNW_OBJ(resume) (unw_cursor_t *c);
178extern int UNW_OBJ(get_reg) (unw_cursor_t *c, int regnum, unw_word_t *valp);
179extern int UNW_OBJ(set_reg) (unw_cursor_t *c, int regnum, unw_word_t val);
180extern int UNW_OBJ(get_fpreg) (unw_cursor_t *c, int regnum, unw_fpreg_t *val);
181extern int UNW_OBJ(set_fpreg) (unw_cursor_t *c, int regnum, unw_fpreg_t val);
182extern int UNW_OBJ(get_save_loc) (unw_cursor_t *c, int regnum,
183 unw_save_loc_t *loc);
184extern int UNW_OBJ(is_signal_frame) (unw_cursor_t *c);
mostang.com!davidm58142c02002-04-12 05:02:40 +0000185extern const char *UNW_OBJ(regname) (int regnum);
hp.com!davidm76166fb2002-04-05 23:37:55 +0000186
187/* Initialize cursor C such that unwinding starts at the point
188 represented by the context U. Returns zero on success, negative
189 value on failure. */
190#define unw_init_local(c,u) UNW_OBJ(init_local)(c, u)
191
192/* Initialize cursor C such that it accesses the unwind target through
193 accessors A. */
194#define unw_init_remote(c,a) UNW_OBJ(init_remote)(c, a)
195
196/* Move cursor up by one step (up meaning toward earlier, less deeply
197 nested frames). Returns positive number if there are more frames
198 to unwind, 0 if last frame has been reached, negative number in
199 case of an error. */
200#define unw_step(c) UNW_OBJ(step)(c)
201
202/* Resume execution at the point identified by the cursor. */
203#define unw_resume(c) UNW_OBJ(resume)(c)
204
205/* Register accessor routines. Return zero on success, negative value
206 on failure. */
207#define unw_get_reg(c,r,v) UNW_OBJ(get_reg)(c,r,v)
208#define unw_set_reg(c,r,v) UNW_OBJ(set_reg)(c,r,v)
209
210/* Floating-point accessor routines. Return zero on success, negative
211 value on failure. */
212#define unw_get_fpreg(c,r,v) UNW_OBJ(get_fpreg)(c,r,v)
213#define unw_set_fpreg(c,r,v) UNW_OBJ(set_fpreg)(c,r,v)
214
215#define unw_get_save_loc(c,r,l) UNW_OBJ(get_save_loc)(c,r,l)
216
217/* Return 1 if register number R is a floating-point register, zero
218 otherwise. */
219#define unw_is_fpreg(r) unw_tdep_is_fpreg(r)
220
221/* Returns non-zero value if the cursor points to a signal frame. */
222#define unw_is_signal_frame(c) UNW_OBJ(is_signal_frame)(c)
mostang.com!davidm58142c02002-04-12 05:02:40 +0000223
224/* Returns the canonical register name of register R. R must be in
225 the range from 0 to UNW_REG_LAST. Like all other unwind routines,
226 this one is re-entrant (i.e., the returned string must be a string
227 constant. */
228#define unw_regname(r) UNW_OBJ(regname)(r)
mostang.com!davidm16f21892002-11-09 07:59:02 +0000229
230/* Sets the caching policy. Caching can be disabled completely by
231 setting the policy to UNW_CACHE_NONE. With UNW_CACHE_GLOBAL, there
232 is a single cache that is shared across all threads. With
233 UNW_CACHE_PER_THREAD, each thread gets its own cache, which can
234 improve performance thanks to less locking and better locality. By
235 default, UNW_CACHE_GLOBAL is in effect. */
236#define unw_set_caching_policy(p) UNW_OBJ(set_caching_policy)(p)
237
238/* Flush all caches (global, per-thread, or any other caches that
239 might exist). This function must be called if any of unwind
240 information might have changed (e.g., because a library might have
241 been removed via a call to dlclose()). */
242#define unw_flush_cache() UNW_OBJ(flush_cache)()