OSDN Git Service

2004-09-16 Frank Ch. Eigler <fche@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / unwind-dw2-fde.h
1 /* Subroutines needed for unwinding stack frames for exception handling.  */
2 /* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004
3    Free Software Foundation, Inc.
4    Contributed by Jason Merrill <jason@cygnus.com>.
5
6 This file is part of GCC.
7
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.
12
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.)
21
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.
26
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.  */
31
32 #ifndef GCC_UNWIND_DW2_FDE_H
33 #define GCC_UNWIND_DW2_FDE_H
34
35 #pragma GCC visibility push(default)
36
37 struct fde_vector
38 {
39   const void *orig_data;
40   size_t count;
41   const struct dwarf_fde *array[];
42 };
43
44 struct object
45 {
46   void *pc_begin;
47   void *tbase;
48   void *dbase;
49   union {
50     const struct dwarf_fde *single;
51     struct dwarf_fde **array;
52     struct fde_vector *sort;
53   } u;
54
55   union {
56     struct {
57       unsigned long sorted : 1;
58       unsigned long from_array : 1;
59       unsigned long mixed_encoding : 1;
60       unsigned long encoding : 8;
61       /* ??? Wish there was an easy way to detect a 64-bit host here;
62          we've got 32 bits left to play with...  */
63       unsigned long count : 21;
64     } b;
65     size_t i;
66   } s;
67
68 #ifdef DWARF2_OBJECT_END_PTR_EXTENSION
69   char *fde_end;
70 #endif
71
72   struct object *next;
73 };
74
75 /* This is the original definition of struct object.  While the struct
76    itself was opaque to users, they did know how large it was, and
77    allocate one statically in crtbegin for each DSO.  Keep this around
78    so that we're aware of the static size limitations for the new struct.  */
79 struct old_object
80 {
81   void *pc_begin;
82   void *pc_end;
83   struct dwarf_fde *fde_begin;
84   struct dwarf_fde **fde_array;
85   size_t count;
86   struct old_object *next;
87 };
88
89 struct dwarf_eh_bases
90 {
91   void *tbase;
92   void *dbase;
93   void *func;
94 };
95
96
97 extern void __register_frame_info_bases (const void *, struct object *,
98                                          void *, void *);
99 extern void __register_frame_info (const void *, struct object *);
100 extern void __register_frame (void *);
101 extern void __register_frame_info_table_bases (void *, struct object *,
102                                                void *, void *);
103 extern void __register_frame_info_table (void *, struct object *);
104 extern void __register_frame_table (void *);
105 extern void *__deregister_frame_info (const void *);
106 extern void *__deregister_frame_info_bases (const void *);
107 extern void __deregister_frame (void *);
108
109 \f
110 typedef          int  sword __attribute__ ((mode (SI)));
111 typedef unsigned int  uword __attribute__ ((mode (SI)));
112 typedef unsigned int  uaddr __attribute__ ((mode (pointer)));
113 typedef          int  saddr __attribute__ ((mode (pointer)));
114 typedef unsigned char ubyte;
115
116 /* Terminology:
117    CIE - Common Information Element
118    FDE - Frame Descriptor Element
119
120    There is one per function, and it describes where the function code
121    is located, and what the register lifetimes and stack layout are
122    within the function.
123
124    The data structures are defined in the DWARF specification, although
125    not in a very readable way (see LITERATURE).
126
127    Every time an exception is thrown, the code needs to locate the FDE
128    for the current function, and starts to look for exception regions
129    from that FDE. This works in a two-level search:
130    a) in a linear search, find the shared image (i.e. DLL) containing
131       the PC
132    b) using the FDE table for that shared object, locate the FDE using
133       binary search (which requires the sorting).  */
134
135 /* The first few fields of a CIE.  The CIE_id field is 0 for a CIE,
136    to distinguish it from a valid FDE.  FDEs are aligned to an addressing
137    unit boundary, but the fields within are unaligned.  */
138 struct dwarf_cie
139 {
140   uword length;
141   sword CIE_id;
142   ubyte version;
143   unsigned char augmentation[];
144 } __attribute__ ((packed, aligned (__alignof__ (void *))));
145
146 /* The first few fields of an FDE.  */
147 struct dwarf_fde
148 {
149   uword length;
150   sword CIE_delta;
151   unsigned char pc_begin[];
152 } __attribute__ ((packed, aligned (__alignof__ (void *))));
153
154 typedef struct dwarf_fde fde;
155
156 /* Locate the CIE for a given FDE.  */
157
158 static inline const struct dwarf_cie *
159 get_cie (const struct dwarf_fde *f)
160 {
161   return (void *)&f->CIE_delta - f->CIE_delta;
162 }
163
164 static inline const fde *
165 next_fde (const fde *f)
166 {
167   return (const fde *) ((char *) f + f->length + sizeof (f->length));
168 }
169
170 extern const fde * _Unwind_Find_FDE (void *, struct dwarf_eh_bases *);
171
172 static inline int
173 last_fde (struct object *obj __attribute__ ((__unused__)), const fde *f)
174 {
175 #ifdef DWARF2_OBJECT_END_PTR_EXTENSION
176   return (char *)f == obj->fde_end || f->length == 0;
177 #else
178   return f->length == 0;
179 #endif
180 }
181
182 #pragma GCC visibility pop
183
184 #endif /* unwind-dw2-fde.h */