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