1------------------------------------------------------------------------------
2--                                                                          --
3--                  GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                --
4--                                                                          --
5--                  S Y S T E M . T A S K I N G . D E B U G                 --
6--                                                                          --
7--                                  S p e c                                 --
8--                                                                          --
9--          Copyright (C) 1997-2021, Free Software Foundation, Inc.         --
10--                                                                          --
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.                                     --
17--                                                                          --
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.               --
21--                                                                          --
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/>.                                          --
26--                                                                          --
27-- GNARL was developed by the GNARL team at Florida State University.       --
28-- Extensive contributions were provided by Ada Core Technologies, Inc.     --
29--                                                                          --
30------------------------------------------------------------------------------
31
32--  This package encapsulates all direct interfaces to task debugging services
33--  that are needed by gdb with gnat mode.
34
35with System.Tasking;
36with System.OS_Interface;
37
38package System.Tasking.Debug is
39   pragma Preelaborate;
40
41   ------------------------------------------
42   -- Application-level debugging routines --
43   ------------------------------------------
44
45   procedure List_Tasks;
46   --  Print a list of all the known Ada tasks with abbreviated state
47   --  information, one-per-line, to the standard error file.
48
49   procedure Print_Current_Task;
50   --  Write information about current task, in hexadecimal, as one line, to
51   --  the standard error file.
52
53   procedure Print_Task_Info (T : Task_Id);
54   --  Similar to Print_Current_Task, for a given task
55
56   procedure Set_User_State (Value : Long_Integer);
57   --  Set user state value in the current task. This state will be displayed
58   --  when calling List_Tasks or Print_Current_Task. It is useful for setting
59   --  task specific state.
60
61   function Get_User_State return Long_Integer;
62   --  Return the user state for the current task
63
64   -------------------------
65   -- General GDB support --
66   -------------------------
67
68   Known_Tasks : array (0 .. 999) of Task_Id := [others => null]
69     with Atomic_Components;
70   --  Global array of tasks read by gdb, and updated by Create_Task and
71   --  Finalize_TCB. Ensure access to its components is atomic to allow
72   --  lock-free concurrent access.
73
74   Debug_Event_Activating           : constant := 1;
75   Debug_Event_Run                  : constant := 2;
76   Debug_Event_Suspended            : constant := 3;
77   Debug_Event_Preempted            : constant := 4;
78   Debug_Event_Terminated           : constant := 5;
79   Debug_Event_Abort_Terminated     : constant := 6;
80   Debug_Event_Exception_Terminated : constant := 7;
81   Debug_Event_Rendezvous_Exception : constant := 8;
82   Debug_Event_Handled              : constant := 9;
83   Debug_Event_Dependents_Exception : constant := 10;
84   Debug_Event_Handled_Others       : constant := 11;
85
86   subtype Event_Kind_Type is Positive range 1 .. 11;
87   --  Event kinds currently defined for debugging, used globally
88   --  below and on a per task basis.
89
90   procedure Signal_Debug_Event
91     (Event_Kind : Event_Kind_Type;
92      Task_Value : Task_Id);
93
94   ----------------------------------
95   -- VxWorks specific GDB support --
96   ----------------------------------
97
98   --  Although the following routines are implemented in a target independent
99   --  manner, only VxWorks currently uses them.
100
101   procedure Task_Creation_Hook (Thread : OS_Interface.Thread_Id);
102   --  This procedure is used to notify GDB of task's creation. It must be
103   --  called by the task's creator.
104
105   procedure Task_Termination_Hook;
106   --  This procedure is used to notify GDB of task's termination
107
108   procedure Suspend_All_Tasks (Thread_Self : OS_Interface.Thread_Id);
109   --  Suspend all the tasks except the one whose associated thread is
110   --  Thread_Self by traversing All_Tasks_List and calling
111   --  System.Task_Primitives.Operations.Suspend_Task.
112
113   procedure Resume_All_Tasks (Thread_Self : OS_Interface.Thread_Id);
114   --  Resume all the tasks except the one whose associated thread is
115   --  Thread_Self by traversing All_Tasks_List and calling
116   --  System.Task_Primitives.Operations.Continue_Task.
117
118   procedure Stop_All_Tasks_Handler;
119   --  Stop all the tasks by traversing All_Tasks_List and calling
120   --  System.Task_Primitives.Operations.Stop_All_Task. This function
121   --  can be used in an interrupt handler.
122
123   procedure Stop_All_Tasks;
124   --  Stop all the tasks by traversing All_Tasks_List and calling
125   --  System.Task_Primitives.Operations.Stop_Task.
126
127   procedure Continue_All_Tasks;
128   --  Continue all the tasks by traversing All_Tasks_List and calling
129   --  System.Task_Primitives.Operations.Continue_Task.
130
131   -------------------------------
132   -- Run-time tracing routines --
133   -------------------------------
134
135   procedure Trace
136     (Self_Id  : Task_Id;
137      Msg      : String;
138      Flag     : Character;
139      Other_Id : Task_Id := null);
140   --  If traces for Flag are enabled, display on Standard_Error a given
141   --  message for the current task. Other_Id is an optional second task id
142   --  to display.
143
144   procedure Set_Trace
145     (Flag  : Character;
146      Value : Boolean := True);
147   --  Enable or disable tracing for Flag. By default, flags in the range
148   --  'A' .. 'Z' are disabled, others are enabled.
149
150   ---------------------------------
151   -- Hooks for Valgrind/Helgrind --
152   ---------------------------------
153
154   procedure Master_Hook
155     (Dependent    : Task_Id;
156      Parent       : Task_Id;
157      Master_Level : Integer);
158   --  Indicate to Valgrind/Helgrind that the master of Dependent is
159   --  Parent + Master_Level.
160
161   procedure Master_Completed_Hook
162     (Self_ID      : Task_Id;
163      Master_Level : Integer);
164   --  Indicate to Valgrind/Helgrind that Self_ID has completed the master
165   --  Master_Level.
166
167end System.Tasking.Debug;
168