aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/s-tfsetr-default.adb
blob: 28cebd3891b5badeb64cec3547b8638dd41db471 (plain)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
------------------------------------------------------------------------------
--                                                                          --
--                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
--                                                                          --
--                     S Y S T E M . T R A C E S . S E N D                  --
--                                                                          --
--                                  B o d y                                 --
--                                                                          --
--          Copyright (C) 2001-2005 Free Software Foundation, Inc.          --
--                                                                          --
-- GNARL 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. GNARL 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 GNARL; see file COPYING.  If not, write --
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
-- Boston, MA 02110-1301, 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 was originally developed  by the GNAT team at  New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
--                                                                          --
------------------------------------------------------------------------------

--  This version is for all targets, provided that System.IO.Put_Line is
--  functional. It prints debug information to Standard Output

with System.IO;   use System.IO;
with GNAT.Regpat; use GNAT.Regpat;

----------------
-- Send_Trace --
----------------

--  Prints debug information both in a human readable form
--  and in the form they are sent from upper layers.

separate (System.Traces.Format)
procedure Send_Trace (Id : Trace_T; Info : String) is

   type Param_Type is
     (Name_Param,
      Caller_Param,
      Entry_Param,
      Timeout_Param,
      Acceptor_Param,
      Parent_Param,
      Number_Param);
   --  Type of parameter found in the message

   Info_Trace : String_Trace := Format_Trace (Info);

   function Get_Param
     (Input    : String_Trace;
      Param    : Param_Type;
      How_Many : Integer)
      return     String;
   --  Extract a parameter from the given input string

   ---------------
   -- Get_Param --
   ---------------

   function Get_Param
     (Input    : String_Trace;
      Param    : Param_Type;
      How_Many : Integer)
      return     String
   is
      pragma Unreferenced (How_Many);

      Matches : Match_Array (1 .. 2);
   begin
      --  We need comments here ???

      case Param is
         when Name_Param     =>
            Match ("/N:([\w]+)", Input, Matches);

         when Caller_Param   =>
            Match ("/C:([\w]+)", Input, Matches);

         when Entry_Param =>
            Match ("/E:([\s]*) +([0-9 ,]+)", Input, Matches);

         when Timeout_Param =>
            Match ("/T:([\s]*) +([0-9]+.[0-9]+)", Input, Matches);

         when Acceptor_Param =>
            Match ("/A:([\w]+)", Input, Matches);

         when Parent_Param   =>
            Match ("/P:([\w]+)", Input, Matches);

         when Number_Param =>
            Match ("/#:([\s]*) +([0-9]+)", Input, Matches);
      end case;

      if Matches (1).First < Input'First then
         return "";
      end if;

      case Param is
         when Timeout_Param | Entry_Param | Number_Param =>
            return Input (Matches (2).First .. Matches (2).Last);

         when others =>
            return Input (Matches (1).First .. Matches (1).Last);
      end case;
   end Get_Param;

--  Start of processing for Send_Trace

begin
   New_Line;
   Put_Line ("- Trace Debug Info ----------------");
   Put ("Caught event Id : ");

   case Id is
      when M_Accept_Complete => Put ("M_Accept_Complete");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " completes accept on entry "
                   & Get_Param (Info_Trace, Entry_Param, 1) & " with "
                   & Get_Param (Info_Trace, Caller_Param, 1));

      when M_Select_Else     => Put ("M_Select_Else");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " selects else statement");

      when M_RDV_Complete    => Put ("M_RDV_Complete");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " completes rendezvous with "
                   & Get_Param (Info_Trace, Caller_Param, 1));

      when M_Call_Complete   => Put ("M_Call_Complete");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " completes call");

      when M_Delay           => Put ("M_Delay");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " completes delay "
                   & Get_Param (Info_Trace, Timeout_Param, 1));

      when E_Missed          => Put ("E_Missed");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " got an invalid acceptor "
                   & Get_Param (Info_Trace, Acceptor_Param, 1));

      when E_Timeout         => Put ("E_Timeout");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " ends select due to timeout ");

      when E_Kill            => Put ("E_Kill");
         New_Line;
         Put_Line ("Asynchronous Transfer of Control on task "
                   & Get_Param (Info_Trace, Name_Param, 1));

      when W_Delay           => Put ("W_Delay");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " sleeping "
                   & Get_Param (Info_Trace, Timeout_Param, 1)
                   & " seconds");

      when WU_Delay           => Put ("WU_Delay");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " sleeping until "
                   & Get_Param (Info_Trace, Timeout_Param, 1));

      when W_Call            => Put ("W_Call");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " calling entry "
                   & Get_Param (Info_Trace, Entry_Param, 1)
                   & " of "  & Get_Param (Info_Trace, Acceptor_Param, 1));

      when W_Accept          => Put ("W_Accept");
         New_Line;
         Put ("Task " & Get_Param (Info_Trace, Name_Param, 1)
              & " waiting on "
              & Get_Param (Info_Trace, Number_Param, 1)
              & " accept(s)"
              & ", " & Get_Param (Info_Trace, Entry_Param, 1));
         New_Line;

      when W_Select          => Put ("W_Select");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " waiting on "
                   & Get_Param (Info_Trace, Number_Param, 1)
                   & " select(s)"
                      & ", " & Get_Param (Info_Trace, Entry_Param, 1));
         New_Line;

      when W_Completion      => Put ("W_Completion");
         New_Line;
            Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                      & " waiting for completion ");

      when WT_Select         => Put ("WT_Select");
         New_Line;
         Put ("Task " & Get_Param (Info_Trace, Name_Param, 1)
              & " waiting " & Get_Param (Info_Trace, Timeout_Param, 1)
              & " seconds  on "
              & Get_Param (Info_Trace, Number_Param, 1)
              & " select(s)");

         if Get_Param (Info_Trace, Number_Param, 1) /= "" then
            Put (", " & Get_Param (Info_Trace, Entry_Param, 1));
         end if;

         New_Line;

      when WT_Call           => Put ("WT_Call");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " calling entry "
                   & Get_Param (Info_Trace, Entry_Param, 1)
                   & " of "  & Get_Param (Info_Trace, Acceptor_Param, 1)
                   & " with timeout "
                   & Get_Param (Info_Trace, Timeout_Param, 1));

      when WT_Completion     => Put ("WT_Completion");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " waiting "
                   & Get_Param (Info_Trace, Timeout_Param, 1)
                   & " for call completion");

      when PO_Call           => Put ("PO_Call");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " calling protected entry  "
                   & Get_Param (Info_Trace, Entry_Param, 1));

      when POT_Call          => Put ("POT_Call");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " calling protected entry  "
                   & Get_Param (Info_Trace, Entry_Param, 1)
                   & " with timeout "
                   & Get_Param (Info_Trace, Timeout_Param, 1));

      when PO_Run            => Put ("PO_Run");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                      & " running entry  "
                   & Get_Param (Info_Trace, Entry_Param, 1)
                   & " for "
                   & Get_Param (Info_Trace, Caller_Param, 1));

      when PO_Done           => Put ("PO_Done");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " finished call from "
                   & Get_Param (Info_Trace, Caller_Param, 1));

      when PO_Lock           => Put ("PO_Lock");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " took lock");

      when PO_Unlock         => Put ("PO_Unlock");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " released lock");

      when T_Create          => Put ("T_Create");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " created");

      when T_Activate        => Put ("T_Activate");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " activated");

      when T_Abort           => Put ("T_Abort");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " aborted by "
                   & Get_Param (Info_Trace, Parent_Param, 1));

      when T_Terminate       => Put ("T_Terminate");
         New_Line;
         Put_Line ("Task " & Get_Param (Info_Trace, Name_Param, 1)
                   & " terminated");

      when others
        => Put ("Invalid Id");
   end case;

   Put_Line ("  --> " & Info_Trace);
   Put_Line ("-----------------------------------");
   New_Line;
end Send_Trace;