1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- G N A T . E X C E P T I O N _ T R A C E S --
11 -- Copyright (C) 2000-2001 Ada Core Technologies, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
35 with System
.Standard_Library
; use System
.Standard_Library
;
36 with System
.Soft_Links
; use System
.Soft_Links
;
38 package body GNAT
.Exception_Traces
is
40 -- Calling the decorator directly from where it is needed would require
41 -- introducing nasty dependencies upon the spec of this package (typically
42 -- in a-except.adb). We also have to deal with the fact that the traceback
43 -- array within an exception occurrence and the one the decorator shall
44 -- accept are of different types. These are two reasons for which a wrapper
45 -- with a System.Address argument is indeed used to call the decorator
46 -- provided by the user of this package. This wrapper is called via a
47 -- soft-link, which either is null when no decorator is in place or "points
48 -- to" the following function otherwise.
50 function Decorator_Wrapper
51 (Traceback
: System
.Address
;
54 -- The wrapper to be called when a decorator is in place for exception
57 -- Traceback is the address of the call chain array as stored in the
58 -- exception occurrence and Len is the number of significant addresses
59 -- contained in this array.
61 Current_Decorator
: Traceback_Decorator
:= null;
62 -- The decorator to be called by the wrapper when it is not null, as set
63 -- by Set_Trace_Decorator. When this access is null, the wrapper is null
64 -- also and shall then not be called.
66 -----------------------
67 -- Decorator_Wrapper --
68 -----------------------
70 function Decorator_Wrapper
71 (Traceback
: System
.Address
;
75 Decorator_Traceback
: Tracebacks_Array
(1 .. Len
);
76 for Decorator_Traceback
'Address use Traceback
;
78 -- Handle the "transition" from the array stored in the exception
79 -- occurrence to the array expected by the decorator.
81 pragma Import
(Ada
, Decorator_Traceback
);
84 return Current_Decorator
.all (Decorator_Traceback
);
85 end Decorator_Wrapper
;
87 -------------------------
88 -- Set_Trace_Decorator --
89 -------------------------
91 procedure Set_Trace_Decorator
(Decorator
: Traceback_Decorator
) is
93 Current_Decorator
:= Decorator
;
95 if Current_Decorator
/= null then
96 Traceback_Decorator_Wrapper
:= Decorator_Wrapper
'Access;
98 Traceback_Decorator_Wrapper
:= null;
100 end Set_Trace_Decorator
;
102 -- Trace_On/Trace_Off control the kind of automatic output to occur
103 -- by way of the global Exception_Trace variable.
109 procedure Trace_Off
is
111 Exception_Trace
:= RM_Convention
;
118 procedure Trace_On
(Kind
: in Trace_Kind
) is
122 Exception_Trace
:= Every_Raise
;
123 when Unhandled_Raise
=>
124 Exception_Trace
:= Unhandled_Raise
;
128 end GNAT
.Exception_Traces
;