re PR target/8343 ([m68k] [3.2 regression] m68k-elf/rtems ICE at instantiate_virtual_...
[official-gcc.git] / gcc / unwind-dw2-fde.h
blob58e4414531883c8a34f102442487c60682a5506b
1 /* Subroutines needed for unwinding stack frames for exception handling. */
2 /* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Jason Merrill <jason@cygnus.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combine
20 executable.)
22 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 for more details.
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING. If not, write to the Free
29 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 02111-1307, USA. */
33 struct fde_vector
35 void *orig_data;
36 size_t count;
37 struct dwarf_fde *array[];
40 struct object
42 void *pc_begin;
43 void *tbase;
44 void *dbase;
45 union {
46 struct dwarf_fde *single;
47 struct dwarf_fde **array;
48 struct fde_vector *sort;
49 } u;
51 union {
52 struct {
53 unsigned long sorted : 1;
54 unsigned long from_array : 1;
55 unsigned long mixed_encoding : 1;
56 unsigned long encoding : 8;
57 /* ??? Wish there was an easy way to detect a 64-bit host here;
58 we've got 32 bits left to play with... */
59 unsigned long count : 21;
60 } b;
61 size_t i;
62 } s;
64 #ifdef DWARF2_OBJECT_END_PTR_EXTENSION
65 char *fde_end;
66 #endif
68 struct object *next;
71 /* This is the original definition of struct object. While the struct
72 itself was opaque to users, they did know how large it was, and
73 allocate one statically in crtbegin for each DSO. Keep this around
74 so that we're aware of the static size limitations for the new struct. */
75 struct old_object
77 void *pc_begin;
78 void *pc_end;
79 struct dwarf_fde *fde_begin;
80 struct dwarf_fde **fde_array;
81 size_t count;
82 struct old_object *next;
85 struct dwarf_eh_bases
87 void *tbase;
88 void *dbase;
89 void *func;
93 extern void __register_frame_info_bases (void *, struct object *,
94 void *, void *);
95 extern void __register_frame_info (void *, struct object *);
96 extern void __register_frame (void *);
97 extern void __register_frame_info_table_bases (void *, struct object *,
98 void *, void *);
99 extern void __register_frame_info_table (void *, struct object *);
100 extern void __register_frame_table (void *);
101 extern void *__deregister_frame_info (void *);
102 extern void *__deregister_frame_info_bases (void *);
103 extern void __deregister_frame (void *);
106 typedef int sword __attribute__ ((mode (SI)));
107 typedef unsigned int uword __attribute__ ((mode (SI)));
108 typedef unsigned int uaddr __attribute__ ((mode (pointer)));
109 typedef int saddr __attribute__ ((mode (pointer)));
110 typedef unsigned char ubyte;
112 /* Terminology:
113 CIE - Common Information Element
114 FDE - Frame Descriptor Element
116 There is one per function, and it describes where the function code
117 is located, and what the register lifetimes and stack layout are
118 within the function.
120 The data structures are defined in the DWARF specification, although
121 not in a very readable way (see LITERATURE).
123 Every time an exception is thrown, the code needs to locate the FDE
124 for the current function, and starts to look for exception regions
125 from that FDE. This works in a two-level search:
126 a) in a linear search, find the shared image (i.e. DLL) containing
127 the PC
128 b) using the FDE table for that shared object, locate the FDE using
129 binary search (which requires the sorting). */
131 /* The first few fields of a CIE. The CIE_id field is 0 for a CIE,
132 to distinguish it from a valid FDE. FDEs are aligned to an addressing
133 unit boundary, but the fields within are unaligned. */
134 struct dwarf_cie
136 uword length;
137 sword CIE_id;
138 ubyte version;
139 unsigned char augmentation[];
140 } __attribute__ ((packed, aligned (__alignof__ (void *))));
142 /* The first few fields of an FDE. */
143 struct dwarf_fde
145 uword length;
146 sword CIE_delta;
147 unsigned char pc_begin[];
148 } __attribute__ ((packed, aligned (__alignof__ (void *))));
150 typedef struct dwarf_fde fde;
152 /* Locate the CIE for a given FDE. */
154 static inline struct dwarf_cie *
155 get_cie (struct dwarf_fde *f)
157 return (void *)&f->CIE_delta - f->CIE_delta;
160 static inline fde *
161 next_fde (fde *f)
163 return (fde *) ((char *) f + f->length + sizeof (f->length));
166 extern fde * _Unwind_Find_FDE (void *, struct dwarf_eh_bases *);
168 static inline int
169 last_fde (struct object *obj ATTRIBUTE_UNUSED, fde *f)
171 #ifdef DWARF2_OBJECT_END_PTR_EXTENSION
172 return (char *)f == obj->fde_end || f->length == 0;
173 #else
174 return f->length == 0;
175 #endif