Initial import
[external/libunwind.git] / include / libunwind-common.h.in
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2001-2004 Hewlett-Packard Co
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 #define UNW_VERSION_MAJOR       @PKG_MAJOR@
27 #define UNW_VERSION_MINOR       @PKG_MINOR@
28 #define UNW_VERSION_EXTRA       @PKG_EXTRA@
29
30 #define UNW_VERSION_CODE(maj,min)       (((maj) << 16) | (min))
31 #define UNW_VERSION     UNW_VERSION_CODE(UNW_VERSION_MAJOR, UNW_VERSION_MINOR)
32
33 #define UNW_PASTE2(x,y) x##y
34 #define UNW_PASTE(x,y)  UNW_PASTE2(x,y)
35 #define UNW_OBJ(fn)     UNW_PASTE(UNW_PREFIX, fn)
36 #define UNW_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_), fn)
37
38 #ifdef UNW_LOCAL_ONLY
39 # define UNW_PREFIX     UNW_PASTE(UNW_PASTE(_UL,UNW_TARGET),_)
40 #else /* !UNW_LOCAL_ONLY */
41 # define UNW_PREFIX     UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_)
42 #endif /* !UNW_LOCAL_ONLY */
43
44 /* Error codes.  The unwind routines return the *negated* values of
45    these error codes on error and a non-negative value on success.  */
46 typedef enum
47   {
48     UNW_ESUCCESS = 0,           /* no error */
49     UNW_EUNSPEC,                /* unspecified (general) error */
50     UNW_ENOMEM,                 /* out of memory */
51     UNW_EBADREG,                /* bad register number */
52     UNW_EREADONLYREG,           /* attempt to write read-only register */
53     UNW_ESTOPUNWIND,            /* stop unwinding */
54     UNW_EINVALIDIP,             /* invalid IP */
55     UNW_EBADFRAME,              /* bad frame */
56     UNW_EINVAL,                 /* unsupported operation or bad value */
57     UNW_EBADVERSION,            /* unwind info has unsupported version */
58     UNW_ENOINFO                 /* no unwind info found */
59   }
60 unw_error_t;
61
62 /* The following enum defines the indices for a couple of
63    (pseudo-)registers which have the same meaning across all
64    platforms.  (RO) means read-only.  (RW) means read-write.  General
65    registers (aka "integer registers") are expected to start with
66    index 0.  The number of such registers is architecture-dependent.
67    The remaining indices can be used as an architecture sees fit.  The
68    last valid register index is given by UNW_REG_LAST.  */
69 typedef enum
70   {
71     UNW_REG_IP = UNW_TDEP_IP,           /* (rw) instruction pointer (pc) */
72     UNW_REG_SP = UNW_TDEP_SP,           /* (ro) stack pointer */
73     UNW_REG_EH = UNW_TDEP_EH,           /* (rw) exception-handling reg base */
74     UNW_REG_LAST = UNW_TDEP_LAST_REG
75   }
76 unw_frame_regnum_t;
77
78 /* Number of exception-handler argument registers: */
79 #define UNW_NUM_EH_REGS         UNW_TDEP_NUM_EH_REGS
80
81 typedef enum
82   {
83     UNW_CACHE_NONE,                     /* no caching */
84     UNW_CACHE_GLOBAL,                   /* shared global cache */
85     UNW_CACHE_PER_THREAD                /* per-thread caching */
86   }
87 unw_caching_policy_t;
88
89 typedef int unw_regnum_t;
90
91 /* The unwind cursor starts at the youngest (most deeply nested) frame
92    and is used to track the frame state as the unwinder steps from
93    frame to frame.  It is safe to make (shallow) copies of variables
94    of this type.  */
95 typedef struct unw_cursor
96   {
97     unw_word_t opaque[UNW_TDEP_CURSOR_LEN];
98   }
99 unw_cursor_t;
100
101 /* This type encapsulates the entire (preserved) machine-state.  */
102 typedef unw_tdep_context_t unw_context_t;
103
104 /* unw_getcontext() fills the unw_context_t pointed to by UC with the
105    machine state as it exists at the call-site.  For implementation
106    reasons, this needs to be a target-dependent macro.  It's easiest
107    to think of unw_getcontext() as being identical to getcontext(). */
108 #define unw_getcontext(uc)              unw_tdep_getcontext(uc)
109
110 /* Return 1 if register number R is a floating-point register, zero
111    otherwise.
112    This routine is signal-safe.  */
113 #define unw_is_fpreg(r)                 unw_tdep_is_fpreg(r)
114
115 typedef unw_tdep_fpreg_t unw_fpreg_t;
116
117 typedef struct unw_addr_space *unw_addr_space_t;
118
119 /* Each target may define it's own set of flags, but bits 0-15 are
120    reserved for general libunwind-use.  */
121 #define UNW_PI_FLAG_FIRST_TDEP_BIT      16
122 /* The information comes from a .debug_frame section.  */
123 #define UNW_PI_FLAG_DEBUG_FRAME 32
124
125 typedef struct unw_proc_info
126   {
127     unw_word_t start_ip;        /* first IP covered by this procedure */
128     unw_word_t end_ip;          /* first IP NOT covered by this procedure */
129     unw_word_t lsda;            /* address of lang.-spec. data area (if any) */
130     unw_word_t handler;         /* optional personality routine */
131     unw_word_t gp;              /* global-pointer value for this procedure */
132     unw_word_t flags;           /* misc. flags */
133
134     int format;                 /* unwind-info format (arch-specific) */
135     int unwind_info_size;       /* size of the information (if applicable) */
136     void *unwind_info;          /* unwind-info (arch-specific) */
137     unw_tdep_proc_info_t extra; /* target-dependent auxiliary proc-info */
138   }
139 unw_proc_info_t;
140
141 /* These are backend callback routines that provide access to the
142    state of a "remote" process.  This can be used, for example, to
143    unwind another process through the ptrace() interface.  */
144 typedef struct unw_accessors
145   {
146     /* Look up the unwind info associated with instruction-pointer IP.
147        On success, the routine fills in the PROC_INFO structure.  */
148     int (*find_proc_info) (unw_addr_space_t, unw_word_t, unw_proc_info_t *,
149                            int, void *);
150
151     /* Release any resources (e.g., memory) that were allocated for
152        the unwind info returned in by a previous call to
153        find_proc_info() with NEED_UNWIND_INFO set to 1.  */
154     void (*put_unwind_info) (unw_addr_space_t, unw_proc_info_t *, void *);
155
156     /* Return the list-head of the dynamically registered unwind
157        info.  */
158     int (*get_dyn_info_list_addr) (unw_addr_space_t, unw_word_t *, void *);
159
160     /* Access aligned word at address ADDR.  The value is returned
161        according to the endianness of the host (e.g., if the host is
162        little-endian and the target is big-endian, access_mem() needs
163        to byte-swap the value before returning it).  */
164     int (*access_mem) (unw_addr_space_t, unw_word_t, unw_word_t *, int,
165                        void *);
166
167     /* Access register number REG at address ADDR.  */
168     int (*access_reg) (unw_addr_space_t, unw_regnum_t, unw_word_t *, int,
169                        void *);
170
171     /* Access register number REG at address ADDR.  */
172     int (*access_fpreg) (unw_addr_space_t, unw_regnum_t,
173                          unw_fpreg_t *, int, void *);
174
175     int (*resume) (unw_addr_space_t, unw_cursor_t *, void *);
176
177     /* Optional call back to obtain the name of a (static) procedure.
178        Dynamically generated procedures are handled automatically by
179        libunwind.  This callback is optional and may be set to
180        NULL.  */
181     int (*get_proc_name) (unw_addr_space_t, unw_word_t, char *, size_t,
182                           unw_word_t *, void *);
183   }
184 unw_accessors_t;
185
186 typedef enum unw_save_loc_type
187   {
188     UNW_SLT_NONE,       /* register is not saved ("not an l-value") */
189     UNW_SLT_MEMORY,     /* register has been saved in memory */
190     UNW_SLT_REG         /* register has been saved in (another) register */
191   }
192 unw_save_loc_type_t;
193
194 typedef struct unw_save_loc
195   {
196     unw_save_loc_type_t type;
197     union
198       {
199         unw_word_t addr;        /* valid if type==UNW_SLT_MEMORY */
200         unw_regnum_t regnum;    /* valid if type==UNW_SLT_REG */
201       }
202     u;
203     unw_tdep_save_loc_t extra;  /* target-dependent additional information */
204   }
205 unw_save_loc_t;
206
207 /* These routines work both for local and remote unwinding.  */
208
209 #define unw_local_addr_space    UNW_OBJ(local_addr_space)
210 #define unw_create_addr_space   UNW_OBJ(create_addr_space)
211 #define unw_destroy_addr_space  UNW_OBJ(destroy_addr_space)
212 #define unw_get_accessors       UNW_ARCH_OBJ(get_accessors)
213 #define unw_init_local          UNW_OBJ(init_local)
214 #define unw_init_remote         UNW_OBJ(init_remote)
215 #define unw_step                UNW_OBJ(step)
216 #define unw_resume              UNW_OBJ(resume)
217 #define unw_get_proc_info       UNW_OBJ(get_proc_info)
218 #define unw_get_proc_info_by_ip UNW_OBJ(get_proc_info_by_ip)
219 #define unw_get_reg             UNW_OBJ(get_reg)
220 #define unw_set_reg             UNW_OBJ(set_reg)
221 #define unw_get_fpreg           UNW_OBJ(get_fpreg)
222 #define unw_set_fpreg           UNW_OBJ(set_fpreg)
223 #define unw_get_save_loc        UNW_OBJ(get_save_loc)
224 #define unw_is_signal_frame     UNW_OBJ(is_signal_frame)
225 #define unw_handle_signal_frame UNW_OBJ(handle_signal_frame)
226 #define unw_get_proc_name       UNW_OBJ(get_proc_name)
227 #define unw_set_caching_policy  UNW_OBJ(set_caching_policy)
228 #define unw_regname             UNW_ARCH_OBJ(regname)
229 #define unw_flush_cache         UNW_ARCH_OBJ(flush_cache)
230 #define unw_strerror            UNW_ARCH_OBJ(strerror)
231
232 extern unw_addr_space_t unw_create_addr_space (unw_accessors_t *, int);
233 extern void unw_destroy_addr_space (unw_addr_space_t);
234 extern unw_accessors_t *unw_get_accessors (unw_addr_space_t);
235 extern void unw_flush_cache (unw_addr_space_t, unw_word_t, unw_word_t);
236 extern int unw_set_caching_policy (unw_addr_space_t, unw_caching_policy_t);
237 extern const char *unw_regname (unw_regnum_t);
238
239 extern int unw_init_local (unw_cursor_t *, unw_context_t *);
240 extern int unw_init_remote (unw_cursor_t *, unw_addr_space_t, void *);
241 extern int unw_step (unw_cursor_t *);
242 extern int unw_resume (unw_cursor_t *);
243 extern int unw_get_proc_info (unw_cursor_t *, unw_proc_info_t *);
244 extern int unw_get_proc_info_by_ip (unw_addr_space_t, unw_word_t,
245                                     unw_proc_info_t *, void *);
246 extern int unw_get_reg (unw_cursor_t *, int, unw_word_t *);
247 extern int unw_set_reg (unw_cursor_t *, int, unw_word_t);
248 extern int unw_get_fpreg (unw_cursor_t *, int, unw_fpreg_t *);
249 extern int unw_set_fpreg (unw_cursor_t *, int, unw_fpreg_t);
250 extern int unw_get_save_loc (unw_cursor_t *, int, unw_save_loc_t *);
251 extern int unw_is_signal_frame (unw_cursor_t *);
252 extern int unw_handle_signal_frame (unw_cursor_t *);
253 extern int unw_get_proc_name (unw_cursor_t *, char *, size_t, unw_word_t *);
254 extern const char *unw_strerror (int);
255 extern int unw_backtrace (void **, int);
256
257 extern unw_addr_space_t unw_local_addr_space;