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
258 pragma Unreferenced
(Dummy
);
265 Dummy
:= STPO
.Stop_Task
(C
);
266 C
:= C
.Common
.All_Tasks_Link
;
272 ----------------------------
273 -- Stop_All_Tasks_Handler --
274 ----------------------------
276 procedure Stop_All_Tasks_Handler
is
279 end Stop_All_Tasks_Handler
;
281 -----------------------
282 -- Suspend_All_Tasks --
283 -----------------------
285 procedure Suspend_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
) is
288 pragma Unreferenced
(Dummy
);
295 Dummy
:= STPO
.Suspend_Task
(C
, Thread_Self
);
296 C
:= C
.Common
.All_Tasks_Link
;
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.
313 end Task_Creation_Hook
;
315 ---------------------------
316 -- Task_Termination_Hook --
317 ---------------------------
319 procedure Task_Termination_Hook
is
322 end Task_Termination_Hook
;
332 Other_Id
: Task_Id
:= null)
335 if Trace_On
(Flag
) then
336 Put
(To_Integer
(Self_Id
)'Img &
338 Self_Id
.Common
.Task_Image
(1 .. Self_Id
.Common
.Task_Image_Len
) &
341 if Other_Id
/= null then
342 Put
(To_Integer
(Other_Id
)'Img & ':');
353 procedure Write
(Fd
: Integer; S
: String; Count
: Integer) is
355 pragma Unreferenced
(Discard
);
357 Discard
:= System
.CRTL
.write
(Fd
, S
(S
'First)'Address, Count
);
358 -- Is it really right to ignore write errors here ???
361 end System
.Tasking
.Debug
;