OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-tasdeb.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                  GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                --
4 --                                                                          --
5 --                  S Y S T E M . T A S K I N G . D E B U G                 --
6 --                                                                          --
7 --                                  B o d y                                 --
8 --                                                                          --
9 --          Copyright (C) 1997-2008, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNARL 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 2,  or (at your option) any later ver- --
14 -- sion. GNARL 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.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNARL was developed by the GNARL team at Florida State University.       --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package encapsulates all direct interfaces to task debugging services
35 --  that are needed by gdb with gnat mode.
36
37 --  Note : This file *must* be compiled with debugging information
38
39 --  Do not add any dependency to GNARL packages since this package is used
40 --  in both normal and restricted (ravenscar) environments.
41
42 with System.CRTL;
43 with System.Task_Primitives;
44 with System.Task_Primitives.Operations;
45 with Ada.Unchecked_Conversion;
46
47 package body System.Tasking.Debug is
48
49    package STPO renames System.Task_Primitives.Operations;
50
51    function To_Integer is new
52      Ada.Unchecked_Conversion (Task_Id, System.Task_Primitives.Task_Address);
53
54    type Trace_Flag_Set is array (Character) of Boolean;
55
56    Trace_On : Trace_Flag_Set := ('A' .. 'Z' => False, others => True);
57
58    -----------------------
59    -- Local Subprograms --
60    -----------------------
61
62    procedure Write (Fd : Integer; S : String; Count : Integer);
63
64    procedure Put (S : String);
65    --  Display S on standard output
66
67    procedure Put_Line (S : String := "");
68    --  Display S on standard output with an additional line terminator
69
70    ------------------------
71    -- Continue_All_Tasks --
72    ------------------------
73
74    procedure Continue_All_Tasks is
75       C : Task_Id;
76
77       Dummy : Boolean;
78       pragma Unreferenced (Dummy);
79
80    begin
81       STPO.Lock_RTS;
82
83       C := All_Tasks_List;
84       while C /= null loop
85          Dummy := STPO.Continue_Task (C);
86          C := C.Common.All_Tasks_Link;
87       end loop;
88
89       STPO.Unlock_RTS;
90    end Continue_All_Tasks;
91
92    --------------------
93    -- Get_User_State --
94    --------------------
95
96    function Get_User_State return Long_Integer is
97    begin
98       return STPO.Self.User_State;
99    end Get_User_State;
100
101    ----------------
102    -- List_Tasks --
103    ----------------
104
105    procedure List_Tasks is
106       C : Task_Id;
107    begin
108       C := All_Tasks_List;
109
110       while C /= null loop
111          Print_Task_Info (C);
112          C := C.Common.All_Tasks_Link;
113       end loop;
114    end List_Tasks;
115
116    ------------------------
117    -- Print_Current_Task --
118    ------------------------
119
120    procedure Print_Current_Task is
121    begin
122       Print_Task_Info (STPO.Self);
123    end Print_Current_Task;
124
125    ---------------------
126    -- Print_Task_Info --
127    ---------------------
128
129    procedure Print_Task_Info (T : Task_Id) is
130       Entry_Call : Entry_Call_Link;
131       Parent     : Task_Id;
132
133    begin
134       if T = null then
135          Put_Line ("null task");
136          return;
137       end if;
138
139       Put (T.Common.Task_Image (1 .. T.Common.Task_Image_Len) & ": " &
140            Task_States'Image (T.Common.State));
141
142       Parent := T.Common.Parent;
143
144       if Parent = null then
145          Put (", parent: <none>");
146       else
147          Put (", parent: " &
148               Parent.Common.Task_Image (1 .. Parent.Common.Task_Image_Len));
149       end if;
150
151       Put (", prio:" & T.Common.Current_Priority'Img);
152
153       if not T.Callable then
154          Put (", not callable");
155       end if;
156
157       if T.Aborting then
158          Put (", aborting");
159       end if;
160
161       if T.Deferral_Level /= 0 then
162          Put (", abort deferred");
163       end if;
164
165       if T.Common.Call /= null then
166          Entry_Call := T.Common.Call;
167          Put (", serving:");
168
169          while Entry_Call /= null loop
170             Put (To_Integer (Entry_Call.Self)'Img);
171             Entry_Call := Entry_Call.Acceptor_Prev_Call;
172          end loop;
173       end if;
174
175       if T.Open_Accepts /= null then
176          Put (", accepting:");
177
178          for J in T.Open_Accepts'Range loop
179             Put (T.Open_Accepts (J).S'Img);
180          end loop;
181
182          if T.Terminate_Alternative then
183             Put (" or terminate");
184          end if;
185       end if;
186
187       if T.User_State /= 0 then
188          Put (", state:" & T.User_State'Img);
189       end if;
190
191       Put_Line;
192    end Print_Task_Info;
193
194    ---------
195    -- Put --
196    ---------
197
198    procedure Put (S : String) is
199    begin
200       Write (2, S, S'Length);
201    end Put;
202
203    --------------
204    -- Put_Line --
205    --------------
206
207    procedure Put_Line (S : String := "") is
208    begin
209       Write (2, S & ASCII.LF, S'Length + 1);
210    end Put_Line;
211
212    ----------------------
213    -- Resume_All_Tasks --
214    ----------------------
215
216    procedure Resume_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
217       C     : Task_Id;
218       Dummy : Boolean;
219       pragma Unreferenced (Dummy);
220
221    begin
222       STPO.Lock_RTS;
223       C := All_Tasks_List;
224
225       while C /= null loop
226          Dummy := STPO.Resume_Task (C, Thread_Self);
227          C := C.Common.All_Tasks_Link;
228       end loop;
229
230       STPO.Unlock_RTS;
231    end Resume_All_Tasks;
232
233    ---------------
234    -- Set_Trace --
235    ---------------
236
237    procedure Set_Trace (Flag  : Character; Value : Boolean := True) is
238    begin
239       Trace_On (Flag) := Value;
240    end Set_Trace;
241
242    --------------------
243    -- Set_User_State --
244    --------------------
245
246    procedure Set_User_State (Value : Long_Integer) is
247    begin
248       STPO.Self.User_State := Value;
249    end Set_User_State;
250
251    --------------------
252    -- Stop_All_Tasks --
253    --------------------
254
255    procedure Stop_All_Tasks is
256       C : Task_Id;
257
258       Dummy : Boolean;
259       pragma Unreferenced (Dummy);
260
261    begin
262       STPO.Lock_RTS;
263
264       C := All_Tasks_List;
265       while C /= null loop
266          Dummy := STPO.Stop_Task (C);
267          C := C.Common.All_Tasks_Link;
268       end loop;
269
270       STPO.Unlock_RTS;
271    end Stop_All_Tasks;
272
273    ----------------------------
274    -- Stop_All_Tasks_Handler --
275    ----------------------------
276
277    procedure Stop_All_Tasks_Handler is
278    begin
279       STPO.Stop_All_Tasks;
280    end Stop_All_Tasks_Handler;
281
282    -----------------------
283    -- Suspend_All_Tasks --
284    -----------------------
285
286    procedure Suspend_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
287       C     : Task_Id;
288       Dummy : Boolean;
289       pragma Unreferenced (Dummy);
290
291    begin
292       STPO.Lock_RTS;
293       C := All_Tasks_List;
294
295       while C /= null loop
296          Dummy := STPO.Suspend_Task (C, Thread_Self);
297          C := C.Common.All_Tasks_Link;
298       end loop;
299
300       STPO.Unlock_RTS;
301    end Suspend_All_Tasks;
302
303    ------------------------
304    -- Task_Creation_Hook --
305    ------------------------
306
307    procedure Task_Creation_Hook (Thread : OS_Interface.Thread_Id) is
308       pragma Inspection_Point (Thread);
309       --  gdb needs to access the thread parameter in order to implement
310       --  the multitask mode under VxWorks.
311
312    begin
313       null;
314    end Task_Creation_Hook;
315
316    ---------------------------
317    -- Task_Termination_Hook --
318    ---------------------------
319
320    procedure Task_Termination_Hook is
321    begin
322       null;
323    end Task_Termination_Hook;
324
325    -----------
326    -- Trace --
327    -----------
328
329    procedure Trace
330      (Self_Id  : Task_Id;
331       Msg      : String;
332       Flag     : Character;
333       Other_Id : Task_Id := null)
334    is
335    begin
336       if Trace_On (Flag) then
337          Put (To_Integer (Self_Id)'Img &
338               ':' & Flag & ':' &
339               Self_Id.Common.Task_Image (1 .. Self_Id.Common.Task_Image_Len) &
340               ':');
341
342          if Other_Id /= null then
343             Put (To_Integer (Other_Id)'Img & ':');
344          end if;
345
346          Put_Line (Msg);
347       end if;
348    end Trace;
349
350    -----------
351    -- Write --
352    -----------
353
354    procedure Write (Fd : Integer; S : String; Count : Integer) is
355       Discard : Integer;
356       pragma Unreferenced (Discard);
357    begin
358       Discard := System.CRTL.write (Fd, S (S'First)'Address, Count);
359       --  Is it really right to ignore write errors here ???
360    end Write;
361
362 end System.Tasking.Debug;