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-2005 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 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.
73 function Get_User_State
return Long_Integer is
75 return STPO
.Self
.User_State
;
82 procedure List_Tasks
is
89 C
:= C
.Common
.All_Tasks_Link
;
93 ------------------------
94 -- Print_Current_Task --
95 ------------------------
97 procedure Print_Current_Task
is
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
;
112 Put_Line
("null task");
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>");
125 Parent
.Common
.Task_Image
(1 .. Parent
.Common
.Task_Image_Len
));
128 Put
(", prio:" & T
.Common
.Current_Priority
'Img);
130 if not T
.Callable
then
131 Put
(", not callable");
138 if T
.Deferral_Level
/= 0 then
139 Put
(", abort deferred");
142 if T
.Common
.Call
/= null then
143 Entry_Call
:= T
.Common
.Call
;
146 while Entry_Call
/= null loop
147 Put
(To_Integer
(Entry_Call
.Self
)'Img);
148 Entry_Call
:= Entry_Call
.Acceptor_Prev_Call
;
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);
159 if T
.Terminate_Alternative
then
160 Put
(" or terminate");
164 if T
.User_State
/= 0 then
165 Put
(", state:" & T
.User_State
'Img);
175 procedure Put
(S
: String) is
177 Write
(2, S
, S
'Length);
184 procedure Put_Line
(S
: String := "") is
186 Write
(2, S
& ASCII
.LF
, S
'Length + 1);
189 ----------------------
190 -- Resume_All_Tasks --
191 ----------------------
193 procedure Resume_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
) is
196 pragma Unreferenced
(Dummy
);
203 Dummy
:= STPO
.Resume_Task
(C
, Thread_Self
);
204 C
:= C
.Common
.All_Tasks_Link
;
208 end Resume_All_Tasks
;
214 procedure Set_Trace
(Flag
: Character; Value
: Boolean := True) is
216 Trace_On
(Flag
) := Value
;
223 procedure Set_User_State
(Value
: Long_Integer) is
225 STPO
.Self
.User_State
:= Value
;
228 -----------------------
229 -- Suspend_All_Tasks --
230 -----------------------
232 procedure Suspend_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
) is
235 pragma Unreferenced
(Dummy
);
242 Dummy
:= STPO
.Suspend_Task
(C
, Thread_Self
);
243 C
:= C
.Common
.All_Tasks_Link
;
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.
260 end Task_Creation_Hook
;
262 ---------------------------
263 -- Task_Termination_Hook --
264 ---------------------------
266 procedure Task_Termination_Hook
is
269 end Task_Termination_Hook
;
279 Other_Id
: Task_Id
:= null)
282 if Trace_On
(Flag
) then
283 Put
(To_Integer
(Self_Id
)'Img &
285 Self_Id
.Common
.Task_Image
(1 .. Self_Id
.Common
.Task_Image_Len
) &
288 if Other_Id
/= null then
289 Put
(To_Integer
(Other_Id
)'Img & ':');
300 procedure Write
(Fd
: Integer; S
: String; Count
: Integer) is
302 pragma Unreferenced
(Discard
);
304 Discard
:= System
.CRTL
.write
(Fd
, S
(S
'First)'Address, Count
);
305 -- Is it really right to ignore write errors here ???
308 end System
.Tasking
.Debug
;