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-2008, 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
;
44 with System
.Task_Primitives
.Operations
;
45 with Ada
.Unchecked_Conversion
;
47 package body System
.Tasking
.Debug
is
49 package STPO
renames System
.Task_Primitives
.Operations
;
51 function To_Integer
is new
52 Ada
.Unchecked_Conversion
(Task_Id
, System
.Task_Primitives
.Task_Address
);
54 type Trace_Flag_Set
is array (Character) of Boolean;
56 Trace_On
: Trace_Flag_Set
:= ('A' .. 'Z' => False, others => True);
58 -----------------------
59 -- Local Subprograms --
60 -----------------------
62 procedure Write
(Fd
: Integer; S
: String; Count
: Integer);
64 procedure Put
(S
: String);
65 -- Display S on standard output
67 procedure Put_Line
(S
: String := "");
68 -- Display S on standard output with an additional line terminator
70 ------------------------
71 -- Continue_All_Tasks --
72 ------------------------
74 procedure Continue_All_Tasks
is
78 pragma Unreferenced
(Dummy
);
85 Dummy
:= STPO
.Continue_Task
(C
);
86 C
:= C
.Common
.All_Tasks_Link
;
90 end Continue_All_Tasks
;
96 function Get_User_State
return Long_Integer is
98 return STPO
.Self
.User_State
;
105 procedure List_Tasks
is
112 C
:= C
.Common
.All_Tasks_Link
;
116 ------------------------
117 -- Print_Current_Task --
118 ------------------------
120 procedure Print_Current_Task
is
122 Print_Task_Info
(STPO
.Self
);
123 end Print_Current_Task
;
125 ---------------------
126 -- Print_Task_Info --
127 ---------------------
129 procedure Print_Task_Info
(T
: Task_Id
) is
130 Entry_Call
: Entry_Call_Link
;
135 Put_Line
("null task");
139 Put
(T
.Common
.Task_Image
(1 .. T
.Common
.Task_Image_Len
) & ": " &
140 Task_States
'Image (T
.Common
.State
));
142 Parent
:= T
.Common
.Parent
;
144 if Parent
= null then
145 Put
(", parent: <none>");
148 Parent
.Common
.Task_Image
(1 .. Parent
.Common
.Task_Image_Len
));
151 Put
(", prio:" & T
.Common
.Current_Priority
'Img);
153 if not T
.Callable
then
154 Put
(", not callable");
161 if T
.Deferral_Level
/= 0 then
162 Put
(", abort deferred");
165 if T
.Common
.Call
/= null then
166 Entry_Call
:= T
.Common
.Call
;
169 while Entry_Call
/= null loop
170 Put
(To_Integer
(Entry_Call
.Self
)'Img);
171 Entry_Call
:= Entry_Call
.Acceptor_Prev_Call
;
175 if T
.Open_Accepts
/= null then
176 Put
(", accepting:");
178 for J
in T
.Open_Accepts
'Range loop
179 Put
(T
.Open_Accepts
(J
).S
'Img);
182 if T
.Terminate_Alternative
then
183 Put
(" or terminate");
187 if T
.User_State
/= 0 then
188 Put
(", state:" & T
.User_State
'Img);
198 procedure Put
(S
: String) is
200 Write
(2, S
, S
'Length);
207 procedure Put_Line
(S
: String := "") is
209 Write
(2, S
& ASCII
.LF
, S
'Length + 1);
212 ----------------------
213 -- Resume_All_Tasks --
214 ----------------------
216 procedure Resume_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
) is
219 pragma Unreferenced
(Dummy
);
226 Dummy
:= STPO
.Resume_Task
(C
, Thread_Self
);
227 C
:= C
.Common
.All_Tasks_Link
;
231 end Resume_All_Tasks
;
237 procedure Set_Trace
(Flag
: Character; Value
: Boolean := True) is
239 Trace_On
(Flag
) := Value
;
246 procedure Set_User_State
(Value
: Long_Integer) is
248 STPO
.Self
.User_State
:= Value
;
255 procedure Stop_All_Tasks
is
259 pragma Unreferenced
(Dummy
);
266 Dummy
:= STPO
.Stop_Task
(C
);
267 C
:= C
.Common
.All_Tasks_Link
;
273 ----------------------------
274 -- Stop_All_Tasks_Handler --
275 ----------------------------
277 procedure Stop_All_Tasks_Handler
is
280 end Stop_All_Tasks_Handler
;
282 -----------------------
283 -- Suspend_All_Tasks --
284 -----------------------
286 procedure Suspend_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
) is
289 pragma Unreferenced
(Dummy
);
296 Dummy
:= STPO
.Suspend_Task
(C
, Thread_Self
);
297 C
:= C
.Common
.All_Tasks_Link
;
301 end Suspend_All_Tasks
;
303 ------------------------
304 -- Task_Creation_Hook --
305 ------------------------
307 procedure Task_Creation_Hook
(Thread
: OS_Interface
.Thread_Id
) is
308 pragma Inspection_Point
(Thread
);
309 -- gdb needs to access the thread parameter in order to implement
310 -- the multitask mode under VxWorks.
314 end Task_Creation_Hook
;
316 ---------------------------
317 -- Task_Termination_Hook --
318 ---------------------------
320 procedure Task_Termination_Hook
is
323 end Task_Termination_Hook
;
333 Other_Id
: Task_Id
:= null)
336 if Trace_On
(Flag
) then
337 Put
(To_Integer
(Self_Id
)'Img &
339 Self_Id
.Common
.Task_Image
(1 .. Self_Id
.Common
.Task_Image_Len
) &
342 if Other_Id
/= null then
343 Put
(To_Integer
(Other_Id
)'Img & ':');
354 procedure Write
(Fd
: Integer; S
: String; Count
: Integer) is
356 pragma Unreferenced
(Discard
);
358 Discard
:= System
.CRTL
.write
(Fd
, S
(S
'First)'Address, Count
);
359 -- Is it really right to ignore write errors here ???
362 end System
.Tasking
.Debug
;