1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- ADA.EXCEPTIONS.STREAM_ATTRIBUTES --
9 -- Copyright (C) 1992-2018, 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 3, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 pragma Warnings
(Off
);
33 -- Allow withing of non-Preelaborated units in Ada 2005 mode where this
34 -- package will be categorized as Preelaborate. See AI-362 for details.
35 -- It is safe in the context of the run-time to violate the rules.
37 with System
.Exception_Table
; use System
.Exception_Table
;
38 with System
.Storage_Elements
; use System
.Storage_Elements
;
42 separate (Ada
.Exceptions
)
43 package body Stream_Attributes
is
49 function EId_To_String
(X
: Exception_Id
) return String is
54 return Exception_Name
(X
);
62 -- We use the null string to represent the null occurrence, otherwise we
63 -- output the Untailored_Exception_Information string for the occurrence.
65 function EO_To_String
(X
: Exception_Occurrence
) return String is
67 if X
.Id
= Null_Id
then
70 return Exception_Data
.Untailored_Exception_Information
(X
);
78 function String_To_EId
(S
: String) return Exception_Id
is
83 return Exception_Id
(Internal_Exception
(S
));
91 function String_To_EO
(S
: String) return Exception_Occurrence
is
95 X
: aliased Exception_Occurrence
;
96 -- This is the exception occurrence we will create
99 pragma No_Return
(Bad_EO
);
100 -- Signal bad exception occurrence string
102 procedure Next_String
;
103 -- On entry, To points to last character of previous line of the
104 -- message, terminated by LF. On return, From .. To are set to
105 -- specify the next string, or From > To if there are no more lines.
110 (Program_Error
'Identity,
111 "bad exception occurrence in stream input");
113 -- The following junk raise of Program_Error is required because
114 -- this is a No_Return procedure, and unfortunately Raise_Exception
115 -- can return (this particular call can't, but the back end is not
116 -- clever enough to know that).
121 procedure Next_String
is
125 if From
< S
'Last then
128 while To
< S
'Last - 1 loop
131 elsif S
(To
+ 1) = ASCII
.LF
then
140 -- Start of processing for String_To_EO
144 return Null_Occurrence
;
150 if S
(From
.. From
+ 6) /= "raised " then
155 Name_Start
: constant Positive := From
+ 7;
157 From
:= Name_Start
+ 1;
159 while From
< To
and then S
(From
) /= ' ' loop
164 Exception_Id
(Internal_Exception
(S
(Name_Start
.. From
- 1)));
168 if S
(From
.. From
+ 2) /= " : " then
172 X
.Msg_Length
:= To
- From
- 2;
173 X
.Msg
(1 .. X
.Msg_Length
) := S
(From
+ 3 .. To
);
182 if From
<= To
and then S
(From
) = 'P' then
183 if S
(From
.. From
+ 3) /= "PID:" then
187 From
:= From
+ 5; -- skip past PID: space
189 while From
<= To
loop
190 X
.Pid
:= X
.Pid
* 10 +
191 (Character'Pos (S
(From
)) - Character'Pos ('0'));
198 X
.Num_Tracebacks
:= 0;
201 if S
(From
.. To
) /= "Call stack traceback locations:" then
216 or else S
(From
+ 1) /= 'x'
224 while From
<= To
loop
227 if Ch
in '0' .. '9' then
229 Character'Pos (S
(From
)) - Character'Pos ('0');
231 elsif Ch
in 'a' .. 'f' then
233 Character'Pos (S
(From
)) - Character'Pos ('a') + 10;
248 if X
.Num_Tracebacks
= Max_Tracebacks
then
252 X
.Num_Tracebacks
:= X
.Num_Tracebacks
+ 1;
253 X
.Tracebacks
(X
.Num_Tracebacks
) :=
254 TBE
.TB_Entry_For
(To_Address
(C
));
259 -- If an exception was converted to a string, it must have
260 -- already been raised, so flag it accordingly and we are done.
262 X
.Exception_Raised
:= True;
266 end Stream_Attributes
;