Subversion Repositories Kolibri OS

Rev

Rev 4383 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4383 Rev 5963
1
/* DWARF2 exception handling and frame unwind runtime interface routines.
1
/* DWARF2 exception handling and frame unwind runtime interface routines.
2
   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-
 
3
   2008, 2009, 2010  Free Software Foundation, Inc.
2
   Copyright (C) 1997-2013 Free Software Foundation, Inc.
4
 
3
 
5
   This file is part of GCC.
4
   This file is part of GCC.
6
 
5
 
7
   GCC is free software; you can redistribute it and/or modify it
6
   GCC is free software; you can redistribute it and/or modify it
8
   under the terms of the GNU General Public License as published by
7
   under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
8
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
9
   any later version.
11
 
10
 
12
   GCC is distributed in the hope that it will be useful, but WITHOUT
11
   GCC is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
13
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
14
   License for more details.
16
 
15
 
17
   Under Section 7 of GPL version 3, you are granted additional
16
   Under Section 7 of GPL version 3, you are granted additional
18
   permissions described in the GCC Runtime Library Exception, version
17
   permissions described in the GCC Runtime Library Exception, version
19
   3.1, as published by the Free Software Foundation.
18
   3.1, as published by the Free Software Foundation.
20
 
19
 
21
   You should have received a copy of the GNU General Public License and
20
   You should have received a copy of the GNU General Public License and
22
   a copy of the GCC Runtime Library Exception along with this program;
21
   a copy of the GCC Runtime Library Exception along with this program;
23
   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
22
   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
   .  */
23
   .  */
25
 
24
 
26
#include "tconfig.h"
25
#include "tconfig.h"
27
#include "tsystem.h"
26
#include "tsystem.h"
28
#include "coretypes.h"
27
#include "coretypes.h"
29
#include "tm.h"
28
#include "tm.h"
30
#include "dwarf2.h"
29
#include "dwarf2.h"
31
#include "unwind.h"
30
#include "unwind.h"
32
#ifdef __USING_SJLJ_EXCEPTIONS__
31
#ifdef __USING_SJLJ_EXCEPTIONS__
33
# define NO_SIZE_OF_ENCODED_VALUE
32
# define NO_SIZE_OF_ENCODED_VALUE
34
#endif
33
#endif
35
#include "unwind-pe.h"
34
#include "unwind-pe.h"
36
#include "unwind-dw2-fde.h"
35
#include "unwind-dw2-fde.h"
37
#include "gthr.h"
36
#include "gthr.h"
38
#include "unwind-dw2.h"
37
#include "unwind-dw2.h"
39
 
38
 
40
#ifndef __USING_SJLJ_EXCEPTIONS__
39
#ifndef __USING_SJLJ_EXCEPTIONS__
41
 
40
 
42
#ifndef STACK_GROWS_DOWNWARD
41
#ifndef STACK_GROWS_DOWNWARD
43
#define STACK_GROWS_DOWNWARD 0
42
#define STACK_GROWS_DOWNWARD 0
44
#else
43
#else
45
#undef STACK_GROWS_DOWNWARD
44
#undef STACK_GROWS_DOWNWARD
46
#define STACK_GROWS_DOWNWARD 1
45
#define STACK_GROWS_DOWNWARD 1
47
#endif
46
#endif
48
 
47
 
49
/* Dwarf frame registers used for pre gcc 3.0 compiled glibc.  */
48
/* Dwarf frame registers used for pre gcc 3.0 compiled glibc.  */
50
#ifndef PRE_GCC3_DWARF_FRAME_REGISTERS
49
#ifndef PRE_GCC3_DWARF_FRAME_REGISTERS
51
#define PRE_GCC3_DWARF_FRAME_REGISTERS DWARF_FRAME_REGISTERS
50
#define PRE_GCC3_DWARF_FRAME_REGISTERS DWARF_FRAME_REGISTERS
52
#endif
51
#endif
53
 
52
 
54
#ifndef DWARF_REG_TO_UNWIND_COLUMN
53
#ifndef DWARF_REG_TO_UNWIND_COLUMN
55
#define DWARF_REG_TO_UNWIND_COLUMN(REGNO) (REGNO)
54
#define DWARF_REG_TO_UNWIND_COLUMN(REGNO) (REGNO)
56
#endif
55
#endif
-
 
56
 
-
 
57
/* ??? For the public function interfaces, we tend to gcc_assert that the
-
 
58
   column numbers are in range.  For the dwarf2 unwind info this does happen,
-
 
59
   although so far in a case that doesn't actually matter.
-
 
60
 
-
 
61
   See PR49146, in which a call from x86_64 ms abi to x86_64 unix abi stores
-
 
62
   the call-saved xmm registers and annotates them.  We havn't bothered
-
 
63
   providing support for the xmm registers for the x86_64 port primarily
-
 
64
   because the 64-bit windows targets don't use dwarf2 unwind, using sjlj or
-
 
65
   SEH instead.  Adding the support for unix targets would generally be a
-
 
66
   waste.  However, some runtime libraries supplied with ICC do contain such
-
 
67
   an unorthodox transition, as well as the unwind info to match.  This loss
-
 
68
   of register restoration doesn't matter in practice, because the exception
-
 
69
   is caught in the native unix abi, where all of the xmm registers are 
-
 
70
   call clobbered.
-
 
71
 
-
 
72
   Ideally, we'd record some bit to notice when we're failing to restore some
-
 
73
   register recorded in the unwind info, but to do that we need annotation on
-
 
74
   the unix->ms abi edge, so that we know when the register data may be
-
 
75
   discarded.  And since this edge is also within the ICC library, we're
-
 
76
   unlikely to be able to get the new annotation.
-
 
77
 
-
 
78
   Barring a magic solution to restore the ms abi defined 128-bit xmm registers
-
 
79
   (as distictly opposed to the full runtime width) without causing extra
-
 
80
   overhead for normal unix abis, the best solution seems to be to simply
-
 
81
   ignore unwind data for unknown columns.  */
-
 
82
 
-
 
83
#define UNWIND_COLUMN_IN_RANGE(x) \
-
 
84
    __builtin_expect((x) <= DWARF_FRAME_REGISTERS, 1)
-
 
85
 
-
 
86
#ifdef REG_VALUE_IN_UNWIND_CONTEXT
-
 
87
typedef _Unwind_Word _Unwind_Context_Reg_Val;
-
 
88
 
-
 
89
#ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
-
 
90
#define ASSUME_EXTENDED_UNWIND_CONTEXT 1
-
 
91
#endif
-
 
92
 
-
 
93
static inline _Unwind_Word
-
 
94
_Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
-
 
95
{
-
 
96
  return val;
-
 
97
}
-
 
98
 
-
 
99
static inline _Unwind_Context_Reg_Val
-
 
100
_Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
-
 
101
{
-
 
102
  return val;
-
 
103
}
-
 
104
#else
-
 
105
typedef void *_Unwind_Context_Reg_Val;
-
 
106
 
-
 
107
static inline _Unwind_Word
-
 
108
_Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
-
 
109
{
-
 
110
  return (_Unwind_Word) (_Unwind_Internal_Ptr) val;
-
 
111
}
-
 
112
 
-
 
113
static inline _Unwind_Context_Reg_Val
-
 
114
_Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
-
 
115
{
-
 
116
  return (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) val;
-
 
117
}
-
 
118
#endif
-
 
119
 
-
 
120
#ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
-
 
121
#define ASSUME_EXTENDED_UNWIND_CONTEXT 0
-
 
122
#endif
57
 
123
 
58
/* This is the register and unwind state for a particular frame.  This
124
/* This is the register and unwind state for a particular frame.  This
59
   provides the information necessary to unwind up past a frame and return
125
   provides the information necessary to unwind up past a frame and return
60
   to its caller.  */
126
   to its caller.  */
61
struct _Unwind_Context
127
struct _Unwind_Context
62
{
128
{
63
  void *reg[DWARF_FRAME_REGISTERS+1];
129
  _Unwind_Context_Reg_Val reg[DWARF_FRAME_REGISTERS+1];
64
  void *cfa;
130
  void *cfa;
65
  void *ra;
131
  void *ra;
66
  void *lsda;
132
  void *lsda;
67
  struct dwarf_eh_bases bases;
133
  struct dwarf_eh_bases bases;
68
  /* Signal frame context.  */
134
  /* Signal frame context.  */
69
#define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1)
135
#define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1)
70
  /* Context which has version/args_size/by_value fields.  */
136
  /* Context which has version/args_size/by_value fields.  */
71
#define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1)
137
#define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1)
72
  _Unwind_Word flags;
138
  _Unwind_Word flags;
73
  /* 0 for now, can be increased when further fields are added to
139
  /* 0 for now, can be increased when further fields are added to
74
     struct _Unwind_Context.  */
140
     struct _Unwind_Context.  */
75
  _Unwind_Word version;
141
  _Unwind_Word version;
76
  _Unwind_Word args_size;
142
  _Unwind_Word args_size;
77
  char by_value[DWARF_FRAME_REGISTERS+1];
143
  char by_value[DWARF_FRAME_REGISTERS+1];
78
};
144
};
79
 
145
 
80
/* Byte size of every register managed by these routines.  */
146
/* Byte size of every register managed by these routines.  */
81
static unsigned char dwarf_reg_size_table[DWARF_FRAME_REGISTERS+1];
147
static unsigned char dwarf_reg_size_table[DWARF_FRAME_REGISTERS+1];
82
 
148
 
83

149

84
/* Read unaligned data from the instruction buffer.  */
150
/* Read unaligned data from the instruction buffer.  */
85
 
151
 
86
union unaligned
152
union unaligned
87
{
153
{
88
  void *p;
154
  void *p;
89
  unsigned u2 __attribute__ ((mode (HI)));
155
  unsigned u2 __attribute__ ((mode (HI)));
90
  unsigned u4 __attribute__ ((mode (SI)));
156
  unsigned u4 __attribute__ ((mode (SI)));
91
  unsigned u8 __attribute__ ((mode (DI)));
157
  unsigned u8 __attribute__ ((mode (DI)));
92
  signed s2 __attribute__ ((mode (HI)));
158
  signed s2 __attribute__ ((mode (HI)));
93
  signed s4 __attribute__ ((mode (SI)));
159
  signed s4 __attribute__ ((mode (SI)));
94
  signed s8 __attribute__ ((mode (DI)));
160
  signed s8 __attribute__ ((mode (DI)));
95
} __attribute__ ((packed));
161
} __attribute__ ((packed));
96
 
162
 
97
static void uw_update_context (struct _Unwind_Context *, _Unwind_FrameState *);
163
static void uw_update_context (struct _Unwind_Context *, _Unwind_FrameState *);
98
static _Unwind_Reason_Code uw_frame_state_for (struct _Unwind_Context *,
164
static _Unwind_Reason_Code uw_frame_state_for (struct _Unwind_Context *,
99
					       _Unwind_FrameState *);
165
					       _Unwind_FrameState *);
100
 
166
 
101
static inline void *
167
static inline void *
102
read_pointer (const void *p) { const union unaligned *up = p; return up->p; }
168
read_pointer (const void *p) { const union unaligned *up = p; return up->p; }
103
 
169
 
104
static inline int
170
static inline int
105
read_1u (const void *p) { return *(const unsigned char *) p; }
171
read_1u (const void *p) { return *(const unsigned char *) p; }
106
 
172
 
107
static inline int
173
static inline int
108
read_1s (const void *p) { return *(const signed char *) p; }
174
read_1s (const void *p) { return *(const signed char *) p; }
109
 
175
 
110
static inline int
176
static inline int
111
read_2u (const void *p) { const union unaligned *up = p; return up->u2; }
177
read_2u (const void *p) { const union unaligned *up = p; return up->u2; }
112
 
178
 
113
static inline int
179
static inline int
114
read_2s (const void *p) { const union unaligned *up = p; return up->s2; }
180
read_2s (const void *p) { const union unaligned *up = p; return up->s2; }
115
 
181
 
116
static inline unsigned int
182
static inline unsigned int
117
read_4u (const void *p) { const union unaligned *up = p; return up->u4; }
183
read_4u (const void *p) { const union unaligned *up = p; return up->u4; }
118
 
184
 
119
static inline int
185
static inline int
120
read_4s (const void *p) { const union unaligned *up = p; return up->s4; }
186
read_4s (const void *p) { const union unaligned *up = p; return up->s4; }
121
 
187
 
122
static inline unsigned long
188
static inline unsigned long
123
read_8u (const void *p) { const union unaligned *up = p; return up->u8; }
189
read_8u (const void *p) { const union unaligned *up = p; return up->u8; }
124
 
190
 
125
static inline unsigned long
191
static inline unsigned long
126
read_8s (const void *p) { const union unaligned *up = p; return up->s8; }
192
read_8s (const void *p) { const union unaligned *up = p; return up->s8; }
127

193

128
static inline _Unwind_Word
194
static inline _Unwind_Word
129
_Unwind_IsSignalFrame (struct _Unwind_Context *context)
195
_Unwind_IsSignalFrame (struct _Unwind_Context *context)
130
{
196
{
131
  return (context->flags & SIGNAL_FRAME_BIT) ? 1 : 0;
197
  return (context->flags & SIGNAL_FRAME_BIT) ? 1 : 0;
132
}
198
}
133
 
199
 
134
static inline void
200
static inline void
135
_Unwind_SetSignalFrame (struct _Unwind_Context *context, int val)
201
_Unwind_SetSignalFrame (struct _Unwind_Context *context, int val)
136
{
202
{
137
  if (val)
203
  if (val)
138
    context->flags |= SIGNAL_FRAME_BIT;
204
    context->flags |= SIGNAL_FRAME_BIT;
139
  else
205
  else
140
    context->flags &= ~SIGNAL_FRAME_BIT;
206
    context->flags &= ~SIGNAL_FRAME_BIT;
141
}
207
}
142
 
208
 
143
static inline _Unwind_Word
209
static inline _Unwind_Word
144
_Unwind_IsExtendedContext (struct _Unwind_Context *context)
210
_Unwind_IsExtendedContext (struct _Unwind_Context *context)
145
{
211
{
-
 
212
  return (ASSUME_EXTENDED_UNWIND_CONTEXT
146
  return context->flags & EXTENDED_CONTEXT_BIT;
213
	  || (context->flags & EXTENDED_CONTEXT_BIT));
147
}
214
}
148

215

149
/* Get the value of register INDEX as saved in CONTEXT.  */
216
/* Get the value of register INDEX as saved in CONTEXT.  */
150
 
217
 
151
inline _Unwind_Word
218
inline _Unwind_Word
152
_Unwind_GetGR (struct _Unwind_Context *context, int index)
219
_Unwind_GetGR (struct _Unwind_Context *context, int index)
153
{
220
{
154
  int size;
221
  int size;
155
  void *ptr;
222
  _Unwind_Context_Reg_Val val;
156
 
223
 
157
#ifdef DWARF_ZERO_REG
224
#ifdef DWARF_ZERO_REG
158
  if (index == DWARF_ZERO_REG)
225
  if (index == DWARF_ZERO_REG)
159
    return 0;
226
    return 0;
160
#endif
227
#endif
161
 
228
 
162
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
229
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
163
  gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
230
  gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
164
  size = dwarf_reg_size_table[index];
231
  size = dwarf_reg_size_table[index];
165
  ptr = context->reg[index];
232
  val = context->reg[index];
166
 
233
 
167
  if (_Unwind_IsExtendedContext (context) && context->by_value[index])
234
  if (_Unwind_IsExtendedContext (context) && context->by_value[index])
168
    return (_Unwind_Word) (_Unwind_Internal_Ptr) ptr;
235
    return _Unwind_Get_Unwind_Word (val);
169
 
236
 
170
  /* This will segfault if the register hasn't been saved.  */
237
  /* This will segfault if the register hasn't been saved.  */
171
  if (size == sizeof(_Unwind_Ptr))
238
  if (size == sizeof(_Unwind_Ptr))
172
    return * (_Unwind_Ptr *) ptr;
239
    return * (_Unwind_Ptr *) (_Unwind_Internal_Ptr) val;
173
  else
240
  else
174
    {
241
    {
175
      gcc_assert (size == sizeof(_Unwind_Word));
242
      gcc_assert (size == sizeof(_Unwind_Word));
176
      return * (_Unwind_Word *) ptr;
243
      return * (_Unwind_Word *) (_Unwind_Internal_Ptr) val;
177
    }
244
    }
178
}
245
}
179
 
246
 
180
static inline void *
247
static inline void *
181
_Unwind_GetPtr (struct _Unwind_Context *context, int index)
248
_Unwind_GetPtr (struct _Unwind_Context *context, int index)
182
{
249
{
183
  return (void *)(_Unwind_Ptr) _Unwind_GetGR (context, index);
250
  return (void *)(_Unwind_Ptr) _Unwind_GetGR (context, index);
184
}
251
}
185
 
252
 
186
/* Get the value of the CFA as saved in CONTEXT.  */
253
/* Get the value of the CFA as saved in CONTEXT.  */
187
 
254
 
188
_Unwind_Word
255
_Unwind_Word
189
_Unwind_GetCFA (struct _Unwind_Context *context)
256
_Unwind_GetCFA (struct _Unwind_Context *context)
190
{
257
{
191
  return (_Unwind_Ptr) context->cfa;
258
  return (_Unwind_Ptr) context->cfa;
192
}
259
}
193
 
260
 
194
/* Overwrite the saved value for register INDEX in CONTEXT with VAL.  */
261
/* Overwrite the saved value for register INDEX in CONTEXT with VAL.  */
195
 
262
 
196
inline void
263
inline void
197
_Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
264
_Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
198
{
265
{
199
  int size;
266
  int size;
200
  void *ptr;
267
  void *ptr;
201
 
268
 
202
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
269
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
203
  gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
270
  gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
204
  size = dwarf_reg_size_table[index];
271
  size = dwarf_reg_size_table[index];
205
 
272
 
206
  if (_Unwind_IsExtendedContext (context) && context->by_value[index])
273
  if (_Unwind_IsExtendedContext (context) && context->by_value[index])
207
    {
274
    {
208
      context->reg[index] = (void *) (_Unwind_Internal_Ptr) val;
275
      context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
209
      return;
276
      return;
210
    }
277
    }
211
 
278
 
212
  ptr = context->reg[index];
279
  ptr = (void *) (_Unwind_Internal_Ptr) context->reg[index];
213
 
280
 
214
  if (size == sizeof(_Unwind_Ptr))
281
  if (size == sizeof(_Unwind_Ptr))
215
    * (_Unwind_Ptr *) ptr = val;
282
    * (_Unwind_Ptr *) ptr = val;
216
  else
283
  else
217
    {
284
    {
218
      gcc_assert (size == sizeof(_Unwind_Word));
285
      gcc_assert (size == sizeof(_Unwind_Word));
219
      * (_Unwind_Word *) ptr = val;
286
      * (_Unwind_Word *) ptr = val;
220
    }
287
    }
221
}
288
}
222
 
289
 
223
/* Get the pointer to a register INDEX as saved in CONTEXT.  */
290
/* Get the pointer to a register INDEX as saved in CONTEXT.  */
224
 
291
 
225
static inline void *
292
static inline void *
226
_Unwind_GetGRPtr (struct _Unwind_Context *context, int index)
293
_Unwind_GetGRPtr (struct _Unwind_Context *context, int index)
227
{
294
{
228
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
295
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
229
  if (_Unwind_IsExtendedContext (context) && context->by_value[index])
296
  if (_Unwind_IsExtendedContext (context) && context->by_value[index])
230
    return &context->reg[index];
297
    return &context->reg[index];
231
  return context->reg[index];
298
  return (void *) (_Unwind_Internal_Ptr) context->reg[index];
232
}
299
}
233
 
300
 
234
/* Set the pointer to a register INDEX as saved in CONTEXT.  */
301
/* Set the pointer to a register INDEX as saved in CONTEXT.  */
235
 
302
 
236
static inline void
303
static inline void
237
_Unwind_SetGRPtr (struct _Unwind_Context *context, int index, void *p)
304
_Unwind_SetGRPtr (struct _Unwind_Context *context, int index, void *p)
238
{
305
{
239
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
306
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
240
  if (_Unwind_IsExtendedContext (context))
307
  if (_Unwind_IsExtendedContext (context))
241
    context->by_value[index] = 0;
308
    context->by_value[index] = 0;
242
  context->reg[index] = p;
309
  context->reg[index] = (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) p;
243
}
310
}
244
 
311
 
245
/* Overwrite the saved value for register INDEX in CONTEXT with VAL.  */
312
/* Overwrite the saved value for register INDEX in CONTEXT with VAL.  */
246
 
313
 
247
static inline void
314
static inline void
248
_Unwind_SetGRValue (struct _Unwind_Context *context, int index,
315
_Unwind_SetGRValue (struct _Unwind_Context *context, int index,
249
		    _Unwind_Word val)
316
		    _Unwind_Word val)
250
{
317
{
251
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
318
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
252
  gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
319
  gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
-
 
320
  /* Return column size may be smaller than _Unwind_Context_Reg_Val.  */
253
  gcc_assert (dwarf_reg_size_table[index] == sizeof (_Unwind_Ptr));
321
  gcc_assert (dwarf_reg_size_table[index] <= sizeof (_Unwind_Context_Reg_Val));
254
 
322
 
255
  context->by_value[index] = 1;
323
  context->by_value[index] = 1;
256
  context->reg[index] = (void *) (_Unwind_Internal_Ptr) val;
324
  context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
257
}
325
}
258
 
326
 
259
/* Return nonzero if register INDEX is stored by value rather than
327
/* Return nonzero if register INDEX is stored by value rather than
260
   by reference.  */
328
   by reference.  */
261
 
329
 
262
static inline int
330
static inline int
263
_Unwind_GRByValue (struct _Unwind_Context *context, int index)
331
_Unwind_GRByValue (struct _Unwind_Context *context, int index)
264
{
332
{
265
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
333
  index = DWARF_REG_TO_UNWIND_COLUMN (index);
266
  return context->by_value[index];
334
  return context->by_value[index];
267
}
335
}
268
 
336
 
269
/* Retrieve the return address for CONTEXT.  */
337
/* Retrieve the return address for CONTEXT.  */
270
 
338
 
271
inline _Unwind_Ptr
339
inline _Unwind_Ptr
272
_Unwind_GetIP (struct _Unwind_Context *context)
340
_Unwind_GetIP (struct _Unwind_Context *context)
273
{
341
{
274
  return (_Unwind_Ptr) context->ra;
342
  return (_Unwind_Ptr) context->ra;
275
}
343
}
276
 
344
 
277
/* Retrieve the return address and flag whether that IP is before
345
/* Retrieve the return address and flag whether that IP is before
278
   or after first not yet fully executed instruction.  */
346
   or after first not yet fully executed instruction.  */
279
 
347
 
280
inline _Unwind_Ptr
348
inline _Unwind_Ptr
281
_Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
349
_Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
282
{
350
{
283
  *ip_before_insn = _Unwind_IsSignalFrame (context);
351
  *ip_before_insn = _Unwind_IsSignalFrame (context);
284
  return (_Unwind_Ptr) context->ra;
352
  return (_Unwind_Ptr) context->ra;
285
}
353
}
286
 
354
 
287
/* Overwrite the return address for CONTEXT with VAL.  */
355
/* Overwrite the return address for CONTEXT with VAL.  */
288
 
356
 
289
inline void
357
inline void
290
_Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
358
_Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
291
{
359
{
292
  context->ra = (void *) val;
360
  context->ra = (void *) val;
293
}
361
}
294
 
362
 
295
void *
363
void *
296
_Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
364
_Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
297
{
365
{
298
  return context->lsda;
366
  return context->lsda;
299
}
367
}
300
 
368
 
301
_Unwind_Ptr
369
_Unwind_Ptr
302
_Unwind_GetRegionStart (struct _Unwind_Context *context)
370
_Unwind_GetRegionStart (struct _Unwind_Context *context)
303
{
371
{
304
  return (_Unwind_Ptr) context->bases.func;
372
  return (_Unwind_Ptr) context->bases.func;
305
}
373
}
306
 
374
 
307
void *
375
void *
308
_Unwind_FindEnclosingFunction (void *pc)
376
_Unwind_FindEnclosingFunction (void *pc)
309
{
377
{
310
  struct dwarf_eh_bases bases;
378
  struct dwarf_eh_bases bases;
311
  const struct dwarf_fde *fde = _Unwind_Find_FDE (pc-1, &bases);
379
  const struct dwarf_fde *fde = _Unwind_Find_FDE (pc-1, &bases);
312
  if (fde)
380
  if (fde)
313
    return bases.func;
381
    return bases.func;
314
  else
382
  else
315
    return NULL;
383
    return NULL;
316
}
384
}
317
 
385
 
318
#ifndef __ia64__
386
#ifndef __ia64__
319
_Unwind_Ptr
387
_Unwind_Ptr
320
_Unwind_GetDataRelBase (struct _Unwind_Context *context)
388
_Unwind_GetDataRelBase (struct _Unwind_Context *context)
321
{
389
{
322
  return (_Unwind_Ptr) context->bases.dbase;
390
  return (_Unwind_Ptr) context->bases.dbase;
323
}
391
}
324
 
392
 
325
_Unwind_Ptr
393
_Unwind_Ptr
326
_Unwind_GetTextRelBase (struct _Unwind_Context *context)
394
_Unwind_GetTextRelBase (struct _Unwind_Context *context)
327
{
395
{
328
  return (_Unwind_Ptr) context->bases.tbase;
396
  return (_Unwind_Ptr) context->bases.tbase;
329
}
397
}
330
#endif
398
#endif
331
 
399
 
332
#ifdef MD_UNWIND_SUPPORT
400
#ifdef MD_UNWIND_SUPPORT
333
#include MD_UNWIND_SUPPORT
401
#include MD_UNWIND_SUPPORT
334
#endif
402
#endif
335

403

336
/* Extract any interesting information from the CIE for the translation
404
/* Extract any interesting information from the CIE for the translation
337
   unit F belongs to.  Return a pointer to the byte after the augmentation,
405
   unit F belongs to.  Return a pointer to the byte after the augmentation,
338
   or NULL if we encountered an undecipherable augmentation.  */
406
   or NULL if we encountered an undecipherable augmentation.  */
339
 
407
 
340
static const unsigned char *
408
static const unsigned char *
341
extract_cie_info (const struct dwarf_cie *cie, struct _Unwind_Context *context,
409
extract_cie_info (const struct dwarf_cie *cie, struct _Unwind_Context *context,
342
		  _Unwind_FrameState *fs)
410
		  _Unwind_FrameState *fs)
343
{
411
{
344
  const unsigned char *aug = cie->augmentation;
412
  const unsigned char *aug = cie->augmentation;
345
  const unsigned char *p = aug + strlen ((const char *)aug) + 1;
413
  const unsigned char *p = aug + strlen ((const char *)aug) + 1;
346
  const unsigned char *ret = NULL;
414
  const unsigned char *ret = NULL;
347
  _uleb128_t utmp;
415
  _uleb128_t utmp;
348
  _sleb128_t stmp;
416
  _sleb128_t stmp;
349
 
417
 
350
  /* g++ v2 "eh" has pointer immediately following augmentation string,
418
  /* g++ v2 "eh" has pointer immediately following augmentation string,
351
     so it must be handled first.  */
419
     so it must be handled first.  */
352
  if (aug[0] == 'e' && aug[1] == 'h')
420
  if (aug[0] == 'e' && aug[1] == 'h')
353
    {
421
    {
354
      fs->eh_ptr = read_pointer (p);
422
      fs->eh_ptr = read_pointer (p);
355
      p += sizeof (void *);
423
      p += sizeof (void *);
356
      aug += 2;
424
      aug += 2;
357
    }
425
    }
-
 
426
 
-
 
427
  /* After the augmentation resp. pointer for "eh" augmentation
-
 
428
     follows for CIE version >= 4 address size byte and
-
 
429
     segment size byte.  */
-
 
430
  if (__builtin_expect (cie->version >= 4, 0))
-
 
431
    {
-
 
432
      if (p[0] != sizeof (void *) || p[1] != 0)
-
 
433
	return NULL;
-
 
434
      p += 2;
358
 
435
    }
359
  /* Immediately following the augmentation are the code and
436
  /* Immediately following this are the code and
360
     data alignment and return address column.  */
437
     data alignment and return address column.  */
361
  p = read_uleb128 (p, &utmp);
438
  p = read_uleb128 (p, &utmp);
362
  fs->code_align = (_Unwind_Word)utmp;
439
  fs->code_align = (_Unwind_Word)utmp;
363
  p = read_sleb128 (p, &stmp);
440
  p = read_sleb128 (p, &stmp);
364
  fs->data_align = (_Unwind_Sword)stmp;
441
  fs->data_align = (_Unwind_Sword)stmp;
365
  if (cie->version == 1)
442
  if (cie->version == 1)
366
    fs->retaddr_column = *p++;
443
    fs->retaddr_column = *p++;
367
  else
444
  else
368
    {
445
    {
369
      p = read_uleb128 (p, &utmp);
446
      p = read_uleb128 (p, &utmp);
370
      fs->retaddr_column = (_Unwind_Word)utmp;
447
      fs->retaddr_column = (_Unwind_Word)utmp;
371
    }
448
    }
372
  fs->lsda_encoding = DW_EH_PE_omit;
449
  fs->lsda_encoding = DW_EH_PE_omit;
373
 
450
 
374
  /* If the augmentation starts with 'z', then a uleb128 immediately
451
  /* If the augmentation starts with 'z', then a uleb128 immediately
375
     follows containing the length of the augmentation field following
452
     follows containing the length of the augmentation field following
376
     the size.  */
453
     the size.  */
377
  if (*aug == 'z')
454
  if (*aug == 'z')
378
    {
455
    {
379
      p = read_uleb128 (p, &utmp);
456
      p = read_uleb128 (p, &utmp);
380
      ret = p + utmp;
457
      ret = p + utmp;
381
 
458
 
382
      fs->saw_z = 1;
459
      fs->saw_z = 1;
383
      ++aug;
460
      ++aug;
384
    }
461
    }
385
 
462
 
386
  /* Iterate over recognized augmentation subsequences.  */
463
  /* Iterate over recognized augmentation subsequences.  */
387
  while (*aug != '\0')
464
  while (*aug != '\0')
388
    {
465
    {
389
      /* "L" indicates a byte showing how the LSDA pointer is encoded.  */
466
      /* "L" indicates a byte showing how the LSDA pointer is encoded.  */
390
      if (aug[0] == 'L')
467
      if (aug[0] == 'L')
391
	{
468
	{
392
	  fs->lsda_encoding = *p++;
469
	  fs->lsda_encoding = *p++;
393
	  aug += 1;
470
	  aug += 1;
394
	}
471
	}
395
 
472
 
396
      /* "R" indicates a byte indicating how FDE addresses are encoded.  */
473
      /* "R" indicates a byte indicating how FDE addresses are encoded.  */
397
      else if (aug[0] == 'R')
474
      else if (aug[0] == 'R')
398
	{
475
	{
399
	  fs->fde_encoding = *p++;
476
	  fs->fde_encoding = *p++;
400
	  aug += 1;
477
	  aug += 1;
401
	}
478
	}
402
 
479
 
403
      /* "P" indicates a personality routine in the CIE augmentation.  */
480
      /* "P" indicates a personality routine in the CIE augmentation.  */
404
      else if (aug[0] == 'P')
481
      else if (aug[0] == 'P')
405
	{
482
	{
406
	  _Unwind_Ptr personality;
483
	  _Unwind_Ptr personality;
407
 
484
 
408
	  p = read_encoded_value (context, *p, p + 1, &personality);
485
	  p = read_encoded_value (context, *p, p + 1, &personality);
409
	  fs->personality = (_Unwind_Personality_Fn) personality;
486
	  fs->personality = (_Unwind_Personality_Fn) personality;
410
	  aug += 1;
487
	  aug += 1;
411
	}
488
	}
412
 
489
 
413
      /* "S" indicates a signal frame.  */
490
      /* "S" indicates a signal frame.  */
414
      else if (aug[0] == 'S')
491
      else if (aug[0] == 'S')
415
	{
492
	{
416
	  fs->signal_frame = 1;
493
	  fs->signal_frame = 1;
417
	  aug += 1;
494
	  aug += 1;
418
	}
495
	}
419
 
496
 
420
      /* Otherwise we have an unknown augmentation string.
497
      /* Otherwise we have an unknown augmentation string.
421
	 Bail unless we saw a 'z' prefix.  */
498
	 Bail unless we saw a 'z' prefix.  */
422
      else
499
      else
423
	return ret;
500
	return ret;
424
    }
501
    }
425
 
502
 
426
  return ret ? ret : p;
503
  return ret ? ret : p;
427
}
504
}
428
 
505
 
429
 
506
 
430
/* Decode a DW_OP stack program.  Return the top of stack.  Push INITIAL
507
/* Decode a DW_OP stack program.  Return the top of stack.  Push INITIAL
431
   onto the stack to start.  */
508
   onto the stack to start.  */
432
 
509
 
433
static _Unwind_Word
510
static _Unwind_Word
434
execute_stack_op (const unsigned char *op_ptr, const unsigned char *op_end,
511
execute_stack_op (const unsigned char *op_ptr, const unsigned char *op_end,
435
		  struct _Unwind_Context *context, _Unwind_Word initial)
512
		  struct _Unwind_Context *context, _Unwind_Word initial)
436
{
513
{
437
  _Unwind_Word stack[64];	/* ??? Assume this is enough.  */
514
  _Unwind_Word stack[64];	/* ??? Assume this is enough.  */
438
  int stack_elt;
515
  int stack_elt;
439
 
516
 
440
  stack[0] = initial;
517
  stack[0] = initial;
441
  stack_elt = 1;
518
  stack_elt = 1;
442
 
519
 
443
  while (op_ptr < op_end)
520
  while (op_ptr < op_end)
444
    {
521
    {
445
      enum dwarf_location_atom op = *op_ptr++;
522
      enum dwarf_location_atom op = *op_ptr++;
446
      _Unwind_Word result;
523
      _Unwind_Word result;
447
      _uleb128_t reg, utmp;
524
      _uleb128_t reg, utmp;
448
      _sleb128_t offset, stmp;
525
      _sleb128_t offset, stmp;
449
 
526
 
450
      switch (op)
527
      switch (op)
451
	{
528
	{
452
	case DW_OP_lit0:
529
	case DW_OP_lit0:
453
	case DW_OP_lit1:
530
	case DW_OP_lit1:
454
	case DW_OP_lit2:
531
	case DW_OP_lit2:
455
	case DW_OP_lit3:
532
	case DW_OP_lit3:
456
	case DW_OP_lit4:
533
	case DW_OP_lit4:
457
	case DW_OP_lit5:
534
	case DW_OP_lit5:
458
	case DW_OP_lit6:
535
	case DW_OP_lit6:
459
	case DW_OP_lit7:
536
	case DW_OP_lit7:
460
	case DW_OP_lit8:
537
	case DW_OP_lit8:
461
	case DW_OP_lit9:
538
	case DW_OP_lit9:
462
	case DW_OP_lit10:
539
	case DW_OP_lit10:
463
	case DW_OP_lit11:
540
	case DW_OP_lit11:
464
	case DW_OP_lit12:
541
	case DW_OP_lit12:
465
	case DW_OP_lit13:
542
	case DW_OP_lit13:
466
	case DW_OP_lit14:
543
	case DW_OP_lit14:
467
	case DW_OP_lit15:
544
	case DW_OP_lit15:
468
	case DW_OP_lit16:
545
	case DW_OP_lit16:
469
	case DW_OP_lit17:
546
	case DW_OP_lit17:
470
	case DW_OP_lit18:
547
	case DW_OP_lit18:
471
	case DW_OP_lit19:
548
	case DW_OP_lit19:
472
	case DW_OP_lit20:
549
	case DW_OP_lit20:
473
	case DW_OP_lit21:
550
	case DW_OP_lit21:
474
	case DW_OP_lit22:
551
	case DW_OP_lit22:
475
	case DW_OP_lit23:
552
	case DW_OP_lit23:
476
	case DW_OP_lit24:
553
	case DW_OP_lit24:
477
	case DW_OP_lit25:
554
	case DW_OP_lit25:
478
	case DW_OP_lit26:
555
	case DW_OP_lit26:
479
	case DW_OP_lit27:
556
	case DW_OP_lit27:
480
	case DW_OP_lit28:
557
	case DW_OP_lit28:
481
	case DW_OP_lit29:
558
	case DW_OP_lit29:
482
	case DW_OP_lit30:
559
	case DW_OP_lit30:
483
	case DW_OP_lit31:
560
	case DW_OP_lit31:
484
	  result = op - DW_OP_lit0;
561
	  result = op - DW_OP_lit0;
485
	  break;
562
	  break;
486
 
563
 
487
	case DW_OP_addr:
564
	case DW_OP_addr:
488
	  result = (_Unwind_Word) (_Unwind_Ptr) read_pointer (op_ptr);
565
	  result = (_Unwind_Word) (_Unwind_Ptr) read_pointer (op_ptr);
489
	  op_ptr += sizeof (void *);
566
	  op_ptr += sizeof (void *);
490
	  break;
567
	  break;
491
 
568
 
492
	case DW_OP_GNU_encoded_addr:
569
	case DW_OP_GNU_encoded_addr:
493
	  {
570
	  {
494
	    _Unwind_Ptr presult;
571
	    _Unwind_Ptr presult;
495
	    op_ptr = read_encoded_value (context, *op_ptr, op_ptr+1, &presult);
572
	    op_ptr = read_encoded_value (context, *op_ptr, op_ptr+1, &presult);
496
	    result = presult;
573
	    result = presult;
497
	  }
574
	  }
498
	  break;
575
	  break;
499
 
576
 
500
	case DW_OP_const1u:
577
	case DW_OP_const1u:
501
	  result = read_1u (op_ptr);
578
	  result = read_1u (op_ptr);
502
	  op_ptr += 1;
579
	  op_ptr += 1;
503
	  break;
580
	  break;
504
	case DW_OP_const1s:
581
	case DW_OP_const1s:
505
	  result = read_1s (op_ptr);
582
	  result = read_1s (op_ptr);
506
	  op_ptr += 1;
583
	  op_ptr += 1;
507
	  break;
584
	  break;
508
	case DW_OP_const2u:
585
	case DW_OP_const2u:
509
	  result = read_2u (op_ptr);
586
	  result = read_2u (op_ptr);
510
	  op_ptr += 2;
587
	  op_ptr += 2;
511
	  break;
588
	  break;
512
	case DW_OP_const2s:
589
	case DW_OP_const2s:
513
	  result = read_2s (op_ptr);
590
	  result = read_2s (op_ptr);
514
	  op_ptr += 2;
591
	  op_ptr += 2;
515
	  break;
592
	  break;
516
	case DW_OP_const4u:
593
	case DW_OP_const4u:
517
	  result = read_4u (op_ptr);
594
	  result = read_4u (op_ptr);
518
	  op_ptr += 4;
595
	  op_ptr += 4;
519
	  break;
596
	  break;
520
	case DW_OP_const4s:
597
	case DW_OP_const4s:
521
	  result = read_4s (op_ptr);
598
	  result = read_4s (op_ptr);
522
	  op_ptr += 4;
599
	  op_ptr += 4;
523
	  break;
600
	  break;
524
	case DW_OP_const8u:
601
	case DW_OP_const8u:
525
	  result = read_8u (op_ptr);
602
	  result = read_8u (op_ptr);
526
	  op_ptr += 8;
603
	  op_ptr += 8;
527
	  break;
604
	  break;
528
	case DW_OP_const8s:
605
	case DW_OP_const8s:
529
	  result = read_8s (op_ptr);
606
	  result = read_8s (op_ptr);
530
	  op_ptr += 8;
607
	  op_ptr += 8;
531
	  break;
608
	  break;
532
	case DW_OP_constu:
609
	case DW_OP_constu:
533
	  op_ptr = read_uleb128 (op_ptr, &utmp);
610
	  op_ptr = read_uleb128 (op_ptr, &utmp);
534
	  result = (_Unwind_Word)utmp;
611
	  result = (_Unwind_Word)utmp;
535
	  break;
612
	  break;
536
	case DW_OP_consts:
613
	case DW_OP_consts:
537
	  op_ptr = read_sleb128 (op_ptr, &stmp);
614
	  op_ptr = read_sleb128 (op_ptr, &stmp);
538
	  result = (_Unwind_Sword)stmp;
615
	  result = (_Unwind_Sword)stmp;
539
	  break;
616
	  break;
540
 
617
 
541
	case DW_OP_reg0:
618
	case DW_OP_reg0:
542
	case DW_OP_reg1:
619
	case DW_OP_reg1:
543
	case DW_OP_reg2:
620
	case DW_OP_reg2:
544
	case DW_OP_reg3:
621
	case DW_OP_reg3:
545
	case DW_OP_reg4:
622
	case DW_OP_reg4:
546
	case DW_OP_reg5:
623
	case DW_OP_reg5:
547
	case DW_OP_reg6:
624
	case DW_OP_reg6:
548
	case DW_OP_reg7:
625
	case DW_OP_reg7:
549
	case DW_OP_reg8:
626
	case DW_OP_reg8:
550
	case DW_OP_reg9:
627
	case DW_OP_reg9:
551
	case DW_OP_reg10:
628
	case DW_OP_reg10:
552
	case DW_OP_reg11:
629
	case DW_OP_reg11:
553
	case DW_OP_reg12:
630
	case DW_OP_reg12:
554
	case DW_OP_reg13:
631
	case DW_OP_reg13:
555
	case DW_OP_reg14:
632
	case DW_OP_reg14:
556
	case DW_OP_reg15:
633
	case DW_OP_reg15:
557
	case DW_OP_reg16:
634
	case DW_OP_reg16:
558
	case DW_OP_reg17:
635
	case DW_OP_reg17:
559
	case DW_OP_reg18:
636
	case DW_OP_reg18:
560
	case DW_OP_reg19:
637
	case DW_OP_reg19:
561
	case DW_OP_reg20:
638
	case DW_OP_reg20:
562
	case DW_OP_reg21:
639
	case DW_OP_reg21:
563
	case DW_OP_reg22:
640
	case DW_OP_reg22:
564
	case DW_OP_reg23:
641
	case DW_OP_reg23:
565
	case DW_OP_reg24:
642
	case DW_OP_reg24:
566
	case DW_OP_reg25:
643
	case DW_OP_reg25:
567
	case DW_OP_reg26:
644
	case DW_OP_reg26:
568
	case DW_OP_reg27:
645
	case DW_OP_reg27:
569
	case DW_OP_reg28:
646
	case DW_OP_reg28:
570
	case DW_OP_reg29:
647
	case DW_OP_reg29:
571
	case DW_OP_reg30:
648
	case DW_OP_reg30:
572
	case DW_OP_reg31:
649
	case DW_OP_reg31:
573
	  result = _Unwind_GetGR (context, op - DW_OP_reg0);
650
	  result = _Unwind_GetGR (context, op - DW_OP_reg0);
574
	  break;
651
	  break;
575
	case DW_OP_regx:
652
	case DW_OP_regx:
576
	  op_ptr = read_uleb128 (op_ptr, ®);
653
	  op_ptr = read_uleb128 (op_ptr, ®);
577
	  result = _Unwind_GetGR (context, reg);
654
	  result = _Unwind_GetGR (context, reg);
578
	  break;
655
	  break;
579
 
656
 
580
	case DW_OP_breg0:
657
	case DW_OP_breg0:
581
	case DW_OP_breg1:
658
	case DW_OP_breg1:
582
	case DW_OP_breg2:
659
	case DW_OP_breg2:
583
	case DW_OP_breg3:
660
	case DW_OP_breg3:
584
	case DW_OP_breg4:
661
	case DW_OP_breg4:
585
	case DW_OP_breg5:
662
	case DW_OP_breg5:
586
	case DW_OP_breg6:
663
	case DW_OP_breg6:
587
	case DW_OP_breg7:
664
	case DW_OP_breg7:
588
	case DW_OP_breg8:
665
	case DW_OP_breg8:
589
	case DW_OP_breg9:
666
	case DW_OP_breg9:
590
	case DW_OP_breg10:
667
	case DW_OP_breg10:
591
	case DW_OP_breg11:
668
	case DW_OP_breg11:
592
	case DW_OP_breg12:
669
	case DW_OP_breg12:
593
	case DW_OP_breg13:
670
	case DW_OP_breg13:
594
	case DW_OP_breg14:
671
	case DW_OP_breg14:
595
	case DW_OP_breg15:
672
	case DW_OP_breg15:
596
	case DW_OP_breg16:
673
	case DW_OP_breg16:
597
	case DW_OP_breg17:
674
	case DW_OP_breg17:
598
	case DW_OP_breg18:
675
	case DW_OP_breg18:
599
	case DW_OP_breg19:
676
	case DW_OP_breg19:
600
	case DW_OP_breg20:
677
	case DW_OP_breg20:
601
	case DW_OP_breg21:
678
	case DW_OP_breg21:
602
	case DW_OP_breg22:
679
	case DW_OP_breg22:
603
	case DW_OP_breg23:
680
	case DW_OP_breg23:
604
	case DW_OP_breg24:
681
	case DW_OP_breg24:
605
	case DW_OP_breg25:
682
	case DW_OP_breg25:
606
	case DW_OP_breg26:
683
	case DW_OP_breg26:
607
	case DW_OP_breg27:
684
	case DW_OP_breg27:
608
	case DW_OP_breg28:
685
	case DW_OP_breg28:
609
	case DW_OP_breg29:
686
	case DW_OP_breg29:
610
	case DW_OP_breg30:
687
	case DW_OP_breg30:
611
	case DW_OP_breg31:
688
	case DW_OP_breg31:
612
	  op_ptr = read_sleb128 (op_ptr, &offset);
689
	  op_ptr = read_sleb128 (op_ptr, &offset);
613
	  result = _Unwind_GetGR (context, op - DW_OP_breg0) + offset;
690
	  result = _Unwind_GetGR (context, op - DW_OP_breg0) + offset;
614
	  break;
691
	  break;
615
	case DW_OP_bregx:
692
	case DW_OP_bregx:
616
	  op_ptr = read_uleb128 (op_ptr, ®);
693
	  op_ptr = read_uleb128 (op_ptr, ®);
617
	  op_ptr = read_sleb128 (op_ptr, &offset);
694
	  op_ptr = read_sleb128 (op_ptr, &offset);
618
	  result = _Unwind_GetGR (context, reg) + (_Unwind_Word)offset;
695
	  result = _Unwind_GetGR (context, reg) + (_Unwind_Word)offset;
619
	  break;
696
	  break;
620
 
697
 
621
	case DW_OP_dup:
698
	case DW_OP_dup:
622
	  gcc_assert (stack_elt);
699
	  gcc_assert (stack_elt);
623
	  result = stack[stack_elt - 1];
700
	  result = stack[stack_elt - 1];
624
	  break;
701
	  break;
625
 
702
 
626
	case DW_OP_drop:
703
	case DW_OP_drop:
627
	  gcc_assert (stack_elt);
704
	  gcc_assert (stack_elt);
628
	  stack_elt -= 1;
705
	  stack_elt -= 1;
629
	  goto no_push;
706
	  goto no_push;
630
 
707
 
631
	case DW_OP_pick:
708
	case DW_OP_pick:
632
	  offset = *op_ptr++;
709
	  offset = *op_ptr++;
633
	  gcc_assert (offset < stack_elt - 1);
710
	  gcc_assert (offset < stack_elt - 1);
634
	  result = stack[stack_elt - 1 - offset];
711
	  result = stack[stack_elt - 1 - offset];
635
	  break;
712
	  break;
636
 
713
 
637
	case DW_OP_over:
714
	case DW_OP_over:
638
	  gcc_assert (stack_elt >= 2);
715
	  gcc_assert (stack_elt >= 2);
639
	  result = stack[stack_elt - 2];
716
	  result = stack[stack_elt - 2];
640
	  break;
717
	  break;
641
 
718
 
642
	case DW_OP_swap:
719
	case DW_OP_swap:
643
	  {
720
	  {
644
	    _Unwind_Word t;
721
	    _Unwind_Word t;
645
	    gcc_assert (stack_elt >= 2);
722
	    gcc_assert (stack_elt >= 2);
646
	    t = stack[stack_elt - 1];
723
	    t = stack[stack_elt - 1];
647
	    stack[stack_elt - 1] = stack[stack_elt - 2];
724
	    stack[stack_elt - 1] = stack[stack_elt - 2];
648
	    stack[stack_elt - 2] = t;
725
	    stack[stack_elt - 2] = t;
649
	    goto no_push;
726
	    goto no_push;
650
	  }
727
	  }
651
 
728
 
652
	case DW_OP_rot:
729
	case DW_OP_rot:
653
	  {
730
	  {
654
	    _Unwind_Word t1, t2, t3;
731
	    _Unwind_Word t1, t2, t3;
655
 
732
 
656
	    gcc_assert (stack_elt >= 3);
733
	    gcc_assert (stack_elt >= 3);
657
	    t1 = stack[stack_elt - 1];
734
	    t1 = stack[stack_elt - 1];
658
	    t2 = stack[stack_elt - 2];
735
	    t2 = stack[stack_elt - 2];
659
	    t3 = stack[stack_elt - 3];
736
	    t3 = stack[stack_elt - 3];
660
	    stack[stack_elt - 1] = t2;
737
	    stack[stack_elt - 1] = t2;
661
	    stack[stack_elt - 2] = t3;
738
	    stack[stack_elt - 2] = t3;
662
	    stack[stack_elt - 3] = t1;
739
	    stack[stack_elt - 3] = t1;
663
	    goto no_push;
740
	    goto no_push;
664
	  }
741
	  }
665
 
742
 
666
	case DW_OP_deref:
743
	case DW_OP_deref:
667
	case DW_OP_deref_size:
744
	case DW_OP_deref_size:
668
	case DW_OP_abs:
745
	case DW_OP_abs:
669
	case DW_OP_neg:
746
	case DW_OP_neg:
670
	case DW_OP_not:
747
	case DW_OP_not:
671
	case DW_OP_plus_uconst:
748
	case DW_OP_plus_uconst:
672
	  /* Unary operations.  */
749
	  /* Unary operations.  */
673
	  gcc_assert (stack_elt);
750
	  gcc_assert (stack_elt);
674
	  stack_elt -= 1;
751
	  stack_elt -= 1;
675
 
752
 
676
	  result = stack[stack_elt];
753
	  result = stack[stack_elt];
677
 
754
 
678
	  switch (op)
755
	  switch (op)
679
	    {
756
	    {
680
	    case DW_OP_deref:
757
	    case DW_OP_deref:
681
	      {
758
	      {
682
		void *ptr = (void *) (_Unwind_Ptr) result;
759
		void *ptr = (void *) (_Unwind_Ptr) result;
683
		result = (_Unwind_Ptr) read_pointer (ptr);
760
		result = (_Unwind_Ptr) read_pointer (ptr);
684
	      }
761
	      }
685
	      break;
762
	      break;
686
 
763
 
687
	    case DW_OP_deref_size:
764
	    case DW_OP_deref_size:
688
	      {
765
	      {
689
		void *ptr = (void *) (_Unwind_Ptr) result;
766
		void *ptr = (void *) (_Unwind_Ptr) result;
690
		switch (*op_ptr++)
767
		switch (*op_ptr++)
691
		  {
768
		  {
692
		  case 1:
769
		  case 1:
693
		    result = read_1u (ptr);
770
		    result = read_1u (ptr);
694
		    break;
771
		    break;
695
		  case 2:
772
		  case 2:
696
		    result = read_2u (ptr);
773
		    result = read_2u (ptr);
697
		    break;
774
		    break;
698
		  case 4:
775
		  case 4:
699
		    result = read_4u (ptr);
776
		    result = read_4u (ptr);
700
		    break;
777
		    break;
701
		  case 8:
778
		  case 8:
702
		    result = read_8u (ptr);
779
		    result = read_8u (ptr);
703
		    break;
780
		    break;
704
		  default:
781
		  default:
705
		    gcc_unreachable ();
782
		    gcc_unreachable ();
706
		  }
783
		  }
707
	      }
784
	      }
708
	      break;
785
	      break;
709
 
786
 
710
	    case DW_OP_abs:
787
	    case DW_OP_abs:
711
	      if ((_Unwind_Sword) result < 0)
788
	      if ((_Unwind_Sword) result < 0)
712
		result = -result;
789
		result = -result;
713
	      break;
790
	      break;
714
	    case DW_OP_neg:
791
	    case DW_OP_neg:
715
	      result = -result;
792
	      result = -result;
716
	      break;
793
	      break;
717
	    case DW_OP_not:
794
	    case DW_OP_not:
718
	      result = ~result;
795
	      result = ~result;
719
	      break;
796
	      break;
720
	    case DW_OP_plus_uconst:
797
	    case DW_OP_plus_uconst:
721
	      op_ptr = read_uleb128 (op_ptr, &utmp);
798
	      op_ptr = read_uleb128 (op_ptr, &utmp);
722
	      result += (_Unwind_Word)utmp;
799
	      result += (_Unwind_Word)utmp;
723
	      break;
800
	      break;
724
 
801
 
725
	    default:
802
	    default:
726
	      gcc_unreachable ();
803
	      gcc_unreachable ();
727
	    }
804
	    }
728
	  break;
805
	  break;
729
 
806
 
730
	case DW_OP_and:
807
	case DW_OP_and:
731
	case DW_OP_div:
808
	case DW_OP_div:
732
	case DW_OP_minus:
809
	case DW_OP_minus:
733
	case DW_OP_mod:
810
	case DW_OP_mod:
734
	case DW_OP_mul:
811
	case DW_OP_mul:
735
	case DW_OP_or:
812
	case DW_OP_or:
736
	case DW_OP_plus:
813
	case DW_OP_plus:
737
	case DW_OP_shl:
814
	case DW_OP_shl:
738
	case DW_OP_shr:
815
	case DW_OP_shr:
739
	case DW_OP_shra:
816
	case DW_OP_shra:
740
	case DW_OP_xor:
817
	case DW_OP_xor:
741
	case DW_OP_le:
818
	case DW_OP_le:
742
	case DW_OP_ge:
819
	case DW_OP_ge:
743
	case DW_OP_eq:
820
	case DW_OP_eq:
744
	case DW_OP_lt:
821
	case DW_OP_lt:
745
	case DW_OP_gt:
822
	case DW_OP_gt:
746
	case DW_OP_ne:
823
	case DW_OP_ne:
747
	  {
824
	  {
748
	    /* Binary operations.  */
825
	    /* Binary operations.  */
749
	    _Unwind_Word first, second;
826
	    _Unwind_Word first, second;
750
	    gcc_assert (stack_elt >= 2);
827
	    gcc_assert (stack_elt >= 2);
751
	    stack_elt -= 2;
828
	    stack_elt -= 2;
752
 
829
 
753
	    second = stack[stack_elt];
830
	    second = stack[stack_elt];
754
	    first = stack[stack_elt + 1];
831
	    first = stack[stack_elt + 1];
755
 
832
 
756
	    switch (op)
833
	    switch (op)
757
	      {
834
	      {
758
	      case DW_OP_and:
835
	      case DW_OP_and:
759
		result = second & first;
836
		result = second & first;
760
		break;
837
		break;
761
	      case DW_OP_div:
838
	      case DW_OP_div:
762
		result = (_Unwind_Sword) second / (_Unwind_Sword) first;
839
		result = (_Unwind_Sword) second / (_Unwind_Sword) first;
763
		break;
840
		break;
764
	      case DW_OP_minus:
841
	      case DW_OP_minus:
765
		result = second - first;
842
		result = second - first;
766
		break;
843
		break;
767
	      case DW_OP_mod:
844
	      case DW_OP_mod:
768
		result = second % first;
845
		result = second % first;
769
		break;
846
		break;
770
	      case DW_OP_mul:
847
	      case DW_OP_mul:
771
		result = second * first;
848
		result = second * first;
772
		break;
849
		break;
773
	      case DW_OP_or:
850
	      case DW_OP_or:
774
		result = second | first;
851
		result = second | first;
775
		break;
852
		break;
776
	      case DW_OP_plus:
853
	      case DW_OP_plus:
777
		result = second + first;
854
		result = second + first;
778
		break;
855
		break;
779
	      case DW_OP_shl:
856
	      case DW_OP_shl:
780
		result = second << first;
857
		result = second << first;
781
		break;
858
		break;
782
	      case DW_OP_shr:
859
	      case DW_OP_shr:
783
		result = second >> first;
860
		result = second >> first;
784
		break;
861
		break;
785
	      case DW_OP_shra:
862
	      case DW_OP_shra:
786
		result = (_Unwind_Sword) second >> first;
863
		result = (_Unwind_Sword) second >> first;
787
		break;
864
		break;
788
	      case DW_OP_xor:
865
	      case DW_OP_xor:
789
		result = second ^ first;
866
		result = second ^ first;
790
		break;
867
		break;
791
	      case DW_OP_le:
868
	      case DW_OP_le:
792
		result = (_Unwind_Sword) second <= (_Unwind_Sword) first;
869
		result = (_Unwind_Sword) second <= (_Unwind_Sword) first;
793
		break;
870
		break;
794
	      case DW_OP_ge:
871
	      case DW_OP_ge:
795
		result = (_Unwind_Sword) second >= (_Unwind_Sword) first;
872
		result = (_Unwind_Sword) second >= (_Unwind_Sword) first;
796
		break;
873
		break;
797
	      case DW_OP_eq:
874
	      case DW_OP_eq:
798
		result = (_Unwind_Sword) second == (_Unwind_Sword) first;
875
		result = (_Unwind_Sword) second == (_Unwind_Sword) first;
799
		break;
876
		break;
800
	      case DW_OP_lt:
877
	      case DW_OP_lt:
801
		result = (_Unwind_Sword) second < (_Unwind_Sword) first;
878
		result = (_Unwind_Sword) second < (_Unwind_Sword) first;
802
		break;
879
		break;
803
	      case DW_OP_gt:
880
	      case DW_OP_gt:
804
		result = (_Unwind_Sword) second > (_Unwind_Sword) first;
881
		result = (_Unwind_Sword) second > (_Unwind_Sword) first;
805
		break;
882
		break;
806
	      case DW_OP_ne:
883
	      case DW_OP_ne:
807
		result = (_Unwind_Sword) second != (_Unwind_Sword) first;
884
		result = (_Unwind_Sword) second != (_Unwind_Sword) first;
808
		break;
885
		break;
809
 
886
 
810
	      default:
887
	      default:
811
		gcc_unreachable ();
888
		gcc_unreachable ();
812
	      }
889
	      }
813
	  }
890
	  }
814
	  break;
891
	  break;
815
 
892
 
816
	case DW_OP_skip:
893
	case DW_OP_skip:
817
	  offset = read_2s (op_ptr);
894
	  offset = read_2s (op_ptr);
818
	  op_ptr += 2;
895
	  op_ptr += 2;
819
	  op_ptr += offset;
896
	  op_ptr += offset;
820
	  goto no_push;
897
	  goto no_push;
821
 
898
 
822
	case DW_OP_bra:
899
	case DW_OP_bra:
823
	  gcc_assert (stack_elt);
900
	  gcc_assert (stack_elt);
824
	  stack_elt -= 1;
901
	  stack_elt -= 1;
825
 
902
 
826
	  offset = read_2s (op_ptr);
903
	  offset = read_2s (op_ptr);
827
	  op_ptr += 2;
904
	  op_ptr += 2;
828
	  if (stack[stack_elt] != 0)
905
	  if (stack[stack_elt] != 0)
829
	    op_ptr += offset;
906
	    op_ptr += offset;
830
	  goto no_push;
907
	  goto no_push;
831
 
908
 
832
	case DW_OP_nop:
909
	case DW_OP_nop:
833
	  goto no_push;
910
	  goto no_push;
834
 
911
 
835
	default:
912
	default:
836
	  gcc_unreachable ();
913
	  gcc_unreachable ();
837
	}
914
	}
838
 
915
 
839
      /* Most things push a result value.  */
916
      /* Most things push a result value.  */
840
      gcc_assert ((size_t) stack_elt < sizeof(stack)/sizeof(*stack));
917
      gcc_assert ((size_t) stack_elt < sizeof(stack)/sizeof(*stack));
841
      stack[stack_elt++] = result;
918
      stack[stack_elt++] = result;
842
    no_push:;
919
    no_push:;
843
    }
920
    }
844
 
921
 
845
  /* We were executing this program to get a value.  It should be
922
  /* We were executing this program to get a value.  It should be
846
     at top of stack.  */
923
     at top of stack.  */
847
  gcc_assert (stack_elt);
924
  gcc_assert (stack_elt);
848
  stack_elt -= 1;
925
  stack_elt -= 1;
849
  return stack[stack_elt];
926
  return stack[stack_elt];
850
}
927
}
851
 
928
 
852
 
929
 
853
/* Decode DWARF 2 call frame information. Takes pointers the
930
/* Decode DWARF 2 call frame information. Takes pointers the
854
   instruction sequence to decode, current register information and
931
   instruction sequence to decode, current register information and
855
   CIE info, and the PC range to evaluate.  */
932
   CIE info, and the PC range to evaluate.  */
856
 
933
 
857
static void
934
static void
858
execute_cfa_program (const unsigned char *insn_ptr,
935
execute_cfa_program (const unsigned char *insn_ptr,
859
		     const unsigned char *insn_end,
936
		     const unsigned char *insn_end,
860
		     struct _Unwind_Context *context,
937
		     struct _Unwind_Context *context,
861
		     _Unwind_FrameState *fs)
938
		     _Unwind_FrameState *fs)
862
{
939
{
863
  struct frame_state_reg_info *unused_rs = NULL;
940
  struct frame_state_reg_info *unused_rs = NULL;
864
 
941
 
865
  /* Don't allow remember/restore between CIE and FDE programs.  */
942
  /* Don't allow remember/restore between CIE and FDE programs.  */
866
  fs->regs.prev = NULL;
943
  fs->regs.prev = NULL;
867
 
944
 
868
  /* The comparison with the return address uses < rather than <= because
945
  /* The comparison with the return address uses < rather than <= because
869
     we are only interested in the effects of code before the call; for a
946
     we are only interested in the effects of code before the call; for a
870
     noreturn function, the return address may point to unrelated code with
947
     noreturn function, the return address may point to unrelated code with
871
     a different stack configuration that we are not interested in.  We
948
     a different stack configuration that we are not interested in.  We
872
     assume that the call itself is unwind info-neutral; if not, or if
949
     assume that the call itself is unwind info-neutral; if not, or if
873
     there are delay instructions that adjust the stack, these must be
950
     there are delay instructions that adjust the stack, these must be
874
     reflected at the point immediately before the call insn.
951
     reflected at the point immediately before the call insn.
875
     In signal frames, return address is after last completed instruction,
952
     In signal frames, return address is after last completed instruction,
876
     so we add 1 to return address to make the comparison <=.  */
953
     so we add 1 to return address to make the comparison <=.  */
877
  while (insn_ptr < insn_end
954
  while (insn_ptr < insn_end
878
	 && fs->pc < context->ra + _Unwind_IsSignalFrame (context))
955
	 && fs->pc < context->ra + _Unwind_IsSignalFrame (context))
879
    {
956
    {
880
      unsigned char insn = *insn_ptr++;
957
      unsigned char insn = *insn_ptr++;
881
      _uleb128_t reg, utmp;
958
      _uleb128_t reg, utmp;
882
      _sleb128_t offset, stmp;
959
      _sleb128_t offset, stmp;
883
 
960
 
884
      if ((insn & 0xc0) == DW_CFA_advance_loc)
961
      if ((insn & 0xc0) == DW_CFA_advance_loc)
885
	fs->pc += (insn & 0x3f) * fs->code_align;
962
	fs->pc += (insn & 0x3f) * fs->code_align;
886
      else if ((insn & 0xc0) == DW_CFA_offset)
963
      else if ((insn & 0xc0) == DW_CFA_offset)
887
	{
964
	{
888
	  reg = insn & 0x3f;
965
	  reg = insn & 0x3f;
889
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
966
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
890
	  offset = (_Unwind_Sword) utmp * fs->data_align;
967
	  offset = (_Unwind_Sword) utmp * fs->data_align;
891
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
968
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
969
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
970
	    {
892
	    = REG_SAVED_OFFSET;
971
	      fs->regs.reg[reg].how = REG_SAVED_OFFSET;
893
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
972
	      fs->regs.reg[reg].loc.offset = offset;
-
 
973
	    }
894
	}
974
	}
895
      else if ((insn & 0xc0) == DW_CFA_restore)
975
      else if ((insn & 0xc0) == DW_CFA_restore)
896
	{
976
	{
897
	  reg = insn & 0x3f;
977
	  reg = insn & 0x3f;
898
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how = REG_UNSAVED;
978
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
979
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
980
	    fs->regs.reg[reg].how = REG_UNSAVED;
899
	}
981
	}
900
      else switch (insn)
982
      else switch (insn)
901
	{
983
	{
902
	case DW_CFA_set_loc:
984
	case DW_CFA_set_loc:
903
	  {
985
	  {
904
	    _Unwind_Ptr pc;
986
	    _Unwind_Ptr pc;
905
 
987
 
906
	    insn_ptr = read_encoded_value (context, fs->fde_encoding,
988
	    insn_ptr = read_encoded_value (context, fs->fde_encoding,
907
					   insn_ptr, &pc);
989
					   insn_ptr, &pc);
908
	    fs->pc = (void *) pc;
990
	    fs->pc = (void *) pc;
909
	  }
991
	  }
910
	  break;
992
	  break;
911
 
993
 
912
	case DW_CFA_advance_loc1:
994
	case DW_CFA_advance_loc1:
913
	  fs->pc += read_1u (insn_ptr) * fs->code_align;
995
	  fs->pc += read_1u (insn_ptr) * fs->code_align;
914
	  insn_ptr += 1;
996
	  insn_ptr += 1;
915
	  break;
997
	  break;
916
	case DW_CFA_advance_loc2:
998
	case DW_CFA_advance_loc2:
917
	  fs->pc += read_2u (insn_ptr) * fs->code_align;
999
	  fs->pc += read_2u (insn_ptr) * fs->code_align;
918
	  insn_ptr += 2;
1000
	  insn_ptr += 2;
919
	  break;
1001
	  break;
920
	case DW_CFA_advance_loc4:
1002
	case DW_CFA_advance_loc4:
921
	  fs->pc += read_4u (insn_ptr) * fs->code_align;
1003
	  fs->pc += read_4u (insn_ptr) * fs->code_align;
922
	  insn_ptr += 4;
1004
	  insn_ptr += 4;
923
	  break;
1005
	  break;
924
 
1006
 
925
	case DW_CFA_offset_extended:
1007
	case DW_CFA_offset_extended:
926
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1008
	  insn_ptr = read_uleb128 (insn_ptr, ®);
927
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1009
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
928
	  offset = (_Unwind_Sword) utmp * fs->data_align;
1010
	  offset = (_Unwind_Sword) utmp * fs->data_align;
929
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
1011
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1012
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1013
	    {
930
	    = REG_SAVED_OFFSET;
1014
	      fs->regs.reg[reg].how = REG_SAVED_OFFSET;
931
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
1015
	      fs->regs.reg[reg].loc.offset = offset;
-
 
1016
	    }
932
	  break;
1017
	  break;
933
 
1018
 
934
	case DW_CFA_restore_extended:
1019
	case DW_CFA_restore_extended:
935
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1020
	  insn_ptr = read_uleb128 (insn_ptr, ®);
936
	  /* FIXME, this is wrong; the CIE might have said that the
1021
	  /* FIXME, this is wrong; the CIE might have said that the
937
	     register was saved somewhere.  */
1022
	     register was saved somewhere.  */
938
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNSAVED;
1023
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1024
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1025
	    fs->regs.reg[reg].how = REG_UNSAVED;
939
	  break;
1026
	  break;
940
 
1027
 
941
	case DW_CFA_same_value:
1028
	case DW_CFA_same_value:
942
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1029
	  insn_ptr = read_uleb128 (insn_ptr, ®);
943
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNSAVED;
1030
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1031
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1032
	    fs->regs.reg[reg].how = REG_UNSAVED;
944
	  break;
1033
	  break;
945
 
1034
 
946
	case DW_CFA_undefined:
1035
	case DW_CFA_undefined:
947
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1036
	  insn_ptr = read_uleb128 (insn_ptr, ®);
-
 
1037
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1038
	  if (UNWIND_COLUMN_IN_RANGE (reg))
948
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNDEFINED;
1039
	    fs->regs.reg[reg].how = REG_UNDEFINED;
949
	  break;
1040
	  break;
950
 
1041
 
951
	case DW_CFA_nop:
1042
	case DW_CFA_nop:
952
	  break;
1043
	  break;
953
 
1044
 
954
	case DW_CFA_register:
1045
	case DW_CFA_register:
955
	  {
1046
	  {
956
	    _uleb128_t reg2;
1047
	    _uleb128_t reg2;
957
	    insn_ptr = read_uleb128 (insn_ptr, ®);
1048
	    insn_ptr = read_uleb128 (insn_ptr, ®);
958
	    insn_ptr = read_uleb128 (insn_ptr, ®2);
1049
	    insn_ptr = read_uleb128 (insn_ptr, ®2);
959
	    fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how = REG_SAVED_REG;
1050
	    reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
960
	    fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.reg =
1051
	    if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1052
	      {
-
 
1053
	        fs->regs.reg[reg].how = REG_SAVED_REG;
961
	      (_Unwind_Word)reg2;
1054
	        fs->regs.reg[reg].loc.reg = (_Unwind_Word)reg2;
-
 
1055
	      }
962
	  }
1056
	  }
963
	  break;
1057
	  break;
964
 
1058
 
965
	case DW_CFA_remember_state:
1059
	case DW_CFA_remember_state:
966
	  {
1060
	  {
967
	    struct frame_state_reg_info *new_rs;
1061
	    struct frame_state_reg_info *new_rs;
968
	    if (unused_rs)
1062
	    if (unused_rs)
969
	      {
1063
	      {
970
		new_rs = unused_rs;
1064
		new_rs = unused_rs;
971
		unused_rs = unused_rs->prev;
1065
		unused_rs = unused_rs->prev;
972
	      }
1066
	      }
973
	    else
1067
	    else
974
	      new_rs = alloca (sizeof (struct frame_state_reg_info));
1068
	      new_rs = alloca (sizeof (struct frame_state_reg_info));
975
 
1069
 
976
	    *new_rs = fs->regs;
1070
	    *new_rs = fs->regs;
977
	    fs->regs.prev = new_rs;
1071
	    fs->regs.prev = new_rs;
978
	  }
1072
	  }
979
	  break;
1073
	  break;
980
 
1074
 
981
	case DW_CFA_restore_state:
1075
	case DW_CFA_restore_state:
982
	  {
1076
	  {
983
	    struct frame_state_reg_info *old_rs = fs->regs.prev;
1077
	    struct frame_state_reg_info *old_rs = fs->regs.prev;
984
	    fs->regs = *old_rs;
1078
	    fs->regs = *old_rs;
985
	    old_rs->prev = unused_rs;
1079
	    old_rs->prev = unused_rs;
986
	    unused_rs = old_rs;
1080
	    unused_rs = old_rs;
987
	  }
1081
	  }
988
	  break;
1082
	  break;
989
 
1083
 
990
	case DW_CFA_def_cfa:
1084
	case DW_CFA_def_cfa:
991
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1085
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
992
	  fs->regs.cfa_reg = (_Unwind_Word)utmp;
1086
	  fs->regs.cfa_reg = (_Unwind_Word)utmp;
993
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1087
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
994
	  fs->regs.cfa_offset = (_Unwind_Word)utmp;
1088
	  fs->regs.cfa_offset = (_Unwind_Word)utmp;
995
	  fs->regs.cfa_how = CFA_REG_OFFSET;
1089
	  fs->regs.cfa_how = CFA_REG_OFFSET;
996
	  break;
1090
	  break;
997
 
1091
 
998
	case DW_CFA_def_cfa_register:
1092
	case DW_CFA_def_cfa_register:
999
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1093
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1000
	  fs->regs.cfa_reg = (_Unwind_Word)utmp;
1094
	  fs->regs.cfa_reg = (_Unwind_Word)utmp;
1001
	  fs->regs.cfa_how = CFA_REG_OFFSET;
1095
	  fs->regs.cfa_how = CFA_REG_OFFSET;
1002
	  break;
1096
	  break;
1003
 
1097
 
1004
	case DW_CFA_def_cfa_offset:
1098
	case DW_CFA_def_cfa_offset:
1005
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1099
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1006
	  fs->regs.cfa_offset = utmp;
1100
	  fs->regs.cfa_offset = utmp;
1007
	  /* cfa_how deliberately not set.  */
1101
	  /* cfa_how deliberately not set.  */
1008
	  break;
1102
	  break;
1009
 
1103
 
1010
	case DW_CFA_def_cfa_expression:
1104
	case DW_CFA_def_cfa_expression:
1011
	  fs->regs.cfa_exp = insn_ptr;
1105
	  fs->regs.cfa_exp = insn_ptr;
1012
	  fs->regs.cfa_how = CFA_EXP;
1106
	  fs->regs.cfa_how = CFA_EXP;
1013
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1107
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1014
	  insn_ptr += utmp;
1108
	  insn_ptr += utmp;
1015
	  break;
1109
	  break;
1016
 
1110
 
1017
	case DW_CFA_expression:
1111
	case DW_CFA_expression:
1018
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1112
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1019
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how = REG_SAVED_EXP;
1113
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1114
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1115
	    {
-
 
1116
	      fs->regs.reg[reg].how = REG_SAVED_EXP;
1020
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.exp = insn_ptr;
1117
	      fs->regs.reg[reg].loc.exp = insn_ptr;
-
 
1118
	    }
1021
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1119
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1022
	  insn_ptr += utmp;
1120
	  insn_ptr += utmp;
1023
	  break;
1121
	  break;
1024
 
1122
 
1025
	  /* Dwarf3.  */
1123
	  /* Dwarf3.  */
1026
	case DW_CFA_offset_extended_sf:
1124
	case DW_CFA_offset_extended_sf:
1027
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1125
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1028
	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
1126
	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
1029
	  offset = stmp * fs->data_align;
1127
	  offset = stmp * fs->data_align;
1030
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
1128
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1129
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1130
	    {
1031
	    = REG_SAVED_OFFSET;
1131
	      fs->regs.reg[reg].how = REG_SAVED_OFFSET;
1032
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
1132
	      fs->regs.reg[reg].loc.offset = offset;
-
 
1133
	    }
1033
	  break;
1134
	  break;
1034
 
1135
 
1035
	case DW_CFA_def_cfa_sf:
1136
	case DW_CFA_def_cfa_sf:
1036
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1137
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1037
	  fs->regs.cfa_reg = (_Unwind_Word)utmp;
1138
	  fs->regs.cfa_reg = (_Unwind_Word)utmp;
1038
	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
1139
	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
1039
	  fs->regs.cfa_offset = (_Unwind_Sword)stmp;
1140
	  fs->regs.cfa_offset = (_Unwind_Sword)stmp;
1040
	  fs->regs.cfa_how = CFA_REG_OFFSET;
1141
	  fs->regs.cfa_how = CFA_REG_OFFSET;
1041
	  fs->regs.cfa_offset *= fs->data_align;
1142
	  fs->regs.cfa_offset *= fs->data_align;
1042
	  break;
1143
	  break;
1043
 
1144
 
1044
	case DW_CFA_def_cfa_offset_sf:
1145
	case DW_CFA_def_cfa_offset_sf:
1045
	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
1146
	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
1046
	  fs->regs.cfa_offset = (_Unwind_Sword)stmp;
1147
	  fs->regs.cfa_offset = (_Unwind_Sword)stmp;
1047
	  fs->regs.cfa_offset *= fs->data_align;
1148
	  fs->regs.cfa_offset *= fs->data_align;
1048
	  /* cfa_how deliberately not set.  */
1149
	  /* cfa_how deliberately not set.  */
1049
	  break;
1150
	  break;
1050
 
1151
 
1051
	case DW_CFA_val_offset:
1152
	case DW_CFA_val_offset:
1052
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1153
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1053
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1154
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1054
	  offset = (_Unwind_Sword) utmp * fs->data_align;
1155
	  offset = (_Unwind_Sword) utmp * fs->data_align;
1055
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
1156
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1157
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1158
	    {
1056
	    = REG_SAVED_VAL_OFFSET;
1159
	      fs->regs.reg[reg].how = REG_SAVED_VAL_OFFSET;
1057
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
1160
	      fs->regs.reg[reg].loc.offset = offset;
-
 
1161
	    }
1058
	  break;
1162
	  break;
1059
 
1163
 
1060
	case DW_CFA_val_offset_sf:
1164
	case DW_CFA_val_offset_sf:
1061
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1165
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1062
	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
1166
	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
1063
	  offset = stmp * fs->data_align;
1167
	  offset = stmp * fs->data_align;
1064
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
1168
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1169
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1170
	    {
1065
	    = REG_SAVED_VAL_OFFSET;
1171
	      fs->regs.reg[reg].how = REG_SAVED_VAL_OFFSET;
1066
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
1172
	      fs->regs.reg[reg].loc.offset = offset;
-
 
1173
	    }
1067
	  break;
1174
	  break;
1068
 
1175
 
1069
	case DW_CFA_val_expression:
1176
	case DW_CFA_val_expression:
1070
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1177
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1071
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
1178
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1179
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1180
	    {
1072
	    = REG_SAVED_VAL_EXP;
1181
	      fs->regs.reg[reg].how = REG_SAVED_VAL_EXP;
1073
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.exp = insn_ptr;
1182
	      fs->regs.reg[reg].loc.exp = insn_ptr;
-
 
1183
	    }
1074
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1184
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1075
	  insn_ptr += utmp;
1185
	  insn_ptr += utmp;
1076
	  break;
1186
	  break;
1077
 
1187
 
1078
	case DW_CFA_GNU_window_save:
1188
	case DW_CFA_GNU_window_save:
1079
	  /* ??? Hardcoded for SPARC register window configuration.  */
1189
	  /* ??? Hardcoded for SPARC register window configuration.  */
-
 
1190
	  if (DWARF_FRAME_REGISTERS >= 32)
1080
	  for (reg = 16; reg < 32; ++reg)
1191
	    for (reg = 16; reg < 32; ++reg)
1081
	    {
1192
	      {
1082
	      fs->regs.reg[reg].how = REG_SAVED_OFFSET;
1193
		fs->regs.reg[reg].how = REG_SAVED_OFFSET;
1083
	      fs->regs.reg[reg].loc.offset = (reg - 16) * sizeof (void *);
1194
		fs->regs.reg[reg].loc.offset = (reg - 16) * sizeof (void *);
1084
	    }
1195
	      }
1085
	  break;
1196
	  break;
1086
 
1197
 
1087
	case DW_CFA_GNU_args_size:
1198
	case DW_CFA_GNU_args_size:
1088
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1199
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1089
	  context->args_size = (_Unwind_Word)utmp;
1200
	  context->args_size = (_Unwind_Word)utmp;
1090
	  break;
1201
	  break;
1091
 
1202
 
1092
	case DW_CFA_GNU_negative_offset_extended:
1203
	case DW_CFA_GNU_negative_offset_extended:
1093
	  /* Obsoleted by DW_CFA_offset_extended_sf, but used by
1204
	  /* Obsoleted by DW_CFA_offset_extended_sf, but used by
1094
	     older PowerPC code.  */
1205
	     older PowerPC code.  */
1095
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1206
	  insn_ptr = read_uleb128 (insn_ptr, ®);
1096
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1207
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
1097
	  offset = (_Unwind_Word) utmp * fs->data_align;
1208
	  offset = (_Unwind_Word) utmp * fs->data_align;
1098
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
1209
	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
-
 
1210
	  if (UNWIND_COLUMN_IN_RANGE (reg))
-
 
1211
	    {
1099
	    = REG_SAVED_OFFSET;
1212
	      fs->regs.reg[reg].how = REG_SAVED_OFFSET;
1100
	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = -offset;
1213
	      fs->regs.reg[reg].loc.offset = -offset;
-
 
1214
	    }
1101
	  break;
1215
	  break;
1102
 
1216
 
1103
	default:
1217
	default:
1104
	  gcc_unreachable ();
1218
	  gcc_unreachable ();
1105
	}
1219
	}
1106
    }
1220
    }
1107
}
1221
}
1108

1222

1109
/* Given the _Unwind_Context CONTEXT for a stack frame, look up the FDE for
1223
/* Given the _Unwind_Context CONTEXT for a stack frame, look up the FDE for
1110
   its caller and decode it into FS.  This function also sets the
1224
   its caller and decode it into FS.  This function also sets the
1111
   args_size and lsda members of CONTEXT, as they are really information
1225
   args_size and lsda members of CONTEXT, as they are really information
1112
   about the caller's frame.  */
1226
   about the caller's frame.  */
1113
 
1227
 
1114
static _Unwind_Reason_Code
1228
static _Unwind_Reason_Code
1115
uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1229
uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1116
{
1230
{
1117
  const struct dwarf_fde *fde;
1231
  const struct dwarf_fde *fde;
1118
  const struct dwarf_cie *cie;
1232
  const struct dwarf_cie *cie;
1119
  const unsigned char *aug, *insn, *end;
1233
  const unsigned char *aug, *insn, *end;
1120
 
1234
 
1121
  memset (fs, 0, sizeof (*fs));
1235
  memset (fs, 0, sizeof (*fs));
1122
  context->args_size = 0;
1236
  context->args_size = 0;
1123
  context->lsda = 0;
1237
  context->lsda = 0;
1124
 
1238
 
1125
  if (context->ra == 0)
1239
  if (context->ra == 0)
1126
    return _URC_END_OF_STACK;
1240
    return _URC_END_OF_STACK;
1127
 
1241
 
1128
  fde = _Unwind_Find_FDE (context->ra + _Unwind_IsSignalFrame (context) - 1,
1242
  fde = _Unwind_Find_FDE (context->ra + _Unwind_IsSignalFrame (context) - 1,
1129
			  &context->bases);
1243
			  &context->bases);
1130
  if (fde == NULL)
1244
  if (fde == NULL)
1131
    {
1245
    {
1132
#ifdef MD_FALLBACK_FRAME_STATE_FOR
1246
#ifdef MD_FALLBACK_FRAME_STATE_FOR
1133
      /* Couldn't find frame unwind info for this function.  Try a
1247
      /* Couldn't find frame unwind info for this function.  Try a
1134
	 target-specific fallback mechanism.  This will necessarily
1248
	 target-specific fallback mechanism.  This will necessarily
1135
	 not provide a personality routine or LSDA.  */
1249
	 not provide a personality routine or LSDA.  */
1136
      return MD_FALLBACK_FRAME_STATE_FOR (context, fs);
1250
      return MD_FALLBACK_FRAME_STATE_FOR (context, fs);
1137
#else
1251
#else
1138
      return _URC_END_OF_STACK;
1252
      return _URC_END_OF_STACK;
1139
#endif
1253
#endif
1140
    }
1254
    }
1141
 
1255
 
1142
  fs->pc = context->bases.func;
1256
  fs->pc = context->bases.func;
1143
 
1257
 
1144
  cie = get_cie (fde);
1258
  cie = get_cie (fde);
1145
  insn = extract_cie_info (cie, context, fs);
1259
  insn = extract_cie_info (cie, context, fs);
1146
  if (insn == NULL)
1260
  if (insn == NULL)
1147
    /* CIE contained unknown augmentation.  */
1261
    /* CIE contained unknown augmentation.  */
1148
    return _URC_FATAL_PHASE1_ERROR;
1262
    return _URC_FATAL_PHASE1_ERROR;
1149
 
1263
 
1150
  /* First decode all the insns in the CIE.  */
1264
  /* First decode all the insns in the CIE.  */
1151
  end = (const unsigned char *) next_fde ((const struct dwarf_fde *) cie);
1265
  end = (const unsigned char *) next_fde ((const struct dwarf_fde *) cie);
1152
  execute_cfa_program (insn, end, context, fs);
1266
  execute_cfa_program (insn, end, context, fs);
1153
 
1267
 
1154
  /* Locate augmentation for the fde.  */
1268
  /* Locate augmentation for the fde.  */
1155
  aug = (const unsigned char *) fde + sizeof (*fde);
1269
  aug = (const unsigned char *) fde + sizeof (*fde);
1156
  aug += 2 * size_of_encoded_value (fs->fde_encoding);
1270
  aug += 2 * size_of_encoded_value (fs->fde_encoding);
1157
  insn = NULL;
1271
  insn = NULL;
1158
  if (fs->saw_z)
1272
  if (fs->saw_z)
1159
    {
1273
    {
1160
      _uleb128_t i;
1274
      _uleb128_t i;
1161
      aug = read_uleb128 (aug, &i);
1275
      aug = read_uleb128 (aug, &i);
1162
      insn = aug + i;
1276
      insn = aug + i;
1163
    }
1277
    }
1164
  if (fs->lsda_encoding != DW_EH_PE_omit)
1278
  if (fs->lsda_encoding != DW_EH_PE_omit)
1165
    {
1279
    {
1166
      _Unwind_Ptr lsda;
1280
      _Unwind_Ptr lsda;
1167
 
1281
 
1168
      aug = read_encoded_value (context, fs->lsda_encoding, aug, &lsda);
1282
      aug = read_encoded_value (context, fs->lsda_encoding, aug, &lsda);
1169
      context->lsda = (void *) lsda;
1283
      context->lsda = (void *) lsda;
1170
    }
1284
    }
1171
 
1285
 
1172
  /* Then the insns in the FDE up to our target PC.  */
1286
  /* Then the insns in the FDE up to our target PC.  */
1173
  if (insn == NULL)
1287
  if (insn == NULL)
1174
    insn = aug;
1288
    insn = aug;
1175
  end = (const unsigned char *) next_fde (fde);
1289
  end = (const unsigned char *) next_fde (fde);
1176
  execute_cfa_program (insn, end, context, fs);
1290
  execute_cfa_program (insn, end, context, fs);
1177
 
1291
 
1178
  return _URC_NO_REASON;
1292
  return _URC_NO_REASON;
1179
}
1293
}
1180

1294

1181
typedef struct frame_state
1295
typedef struct frame_state
1182
{
1296
{
1183
  void *cfa;
1297
  void *cfa;
1184
  void *eh_ptr;
1298
  void *eh_ptr;
1185
  long cfa_offset;
1299
  long cfa_offset;
1186
  long args_size;
1300
  long args_size;
1187
  long reg_or_offset[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
1301
  long reg_or_offset[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
1188
  unsigned short cfa_reg;
1302
  unsigned short cfa_reg;
1189
  unsigned short retaddr_column;
1303
  unsigned short retaddr_column;
1190
  char saved[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
1304
  char saved[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
1191
} frame_state;
1305
} frame_state;
1192
 
1306
 
1193
struct frame_state * __frame_state_for (void *, struct frame_state *);
1307
struct frame_state * __frame_state_for (void *, struct frame_state *);
1194
 
1308
 
1195
/* Called from pre-G++ 3.0 __throw to find the registers to restore for
1309
/* Called from pre-G++ 3.0 __throw to find the registers to restore for
1196
   a given PC_TARGET.  The caller should allocate a local variable of
1310
   a given PC_TARGET.  The caller should allocate a local variable of
1197
   `struct frame_state' and pass its address to STATE_IN.  */
1311
   `struct frame_state' and pass its address to STATE_IN.  */
1198
 
1312
 
1199
struct frame_state *
1313
struct frame_state *
1200
__frame_state_for (void *pc_target, struct frame_state *state_in)
1314
__frame_state_for (void *pc_target, struct frame_state *state_in)
1201
{
1315
{
1202
  struct _Unwind_Context context;
1316
  struct _Unwind_Context context;
1203
  _Unwind_FrameState fs;
1317
  _Unwind_FrameState fs;
1204
  int reg;
1318
  int reg;
1205
 
1319
 
1206
  memset (&context, 0, sizeof (struct _Unwind_Context));
1320
  memset (&context, 0, sizeof (struct _Unwind_Context));
-
 
1321
  if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
1207
  context.flags = EXTENDED_CONTEXT_BIT;
1322
    context.flags = EXTENDED_CONTEXT_BIT;
1208
  context.ra = pc_target + 1;
1323
  context.ra = pc_target + 1;
1209
 
1324
 
1210
  if (uw_frame_state_for (&context, &fs) != _URC_NO_REASON)
1325
  if (uw_frame_state_for (&context, &fs) != _URC_NO_REASON)
1211
    return 0;
1326
    return 0;
1212
 
1327
 
1213
  /* We have no way to pass a location expression for the CFA to our
1328
  /* We have no way to pass a location expression for the CFA to our
1214
     caller.  It wouldn't understand it anyway.  */
1329
     caller.  It wouldn't understand it anyway.  */
1215
  if (fs.regs.cfa_how == CFA_EXP)
1330
  if (fs.regs.cfa_how == CFA_EXP)
1216
    return 0;
1331
    return 0;
1217
 
1332
 
1218
  for (reg = 0; reg < PRE_GCC3_DWARF_FRAME_REGISTERS + 1; reg++)
1333
  for (reg = 0; reg < PRE_GCC3_DWARF_FRAME_REGISTERS + 1; reg++)
1219
    {
1334
    {
1220
      state_in->saved[reg] = fs.regs.reg[reg].how;
1335
      state_in->saved[reg] = fs.regs.reg[reg].how;
1221
      switch (state_in->saved[reg])
1336
      switch (state_in->saved[reg])
1222
	{
1337
	{
1223
	case REG_SAVED_REG:
1338
	case REG_SAVED_REG:
1224
	  state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.reg;
1339
	  state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.reg;
1225
	  break;
1340
	  break;
1226
	case REG_SAVED_OFFSET:
1341
	case REG_SAVED_OFFSET:
1227
	  state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.offset;
1342
	  state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.offset;
1228
	  break;
1343
	  break;
1229
	default:
1344
	default:
1230
	  state_in->reg_or_offset[reg] = 0;
1345
	  state_in->reg_or_offset[reg] = 0;
1231
	  break;
1346
	  break;
1232
	}
1347
	}
1233
    }
1348
    }
1234
 
1349
 
1235
  state_in->cfa_offset = fs.regs.cfa_offset;
1350
  state_in->cfa_offset = fs.regs.cfa_offset;
1236
  state_in->cfa_reg = fs.regs.cfa_reg;
1351
  state_in->cfa_reg = fs.regs.cfa_reg;
1237
  state_in->retaddr_column = fs.retaddr_column;
1352
  state_in->retaddr_column = fs.retaddr_column;
1238
  state_in->args_size = context.args_size;
1353
  state_in->args_size = context.args_size;
1239
  state_in->eh_ptr = fs.eh_ptr;
1354
  state_in->eh_ptr = fs.eh_ptr;
1240
 
1355
 
1241
  return state_in;
1356
  return state_in;
1242
}
1357
}
1243

1358

1244
typedef union { _Unwind_Ptr ptr; _Unwind_Word word; } _Unwind_SpTmp;
1359
typedef union { _Unwind_Ptr ptr; _Unwind_Word word; } _Unwind_SpTmp;
1245
 
1360
 
1246
static inline void
1361
static inline void
1247
_Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa,
1362
_Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa,
1248
		     _Unwind_SpTmp *tmp_sp)
1363
		     _Unwind_SpTmp *tmp_sp)
1249
{
1364
{
1250
  int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()];
1365
  int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()];
1251
 
1366
 
1252
  if (size == sizeof(_Unwind_Ptr))
1367
  if (size == sizeof(_Unwind_Ptr))
1253
    tmp_sp->ptr = (_Unwind_Ptr) cfa;
1368
    tmp_sp->ptr = (_Unwind_Ptr) cfa;
1254
  else
1369
  else
1255
    {
1370
    {
1256
      gcc_assert (size == sizeof(_Unwind_Word));
1371
      gcc_assert (size == sizeof(_Unwind_Word));
1257
      tmp_sp->word = (_Unwind_Ptr) cfa;
1372
      tmp_sp->word = (_Unwind_Ptr) cfa;
1258
    }
1373
    }
1259
  _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), tmp_sp);
1374
  _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), tmp_sp);
1260
}
1375
}
1261
 
1376
 
1262
static void
1377
static void
1263
uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1378
uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1264
{
1379
{
1265
  struct _Unwind_Context orig_context = *context;
1380
  struct _Unwind_Context orig_context = *context;
1266
  void *cfa;
1381
  void *cfa;
1267
  long i;
1382
  long i;
1268
 
1383
 
1269
#ifdef EH_RETURN_STACKADJ_RTX
1384
#ifdef EH_RETURN_STACKADJ_RTX
1270
  /* Special handling here: Many machines do not use a frame pointer,
1385
  /* Special handling here: Many machines do not use a frame pointer,
1271
     and track the CFA only through offsets from the stack pointer from
1386
     and track the CFA only through offsets from the stack pointer from
1272
     one frame to the next.  In this case, the stack pointer is never
1387
     one frame to the next.  In this case, the stack pointer is never
1273
     stored, so it has no saved address in the context.  What we do
1388
     stored, so it has no saved address in the context.  What we do
1274
     have is the CFA from the previous stack frame.
1389
     have is the CFA from the previous stack frame.
1275
 
1390
 
1276
     In very special situations (such as unwind info for signal return),
1391
     In very special situations (such as unwind info for signal return),
1277
     there may be location expressions that use the stack pointer as well.
1392
     there may be location expressions that use the stack pointer as well.
1278
 
1393
 
1279
     Do this conditionally for one frame.  This allows the unwind info
1394
     Do this conditionally for one frame.  This allows the unwind info
1280
     for one frame to save a copy of the stack pointer from the previous
1395
     for one frame to save a copy of the stack pointer from the previous
1281
     frame, and be able to use much easier CFA mechanisms to do it.
1396
     frame, and be able to use much easier CFA mechanisms to do it.
1282
     Always zap the saved stack pointer value for the next frame; carrying
1397
     Always zap the saved stack pointer value for the next frame; carrying
1283
     the value over from one frame to another doesn't make sense.  */
1398
     the value over from one frame to another doesn't make sense.  */
1284
 
1399
 
1285
  _Unwind_SpTmp tmp_sp;
1400
  _Unwind_SpTmp tmp_sp;
1286
 
1401
 
1287
  if (!_Unwind_GetGRPtr (&orig_context, __builtin_dwarf_sp_column ()))
1402
  if (!_Unwind_GetGRPtr (&orig_context, __builtin_dwarf_sp_column ()))
1288
    _Unwind_SetSpColumn (&orig_context, context->cfa, &tmp_sp);
1403
    _Unwind_SetSpColumn (&orig_context, context->cfa, &tmp_sp);
1289
  _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), NULL);
1404
  _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), NULL);
1290
#endif
1405
#endif
1291
 
1406
 
1292
  /* Compute this frame's CFA.  */
1407
  /* Compute this frame's CFA.  */
1293
  switch (fs->regs.cfa_how)
1408
  switch (fs->regs.cfa_how)
1294
    {
1409
    {
1295
    case CFA_REG_OFFSET:
1410
    case CFA_REG_OFFSET:
1296
      cfa = _Unwind_GetPtr (&orig_context, fs->regs.cfa_reg);
1411
      cfa = _Unwind_GetPtr (&orig_context, fs->regs.cfa_reg);
1297
      cfa += fs->regs.cfa_offset;
1412
      cfa += fs->regs.cfa_offset;
1298
      break;
1413
      break;
1299
 
1414
 
1300
    case CFA_EXP:
1415
    case CFA_EXP:
1301
      {
1416
      {
1302
	const unsigned char *exp = fs->regs.cfa_exp;
1417
	const unsigned char *exp = fs->regs.cfa_exp;
1303
	_uleb128_t len;
1418
	_uleb128_t len;
1304
 
1419
 
1305
	exp = read_uleb128 (exp, &len);
1420
	exp = read_uleb128 (exp, &len);
1306
	cfa = (void *) (_Unwind_Ptr)
1421
	cfa = (void *) (_Unwind_Ptr)
1307
	  execute_stack_op (exp, exp + len, &orig_context, 0);
1422
	  execute_stack_op (exp, exp + len, &orig_context, 0);
1308
	break;
1423
	break;
1309
      }
1424
      }
1310
 
1425
 
1311
    default:
1426
    default:
1312
      gcc_unreachable ();
1427
      gcc_unreachable ();
1313
    }
1428
    }
1314
  context->cfa = cfa;
1429
  context->cfa = cfa;
1315
 
1430
 
1316
  /* Compute the addresses of all registers saved in this frame.  */
1431
  /* Compute the addresses of all registers saved in this frame.  */
1317
  for (i = 0; i < DWARF_FRAME_REGISTERS + 1; ++i)
1432
  for (i = 0; i < DWARF_FRAME_REGISTERS + 1; ++i)
1318
    switch (fs->regs.reg[i].how)
1433
    switch (fs->regs.reg[i].how)
1319
      {
1434
      {
1320
      case REG_UNSAVED:
1435
      case REG_UNSAVED:
1321
      case REG_UNDEFINED:
1436
      case REG_UNDEFINED:
1322
	break;
1437
	break;
1323
 
1438
 
1324
      case REG_SAVED_OFFSET:
1439
      case REG_SAVED_OFFSET:
1325
	_Unwind_SetGRPtr (context, i,
1440
	_Unwind_SetGRPtr (context, i,
1326
			  (void *) (cfa + fs->regs.reg[i].loc.offset));
1441
			  (void *) (cfa + fs->regs.reg[i].loc.offset));
1327
	break;
1442
	break;
1328
 
1443
 
1329
      case REG_SAVED_REG:
1444
      case REG_SAVED_REG:
1330
	if (_Unwind_GRByValue (&orig_context, fs->regs.reg[i].loc.reg))
1445
	if (_Unwind_GRByValue (&orig_context, fs->regs.reg[i].loc.reg))
1331
	  _Unwind_SetGRValue (context, i,
1446
	  _Unwind_SetGRValue (context, i,
1332
			      _Unwind_GetGR (&orig_context,
1447
			      _Unwind_GetGR (&orig_context,
1333
					     fs->regs.reg[i].loc.reg));
1448
					     fs->regs.reg[i].loc.reg));
1334
	else
1449
	else
1335
	  _Unwind_SetGRPtr (context, i,
1450
	  _Unwind_SetGRPtr (context, i,
1336
			    _Unwind_GetGRPtr (&orig_context,
1451
			    _Unwind_GetGRPtr (&orig_context,
1337
					      fs->regs.reg[i].loc.reg));
1452
					      fs->regs.reg[i].loc.reg));
1338
	break;
1453
	break;
1339
 
1454
 
1340
      case REG_SAVED_EXP:
1455
      case REG_SAVED_EXP:
1341
	{
1456
	{
1342
	  const unsigned char *exp = fs->regs.reg[i].loc.exp;
1457
	  const unsigned char *exp = fs->regs.reg[i].loc.exp;
1343
	  _uleb128_t len;
1458
	  _uleb128_t len;
1344
	  _Unwind_Ptr val;
1459
	  _Unwind_Ptr val;
1345
 
1460
 
1346
	  exp = read_uleb128 (exp, &len);
1461
	  exp = read_uleb128 (exp, &len);
1347
	  val = execute_stack_op (exp, exp + len, &orig_context,
1462
	  val = execute_stack_op (exp, exp + len, &orig_context,
1348
				  (_Unwind_Ptr) cfa);
1463
				  (_Unwind_Ptr) cfa);
1349
	  _Unwind_SetGRPtr (context, i, (void *) val);
1464
	  _Unwind_SetGRPtr (context, i, (void *) val);
1350
	}
1465
	}
1351
	break;
1466
	break;
1352
 
1467
 
1353
      case REG_SAVED_VAL_OFFSET:
1468
      case REG_SAVED_VAL_OFFSET:
1354
	_Unwind_SetGRValue (context, i,
1469
	_Unwind_SetGRValue (context, i,
1355
			    (_Unwind_Internal_Ptr)
1470
			    (_Unwind_Internal_Ptr)
1356
			    (cfa + fs->regs.reg[i].loc.offset));
1471
			    (cfa + fs->regs.reg[i].loc.offset));
1357
	break;
1472
	break;
1358
 
1473
 
1359
      case REG_SAVED_VAL_EXP:
1474
      case REG_SAVED_VAL_EXP:
1360
	{
1475
	{
1361
	  const unsigned char *exp = fs->regs.reg[i].loc.exp;
1476
	  const unsigned char *exp = fs->regs.reg[i].loc.exp;
1362
	  _uleb128_t len;
1477
	  _uleb128_t len;
1363
	  _Unwind_Ptr val;
1478
	  _Unwind_Ptr val;
1364
 
1479
 
1365
	  exp = read_uleb128 (exp, &len);
1480
	  exp = read_uleb128 (exp, &len);
1366
	  val = execute_stack_op (exp, exp + len, &orig_context,
1481
	  val = execute_stack_op (exp, exp + len, &orig_context,
1367
				  (_Unwind_Ptr) cfa);
1482
				  (_Unwind_Ptr) cfa);
1368
	  _Unwind_SetGRValue (context, i, val);
1483
	  _Unwind_SetGRValue (context, i, val);
1369
	}
1484
	}
1370
	break;
1485
	break;
1371
      }
1486
      }
1372
 
1487
 
1373
  _Unwind_SetSignalFrame (context, fs->signal_frame);
1488
  _Unwind_SetSignalFrame (context, fs->signal_frame);
1374
 
1489
 
1375
#ifdef MD_FROB_UPDATE_CONTEXT
1490
#ifdef MD_FROB_UPDATE_CONTEXT
1376
  MD_FROB_UPDATE_CONTEXT (context, fs);
1491
  MD_FROB_UPDATE_CONTEXT (context, fs);
1377
#endif
1492
#endif
1378
}
1493
}
1379
 
1494
 
1380
/* CONTEXT describes the unwind state for a frame, and FS describes the FDE
1495
/* CONTEXT describes the unwind state for a frame, and FS describes the FDE
1381
   of its caller.  Update CONTEXT to refer to the caller as well.  Note
1496
   of its caller.  Update CONTEXT to refer to the caller as well.  Note
1382
   that the args_size and lsda members are not updated here, but later in
1497
   that the args_size and lsda members are not updated here, but later in
1383
   uw_frame_state_for.  */
1498
   uw_frame_state_for.  */
1384
 
1499
 
1385
static void
1500
static void
1386
uw_update_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1501
uw_update_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1387
{
1502
{
1388
  uw_update_context_1 (context, fs);
1503
  uw_update_context_1 (context, fs);
1389
 
1504
 
1390
  /* In general this unwinder doesn't make any distinction between
1505
  /* In general this unwinder doesn't make any distinction between
1391
     undefined and same_value rule.  Call-saved registers are assumed
1506
     undefined and same_value rule.  Call-saved registers are assumed
1392
     to have same_value rule by default and explicit undefined
1507
     to have same_value rule by default and explicit undefined
1393
     rule is handled like same_value.  The only exception is
1508
     rule is handled like same_value.  The only exception is
1394
     DW_CFA_undefined on retaddr_column which is supposed to
1509
     DW_CFA_undefined on retaddr_column which is supposed to
1395
     mark outermost frame in DWARF 3.  */
1510
     mark outermost frame in DWARF 3.  */
1396
  if (fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (fs->retaddr_column)].how
1511
  if (fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (fs->retaddr_column)].how
1397
      == REG_UNDEFINED)
1512
      == REG_UNDEFINED)
1398
    /* uw_frame_state_for uses context->ra == 0 check to find outermost
1513
    /* uw_frame_state_for uses context->ra == 0 check to find outermost
1399
       stack frame.  */
1514
       stack frame.  */
1400
    context->ra = 0;
1515
    context->ra = 0;
1401
  else
1516
  else
1402
    /* Compute the return address now, since the return address column
1517
    /* Compute the return address now, since the return address column
1403
       can change from frame to frame.  */
1518
       can change from frame to frame.  */
1404
    context->ra = __builtin_extract_return_addr
1519
    context->ra = __builtin_extract_return_addr
1405
      (_Unwind_GetPtr (context, fs->retaddr_column));
1520
      (_Unwind_GetPtr (context, fs->retaddr_column));
1406
}
1521
}
1407
 
1522
 
1408
static void
1523
static void
1409
uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1524
uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1410
{
1525
{
1411
  uw_update_context (context, fs);
1526
  uw_update_context (context, fs);
1412
}
1527
}
1413

1528

1414
/* Fill in CONTEXT for top-of-stack.  The only valid registers at this
1529
/* Fill in CONTEXT for top-of-stack.  The only valid registers at this
1415
   level will be the return address and the CFA.  */
1530
   level will be the return address and the CFA.  */
1416
 
1531
 
1417
#define uw_init_context(CONTEXT)					   \
1532
#define uw_init_context(CONTEXT)					   \
1418
  do									   \
1533
  do									   \
1419
    {									   \
1534
    {									   \
1420
      /* Do any necessary initialization to access arbitrary stack frames. \
1535
      /* Do any necessary initialization to access arbitrary stack frames. \
1421
	 On the SPARC, this means flushing the register windows.  */	   \
1536
	 On the SPARC, this means flushing the register windows.  */	   \
1422
      __builtin_unwind_init ();						   \
1537
      __builtin_unwind_init ();						   \
1423
      uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (),		   \
1538
      uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (),		   \
1424
			 __builtin_return_address (0));			   \
1539
			 __builtin_return_address (0));			   \
1425
    }									   \
1540
    }									   \
1426
  while (0)
1541
  while (0)
1427
 
1542
 
1428
static inline void
1543
static inline void
1429
init_dwarf_reg_size_table (void)
1544
init_dwarf_reg_size_table (void)
1430
{
1545
{
1431
  __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table);
1546
  __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table);
1432
}
1547
}
1433
 
1548
 
1434
static void __attribute__((noinline))
1549
static void __attribute__((noinline))
1435
uw_init_context_1 (struct _Unwind_Context *context,
1550
uw_init_context_1 (struct _Unwind_Context *context,
1436
		   void *outer_cfa, void *outer_ra)
1551
		   void *outer_cfa, void *outer_ra)
1437
{
1552
{
1438
  void *ra = __builtin_extract_return_addr (__builtin_return_address (0));
1553
  void *ra = __builtin_extract_return_addr (__builtin_return_address (0));
1439
  _Unwind_FrameState fs;
1554
  _Unwind_FrameState fs;
1440
  _Unwind_SpTmp sp_slot;
1555
  _Unwind_SpTmp sp_slot;
1441
  _Unwind_Reason_Code code;
1556
  _Unwind_Reason_Code code;
1442
 
1557
 
1443
  memset (context, 0, sizeof (struct _Unwind_Context));
1558
  memset (context, 0, sizeof (struct _Unwind_Context));
1444
  context->ra = ra;
1559
  context->ra = ra;
-
 
1560
  if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
1445
  context->flags = EXTENDED_CONTEXT_BIT;
1561
    context->flags = EXTENDED_CONTEXT_BIT;
1446
 
1562
 
1447
  code = uw_frame_state_for (context, &fs);
1563
  code = uw_frame_state_for (context, &fs);
1448
  gcc_assert (code == _URC_NO_REASON);
1564
  gcc_assert (code == _URC_NO_REASON);
1449
 
1565
 
1450
#if __GTHREADS
1566
#if __GTHREADS
1451
  {
1567
  {
1452
    static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT;
1568
    static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT;
1453
    if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0
1569
    if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0
1454
	&& dwarf_reg_size_table[0] == 0)
1570
	&& dwarf_reg_size_table[0] == 0)
1455
      init_dwarf_reg_size_table ();
1571
      init_dwarf_reg_size_table ();
1456
  }
1572
  }
1457
#else
1573
#else
1458
  if (dwarf_reg_size_table[0] == 0)
1574
  if (dwarf_reg_size_table[0] == 0)
1459
    init_dwarf_reg_size_table ();
1575
    init_dwarf_reg_size_table ();
1460
#endif
1576
#endif
1461
 
1577
 
1462
  /* Force the frame state to use the known cfa value.  */
1578
  /* Force the frame state to use the known cfa value.  */
1463
  _Unwind_SetSpColumn (context, outer_cfa, &sp_slot);
1579
  _Unwind_SetSpColumn (context, outer_cfa, &sp_slot);
1464
  fs.regs.cfa_how = CFA_REG_OFFSET;
1580
  fs.regs.cfa_how = CFA_REG_OFFSET;
1465
  fs.regs.cfa_reg = __builtin_dwarf_sp_column ();
1581
  fs.regs.cfa_reg = __builtin_dwarf_sp_column ();
1466
  fs.regs.cfa_offset = 0;
1582
  fs.regs.cfa_offset = 0;
1467
 
1583
 
1468
  uw_update_context_1 (context, &fs);
1584
  uw_update_context_1 (context, &fs);
1469
 
1585
 
1470
  /* If the return address column was saved in a register in the
1586
  /* If the return address column was saved in a register in the
1471
     initialization context, then we can't see it in the given
1587
     initialization context, then we can't see it in the given
1472
     call frame data.  So have the initialization context tell us.  */
1588
     call frame data.  So have the initialization context tell us.  */
1473
  context->ra = __builtin_extract_return_addr (outer_ra);
1589
  context->ra = __builtin_extract_return_addr (outer_ra);
1474
}
1590
}
1475
 
1591
 
1476
static void _Unwind_DebugHook (void *, void *)
1592
static void _Unwind_DebugHook (void *, void *)
1477
  __attribute__ ((__noinline__, __used__, __noclone__));
1593
  __attribute__ ((__noinline__, __used__, __noclone__));
1478
 
1594
 
1479
/* This function is called during unwinding.  It is intended as a hook
1595
/* This function is called during unwinding.  It is intended as a hook
1480
   for a debugger to intercept exceptions.  CFA is the CFA of the
1596
   for a debugger to intercept exceptions.  CFA is the CFA of the
1481
   target frame.  HANDLER is the PC to which control will be
1597
   target frame.  HANDLER is the PC to which control will be
1482
   transferred.  */
1598
   transferred.  */
1483
static void
1599
static void
1484
_Unwind_DebugHook (void *cfa __attribute__ ((__unused__)),
1600
_Unwind_DebugHook (void *cfa __attribute__ ((__unused__)),
1485
		   void *handler __attribute__ ((__unused__)))
1601
		   void *handler __attribute__ ((__unused__)))
1486
{
1602
{
-
 
1603
  /* We only want to use stap probes starting with v3.  Earlier
-
 
1604
     versions added too much startup cost.  */
-
 
1605
#if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3
-
 
1606
  STAP_PROBE2 (libgcc, unwind, cfa, handler);
-
 
1607
#else
1487
  asm ("");
1608
  asm ("");
-
 
1609
#endif
1488
}
1610
}
1489
 
1611
 
1490
/* Install TARGET into CURRENT so that we can return to it.  This is a
1612
/* Install TARGET into CURRENT so that we can return to it.  This is a
1491
   macro because __builtin_eh_return must be invoked in the context of
1613
   macro because __builtin_eh_return must be invoked in the context of
1492
   our caller.  */
1614
   our caller.  */
1493
 
1615
 
1494
#define uw_install_context(CURRENT, TARGET)				\
1616
#define uw_install_context(CURRENT, TARGET)				\
1495
  do									\
1617
  do									\
1496
    {									\
1618
    {									\
1497
      long offset = uw_install_context_1 ((CURRENT), (TARGET));		\
1619
      long offset = uw_install_context_1 ((CURRENT), (TARGET));		\
1498
      void *handler = __builtin_frob_return_addr ((TARGET)->ra);	\
1620
      void *handler = __builtin_frob_return_addr ((TARGET)->ra);	\
1499
      _Unwind_DebugHook ((TARGET)->cfa, handler);			\
1621
      _Unwind_DebugHook ((TARGET)->cfa, handler);			\
1500
      __builtin_eh_return (offset, handler);				\
1622
      __builtin_eh_return (offset, handler);				\
1501
    }									\
1623
    }									\
1502
  while (0)
1624
  while (0)
1503
 
1625
 
1504
static long
1626
static long
1505
uw_install_context_1 (struct _Unwind_Context *current,
1627
uw_install_context_1 (struct _Unwind_Context *current,
1506
		      struct _Unwind_Context *target)
1628
		      struct _Unwind_Context *target)
1507
{
1629
{
1508
  long i;
1630
  long i;
1509
  _Unwind_SpTmp sp_slot;
1631
  _Unwind_SpTmp sp_slot;
1510
 
1632
 
1511
  /* If the target frame does not have a saved stack pointer,
1633
  /* If the target frame does not have a saved stack pointer,
1512
     then set up the target's CFA.  */
1634
     then set up the target's CFA.  */
1513
  if (!_Unwind_GetGRPtr (target, __builtin_dwarf_sp_column ()))
1635
  if (!_Unwind_GetGRPtr (target, __builtin_dwarf_sp_column ()))
1514
    _Unwind_SetSpColumn (target, target->cfa, &sp_slot);
1636
    _Unwind_SetSpColumn (target, target->cfa, &sp_slot);
1515
 
1637
 
1516
  for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
1638
  for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
1517
    {
1639
    {
1518
      void *c = current->reg[i];
1640
      void *c = (void *) (_Unwind_Internal_Ptr) current->reg[i];
1519
      void *t = target->reg[i];
1641
      void *t = (void *) (_Unwind_Internal_Ptr)target->reg[i];
1520
 
1642
 
1521
      gcc_assert (current->by_value[i] == 0);
1643
      gcc_assert (current->by_value[i] == 0);
1522
      if (target->by_value[i] && c)
1644
      if (target->by_value[i] && c)
1523
	{
1645
	{
1524
	  _Unwind_Word w;
1646
	  _Unwind_Word w;
1525
	  _Unwind_Ptr p;
1647
	  _Unwind_Ptr p;
1526
	  if (dwarf_reg_size_table[i] == sizeof (_Unwind_Word))
1648
	  if (dwarf_reg_size_table[i] == sizeof (_Unwind_Word))
1527
	    {
1649
	    {
1528
	      w = (_Unwind_Internal_Ptr) t;
1650
	      w = (_Unwind_Internal_Ptr) t;
1529
	      memcpy (c, &w, sizeof (_Unwind_Word));
1651
	      memcpy (c, &w, sizeof (_Unwind_Word));
1530
	    }
1652
	    }
1531
	  else
1653
	  else
1532
	    {
1654
	    {
1533
	      gcc_assert (dwarf_reg_size_table[i] == sizeof (_Unwind_Ptr));
1655
	      gcc_assert (dwarf_reg_size_table[i] == sizeof (_Unwind_Ptr));
1534
	      p = (_Unwind_Internal_Ptr) t;
1656
	      p = (_Unwind_Internal_Ptr) t;
1535
	      memcpy (c, &p, sizeof (_Unwind_Ptr));
1657
	      memcpy (c, &p, sizeof (_Unwind_Ptr));
1536
	    }
1658
	    }
1537
	}
1659
	}
1538
      else if (t && c && t != c)
1660
      else if (t && c && t != c)
1539
	memcpy (c, t, dwarf_reg_size_table[i]);
1661
	memcpy (c, t, dwarf_reg_size_table[i]);
1540
    }
1662
    }
1541
 
1663
 
1542
  /* If the current frame doesn't have a saved stack pointer, then we
1664
  /* If the current frame doesn't have a saved stack pointer, then we
1543
     need to rely on EH_RETURN_STACKADJ_RTX to get our target stack
1665
     need to rely on EH_RETURN_STACKADJ_RTX to get our target stack
1544
     pointer value reloaded.  */
1666
     pointer value reloaded.  */
1545
  if (!_Unwind_GetGRPtr (current, __builtin_dwarf_sp_column ()))
1667
  if (!_Unwind_GetGRPtr (current, __builtin_dwarf_sp_column ()))
1546
    {
1668
    {
1547
      void *target_cfa;
1669
      void *target_cfa;
1548
 
1670
 
1549
      target_cfa = _Unwind_GetPtr (target, __builtin_dwarf_sp_column ());
1671
      target_cfa = _Unwind_GetPtr (target, __builtin_dwarf_sp_column ());
1550
 
1672
 
1551
      /* We adjust SP by the difference between CURRENT and TARGET's CFA.  */
1673
      /* We adjust SP by the difference between CURRENT and TARGET's CFA.  */
1552
      if (STACK_GROWS_DOWNWARD)
1674
      if (STACK_GROWS_DOWNWARD)
1553
	return target_cfa - current->cfa + target->args_size;
1675
	return target_cfa - current->cfa + target->args_size;
1554
      else
1676
      else
1555
	return current->cfa - target_cfa - target->args_size;
1677
	return current->cfa - target_cfa - target->args_size;
1556
    }
1678
    }
1557
  return 0;
1679
  return 0;
1558
}
1680
}
1559
 
1681
 
1560
static inline _Unwind_Ptr
1682
static inline _Unwind_Ptr
1561
uw_identify_context (struct _Unwind_Context *context)
1683
uw_identify_context (struct _Unwind_Context *context)
1562
{
1684
{
1563
  /* The CFA is not sufficient to disambiguate the context of a function
1685
  /* The CFA is not sufficient to disambiguate the context of a function
1564
     interrupted by a signal before establishing its frame and the context
1686
     interrupted by a signal before establishing its frame and the context
1565
     of the signal itself.  */
1687
     of the signal itself.  */
1566
  if (STACK_GROWS_DOWNWARD)
1688
  if (STACK_GROWS_DOWNWARD)
1567
    return _Unwind_GetCFA (context) - _Unwind_IsSignalFrame (context);
1689
    return _Unwind_GetCFA (context) - _Unwind_IsSignalFrame (context);
1568
  else
1690
  else
1569
    return _Unwind_GetCFA (context) + _Unwind_IsSignalFrame (context);
1691
    return _Unwind_GetCFA (context) + _Unwind_IsSignalFrame (context);
1570
}
1692
}
1571
 
1693
 
1572
 
1694
 
1573
#include "unwind.inc"
1695
#include "unwind.inc"
1574
 
1696
 
1575
#if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
1697
#if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
1576
alias (_Unwind_Backtrace);
1698
alias (_Unwind_Backtrace);
1577
alias (_Unwind_DeleteException);
1699
alias (_Unwind_DeleteException);
1578
alias (_Unwind_FindEnclosingFunction);
1700
alias (_Unwind_FindEnclosingFunction);
1579
alias (_Unwind_ForcedUnwind);
1701
alias (_Unwind_ForcedUnwind);
1580
alias (_Unwind_GetDataRelBase);
1702
alias (_Unwind_GetDataRelBase);
1581
alias (_Unwind_GetTextRelBase);
1703
alias (_Unwind_GetTextRelBase);
1582
alias (_Unwind_GetCFA);
1704
alias (_Unwind_GetCFA);
1583
alias (_Unwind_GetGR);
1705
alias (_Unwind_GetGR);
1584
alias (_Unwind_GetIP);
1706
alias (_Unwind_GetIP);
1585
alias (_Unwind_GetLanguageSpecificData);
1707
alias (_Unwind_GetLanguageSpecificData);
1586
alias (_Unwind_GetRegionStart);
1708
alias (_Unwind_GetRegionStart);
1587
alias (_Unwind_RaiseException);
1709
alias (_Unwind_RaiseException);
1588
alias (_Unwind_Resume);
1710
alias (_Unwind_Resume);
1589
alias (_Unwind_Resume_or_Rethrow);
1711
alias (_Unwind_Resume_or_Rethrow);
1590
alias (_Unwind_SetGR);
1712
alias (_Unwind_SetGR);
1591
alias (_Unwind_SetIP);
1713
alias (_Unwind_SetIP);
1592
#endif
1714
#endif
1593
 
1715
 
1594
#endif /* !USING_SJLJ_EXCEPTIONS */
1716
#endif /* !USING_SJLJ_EXCEPTIONS */