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