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-2011, 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   --  Global array of tasks read by gdb, and updated by Create_Task and
70   --  Finalize_TCB
71
72   Debug_Event_Activating           : constant := 1;
73   Debug_Event_Run                  : constant := 2;
74   Debug_Event_Suspended            : constant := 3;
75   Debug_Event_Preempted            : constant := 4;
76   Debug_Event_Terminated           : constant := 5;
77   Debug_Event_Abort_Terminated     : constant := 6;
78   Debug_Event_Exception_Terminated : constant := 7;
79   Debug_Event_Rendezvous_Exception : constant := 8;
80   Debug_Event_Handled              : constant := 9;
81   Debug_Event_Dependents_Exception : constant := 10;
82   Debug_Event_Handled_Others       : constant := 11;
83
84   subtype Event_Kind_Type is Positive range 1 .. 11;
85   --  Event kinds currently defined for debugging, used globally
86   --  below and on a per task basis.
87
88   procedure Signal_Debug_Event
89     (Event_Kind : Event_Kind_Type;
90      Task_Value : Task_Id);
91
92   ----------------------------------
93   -- VxWorks specific GDB support --
94   ----------------------------------
95
96   --  Although the following routines are implemented in a target independent
97   --  manner, only VxWorks currently uses them.
98
99   procedure Task_Creation_Hook (Thread : OS_Interface.Thread_Id);
100   --  This procedure is used to notify GDB of task's creation. It must be
101   --  called by the task's creator.
102
103   procedure Task_Termination_Hook;
104   --  This procedure is used to notify GDB of task's termination
105
106   procedure Suspend_All_Tasks (Thread_Self : OS_Interface.Thread_Id);
107   --  Suspend all the tasks except the one whose associated thread is
108   --  Thread_Self by traversing All_Tasks_Lists and calling
109   --  System.Task_Primitives.Operations.Suspend_Task.
110
111   procedure Resume_All_Tasks (Thread_Self : OS_Interface.Thread_Id);
112   --  Resume all the tasks except the one whose associated thread is
113   --  Thread_Self by traversing All_Tasks_Lists and calling
114   --  System.Task_Primitives.Operations.Continue_Task.
115
116   procedure Stop_All_Tasks_Handler;
117   --  Stop all the tasks by traversing All_Tasks_Lists and calling
118   --  System.Task_Primitives.Operations.Stop_All_Task. This function
119   --  can be used in an interrupt handler.
120
121   procedure Stop_All_Tasks;
122   --  Stop all the tasks by traversing All_Tasks_Lists and calling
123   --  System.Task_Primitives.Operations.Stop_Task.
124
125   procedure Continue_All_Tasks;
126   --  Continue all the tasks by traversing All_Tasks_Lists and calling
127   --  System.Task_Primitives.Operations.Continue_Task.
128
129   -------------------------------
130   -- Run-time tracing routines --
131   -------------------------------
132
133   procedure Trace
134     (Self_Id  : Task_Id;
135      Msg      : String;
136      Flag     : Character;
137      Other_Id : Task_Id := null);
138   --  If traces for Flag are enabled, display on Standard_Error a given
139   --  message for the current task. Other_Id is an optional second task id
140   --  to display.
141
142   procedure Set_Trace
143     (Flag  : Character;
144      Value : Boolean := True);
145   --  Enable or disable tracing for Flag. By default, flags in the range
146   --  'A' .. 'Z' are disabled, others are enabled.
147
148end System.Tasking.Debug;
149