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 pragma Restriction_Warnings
(No_Secondary_Stack
);
41 -- We wish to avoid secondary stack usage here, because (e.g.) Trace is called
42 -- at delicate times, such as during task termination after the secondary
43 -- stack has been deallocated. It's just a warning, so we don't require
44 -- partition-wide consistency.
47 with System
.Storage_Elements
; use System
.Storage_Elements
;
48 with System
.Task_Primitives
;
49 with System
.Task_Primitives
.Operations
;
51 package body System
.Tasking
.Debug
is
53 package STPO
renames System
.Task_Primitives
.Operations
;
55 type Trace_Flag_Set
is array (Character) of Boolean;
57 Trace_On
: Trace_Flag_Set
:= ('A' .. 'Z' => False, others => True);
59 Stderr_Fd
: constant := 2;
60 -- File descriptor for standard error
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 procedure Write
(Fd
: Integer; S
: String; Count
: Integer);
67 -- Write Count characters of S to the file descriptor Fd
69 procedure Put
(S
: String);
70 -- Display S on standard error
72 procedure Put_Line
(S
: String := "");
73 -- Display S on standard error with an additional line terminator
75 procedure Put_Task_Image
(T
: Task_Id
);
76 -- Display relevant characters from T.Common.Task_Image on standard error
78 procedure Put_Task_Id_Image
(T
: Task_Id
);
79 -- Display address in hexadecimal form on standard error
81 ------------------------
82 -- Continue_All_Tasks --
83 ------------------------
85 procedure Continue_All_Tasks
is
94 Dummy
:= STPO
.Continue_Task
(C
);
95 C
:= C
.Common
.All_Tasks_Link
;
99 end Continue_All_Tasks
;
105 function Get_User_State
return Long_Integer is
107 return STPO
.Self
.User_State
;
114 procedure List_Tasks
is
120 C
:= C
.Common
.All_Tasks_Link
;
124 ------------------------
125 -- Print_Current_Task --
126 ------------------------
128 procedure Print_Current_Task
is
130 Print_Task_Info
(STPO
.Self
);
131 end Print_Current_Task
;
133 ---------------------
134 -- Print_Task_Info --
135 ---------------------
137 procedure Print_Task_Info
(T
: Task_Id
) is
138 Entry_Call
: Entry_Call_Link
;
143 Put_Line
("null task");
148 Put
(": " & Task_States
'Image (T
.Common
.State
));
149 Parent
:= T
.Common
.Parent
;
151 if Parent
= null then
152 Put
(", parent: <none>");
155 Put_Task_Image
(Parent
);
158 Put
(", prio:" & T
.Common
.Current_Priority
'Img);
160 if not T
.Callable
then
161 Put
(", not callable");
168 if T
.Deferral_Level
/= 0 then
169 Put
(", abort deferred");
172 if T
.Common
.Call
/= null then
173 Entry_Call
:= T
.Common
.Call
;
176 while Entry_Call
/= null loop
177 Put_Task_Id_Image
(Entry_Call
.Self
);
178 Entry_Call
:= Entry_Call
.Acceptor_Prev_Call
;
182 if T
.Open_Accepts
/= null then
183 Put
(", accepting:");
185 for J
in T
.Open_Accepts
'Range loop
186 Put
(T
.Open_Accepts
(J
).S
'Img);
189 if T
.Terminate_Alternative
then
190 Put
(" or terminate");
194 if T
.User_State
/= 0 then
195 Put
(", state:" & T
.User_State
'Img);
205 procedure Put
(S
: String) is
207 Write
(Stderr_Fd
, S
, S
'Length);
214 procedure Put_Line
(S
: String := "") is
216 Write
(Stderr_Fd
, S
& ASCII
.LF
, S
'Length + 1);
219 -----------------------
220 -- Put_Task_Id_Image --
221 -----------------------
223 procedure Put_Task_Id_Image
(T
: Task_Id
) is
224 Address_Image_Length
: constant :=
225 13 + (if Standard
'Address_Size = 64 then 10 else 0);
226 -- Length of string to be printed for address of task
228 H
: constant array (0 .. 15) of Character := "0123456789ABCDEF";
229 -- Table of hex digits
231 S
: String (1 .. Address_Image_Length
);
238 Put
("Null_Task_Id");
242 P
:= Address_Image_Length
- 1;
243 N
:= To_Integer
(T
.all'Address);
253 S
(P
) := H
(Integer (N
mod 16));
261 end Put_Task_Id_Image
;
267 procedure Put_Task_Image
(T
: Task_Id
) is
269 -- In case T.Common.Task_Image_Len is uninitialized junk, we check that
270 -- it is in range, to make this more robust.
272 if T
.Common
.Task_Image_Len
in T
.Common
.Task_Image
'Range then
273 Put
(T
.Common
.Task_Image
(1 .. T
.Common
.Task_Image_Len
));
275 Put
(T
.Common
.Task_Image
);
279 ----------------------
280 -- Resume_All_Tasks --
281 ----------------------
283 procedure Resume_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
) is
292 Dummy
:= STPO
.Resume_Task
(C
, Thread_Self
);
293 C
:= C
.Common
.All_Tasks_Link
;
297 end Resume_All_Tasks
;
303 procedure Set_Trace
(Flag
: Character; Value
: Boolean := True) is
305 Trace_On
(Flag
) := Value
;
312 procedure Set_User_State
(Value
: Long_Integer) is
314 STPO
.Self
.User_State
:= Value
;
317 ------------------------
318 -- Signal_Debug_Event --
319 ------------------------
321 procedure Signal_Debug_Event
322 (Event_Kind
: Event_Kind_Type
;
323 Task_Value
: Task_Id
)
327 end Signal_Debug_Event
;
333 procedure Stop_All_Tasks
is
342 Dummy
:= STPO
.Stop_Task
(C
);
343 C
:= C
.Common
.All_Tasks_Link
;
349 ----------------------------
350 -- Stop_All_Tasks_Handler --
351 ----------------------------
353 procedure Stop_All_Tasks_Handler
is
356 end Stop_All_Tasks_Handler
;
358 -----------------------
359 -- Suspend_All_Tasks --
360 -----------------------
362 procedure Suspend_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
) is
371 Dummy
:= STPO
.Suspend_Task
(C
, Thread_Self
);
372 C
:= C
.Common
.All_Tasks_Link
;
376 end Suspend_All_Tasks
;
378 ------------------------
379 -- Task_Creation_Hook --
380 ------------------------
382 procedure Task_Creation_Hook
(Thread
: OS_Interface
.Thread_Id
) is
383 pragma Inspection_Point
(Thread
);
384 -- gdb needs to access the thread parameter in order to implement
385 -- the multitask mode under VxWorks.
389 end Task_Creation_Hook
;
391 ---------------------------
392 -- Task_Termination_Hook --
393 ---------------------------
395 procedure Task_Termination_Hook
is
398 end Task_Termination_Hook
;
408 Other_Id
: Task_Id
:= null)
411 if Trace_On
(Flag
) then
412 Put_Task_Id_Image
(Self_Id
);
413 Put
(":" & Flag
& ":");
414 Put_Task_Image
(Self_Id
);
417 if Other_Id
/= null then
418 Put_Task_Id_Image
(Other_Id
);
430 procedure Write
(Fd
: Integer; S
: String; Count
: Integer) is
431 Discard
: System
.CRTL
.ssize_t
;
432 -- Ignore write errors here; this is just debugging output, and there's
433 -- nothing to be done about errors anyway.
437 (Fd
, S
'Address, System
.CRTL
.size_t
(Count
));
444 procedure Master_Hook
445 (Dependent
: Task_Id
;
447 Master_Level
: Integer)
449 pragma Inspection_Point
(Dependent
);
450 pragma Inspection_Point
(Parent
);
451 pragma Inspection_Point
(Master_Level
);
456 ---------------------------
457 -- Master_Completed_Hook --
458 ---------------------------
460 procedure Master_Completed_Hook
462 Master_Level
: Integer)
464 pragma Inspection_Point
(Self_ID
);
465 pragma Inspection_Point
(Master_Level
);
468 end Master_Completed_Hook
;
470 end System
.Tasking
.Debug
;