Add hppa-openbsd target
[official-gcc.git] / gcc / ada / s-tasdeb.ads
blobbdffad396507ba18400f7d42815e28ffdf2bccf5
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA 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 -- --
10 -- Copyright (C) 1997-2001, Free Software Foundation, Inc. --
11 -- --
12 -- GNARL is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
33 -- --
34 ------------------------------------------------------------------------------
36 -- This package encapsulates all direct interfaces to task debugging services
37 -- that are needed by gdb with gnat mode (1.17 and higher)
39 with Interfaces.C;
40 with System.Tasking;
41 with System.OS_Interface;
43 package System.Tasking.Debug is
45 subtype int is Interfaces.C.int;
46 subtype unsigned_long is Interfaces.C.unsigned_long;
48 package ST renames System.Tasking;
50 Known_Tasks : array (0 .. 999) of Task_ID;
51 -- Global array of tasks read by gdb, and updated by
52 -- Create_Task and Finalize_TCB
54 procedure Task_Creation_Hook (Thread : OS_Interface.Thread_Id);
55 -- This procedure is used to notify VxGdb of task's creation.
56 -- It must be called by the task's creator.
58 procedure Task_Termination_Hook;
59 -- This procedure is used to notify VxGdb of task's termination.
61 function Self return Task_ID;
62 -- return system ID of current task
64 procedure List_Tasks;
65 -- Print a list of all the known Ada tasks with abbreviated state
66 -- information, one-per-line, to the standard output file
68 procedure Print_Current_Task;
69 procedure Print_Task_Info_Header;
70 procedure Print_Task_Info (T : Task_ID);
71 -- Write TASK_ID of current task, in hexadecimal, as one line, to
72 -- the standard output file
74 -- Beware that Print_Current_Task may print garbage during an early
75 -- stage of activation. There is a small window where a task is just
76 -- initializing itself and has not yet recorded its own task Id.
78 -- Beware that Print_Current_Task will either not work at all or print
79 -- garbage if it has interrupted a thread of control that does not
80 -- correspond to any Ada task. For example, this is could happen if
81 -- the debugger interrupts a signal handler that is using an alternate
82 -- stack, or interrupts the dispatcher in the underlying thread
83 -- implementation.
85 procedure Set_User_State (Value : Integer);
87 procedure Print_Accept_Info (T : Task_ID);
89 procedure Trace
90 (Self_ID : Task_ID;
91 Msg : String;
92 Other_ID : Task_ID;
93 Flag : Character);
95 procedure Trace
96 (Self_ID : Task_ID;
97 Msg : String;
98 Flag : Character);
100 procedure Trace
101 (Msg : String;
102 Flag : Character);
104 procedure Trace
105 (Msg : String;
106 Other_ID : Task_ID;
107 Flag : Character);
109 procedure Set_Trace
110 (Flag : Character;
111 Value : Boolean := True);
113 function Image (T : Task_ID) return String;
115 procedure Suspend_All_Tasks (Thread_Self : OS_Interface.Thread_Id);
116 -- Suspend all the tasks except the one whose associated thread is
117 -- Thread_Self by traversing All_Tasks_Lists and calling
118 -- System.Task_Primitives.Operations.Suspend_Task
119 -- Such functionality is needed by gdb on some targets (e.g VxWorks)
120 -- Warning: for efficiency purposes, there is no locking.
122 procedure Resume_All_Tasks (Thread_Self : OS_Interface.Thread_Id);
123 -- Resume all the tasks except the one whose associated thread is
124 -- Thread_Self by traversing All_Tasks_Lists and calling
125 -- System.Task_Primitives.Operations.Continue_Task
126 -- Such functionality is needed by gdb on some targets (e.g VxWorks)
127 -- Warning: for efficiency purposes, there is no locking.
129 end System.Tasking.Debug;
131 -----------------------------
132 -- Use of These Functions --
133 -----------------------------
135 -- Calling complicated functions from the debugger is generally pretty
136 -- risky, especially in a multithreaded program.
138 -- The debugger may interrupt something that is not an Ada task,
139 -- within the thread implementation, and which is not async-safe.
141 -- For example, under Solaris, it can interrupt code in "_dynamiclwps",
142 -- which seems to serve as dispatcher when all the user threads are
143 -- suspended. By experience, we have found that one cannot safely
144 -- do certain things, apparently including calls to thread primitives
145 -- from the debugger if the debugger has interrupted at one of these
146 -- unsafe points. In general, if you interrupt a running program
147 -- asynchronously (e.g. via control-C), it will not be safe to
148 -- call the subprograms in this package.
150 -----------------
151 -- Future work --
152 -----------------
154 -- It would be nice to be able to tell whether execution has been
155 -- interrupted in an Ada task. A heuristic way of checking this would
156 -- be if we added to the Ada TCB a component that always contains a
157 -- constant value that is unlikely to occur accidentally in code or
158 -- data. We could then check this in the debugger-callable subprograms,
159 -- and simply return an error code if it looks unsafe to proceed.
161 -- ???
162 -- Recently we have added such a marker as a local variable of the
163 -- task-wrapper routine. This allows Self to generate a fake ATCB for
164 -- non-Ada threads of control. Given this capability, it is probably
165 -- time to revisit the issue above.
167 -- DEADLOCK
169 -- We follow a simple rule here to avoid deadlock:
171 -- We do not use any locks in functions called by gdb, and we do not
172 -- traverse linked lists.
174 -- The use of an array (Known_Tasks) has many advantages:
176 -- - Easy and fast to examine;
177 -- - No risk of dangling references (to the next element) when traversing
178 -- the array.