1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . E X C E P T I O N S --
9 -- Copyright (C) 1992-2000 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This package contains definitions used for zero cost exception handling.
35 -- See unit Ada.Exceptions for further details. Note that the reason that
36 -- we separate out these definitions is to avoid problems with recursion
37 -- in rtsfind. They must be in a unit which does not require any exception
38 -- table generation of any kind.
43 with System
.Standard_Library
;
45 with Unchecked_Conversion
;
47 package System
.Exceptions
is
49 package SSL
renames System
.Standard_Library
;
50 package AEX
renames Ada
.Exceptions
;
52 -- The following section defines data structures used for zero cost
53 -- exception handling if System.Parameters.Zero_Cost_Exceptions is
54 -- set true (i.e. zero cost exceptions are implemented on this target).
56 -- The approach is to build tables that describe the PC ranges that
57 -- are covered by various exception frames. When an exception occurs,
58 -- these tables are searched to determine the address of the applicable
59 -- handler for the current exception.
61 subtype Handler_Loc
is System
.Address
;
62 -- Code location representing entry address of a handler. Values of
63 -- this type are created using the N_Handler_Loc node, and then
64 -- passed to the Enter_Handler procedure to enter a handler.
66 subtype Code_Loc
is System
.Address
;
67 -- Code location used in building exception tables and for call
68 -- addresses when propagating an exception (also traceback table)
69 -- Values of this type are created by using Label'Address or
70 -- extracted from machine states using Get_Code_Loc.
76 -- A Handler record is built for each choice for each exception handler
79 function To_Exception_Id
is
80 new Unchecked_Conversion
(SSL
.Exception_Data_Ptr
, AEX
.Exception_Id
);
82 Others_Dummy_Exception
: aliased SSL
.Exception_Data
;
83 Others_Id
: constant AEX
.Exception_Id
:=
84 To_Exception_Id
(Others_Dummy_Exception
'Access);
85 -- Dummy exception used to signal others exception
87 All_Others_Dummy_Exception
: aliased SSL
.Exception_Data
;
88 All_Others_Id
: constant AEX
.Exception_Id
:=
89 To_Exception_Id
(All_Others_Dummy_Exception
'Access);
90 -- Dummy exception used to signal all others exception (including
91 -- exceptions not normally handled by others, e.g. Abort_Signal)
93 type Handler_Record
is record
96 -- Range of PC values of code covered by this handler record. The
97 -- handler covers all code addresses that are greater than the Lo
98 -- value, and less than or equal to the Hi value.
100 Id
: AEX
.Exception_Id
;
101 -- Id of exception being handled, or one of the above special values
103 Handler
: Handler_Loc
;
104 -- Address of label at start of handler
107 type Handler_Record_Ptr
is access all Handler_Record
;
108 type Handler_Record_List
is array (Natural range <>) of Handler_Record_Ptr
;
110 ---------------------------
111 -- Subprogram_Descriptor --
112 ---------------------------
114 -- A Subprogram_Descriptor is built for each subprogram through which
115 -- exceptions may propagate, this includes all Ada subprograms,
116 -- and also all foreign language imported subprograms.
118 subtype Subprogram_Info_Type
is System
.Address
;
119 -- This type is used to represent a value that is used to unwind stack
120 -- frames. It references target dependent data that provides sufficient
121 -- information (e.g. about the location of the return point, use of a
122 -- frame pointer, save-over-call registers etc) to unwind the machine
123 -- state to the caller. For some targets, this is simply a pointer to
124 -- the entry point of the procedure (and the routine to pop the machine
125 -- state disassembles the code at the entry point to obtain the required
126 -- information). On other targets, it is a pointer to data created by the
127 -- backend or assembler to represent the required information.
129 No_Info
: constant Subprogram_Info_Type
:= System
.Null_Address
;
130 -- This is a special value used to indicate that it is not possible
131 -- to pop past this frame. This is used at the outer level (e.g. for
132 -- package elaboration procedures or the main procedure), and for any
133 -- other foreign language procedure for which propagation is known
134 -- to be impossible. An exception is considered unhandled if an
135 -- attempt is made to pop a frame whose Subprogram_Info_Type value
136 -- is set to No_Info.
138 type Subprogram_Descriptor
(Num_Handlers
: Natural) is record
140 -- This is a code location used to determine which procedure we are
141 -- in. Most usually it is simply the entry address for the procedure.
142 -- hA given address is considered to be within the procedure referenced
143 -- by a Subprogram_Descriptor record if this is the descriptor for
144 -- which the Code value is as large as possible without exceeding
147 Subprogram_Info
: Subprogram_Info_Type
;
148 -- This is a pointer to a target dependent data item that provides
149 -- sufficient information for unwinding the stack frame of this
150 -- procedure. A value of No_Info (zero) means that we are the
151 -- outer level procedure.
153 Handler_Records
: Handler_Record_List
(1 .. Num_Handlers
);
154 -- List of pointers to Handler_Records for this procedure. The array
155 -- is sorted inside out, i.e. entries for inner frames appear before
156 -- entries for outer handlers. This ensures that a serial search
157 -- finds the innermost applicable handler
160 subtype Subprogram_Descriptor_0
is Subprogram_Descriptor
(0);
161 subtype Subprogram_Descriptor_1
is Subprogram_Descriptor
(1);
162 subtype Subprogram_Descriptor_2
is Subprogram_Descriptor
(2);
163 subtype Subprogram_Descriptor_3
is Subprogram_Descriptor
(3);
164 -- Predeclare commonly used subtypes for buildingt he tables
166 type Subprogram_Descriptor_Ptr
is access all Subprogram_Descriptor
;
168 type Subprogram_Descriptor_List
169 is array (Natural range <>) of Subprogram_Descriptor_Ptr
;
171 type Subprogram_Descriptors_Record
(Count
: Natural) is record
172 SDesc
: Subprogram_Descriptor_List
(1 .. Count
);
175 type Subprogram_Descriptors_Ptr
is
176 access all Subprogram_Descriptors_Record
;
178 --------------------------
179 -- Unit Exception_Table --
180 --------------------------
182 -- If a unit contains at least one subprogram, then a library level
183 -- declaration of the form:
185 -- Tnn : aliased constant Subprogram_Descriptors :=
188 -- (SD1'Unrestricted_Access,
189 -- SD2'Unrestricted_Access,
191 -- SDn'Unrestricted_Access));
192 -- pragma Export (Ada, Tnn, "__gnat_unit_name__SDP");
194 -- is generated where the initializing expression is an array aggregate
195 -- whose elements are pointers to the generated subprogram descriptors
198 -- Note: the ALI file contains the designation UX in each unit entry
199 -- if a unit exception table is generated.
201 -- The binder generates a list of addresses of pointers to these tables.
203 end System
.Exceptions
;