Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / ada / s-tasdeb.adb
blob05719426d24315f1e81e5fcbf7a8cbe50bb8b014
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-2007, 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 Ada.Unchecked_Conversion;
46 package body System.Tasking.Debug is
48 package STPO renames System.Task_Primitives.Operations;
50 function To_Integer is new
51 Ada.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 -- Continue_All_Tasks --
71 ------------------------
73 procedure Continue_All_Tasks is
74 C : Task_Id;
76 Dummy : Boolean;
77 pragma Unreferenced (Dummy);
79 begin
80 STPO.Lock_RTS;
82 C := All_Tasks_List;
83 while C /= null loop
84 Dummy := STPO.Continue_Task (C);
85 C := C.Common.All_Tasks_Link;
86 end loop;
88 STPO.Unlock_RTS;
89 end Continue_All_Tasks;
91 --------------------
92 -- Get_User_State --
93 --------------------
95 function Get_User_State return Long_Integer is
96 begin
97 return STPO.Self.User_State;
98 end Get_User_State;
100 ----------------
101 -- List_Tasks --
102 ----------------
104 procedure List_Tasks is
105 C : Task_Id;
106 begin
107 C := All_Tasks_List;
109 while C /= null loop
110 Print_Task_Info (C);
111 C := C.Common.All_Tasks_Link;
112 end loop;
113 end List_Tasks;
115 ------------------------
116 -- Print_Current_Task --
117 ------------------------
119 procedure Print_Current_Task is
120 begin
121 Print_Task_Info (STPO.Self);
122 end Print_Current_Task;
124 ---------------------
125 -- Print_Task_Info --
126 ---------------------
128 procedure Print_Task_Info (T : Task_Id) is
129 Entry_Call : Entry_Call_Link;
130 Parent : Task_Id;
132 begin
133 if T = null then
134 Put_Line ("null task");
135 return;
136 end if;
138 Put (T.Common.Task_Image (1 .. T.Common.Task_Image_Len) & ": " &
139 Task_States'Image (T.Common.State));
141 Parent := T.Common.Parent;
143 if Parent = null then
144 Put (", parent: <none>");
145 else
146 Put (", parent: " &
147 Parent.Common.Task_Image (1 .. Parent.Common.Task_Image_Len));
148 end if;
150 Put (", prio:" & T.Common.Current_Priority'Img);
152 if not T.Callable then
153 Put (", not callable");
154 end if;
156 if T.Aborting then
157 Put (", aborting");
158 end if;
160 if T.Deferral_Level /= 0 then
161 Put (", abort deferred");
162 end if;
164 if T.Common.Call /= null then
165 Entry_Call := T.Common.Call;
166 Put (", serving:");
168 while Entry_Call /= null loop
169 Put (To_Integer (Entry_Call.Self)'Img);
170 Entry_Call := Entry_Call.Acceptor_Prev_Call;
171 end loop;
172 end if;
174 if T.Open_Accepts /= null then
175 Put (", accepting:");
177 for J in T.Open_Accepts'Range loop
178 Put (T.Open_Accepts (J).S'Img);
179 end loop;
181 if T.Terminate_Alternative then
182 Put (" or terminate");
183 end if;
184 end if;
186 if T.User_State /= 0 then
187 Put (", state:" & T.User_State'Img);
188 end if;
190 Put_Line;
191 end Print_Task_Info;
193 ---------
194 -- Put --
195 ---------
197 procedure Put (S : String) is
198 begin
199 Write (2, S, S'Length);
200 end Put;
202 --------------
203 -- Put_Line --
204 --------------
206 procedure Put_Line (S : String := "") is
207 begin
208 Write (2, S & ASCII.LF, S'Length + 1);
209 end Put_Line;
211 ----------------------
212 -- Resume_All_Tasks --
213 ----------------------
215 procedure Resume_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
216 C : Task_Id;
217 Dummy : Boolean;
218 pragma Unreferenced (Dummy);
220 begin
221 STPO.Lock_RTS;
222 C := All_Tasks_List;
224 while C /= null loop
225 Dummy := STPO.Resume_Task (C, Thread_Self);
226 C := C.Common.All_Tasks_Link;
227 end loop;
229 STPO.Unlock_RTS;
230 end Resume_All_Tasks;
232 ---------------
233 -- Set_Trace --
234 ---------------
236 procedure Set_Trace (Flag : Character; Value : Boolean := True) is
237 begin
238 Trace_On (Flag) := Value;
239 end Set_Trace;
241 --------------------
242 -- Set_User_State --
243 --------------------
245 procedure Set_User_State (Value : Long_Integer) is
246 begin
247 STPO.Self.User_State := Value;
248 end Set_User_State;
250 --------------------
251 -- Stop_All_Tasks --
252 --------------------
254 procedure Stop_All_Tasks is
255 C : Task_Id;
257 Dummy : Boolean;
258 pragma Unreferenced (Dummy);
260 begin
261 STPO.Lock_RTS;
263 C := All_Tasks_List;
264 while C /= null loop
265 Dummy := STPO.Stop_Task (C);
266 C := C.Common.All_Tasks_Link;
267 end loop;
269 STPO.Unlock_RTS;
270 end Stop_All_Tasks;
272 ----------------------------
273 -- Stop_All_Tasks_Handler --
274 ----------------------------
276 procedure Stop_All_Tasks_Handler is
277 begin
278 STPO.Stop_All_Tasks;
279 end Stop_All_Tasks_Handler;
281 -----------------------
282 -- Suspend_All_Tasks --
283 -----------------------
285 procedure Suspend_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
286 C : Task_Id;
287 Dummy : Boolean;
288 pragma Unreferenced (Dummy);
290 begin
291 STPO.Lock_RTS;
292 C := All_Tasks_List;
294 while C /= null loop
295 Dummy := STPO.Suspend_Task (C, Thread_Self);
296 C := C.Common.All_Tasks_Link;
297 end loop;
299 STPO.Unlock_RTS;
300 end Suspend_All_Tasks;
302 ------------------------
303 -- Task_Creation_Hook --
304 ------------------------
306 procedure Task_Creation_Hook (Thread : OS_Interface.Thread_Id) is
307 pragma Inspection_Point (Thread);
308 -- gdb needs to access the thread parameter in order to implement
309 -- the multitask mode under VxWorks.
311 begin
312 null;
313 end Task_Creation_Hook;
315 ---------------------------
316 -- Task_Termination_Hook --
317 ---------------------------
319 procedure Task_Termination_Hook is
320 begin
321 null;
322 end Task_Termination_Hook;
324 -----------
325 -- Trace --
326 -----------
328 procedure Trace
329 (Self_Id : Task_Id;
330 Msg : String;
331 Flag : Character;
332 Other_Id : Task_Id := null)
334 begin
335 if Trace_On (Flag) then
336 Put (To_Integer (Self_Id)'Img &
337 ':' & Flag & ':' &
338 Self_Id.Common.Task_Image (1 .. Self_Id.Common.Task_Image_Len) &
339 ':');
341 if Other_Id /= null then
342 Put (To_Integer (Other_Id)'Img & ':');
343 end if;
345 Put_Line (Msg);
346 end if;
347 end Trace;
349 -----------
350 -- Write --
351 -----------
353 procedure Write (Fd : Integer; S : String; Count : Integer) is
354 Discard : Integer;
355 pragma Unreferenced (Discard);
356 begin
357 Discard := System.CRTL.write (Fd, S (S'First)'Address, Count);
358 -- Is it really right to ignore write errors here ???
359 end Write;
361 end System.Tasking.Debug;