1 ------------------------------------------------------------------------------
3 -- GNU ADA 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-2001, 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 2, or (at your option) any later ver- --
14 -- sion. GNARL 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This package encapsulates all direct interfaces to task debugging services
35 -- that are needed by gdb with gnat mode (1.17 and higher)
39 with System
.OS_Interface
;
41 package System
.Tasking
.Debug
is
43 subtype int
is Interfaces
.C
.int
;
44 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
46 package ST
renames System
.Tasking
;
48 Known_Tasks
: array (0 .. 999) of Task_ID
;
49 -- Global array of tasks read by gdb, and updated by
50 -- Create_Task and Finalize_TCB
52 procedure Task_Creation_Hook
(Thread
: OS_Interface
.Thread_Id
);
53 -- This procedure is used to notify VxGdb of task's creation.
54 -- It must be called by the task's creator.
56 procedure Task_Termination_Hook
;
57 -- This procedure is used to notify VxGdb of task's termination.
59 function Self
return Task_ID
;
60 -- return system ID of current task
63 -- Print a list of all the known Ada tasks with abbreviated state
64 -- information, one-per-line, to the standard output file
66 procedure Print_Current_Task
;
67 procedure Print_Task_Info_Header
;
68 procedure Print_Task_Info
(T
: Task_ID
);
69 -- Write TASK_ID of current task, in hexadecimal, as one line, to
70 -- the standard output file
72 -- Beware that Print_Current_Task may print garbage during an early
73 -- stage of activation. There is a small window where a task is just
74 -- initializing itself and has not yet recorded its own task Id.
76 -- Beware that Print_Current_Task will either not work at all or print
77 -- garbage if it has interrupted a thread of control that does not
78 -- correspond to any Ada task. For example, this is could happen if
79 -- the debugger interrupts a signal handler that is using an alternate
80 -- stack, or interrupts the dispatcher in the underlying thread
83 procedure Set_User_State
(Value
: Integer);
85 procedure Print_Accept_Info
(T
: Task_ID
);
109 Value
: Boolean := True);
111 function Image
(T
: Task_ID
) return String;
113 procedure Suspend_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
);
114 -- Suspend all the tasks except the one whose associated thread is
115 -- Thread_Self by traversing All_Tasks_Lists and calling
116 -- System.Task_Primitives.Operations.Suspend_Task
117 -- Such functionality is needed by gdb on some targets (e.g VxWorks)
118 -- Warning: for efficiency purposes, there is no locking.
120 procedure Resume_All_Tasks
(Thread_Self
: OS_Interface
.Thread_Id
);
121 -- Resume all the tasks except the one whose associated thread is
122 -- Thread_Self by traversing All_Tasks_Lists and calling
123 -- System.Task_Primitives.Operations.Continue_Task
124 -- Such functionality is needed by gdb on some targets (e.g VxWorks)
125 -- Warning: for efficiency purposes, there is no locking.
127 end System
.Tasking
.Debug
;
129 -----------------------------
130 -- Use of These Functions --
131 -----------------------------
133 -- Calling complicated functions from the debugger is generally pretty
134 -- risky, especially in a multithreaded program.
136 -- The debugger may interrupt something that is not an Ada task,
137 -- within the thread implementation, and which is not async-safe.
139 -- For example, under Solaris, it can interrupt code in "_dynamiclwps",
140 -- which seems to serve as dispatcher when all the user threads are
141 -- suspended. By experience, we have found that one cannot safely
142 -- do certain things, apparently including calls to thread primitives
143 -- from the debugger if the debugger has interrupted at one of these
144 -- unsafe points. In general, if you interrupt a running program
145 -- asynchronously (e.g. via control-C), it will not be safe to
146 -- call the subprograms in this package.
152 -- It would be nice to be able to tell whether execution has been
153 -- interrupted in an Ada task. A heuristic way of checking this would
154 -- be if we added to the Ada TCB a component that always contains a
155 -- constant value that is unlikely to occur accidentally in code or
156 -- data. We could then check this in the debugger-callable subprograms,
157 -- and simply return an error code if it looks unsafe to proceed.
160 -- Recently we have added such a marker as a local variable of the
161 -- task-wrapper routine. This allows Self to generate a fake ATCB for
162 -- non-Ada threads of control. Given this capability, it is probably
163 -- time to revisit the issue above.
167 -- We follow a simple rule here to avoid deadlock:
169 -- We do not use any locks in functions called by gdb, and we do not
170 -- traverse linked lists.
172 -- The use of an array (Known_Tasks) has many advantages:
174 -- - Easy and fast to examine;
175 -- - No risk of dangling references (to the next element) when traversing