1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- G N A T . T R A C E B A C K . S Y M B O L I C --
-- --
-- B o d y --
-- --
-- Copyright (C) 1999-2003 Ada Core Technologies, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
-- Run-time symbolic traceback support for VMS
with Ada.Exceptions.Traceback; use Ada.Exceptions.Traceback;
with Interfaces.C;
with Interfaces.C.Strings;
with System;
with System.Aux_DEC;
with System.Soft_Links;
with System.Traceback_Entries;
package body GNAT.Traceback.Symbolic is
pragma Warnings (Off);
pragma Linker_Options ("--for-linker=sys$library:trace.exe");
use Interfaces.C.Strings;
use System;
use System.Aux_DEC;
use System.Traceback_Entries;
type Dscdef1_Type is record
Maxstrlen : Unsigned_Word;
Dtype : Unsigned_Byte;
Class : Unsigned_Byte;
Pointer : chars_ptr;
end record;
for Dscdef1_Type use record
Maxstrlen at 0 range 0 .. 15;
Dtype at 2 range 0 .. 7;
Class at 3 range 0 .. 7;
Pointer at 4 range 0 .. 31;
end record;
for Dscdef1_Type'Size use 64;
Image_Buf : String (1 .. 10240);
Image_Len : Integer;
Image_Need_Hdr : Boolean := True;
Image_Do_Another_Line : Boolean;
Image_Xtra_Msg : Boolean;
procedure Traceback_Image (Out_Desc : access Dscdef1_Type);
procedure Traceback_Image (Out_Desc : access Dscdef1_Type) is
Image : String (1 .. Integer (Out_Desc.Maxstrlen));
begin
Image := Value (Out_Desc.Pointer,
Interfaces.C.size_t (Out_Desc.Maxstrlen));
if Image_Do_Another_Line and then
(Image_Need_Hdr or else
Image (Image'First .. Image'First + 27) /=
" image module routine")
then
declare
First : Integer := Image_Len + 1;
Last : Integer := First + Image'Length - 1;
begin
Image_Buf (First .. Last + 1) := Image & ASCII.LF;
Image_Len := Last + 1;
end;
Image_Need_Hdr := False;
if Image (Image'First .. Image'First + 3) = "----" then
if Image_Xtra_Msg = False then
Image_Xtra_Msg := True;
else
Image_Xtra_Msg := False;
end if;
end if;
if Out_Desc.Maxstrlen = 79 and then not Image_Xtra_Msg then
Image_Len := Image_Len - 1;
Image_Do_Another_Line := False;
end if;
end if;
end Traceback_Image;
subtype User_Arg_Type is Unsigned_Longword;
subtype Cond_Value_Type is Unsigned_Longword;
procedure Show_Traceback
(Status : out Cond_Value_Type;
Faulting_FP : Address;
Faulting_SP : Address;
Faulting_PC : Address;
Detail_Level : Integer := Integer'Null_Parameter;
User_Act_Proc : Address := Address'Null_Parameter;
User_Arg_Value : User_Arg_Type := User_Arg_Type'Null_Parameter;
Exceptionn : Unsigned_Longword := Unsigned_Longword'Null_Parameter);
pragma Interface (External, Show_Traceback);
pragma Import_Valued_Procedure
(Show_Traceback, "TBK$SHOW_TRACEBACK",
(Cond_Value_Type, Address, Address, Address, Integer, Address,
User_Arg_Type, Unsigned_Longword),
(Value, Value, Value, Value, Reference, Value, Value, Reference),
Detail_Level);
------------------------
-- Symbolic_Traceback --
------------------------
function Symbolic_Traceback (Traceback : Tracebacks_Array) return String is
Res : String (1 .. 256 * Traceback'Length);
Len : Integer;
Status : Cond_Value_Type;
begin
if Traceback'Length > 0 then
Len := 0;
-- Since image computation is not thread-safe we need task lockout
System.Soft_Links.Lock_Task.all;
for I in Traceback'Range loop
Image_Len := 0;
Image_Do_Another_Line := True;
Image_Xtra_Msg := False;
Show_Traceback
(Status,
FP_For (Traceback (I)),
SP_For (Traceback (I)),
PC_For (Traceback (I)),
0,
Traceback_Image'Address);
declare
First : Integer := Len + 1;
Last : Integer := First + Image_Len - 1;
begin
Res (First .. Last + 1) := Image_Buf & ASCII.LF;
Len := Last + 1;
end;
end loop;
System.Soft_Links.Unlock_Task.all;
return Res (1 .. Len);
else
return "";
end if;
end Symbolic_Traceback;
function Symbolic_Traceback (E : Exception_Occurrence) return String is
begin
return Symbolic_Traceback (Tracebacks (E));
end Symbolic_Traceback;
end GNAT.Traceback.Symbolic;
|