blob: 584f392c5676a283eeec5eea6d4e71b515edb1ca [file] [log] [blame]
hp.com!davidmd7e9f752002-11-23 02:12:30 +00001/* libunwind - a platform-independent unwind library
mostang.com!davidm64854d02004-01-21 01:05:07 +00002 Copyright (C) 2002-2004 Hewlett-Packard Co
hp.com!davidmd7e9f752002-11-23 02:12:30 +00003 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
hp.com!davidmd7e9f752002-11-23 02:12:30 +000026/* This file defines the runtime-support routines for dynamically
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000027generated code. Even though it is implemented as part of libunwind,
28it is logically separate from the interface to perform the actual
29unwinding. In particular, this interface is always used in the
30context of the unwind target, whereas the rest of the unwind API is
31used in context of the process that is doing the unwind (which may be
32a debugger running on another machine, for example).
33
34Note that the data-structures declared here server a dual purpose:
35when a program registers a dynamically generated procedure, it uses
36these structures directly. On the other hand, with remote-unwinding,
37the data-structures are read from the remote process's memory and
mostang.com!davidm744b9102002-12-12 09:17:41 +000038translated into internalized versions. To facilitate remote-access,
39the following rules should be followed in declaring these structures:
40
41 (1) Declare a member as a pointer only if the the information the
42 member points to needs to be internalized as well (e.g., a
43 string representing a procedure name should be declared as
44 "const char *", but the instruction pointer should be declared
45 as unw_word_t).
46
47 (2) Provide sufficient padding to ensure that no implicit padding
48 will be needed on any of the supported target architectures. For
49 the time being, padding data structures with the assumption that
50 sizeof (unw_word_t) == 8 should be sufficient. (Note: it's not
51 impossible to internalize structures with internal padding, but
52 it does make the process a bit harder).
53
54 (3) Don't declare members that contain bitfields or floating-point
55 values.
56
57 (4) Don't declare members with enumeration types. Declare them as
58 int32_t instead. */
hp.com!davidmd7e9f752002-11-23 02:12:30 +000059
60typedef enum
61 {
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000062 UNW_DYN_STOP = 0, /* end-of-unwind-info marker */
63 UNW_DYN_SAVE_REG, /* save register to another register */
64 UNW_DYN_SPILL_FP_REL, /* frame-pointer-relative register spill */
65 UNW_DYN_SPILL_SP_REL, /* stack-pointer-relative register spill */
66 UNW_DYN_ADD, /* add constant value to a register */
67 UNW_DYN_POP_FRAMES, /* drop one or more stack frames */
68 UNW_DYN_LABEL_STATE, /* name the current state */
69 UNW_DYN_COPY_STATE, /* set the region's entry-state */
70 UNW_DYN_ALIAS /* get unwind info from an alias */
hp.com!davidmd7e9f752002-11-23 02:12:30 +000071 }
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000072unw_dyn_operation_t;
hp.com!davidmd7e9f752002-11-23 02:12:30 +000073
mostang.com!davidm744b9102002-12-12 09:17:41 +000074typedef enum
75 {
hp.com!davidmdd8806c2003-11-25 22:33:49 +000076 UNW_INFO_FORMAT_DYNAMIC, /* unw_dyn_proc_info_t */
77 UNW_INFO_FORMAT_TABLE, /* unw_dyn_table_t */
Ken Werner545023c2011-07-14 13:44:02 +000078 UNW_INFO_FORMAT_REMOTE_TABLE, /* unw_dyn_remote_table_t */
79 UNW_INFO_FORMAT_ARM_EXIDX /* ARM specific unwind info */
mostang.com!davidm744b9102002-12-12 09:17:41 +000080 }
81unw_dyn_info_format_t;
82
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000083typedef struct unw_dyn_op
hp.com!davidmd7e9f752002-11-23 02:12:30 +000084 {
mostang.com!davidm744b9102002-12-12 09:17:41 +000085 int8_t tag; /* what operation? */
86 int8_t qp; /* qualifying predicate register */
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000087 int16_t reg; /* what register */
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000088 int32_t when; /* when does it take effect? */
89 unw_word_t val; /* auxiliary value */
hp.com!davidmd7e9f752002-11-23 02:12:30 +000090 }
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000091unw_dyn_op_t;
hp.com!davidmd7e9f752002-11-23 02:12:30 +000092
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000093typedef struct unw_dyn_region_info
hp.com!davidmd7e9f752002-11-23 02:12:30 +000094 {
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000095 struct unw_dyn_region_info *next; /* linked list of regions */
mostang.com!davidme6144052003-02-22 08:19:43 +000096 int32_t insn_count; /* region length (# of instructions) */
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +000097 uint32_t op_count; /* length of op-array */
98 unw_dyn_op_t op[1]; /* variable-length op-array */
99 }
100unw_dyn_region_info_t;
101
102typedef struct unw_dyn_proc_info
103 {
mostang.com!davidm744b9102002-12-12 09:17:41 +0000104 unw_word_t name_ptr; /* address of human-readable procedure name */
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000105 unw_word_t handler; /* address of personality routine */
106 uint32_t flags;
mostang.com!davidm744b9102002-12-12 09:17:41 +0000107 int32_t pad0;
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000108 unw_dyn_region_info_t *regions;
109 }
110unw_dyn_proc_info_t;
111
112typedef struct unw_dyn_table_info
113 {
mostang.com!davidm744b9102002-12-12 09:17:41 +0000114 unw_word_t name_ptr; /* addr. of table name (e.g., library name) */
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000115 unw_word_t segbase; /* segment base */
mostang.com!davidm744b9102002-12-12 09:17:41 +0000116 unw_word_t table_len; /* must be a multiple of sizeof(unw_word_t)! */
117 unw_word_t *table_data;
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000118 }
119unw_dyn_table_info_t;
120
hp.com!davidmdd8806c2003-11-25 22:33:49 +0000121typedef struct unw_dyn_remote_table_info
122 {
123 unw_word_t name_ptr; /* addr. of table name (e.g., library name) */
124 unw_word_t segbase; /* segment base */
125 unw_word_t table_len; /* must be a multiple of sizeof(unw_word_t)! */
126 unw_word_t table_data;
127 }
128unw_dyn_remote_table_info_t;
129
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000130typedef struct unw_dyn_info
131 {
mostang.com!davidm744b9102002-12-12 09:17:41 +0000132 /* doubly-linked list of dyn-info structures: */
133 struct unw_dyn_info *next;
134 struct unw_dyn_info *prev;
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000135 unw_word_t start_ip; /* first IP covered by this entry */
136 unw_word_t end_ip; /* first IP NOT covered by this entry */
137 unw_word_t gp; /* global-pointer in effect for this entry */
mostang.com!davidm744b9102002-12-12 09:17:41 +0000138 int32_t format; /* real type: unw_dyn_info_format_t */
139 int32_t pad;
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000140 union
141 {
142 unw_dyn_proc_info_t pi;
143 unw_dyn_table_info_t ti;
hp.com!davidmdd8806c2003-11-25 22:33:49 +0000144 unw_dyn_remote_table_info_t rti;
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000145 }
146 u;
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000147 }
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000148unw_dyn_info_t;
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000149
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000150typedef struct unw_dyn_info_list
151 {
mostang.com!davidm744b9102002-12-12 09:17:41 +0000152 uint32_t version;
153 uint32_t generation;
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000154 unw_dyn_info_t *first;
155 }
156unw_dyn_info_list_t;
157
158/* Return the size (in bytes) of an unw_dyn_region_info_t structure that can
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000159 hold OP_COUNT ops. */
mostang.com!davidm9430d352003-02-27 09:58:57 +0000160#define _U_dyn_region_info_size(op_count) \
161 ((char *) (((unw_dyn_region_info_t *) NULL)->op + (op_count)) \
162 - (char *) NULL)
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000163
164/* Register the unwind info for a single procedure.
165 This routine is NOT signal-safe. */
mostang.com!davidm64854d02004-01-21 01:05:07 +0000166extern void _U_dyn_register (unw_dyn_info_t *);
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000167
168/* Cancel the unwind info for a single procedure.
169 This routine is NOT signal-safe. */
mostang.com!davidm64854d02004-01-21 01:05:07 +0000170extern void _U_dyn_cancel (unw_dyn_info_t *);
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000171
172
173/* Convenience routines. */
174
mostang.com!davidmc5c4fc92004-04-28 01:24:34 +0000175#define _U_dyn_op(_tag, _qp, _when, _reg, _val) \
176 ((unw_dyn_op_t) { (_tag), (_qp), (_reg), (_when), (_val) })
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000177
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000178#define _U_dyn_op_save_reg(op, qp, when, reg, dst) \
179 (*(op) = _U_dyn_op (UNW_DYN_SAVE_REG, (qp), (when), (reg), (dst)))
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000180
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000181#define _U_dyn_op_spill_fp_rel(op, qp, when, reg, offset) \
182 (*(op) = _U_dyn_op (UNW_DYN_SPILL_FP_REL, (qp), (when), (reg), \
183 (offset)))
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000184
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000185#define _U_dyn_op_spill_sp_rel(op, qp, when, reg, offset) \
186 (*(op) = _U_dyn_op (UNW_DYN_SPILL_SP_REL, (qp), (when), (reg), \
187 (offset)))
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000188
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000189#define _U_dyn_op_add(op, qp, when, reg, value) \
190 (*(op) = _U_dyn_op (UNW_DYN_ADD, (qp), (when), (reg), (value)))
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000191
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000192#define _U_dyn_op_pop_frames(op, qp, when, num_frames) \
hp.com!davidmcf3b7562003-02-26 08:33:57 +0000193 (*(op) = _U_dyn_op (UNW_DYN_POP_FRAMES, (qp), (when), 0, (num_frames)))
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000194
mostang.com!davidm9430d352003-02-27 09:58:57 +0000195#define _U_dyn_op_label_state(op, label) \
196 (*(op) = _U_dyn_op (UNW_DYN_LABEL_STATE, _U_QP_TRUE, -1, 0, (label)))
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000197
mostang.com!davidm9430d352003-02-27 09:58:57 +0000198#define _U_dyn_op_copy_state(op, label) \
199 (*(op) = _U_dyn_op (UNW_DYN_COPY_STATE, _U_QP_TRUE, -1, 0, (label)))
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000200
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000201#define _U_dyn_op_alias(op, qp, when, addr) \
202 (*(op) = _U_dyn_op (UNW_DYN_ALIAS, (qp), (when), 0, (addr)))
hp.com!davidmd7e9f752002-11-23 02:12:30 +0000203
mostang.com!davidmdfc08ea2002-12-03 08:19:58 +0000204#define _U_dyn_op_stop(op) \
mostang.com!davidm9430d352003-02-27 09:58:57 +0000205 (*(op) = _U_dyn_op (UNW_DYN_STOP, _U_QP_TRUE, -1, 0, 0))
206
207/* The target-dependent qualifying predicate which is always TRUE. On
208 IA-64, that's p0 (0), on non-predicated architectures, the value is
209 ignored. */
210#define _U_QP_TRUE _U_TDEP_QP_TRUE