1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K I N G . D E B U G --
9 -- Copyright (C) 1997-2007, Free Software Foundation, Inc. --
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. --
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. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
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.
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
77 pragma Unreferenced (Dummy);
84 Dummy := STPO.Continue_Task (C);
85 C := C.Common.All_Tasks_Link;
89 end Continue_All_Tasks;
95 function Get_User_State return Long_Integer is
97 return STPO.Self.User_State;
104 procedure List_Tasks is
111 C := C.Common.All_Tasks_Link;
115 ------------------------
116 -- Print_Current_Task --
117 ------------------------
119 procedure Print_Current_Task is
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;
134 Put_Line ("null task");
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>");
147 Parent.Common.Task_Image (1 .. Parent.Common.Task_Image_Len));
150 Put (", prio:" & T.Common.Current_Priority'Img);
152 if not T.Callable then
153 Put (", not callable");
160 if T.Deferral_Level /= 0 then
161 Put (", abort deferred");
164 if T.Common.Call /= null then
165 Entry_Call := T.Common.Call;
168 while Entry_Call /= null loop
169 Put (To_Integer (Entry_Call.Self)'Img);
170 Entry_Call := Entry_Call.Acceptor_Prev_Call;
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);
181 if T.Terminate_Alternative then
182 Put (" or terminate");
186 if T.User_State /= 0 then
187 Put (", state:" & T.User_State'Img);
197 procedure Put (S : String) is
199 Write (2, S, S'Length);
206 procedure Put_Line (S : String := "") is
208 Write (2, S & ASCII.LF, S'Length + 1);
211 ----------------------
212 -- Resume_All_Tasks --
213 ----------------------
215 procedure Resume_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
218 pragma Unreferenced (Dummy);
225 Dummy := STPO.Resume_Task (C, Thread_Self);
226 C := C.Common.All_Tasks_Link;
230 end Resume_All_Tasks;
236 procedure Set_Trace (Flag : Character; Value : Boolean := True) is
238 Trace_On (Flag) := Value;
245 procedure Set_User_State (Value : Long_Integer) is
247 STPO.Self.User_State := Value;
254 procedure Stop_All_Tasks is
259 -----------------------
260 -- Suspend_All_Tasks --
261 -----------------------
263 procedure Suspend_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
266 pragma Unreferenced (Dummy);
273 Dummy := STPO.Suspend_Task (C, Thread_Self);
274 C := C.Common.All_Tasks_Link;
278 end Suspend_All_Tasks;
280 ------------------------
281 -- Task_Creation_Hook --
282 ------------------------
284 procedure Task_Creation_Hook (Thread : OS_Interface.Thread_Id) is
285 pragma Inspection_Point (Thread);
286 -- gdb needs to access the thread parameter in order to implement
287 -- the multitask mode under VxWorks.
291 end Task_Creation_Hook;
293 ---------------------------
294 -- Task_Termination_Hook --
295 ---------------------------
297 procedure Task_Termination_Hook is
300 end Task_Termination_Hook;
310 Other_Id : Task_Id := null)
313 if Trace_On (Flag) then
314 Put (To_Integer (Self_Id)'Img &
316 Self_Id.Common.Task_Image (1 .. Self_Id.Common.Task_Image_Len) &
319 if Other_Id /= null then
320 Put (To_Integer (Other_Id)'Img & ':');
331 procedure Write (Fd : Integer; S : String; Count : Integer) is
333 pragma Unreferenced (Discard);
335 Discard := System.CRTL.write (Fd, S (S'First)'Address, Count);
336 -- Is it really right to ignore write errors here ???
339 end System.Tasking.Debug;