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-2014, 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 3, or (at your option) any later ver- --
14 -- sion. GNAT 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 -- This package encapsulates all direct interfaces to task debugging services
33 -- that are needed by gdb with gnat mode.
35 -- Note : This file *must* be compiled with debugging information
37 -- Do not add any dependency to GNARL packages since this package is used
38 -- in both normal and restricted (ravenscar) environments.
40 with System
.Address_Image
;
42 with System
.Task_Primitives
;
43 with System
.Task_Primitives
.Operations
;
45 package body System
.Tasking
.Debug
is
47 package STPO
renames System
.Task_Primitives
.Operations
;
49 type Trace_Flag_Set
is array (Character) of Boolean;
51 Trace_On
: Trace_Flag_Set
:= ('A' .. 'Z' => False, others => True);
53 Stderr_Fd
: constant := 2;
54 -- File descriptor for standard error
56 -----------------------
57 -- Local Subprograms --
58 -----------------------
60 procedure Write
(Fd
: Integer; S
: String; Count
: Integer);
61 -- Write Count characters of S to the file descriptor Fd
63 procedure Put
(S
: String);
64 -- Display S on standard error
66 procedure Put_Line
(S
: String := "");
67 -- Display S on standard error with an additional line terminator
69 function Task_Image
(T
: Task_Id
) return String;
70 -- Return the relevant characters from T.Common.Task_Image
72 function Task_Id_Image
(T
: Task_Id
) return String;
73 -- Return the address in hexadecimal form
75 ------------------------
76 -- Continue_All_Tasks --
77 ------------------------
79 procedure Continue_All_Tasks
is
83 pragma Unreferenced
(Dummy
);
90 Dummy
:= STPO
.Continue_Task
(C
);
91 C
:= C
.Common
.All_Tasks_Link
;
95 end Continue_All_Tasks
;
101 function Get_User_State
return Long_Integer is
103 return STPO
.Self
.User_State
;
110 procedure List_Tasks
is
117 C
:= C
.Common
.All_Tasks_Link
;
121 ------------------------
122 -- Print_Current_Task --
123 ------------------------
125 procedure Print_Current_Task
is
127 Print_Task_Info
(STPO
.Self
);
128 end Print_Current_Task
;
130 ---------------------
131 -- Print_Task_Info --
132 ---------------------
134 procedure Print_Task_Info
(T
: Task_Id
) is
135 Entry_Call
: Entry_Call_Link
;
140 Put_Line
("null task");
144 Put
(Task_Image
(T
) & ": " & Task_States
'Image (T
.Common
.State
));
145 Parent
:= T
.Common
.Parent
;
147 if Parent
= null then
148 Put
(", parent: <none>");
150 Put
(", parent: " & Task_Image
(Parent
));
153 Put
(", prio:" & T
.Common
.Current_Priority
'Img);
155 if not T
.Callable
then
156 Put
(", not callable");
163 if T
.Deferral_Level
/= 0 then
164 Put
(", abort deferred");
167 if T
.Common
.Call
/= null then
168 Entry_Call
:= T
.Common
.Call
;
171 while Entry_Call
/= null loop
172 Put
(Task_Id_Image
(Entry_Call
.Self
));
173 Entry_Call
:= Entry_Call
.Acceptor_Prev_Call
;
177 if T
.Open_Accepts
/= null then
178 Put
(", accepting:");
180 for J
in T
.Open_Accepts
'Range loop
181 Put
(T
.Open_Accepts
(J
).S
'Img);
184 if T
.Terminate_Alternative
then
185 Put
(" or terminate");
189 if T
.User_State
/= 0 then
190 Put
(", state:" & T
.User_State
'Img);
200 procedure Put
(S
: String) is
202 Write
(Stderr_Fd
, S
, S
'Length);
209 procedure Put_Line
(S
: String := "") is
211 Write
(Stderr_Fd
, S
& ASCII
.LF
, S
'Length + 1);
214 ----------------------
215 -- Resume_All_Tasks --
216 ----------------------
218 procedure Resume_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
) is
221 pragma Unreferenced
(Dummy
);
228 Dummy
:= STPO
.Resume_Task
(C
, Thread_Self
);
229 C
:= C
.Common
.All_Tasks_Link
;
233 end Resume_All_Tasks
;
239 procedure Set_Trace
(Flag
: Character; Value
: Boolean := True) is
241 Trace_On
(Flag
) := Value
;
248 procedure Set_User_State
(Value
: Long_Integer) is
250 STPO
.Self
.User_State
:= Value
;
253 ------------------------
254 -- Signal_Debug_Event --
255 ------------------------
257 procedure Signal_Debug_Event
258 (Event_Kind
: Event_Kind_Type
;
259 Task_Value
: Task_Id
)
263 end Signal_Debug_Event
;
269 procedure Stop_All_Tasks
is
273 pragma Unreferenced
(Dummy
);
280 Dummy
:= STPO
.Stop_Task
(C
);
281 C
:= C
.Common
.All_Tasks_Link
;
287 ----------------------------
288 -- Stop_All_Tasks_Handler --
289 ----------------------------
291 procedure Stop_All_Tasks_Handler
is
294 end Stop_All_Tasks_Handler
;
296 -----------------------
297 -- Suspend_All_Tasks --
298 -----------------------
300 procedure Suspend_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
) is
303 pragma Unreferenced
(Dummy
);
310 Dummy
:= STPO
.Suspend_Task
(C
, Thread_Self
);
311 C
:= C
.Common
.All_Tasks_Link
;
315 end Suspend_All_Tasks
;
317 ------------------------
318 -- Task_Creation_Hook --
319 ------------------------
321 procedure Task_Creation_Hook
(Thread
: OS_Interface
.Thread_Id
) is
322 pragma Inspection_Point
(Thread
);
323 -- gdb needs to access the thread parameter in order to implement
324 -- the multitask mode under VxWorks.
328 end Task_Creation_Hook
;
334 function Task_Id_Image
(T
: Task_Id
) return String is
337 return "Null_Task_Id";
339 return Address_Image
(T
.all'Address);
347 function Task_Image
(T
: Task_Id
) return String is
349 -- In case T.Common.Task_Image_Len is uninitialized junk, we check that
350 -- it is in range, to make this more robust.
352 if T
.Common
.Task_Image_Len
in T
.Common
.Task_Image
'Range then
353 return T
.Common
.Task_Image
(1 .. T
.Common
.Task_Image_Len
);
355 return T
.Common
.Task_Image
;
359 ---------------------------
360 -- Task_Termination_Hook --
361 ---------------------------
363 procedure Task_Termination_Hook
is
366 end Task_Termination_Hook
;
376 Other_Id
: Task_Id
:= null)
379 if Trace_On
(Flag
) then
380 Put
(Task_Id_Image
(Self_Id
) &
382 Task_Image
(Self_Id
) &
385 if Other_Id
/= null then
386 Put
(Task_Id_Image
(Other_Id
) & ':');
397 procedure Write
(Fd
: Integer; S
: String; Count
: Integer) is
398 Discard
: System
.CRTL
.ssize_t
;
399 -- Ignore write errors here; this is just debugging output, and there's
400 -- nothing to be done about errors anyway.
404 (Fd
, S
'Address, System
.CRTL
.size_t
(Count
));
407 end System
.Tasking
.Debug
;