Add hppa-openbsd target
[official-gcc.git] / gcc / ada / g-exctra.adb
blob179f394386977033f614747df7739b0facf5e9e1
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- G N A T . E X C E P T I O N _ T R A C E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 2000-2001 Ada Core Technologies, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
31 -- --
32 ------------------------------------------------------------------------------
34 with System.Standard_Library; use System.Standard_Library;
35 with System.Soft_Links; use System.Soft_Links;
37 package body GNAT.Exception_Traces is
39 -- Calling the decorator directly from where it is needed would require
40 -- introducing nasty dependencies upon the spec of this package (typically
41 -- in a-except.adb). We also have to deal with the fact that the traceback
42 -- array within an exception occurrence and the one the decorator shall
43 -- accept are of different types. These are two reasons for which a wrapper
44 -- with a System.Address argument is indeed used to call the decorator
45 -- provided by the user of this package. This wrapper is called via a
46 -- soft-link, which either is null when no decorator is in place or "points
47 -- to" the following function otherwise.
49 function Decorator_Wrapper
50 (Traceback : System.Address;
51 Len : Natural)
52 return String;
53 -- The wrapper to be called when a decorator is in place for exception
54 -- backtraces.
56 -- Traceback is the address of the call chain array as stored in the
57 -- exception occurrence and Len is the number of significant addresses
58 -- contained in this array.
60 Current_Decorator : Traceback_Decorator := null;
61 -- The decorator to be called by the wrapper when it is not null, as set
62 -- by Set_Trace_Decorator. When this access is null, the wrapper is null
63 -- also and shall then not be called.
65 -----------------------
66 -- Decorator_Wrapper --
67 -----------------------
69 function Decorator_Wrapper
70 (Traceback : System.Address;
71 Len : Natural)
72 return String
74 Decorator_Traceback : Tracebacks_Array (1 .. Len);
75 for Decorator_Traceback'Address use Traceback;
77 -- Handle the "transition" from the array stored in the exception
78 -- occurrence to the array expected by the decorator.
80 pragma Import (Ada, Decorator_Traceback);
82 begin
83 return Current_Decorator.all (Decorator_Traceback);
84 end Decorator_Wrapper;
86 -------------------------
87 -- Set_Trace_Decorator --
88 -------------------------
90 procedure Set_Trace_Decorator (Decorator : Traceback_Decorator) is
91 begin
92 Current_Decorator := Decorator;
94 if Current_Decorator /= null then
95 Traceback_Decorator_Wrapper := Decorator_Wrapper'Access;
96 else
97 Traceback_Decorator_Wrapper := null;
98 end if;
99 end Set_Trace_Decorator;
101 -- Trace_On/Trace_Off control the kind of automatic output to occur
102 -- by way of the global Exception_Trace variable.
104 ---------------
105 -- Trace_Off --
106 ---------------
108 procedure Trace_Off is
109 begin
110 Exception_Trace := RM_Convention;
111 end Trace_Off;
113 --------------
114 -- Trace_On --
115 --------------
117 procedure Trace_On (Kind : in Trace_Kind) is
118 begin
119 case Kind is
120 when Every_Raise =>
121 Exception_Trace := Every_Raise;
122 when Unhandled_Raise =>
123 Exception_Trace := Unhandled_Raise;
124 end case;
125 end Trace_On;
127 end GNAT.Exception_Traces;