* tree-loop-linear.c: Don't include varray.h.
[official-gcc.git] / gcc / ada / s-tasdeb.adb
blob994ffd221db467f798ce66840619964c59e1af29
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-2005 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 ------------------------------------------------------------------------------
34 -- This package encapsulates all direct interfaces to task debugging services
35 -- that are needed by gdb with gnat mode.
37 -- Note : This file *must* be compiled with debugging information
39 -- Do not add any dependency to GNARL packages since this package is used
40 -- in both normal and restricted (ravenscar) environments.
42 with System.CRTL;
43 with System.Task_Primitives.Operations;
44 with Unchecked_Conversion;
46 package body System.Tasking.Debug is
48 package STPO renames System.Task_Primitives.Operations;
50 function To_Integer is new
51 Unchecked_Conversion (Task_Id, System.Address);
53 type Trace_Flag_Set is array (Character) of Boolean;
55 Trace_On : Trace_Flag_Set := ('A' .. 'Z' => False, others => True);
57 -----------------------
58 -- Local Subprograms --
59 -----------------------
61 procedure Write (Fd : Integer; S : String; Count : Integer);
63 procedure Put (S : String);
64 -- Display S on standard output.
66 procedure Put_Line (S : String := "");
67 -- Display S on standard output with an additional line terminator.
69 --------------------
70 -- Get_User_State --
71 --------------------
73 function Get_User_State return Long_Integer is
74 begin
75 return STPO.Self.User_State;
76 end Get_User_State;
78 ----------------
79 -- List_Tasks --
80 ----------------
82 procedure List_Tasks is
83 C : Task_Id;
84 begin
85 C := All_Tasks_List;
87 while C /= null loop
88 Print_Task_Info (C);
89 C := C.Common.All_Tasks_Link;
90 end loop;
91 end List_Tasks;
93 ------------------------
94 -- Print_Current_Task --
95 ------------------------
97 procedure Print_Current_Task is
98 begin
99 Print_Task_Info (STPO.Self);
100 end Print_Current_Task;
102 ---------------------
103 -- Print_Task_Info --
104 ---------------------
106 procedure Print_Task_Info (T : Task_Id) is
107 Entry_Call : Entry_Call_Link;
108 Parent : Task_Id;
110 begin
111 if T = null then
112 Put_Line ("null task");
113 return;
114 end if;
116 Put (T.Common.Task_Image (1 .. T.Common.Task_Image_Len) & ": " &
117 Task_States'Image (T.Common.State));
119 Parent := T.Common.Parent;
121 if Parent = null then
122 Put (", parent: <none>");
123 else
124 Put (", parent: " &
125 Parent.Common.Task_Image (1 .. Parent.Common.Task_Image_Len));
126 end if;
128 Put (", prio:" & T.Common.Current_Priority'Img);
130 if not T.Callable then
131 Put (", not callable");
132 end if;
134 if T.Aborting then
135 Put (", aborting");
136 end if;
138 if T.Deferral_Level /= 0 then
139 Put (", abort deferred");
140 end if;
142 if T.Common.Call /= null then
143 Entry_Call := T.Common.Call;
144 Put (", serving:");
146 while Entry_Call /= null loop
147 Put (To_Integer (Entry_Call.Self)'Img);
148 Entry_Call := Entry_Call.Acceptor_Prev_Call;
149 end loop;
150 end if;
152 if T.Open_Accepts /= null then
153 Put (", accepting:");
155 for J in T.Open_Accepts'Range loop
156 Put (T.Open_Accepts (J).S'Img);
157 end loop;
159 if T.Terminate_Alternative then
160 Put (" or terminate");
161 end if;
162 end if;
164 if T.User_State /= 0 then
165 Put (", state:" & T.User_State'Img);
166 end if;
168 Put_Line;
169 end Print_Task_Info;
171 ---------
172 -- Put --
173 ---------
175 procedure Put (S : String) is
176 begin
177 Write (2, S, S'Length);
178 end Put;
180 --------------
181 -- Put_Line --
182 --------------
184 procedure Put_Line (S : String := "") is
185 begin
186 Write (2, S & ASCII.LF, S'Length + 1);
187 end Put_Line;
189 ----------------------
190 -- Resume_All_Tasks --
191 ----------------------
193 procedure Resume_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
194 C : Task_Id;
195 Dummy : Boolean;
196 pragma Unreferenced (Dummy);
198 begin
199 STPO.Lock_RTS;
200 C := All_Tasks_List;
202 while C /= null loop
203 Dummy := STPO.Resume_Task (C, Thread_Self);
204 C := C.Common.All_Tasks_Link;
205 end loop;
207 STPO.Unlock_RTS;
208 end Resume_All_Tasks;
210 ---------------
211 -- Set_Trace --
212 ---------------
214 procedure Set_Trace (Flag : Character; Value : Boolean := True) is
215 begin
216 Trace_On (Flag) := Value;
217 end Set_Trace;
219 --------------------
220 -- Set_User_State --
221 --------------------
223 procedure Set_User_State (Value : Long_Integer) is
224 begin
225 STPO.Self.User_State := Value;
226 end Set_User_State;
228 -----------------------
229 -- Suspend_All_Tasks --
230 -----------------------
232 procedure Suspend_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
233 C : Task_Id;
234 Dummy : Boolean;
235 pragma Unreferenced (Dummy);
237 begin
238 STPO.Lock_RTS;
239 C := All_Tasks_List;
241 while C /= null loop
242 Dummy := STPO.Suspend_Task (C, Thread_Self);
243 C := C.Common.All_Tasks_Link;
244 end loop;
246 STPO.Unlock_RTS;
247 end Suspend_All_Tasks;
249 ------------------------
250 -- Task_Creation_Hook --
251 ------------------------
253 procedure Task_Creation_Hook (Thread : OS_Interface.Thread_Id) is
254 pragma Inspection_Point (Thread);
255 -- gdb needs to access the thread parameter in order to implement
256 -- the multitask mode under VxWorks.
258 begin
259 null;
260 end Task_Creation_Hook;
262 ---------------------------
263 -- Task_Termination_Hook --
264 ---------------------------
266 procedure Task_Termination_Hook is
267 begin
268 null;
269 end Task_Termination_Hook;
271 -----------
272 -- Trace --
273 -----------
275 procedure Trace
276 (Self_Id : Task_Id;
277 Msg : String;
278 Flag : Character;
279 Other_Id : Task_Id := null)
281 begin
282 if Trace_On (Flag) then
283 Put (To_Integer (Self_Id)'Img &
284 ':' & Flag & ':' &
285 Self_Id.Common.Task_Image (1 .. Self_Id.Common.Task_Image_Len) &
286 ':');
288 if Other_Id /= null then
289 Put (To_Integer (Other_Id)'Img & ':');
290 end if;
292 Put_Line (Msg);
293 end if;
294 end Trace;
296 -----------
297 -- Write --
298 -----------
300 procedure Write (Fd : Integer; S : String; Count : Integer) is
301 Discard : Integer;
302 pragma Unreferenced (Discard);
303 begin
304 Discard := System.CRTL.write (Fd, S (S'First)'Address, Count);
305 -- Is it really right to ignore write errors here ???
306 end Write;
308 end System.Tasking.Debug;