Commit | Line | Data |
---|---|---|
036b1ba8 JB |
1 | /* Ada Ravenscar thread support. |
2 | ||
e2882c85 | 3 | Copyright (C) 2004-2018 Free Software Foundation, Inc. |
036b1ba8 JB |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "gdbcore.h" | |
22 | #include "gdbthread.h" | |
23 | #include "ada-lang.h" | |
24 | #include "target.h" | |
25 | #include "inferior.h" | |
26 | #include "command.h" | |
27 | #include "ravenscar-thread.h" | |
76727919 | 28 | #include "observable.h" |
036b1ba8 JB |
29 | #include "gdbcmd.h" |
30 | #include "top.h" | |
31 | #include "regcache.h" | |
77e371c0 | 32 | #include "objfiles.h" |
036b1ba8 | 33 | |
9edcc12f JB |
34 | /* This module provides support for "Ravenscar" tasks (Ada) when |
35 | debugging on bare-metal targets. | |
36 | ||
37 | The typical situation is when debugging a bare-metal target over | |
38 | the remote protocol. In that situation, the system does not know | |
39 | about high-level comcepts such as threads, only about some code | |
40 | running on one or more CPUs. And since the remote protocol does not | |
41 | provide any handling for CPUs, the de facto standard for handling | |
42 | them is to have one thread per CPU, where the thread's ptid has | |
43 | its lwp field set to the CPU number (eg: 1 for the first CPU, | |
44 | 2 for the second one, etc). This module will make that assumption. | |
45 | ||
46 | This module then creates and maintains the list of threads based | |
47 | on the list of Ada tasks, with one thread per Ada tasks. The convention | |
48 | is that threads corresponding to the CPUs (see assumption above) | |
49 | have a ptid_t of the form (PID, LWP, 0), which threads corresponding | |
50 | to our Ada tasks have a ptid_t of the form (PID, 0, TID) where TID | |
51 | is the Ada task's ID as extracted from Ada runtime information. | |
52 | ||
53 | Switching to a given Ada tasks (or its underlying thread) is performed | |
54 | by fetching the registers of that tasks from the memory area where | |
55 | the registers were saved. For any of the other operations, the | |
56 | operation is performed by first finding the CPU on which the task | |
57 | is running, switching to its corresponding ptid, and then performing | |
58 | the operation on that ptid using the target beneath us. */ | |
59 | ||
036b1ba8 JB |
60 | /* If non-null, ravenscar task support is enabled. */ |
61 | static int ravenscar_task_support = 1; | |
62 | ||
9edcc12f JB |
63 | /* PTID of the last thread that received an event. |
64 | This can be useful to determine the associated task that received | |
65 | the event, to make it the current task. */ | |
036b1ba8 JB |
66 | static ptid_t base_ptid; |
67 | ||
7f39f34a | 68 | static const char running_thread_name[] = "__gnat_running_thread_table"; |
036b1ba8 JB |
69 | |
70 | static const char known_tasks_name[] = "system__tasking__debug__known_tasks"; | |
6040a59d | 71 | static const char first_task_name[] = "system__tasking__debug__first_task"; |
036b1ba8 | 72 | |
0df8b418 MS |
73 | static const char ravenscar_runtime_initializer[] = |
74 | "system__bb__threads__initialize"; | |
036b1ba8 | 75 | |
f6ac5f3d PA |
76 | struct ravenscar_thread_target final : public target_ops |
77 | { | |
78 | ravenscar_thread_target () | |
79 | { to_stratum = thread_stratum; } | |
80 | ||
81 | const char *shortname () override | |
82 | { return "ravenscar"; } | |
83 | ||
84 | const char *longname () override | |
85 | { return _("Ravenscar tasks."); } | |
86 | ||
87 | const char *doc () override | |
88 | { return _("Ravenscar tasks support."); } | |
89 | ||
90 | ptid_t wait (ptid_t, struct target_waitstatus *, int) override; | |
91 | void resume (ptid_t, int, enum gdb_signal) override; | |
92 | ||
93 | void fetch_registers (struct regcache *, int) override; | |
94 | void store_registers (struct regcache *, int) override; | |
95 | ||
96 | void prepare_to_store (struct regcache *) override; | |
97 | ||
57810aa7 | 98 | bool stopped_by_sw_breakpoint () override; |
f6ac5f3d | 99 | |
57810aa7 | 100 | bool stopped_by_hw_breakpoint () override; |
f6ac5f3d | 101 | |
57810aa7 | 102 | bool stopped_by_watchpoint () override; |
f6ac5f3d | 103 | |
57810aa7 | 104 | bool stopped_data_address (CORE_ADDR *) override; |
f6ac5f3d | 105 | |
57810aa7 | 106 | bool thread_alive (ptid_t ptid) override; |
f6ac5f3d PA |
107 | |
108 | int core_of_thread (ptid_t ptid) override; | |
109 | ||
110 | void update_thread_list () override; | |
111 | ||
112 | const char *extra_thread_info (struct thread_info *) override; | |
113 | ||
114 | const char *pid_to_str (ptid_t) override; | |
115 | ||
116 | ptid_t get_ada_task_ptid (long lwp, long thread) override; | |
117 | ||
118 | void mourn_inferior () override; | |
119 | ||
57810aa7 PA |
120 | bool has_all_memory () override { return default_child_has_all_memory (); } |
121 | bool has_memory () override { return default_child_has_memory (); } | |
122 | bool has_stack () override { return default_child_has_stack (); } | |
123 | bool has_registers () override { return default_child_has_registers (); } | |
124 | bool has_execution (ptid_t ptid) override | |
f6ac5f3d PA |
125 | { return default_child_has_execution (ptid); } |
126 | }; | |
127 | ||
128 | /* This module's target-specific operations. */ | |
129 | static ravenscar_thread_target ravenscar_ops; | |
130 | ||
9edcc12f | 131 | static ptid_t ravenscar_active_task (int cpu); |
036b1ba8 JB |
132 | static void ravenscar_update_inferior_ptid (void); |
133 | static int has_ravenscar_runtime (void); | |
134 | static int ravenscar_runtime_initialized (void); | |
135 | static void ravenscar_inferior_created (struct target_ops *target, | |
136 | int from_tty); | |
137 | ||
9edcc12f JB |
138 | /* Return nonzero iff PTID corresponds to a ravenscar task. */ |
139 | ||
140 | static int | |
141 | is_ravenscar_task (ptid_t ptid) | |
142 | { | |
54aa6c67 JB |
143 | /* By construction, ravenscar tasks have their LWP set to zero. |
144 | Also make sure that the TID is nonzero, as some remotes, when | |
145 | asked for the list of threads, will return the first thread | |
146 | as having its TID set to zero. For instance, TSIM version | |
147 | 2.0.48 for LEON3 sends 'm0' as a reply to the 'qfThreadInfo' | |
148 | query, which the remote protocol layer then treats as a thread | |
149 | whose TID is 0. This is obviously not a ravenscar task. */ | |
150 | return ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) != 0; | |
9edcc12f JB |
151 | } |
152 | ||
153 | /* Given PTID, which can be either a ravenscar task or a CPU thread, | |
154 | return which CPU that ptid is running on. | |
155 | ||
156 | This assume that PTID is a valid ptid_t. Otherwise, a gdb_assert | |
157 | will be triggered. */ | |
158 | ||
159 | static int | |
160 | ravenscar_get_thread_base_cpu (ptid_t ptid) | |
161 | { | |
162 | int base_cpu; | |
163 | ||
164 | if (is_ravenscar_task (ptid)) | |
165 | { | |
166 | struct ada_task_info *task_info = ada_get_task_info_from_ptid (ptid); | |
167 | ||
168 | gdb_assert (task_info != NULL); | |
169 | base_cpu = task_info->base_cpu; | |
170 | } | |
171 | else | |
172 | { | |
173 | /* We assume that the LWP of the PTID is equal to the CPU number. */ | |
174 | base_cpu = ptid_get_lwp (ptid); | |
175 | } | |
176 | ||
177 | return base_cpu; | |
178 | } | |
179 | ||
180 | /* Given a ravenscar task (identified by its ptid_t PTID), return nonzero | |
181 | if this task is the currently active task on the cpu that task is | |
182 | running on. | |
183 | ||
184 | In other words, this function determine which CPU this task is | |
185 | currently running on, and then return nonzero if the CPU in question | |
186 | is executing the code for that task. If that's the case, then | |
187 | that task's registers are in the CPU bank. Otherwise, the task | |
188 | is currently suspended, and its registers have been saved in memory. */ | |
189 | ||
190 | static int | |
191 | ravenscar_task_is_currently_active (ptid_t ptid) | |
192 | { | |
193 | ptid_t active_task_ptid | |
194 | = ravenscar_active_task (ravenscar_get_thread_base_cpu (ptid)); | |
195 | ||
196 | return ptid_equal (ptid, active_task_ptid); | |
197 | } | |
198 | ||
199 | /* Return the CPU thread (as a ptid_t) on which the given ravenscar | |
200 | task is running. | |
201 | ||
202 | This is the thread that corresponds to the CPU on which the task | |
203 | is running. */ | |
204 | ||
205 | static ptid_t | |
206 | get_base_thread_from_ravenscar_task (ptid_t ptid) | |
207 | { | |
208 | int base_cpu; | |
209 | ||
210 | if (!is_ravenscar_task (ptid)) | |
211 | return ptid; | |
212 | ||
213 | base_cpu = ravenscar_get_thread_base_cpu (ptid); | |
214 | return ptid_build (ptid_get_pid (ptid), base_cpu, 0); | |
215 | } | |
216 | ||
036b1ba8 JB |
217 | /* Fetch the ravenscar running thread from target memory and |
218 | update inferior_ptid accordingly. */ | |
219 | ||
220 | static void | |
221 | ravenscar_update_inferior_ptid (void) | |
222 | { | |
9edcc12f JB |
223 | int base_cpu; |
224 | ||
036b1ba8 JB |
225 | base_ptid = inferior_ptid; |
226 | ||
9edcc12f JB |
227 | gdb_assert (!is_ravenscar_task (inferior_ptid)); |
228 | base_cpu = ravenscar_get_thread_base_cpu (base_ptid); | |
229 | ||
036b1ba8 JB |
230 | /* If the runtime has not been initialized yet, the inferior_ptid is |
231 | the only ptid that there is. */ | |
232 | if (!ravenscar_runtime_initialized ()) | |
233 | return; | |
234 | ||
9edcc12f | 235 | /* Make sure we set base_ptid before calling ravenscar_active_task |
036b1ba8 | 236 | as the latter relies on it. */ |
9edcc12f | 237 | inferior_ptid = ravenscar_active_task (base_cpu); |
036b1ba8 JB |
238 | gdb_assert (!ptid_equal (inferior_ptid, null_ptid)); |
239 | ||
240 | /* The running thread may not have been added to | |
e8032dde | 241 | system.tasking.debug's list yet; so ravenscar_update_thread_list |
036b1ba8 JB |
242 | may not always add it to the thread list. Add it here. */ |
243 | if (!find_thread_ptid (inferior_ptid)) | |
244 | add_thread (inferior_ptid); | |
245 | } | |
246 | ||
7f39f34a JB |
247 | /* The Ravenscar Runtime exports a symbol which contains the ID of |
248 | the thread that is currently running. Try to locate that symbol | |
249 | and return its associated minimal symbol. | |
250 | Return NULL if not found. */ | |
251 | ||
3b7344d5 | 252 | static struct bound_minimal_symbol |
7f39f34a JB |
253 | get_running_thread_msymbol (void) |
254 | { | |
3b7344d5 | 255 | struct bound_minimal_symbol msym; |
7f39f34a JB |
256 | |
257 | msym = lookup_minimal_symbol (running_thread_name, NULL, NULL); | |
3b7344d5 | 258 | if (!msym.minsym) |
7f39f34a JB |
259 | /* Older versions of the GNAT runtime were using a different |
260 | (less ideal) name for the symbol where the active thread ID | |
261 | is stored. If we couldn't find the symbol using the latest | |
262 | name, then try the old one. */ | |
263 | msym = lookup_minimal_symbol ("running_thread", NULL, NULL); | |
264 | ||
265 | return msym; | |
266 | } | |
267 | ||
036b1ba8 JB |
268 | /* Return True if the Ada Ravenscar run-time can be found in the |
269 | application. */ | |
270 | ||
271 | static int | |
272 | has_ravenscar_runtime (void) | |
273 | { | |
3b7344d5 | 274 | struct bound_minimal_symbol msym_ravenscar_runtime_initializer = |
036b1ba8 | 275 | lookup_minimal_symbol (ravenscar_runtime_initializer, NULL, NULL); |
3b7344d5 | 276 | struct bound_minimal_symbol msym_known_tasks = |
036b1ba8 | 277 | lookup_minimal_symbol (known_tasks_name, NULL, NULL); |
3b7344d5 | 278 | struct bound_minimal_symbol msym_first_task = |
6040a59d | 279 | lookup_minimal_symbol (first_task_name, NULL, NULL); |
3b7344d5 TT |
280 | struct bound_minimal_symbol msym_running_thread |
281 | = get_running_thread_msymbol (); | |
036b1ba8 | 282 | |
3b7344d5 TT |
283 | return (msym_ravenscar_runtime_initializer.minsym |
284 | && (msym_known_tasks.minsym || msym_first_task.minsym) | |
285 | && msym_running_thread.minsym); | |
036b1ba8 JB |
286 | } |
287 | ||
288 | /* Return True if the Ada Ravenscar run-time can be found in the | |
289 | application, and if it has been initialized on target. */ | |
290 | ||
291 | static int | |
292 | ravenscar_runtime_initialized (void) | |
293 | { | |
9edcc12f | 294 | return (!(ptid_equal (ravenscar_active_task (1), null_ptid))); |
036b1ba8 JB |
295 | } |
296 | ||
7f39f34a JB |
297 | /* Return the ID of the thread that is currently running. |
298 | Return 0 if the ID could not be determined. */ | |
036b1ba8 JB |
299 | |
300 | static CORE_ADDR | |
9edcc12f | 301 | get_running_thread_id (int cpu) |
036b1ba8 | 302 | { |
3b7344d5 | 303 | struct bound_minimal_symbol object_msym = get_running_thread_msymbol (); |
036b1ba8 JB |
304 | int object_size; |
305 | int buf_size; | |
948f8e3d | 306 | gdb_byte *buf; |
036b1ba8 JB |
307 | CORE_ADDR object_addr; |
308 | struct type *builtin_type_void_data_ptr = | |
f5656ead | 309 | builtin_type (target_gdbarch ())->builtin_data_ptr; |
036b1ba8 | 310 | |
3b7344d5 | 311 | if (!object_msym.minsym) |
036b1ba8 JB |
312 | return 0; |
313 | ||
036b1ba8 | 314 | object_size = TYPE_LENGTH (builtin_type_void_data_ptr); |
9edcc12f JB |
315 | object_addr = (BMSYMBOL_VALUE_ADDRESS (object_msym) |
316 | + (cpu - 1) * object_size); | |
036b1ba8 | 317 | buf_size = object_size; |
224c3ddb | 318 | buf = (gdb_byte *) alloca (buf_size); |
036b1ba8 JB |
319 | read_memory (object_addr, buf, buf_size); |
320 | return extract_typed_address (buf, builtin_type_void_data_ptr); | |
321 | } | |
322 | ||
f6ac5f3d PA |
323 | void |
324 | ravenscar_thread_target::resume (ptid_t ptid, int step, enum gdb_signal siggnal) | |
036b1ba8 | 325 | { |
f6ac5f3d | 326 | struct target_ops *beneath = find_target_beneath (this); |
036b1ba8 JB |
327 | |
328 | inferior_ptid = base_ptid; | |
f6ac5f3d | 329 | beneath->resume (base_ptid, step, siggnal); |
036b1ba8 JB |
330 | } |
331 | ||
f6ac5f3d PA |
332 | ptid_t |
333 | ravenscar_thread_target::wait (ptid_t ptid, | |
334 | struct target_waitstatus *status, | |
335 | int options) | |
036b1ba8 | 336 | { |
f6ac5f3d | 337 | struct target_ops *beneath = find_target_beneath (this); |
3b1b69bf | 338 | ptid_t event_ptid; |
036b1ba8 JB |
339 | |
340 | inferior_ptid = base_ptid; | |
f6ac5f3d | 341 | event_ptid = beneath->wait (base_ptid, status, 0); |
bed0c243 JB |
342 | /* Find any new threads that might have been created, and update |
343 | inferior_ptid to the active thread. | |
344 | ||
345 | Only do it if the program is still alive, though. Otherwise, | |
346 | this causes problems when debugging through the remote protocol, | |
347 | because we might try switching threads (and thus sending packets) | |
348 | after the remote has disconnected. */ | |
349 | if (status->kind != TARGET_WAITKIND_EXITED | |
350 | && status->kind != TARGET_WAITKIND_SIGNALLED) | |
351 | { | |
3b1b69bf | 352 | inferior_ptid = event_ptid; |
f6ac5f3d | 353 | this->update_thread_list (); |
bed0c243 JB |
354 | ravenscar_update_inferior_ptid (); |
355 | } | |
036b1ba8 JB |
356 | return inferior_ptid; |
357 | } | |
358 | ||
359 | /* Add the thread associated to the given TASK to the thread list | |
360 | (if the thread has already been added, this is a no-op). */ | |
361 | ||
362 | static void | |
363 | ravenscar_add_thread (struct ada_task_info *task) | |
364 | { | |
365 | if (find_thread_ptid (task->ptid) == NULL) | |
366 | add_thread (task->ptid); | |
367 | } | |
368 | ||
f6ac5f3d PA |
369 | void |
370 | ravenscar_thread_target::update_thread_list () | |
036b1ba8 | 371 | { |
79779fa9 | 372 | ada_build_task_list (); |
036b1ba8 JB |
373 | |
374 | /* Do not clear the thread list before adding the Ada task, to keep | |
375 | the thread that the process stratum has included into it | |
376 | (base_ptid) and the running thread, that may not have been included | |
377 | to system.tasking.debug's list yet. */ | |
378 | ||
379 | iterate_over_live_ada_tasks (ravenscar_add_thread); | |
380 | } | |
381 | ||
382 | static ptid_t | |
9edcc12f | 383 | ravenscar_active_task (int cpu) |
036b1ba8 | 384 | { |
9edcc12f | 385 | CORE_ADDR tid = get_running_thread_id (cpu); |
036b1ba8 JB |
386 | |
387 | if (tid == 0) | |
388 | return null_ptid; | |
389 | else | |
390 | return ptid_build (ptid_get_pid (base_ptid), 0, tid); | |
391 | } | |
392 | ||
f6ac5f3d PA |
393 | const char * |
394 | ravenscar_thread_target::extra_thread_info (thread_info *tp) | |
036b1ba8 JB |
395 | { |
396 | return "Ravenscar task"; | |
397 | } | |
398 | ||
57810aa7 | 399 | bool |
f6ac5f3d | 400 | ravenscar_thread_target::thread_alive (ptid_t ptid) |
036b1ba8 JB |
401 | { |
402 | /* Ravenscar tasks are non-terminating. */ | |
57810aa7 | 403 | return true; |
036b1ba8 JB |
404 | } |
405 | ||
f6ac5f3d PA |
406 | const char * |
407 | ravenscar_thread_target::pid_to_str (ptid_t ptid) | |
036b1ba8 JB |
408 | { |
409 | static char buf[30]; | |
410 | ||
411 | snprintf (buf, sizeof (buf), "Thread %#x", (int) ptid_get_tid (ptid)); | |
412 | return buf; | |
413 | } | |
414 | ||
f6ac5f3d PA |
415 | void |
416 | ravenscar_thread_target::fetch_registers (struct regcache *regcache, int regnum) | |
036b1ba8 | 417 | { |
f6ac5f3d | 418 | struct target_ops *beneath = find_target_beneath (this); |
bcc0c096 | 419 | ptid_t ptid = regcache_get_ptid (regcache); |
036b1ba8 | 420 | |
9edcc12f JB |
421 | if (ravenscar_runtime_initialized () |
422 | && is_ravenscar_task (ptid) | |
423 | && !ravenscar_task_is_currently_active (ptid)) | |
7e35103a | 424 | { |
ac7936df | 425 | struct gdbarch *gdbarch = regcache->arch (); |
7e35103a JB |
426 | struct ravenscar_arch_ops *arch_ops |
427 | = gdbarch_ravenscar_ops (gdbarch); | |
428 | ||
429 | arch_ops->to_fetch_registers (regcache, regnum); | |
430 | } | |
9edcc12f | 431 | else |
f6ac5f3d | 432 | beneath->fetch_registers (regcache, regnum); |
036b1ba8 JB |
433 | } |
434 | ||
f6ac5f3d PA |
435 | void |
436 | ravenscar_thread_target::store_registers (struct regcache *regcache, | |
437 | int regnum) | |
036b1ba8 | 438 | { |
f6ac5f3d | 439 | target_ops *beneath = find_target_beneath (this); |
bcc0c096 | 440 | ptid_t ptid = regcache_get_ptid (regcache); |
036b1ba8 | 441 | |
9edcc12f JB |
442 | if (ravenscar_runtime_initialized () |
443 | && is_ravenscar_task (ptid) | |
444 | && !ravenscar_task_is_currently_active (ptid)) | |
7e35103a | 445 | { |
ac7936df | 446 | struct gdbarch *gdbarch = regcache->arch (); |
7e35103a JB |
447 | struct ravenscar_arch_ops *arch_ops |
448 | = gdbarch_ravenscar_ops (gdbarch); | |
449 | ||
f6ac5f3d | 450 | beneath->store_registers (regcache, regnum); |
7e35103a | 451 | } |
9edcc12f | 452 | else |
f6ac5f3d | 453 | beneath->store_registers (regcache, regnum); |
036b1ba8 JB |
454 | } |
455 | ||
f6ac5f3d PA |
456 | void |
457 | ravenscar_thread_target::prepare_to_store (struct regcache *regcache) | |
036b1ba8 | 458 | { |
f6ac5f3d | 459 | target_ops *beneath = find_target_beneath (this); |
bcc0c096 | 460 | ptid_t ptid = regcache_get_ptid (regcache); |
036b1ba8 | 461 | |
9edcc12f JB |
462 | if (ravenscar_runtime_initialized () |
463 | && is_ravenscar_task (ptid) | |
464 | && !ravenscar_task_is_currently_active (ptid)) | |
7e35103a | 465 | { |
ac7936df | 466 | struct gdbarch *gdbarch = regcache->arch (); |
7e35103a JB |
467 | struct ravenscar_arch_ops *arch_ops |
468 | = gdbarch_ravenscar_ops (gdbarch); | |
469 | ||
f6ac5f3d | 470 | beneath->prepare_to_store (regcache); |
7e35103a | 471 | } |
9edcc12f | 472 | else |
f6ac5f3d | 473 | beneath->prepare_to_store (regcache); |
036b1ba8 JB |
474 | } |
475 | ||
e02544b2 JB |
476 | /* Implement the to_stopped_by_sw_breakpoint target_ops "method". */ |
477 | ||
57810aa7 | 478 | bool |
f6ac5f3d | 479 | ravenscar_thread_target::stopped_by_sw_breakpoint () |
e02544b2 JB |
480 | { |
481 | ptid_t saved_ptid = inferior_ptid; | |
f6ac5f3d | 482 | struct target_ops *beneath = find_target_beneath (this); |
57810aa7 | 483 | bool result; |
e02544b2 | 484 | |
9edcc12f | 485 | inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid); |
f6ac5f3d | 486 | result = beneath->stopped_by_sw_breakpoint (); |
e02544b2 JB |
487 | inferior_ptid = saved_ptid; |
488 | return result; | |
489 | } | |
490 | ||
491 | /* Implement the to_stopped_by_hw_breakpoint target_ops "method". */ | |
492 | ||
57810aa7 | 493 | bool |
f6ac5f3d | 494 | ravenscar_thread_target::stopped_by_hw_breakpoint () |
e02544b2 JB |
495 | { |
496 | ptid_t saved_ptid = inferior_ptid; | |
f6ac5f3d | 497 | struct target_ops *beneath = find_target_beneath (this); |
57810aa7 | 498 | bool result; |
e02544b2 | 499 | |
9edcc12f | 500 | inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid); |
f6ac5f3d | 501 | result = beneath->stopped_by_hw_breakpoint (); |
e02544b2 JB |
502 | inferior_ptid = saved_ptid; |
503 | return result; | |
504 | } | |
505 | ||
506 | /* Implement the to_stopped_by_watchpoint target_ops "method". */ | |
507 | ||
57810aa7 | 508 | bool |
f6ac5f3d | 509 | ravenscar_thread_target::stopped_by_watchpoint () |
e02544b2 JB |
510 | { |
511 | ptid_t saved_ptid = inferior_ptid; | |
f6ac5f3d | 512 | struct target_ops *beneath = find_target_beneath (this); |
57810aa7 | 513 | bool result; |
e02544b2 | 514 | |
9edcc12f | 515 | inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid); |
f6ac5f3d | 516 | result = beneath->stopped_by_watchpoint (); |
e02544b2 JB |
517 | inferior_ptid = saved_ptid; |
518 | return result; | |
519 | } | |
520 | ||
521 | /* Implement the to_stopped_data_address target_ops "method". */ | |
522 | ||
57810aa7 | 523 | bool |
f6ac5f3d | 524 | ravenscar_thread_target::stopped_data_address (CORE_ADDR *addr_p) |
e02544b2 JB |
525 | { |
526 | ptid_t saved_ptid = inferior_ptid; | |
f6ac5f3d | 527 | struct target_ops *beneath = find_target_beneath (this); |
57810aa7 | 528 | bool result; |
e02544b2 | 529 | |
9edcc12f | 530 | inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid); |
f6ac5f3d | 531 | result = beneath->stopped_data_address (addr_p); |
e02544b2 JB |
532 | inferior_ptid = saved_ptid; |
533 | return result; | |
534 | } | |
535 | ||
f6ac5f3d PA |
536 | void |
537 | ravenscar_thread_target::mourn_inferior () | |
036b1ba8 | 538 | { |
f6ac5f3d | 539 | struct target_ops *beneath = find_target_beneath (this); |
036b1ba8 JB |
540 | |
541 | base_ptid = null_ptid; | |
f6ac5f3d | 542 | beneath->mourn_inferior (); |
036b1ba8 JB |
543 | unpush_target (&ravenscar_ops); |
544 | } | |
545 | ||
e02544b2 JB |
546 | /* Implement the to_core_of_thread target_ops "method". */ |
547 | ||
f6ac5f3d PA |
548 | int |
549 | ravenscar_thread_target::core_of_thread (ptid_t ptid) | |
e02544b2 JB |
550 | { |
551 | ptid_t saved_ptid = inferior_ptid; | |
f6ac5f3d | 552 | struct target_ops *beneath = find_target_beneath (this); |
e02544b2 JB |
553 | int result; |
554 | ||
9edcc12f | 555 | inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid); |
f6ac5f3d | 556 | result = beneath->core_of_thread (inferior_ptid); |
e02544b2 JB |
557 | inferior_ptid = saved_ptid; |
558 | return result; | |
559 | } | |
560 | ||
036b1ba8 JB |
561 | /* Observer on inferior_created: push ravenscar thread stratum if needed. */ |
562 | ||
563 | static void | |
564 | ravenscar_inferior_created (struct target_ops *target, int from_tty) | |
565 | { | |
cf3fbed4 | 566 | const char *err_msg; |
7e35103a JB |
567 | |
568 | if (!ravenscar_task_support | |
7dc7c195 | 569 | || gdbarch_ravenscar_ops (target_gdbarch ()) == NULL |
7e35103a | 570 | || !has_ravenscar_runtime ()) |
25abf4de JB |
571 | return; |
572 | ||
cf3fbed4 JB |
573 | err_msg = ada_get_tcb_types_info (); |
574 | if (err_msg != NULL) | |
575 | { | |
8f6cb6c3 | 576 | warning (_("%s. Task/thread support disabled."), err_msg); |
cf3fbed4 JB |
577 | return; |
578 | } | |
579 | ||
25abf4de JB |
580 | ravenscar_update_inferior_ptid (); |
581 | push_target (&ravenscar_ops); | |
036b1ba8 JB |
582 | } |
583 | ||
f6ac5f3d PA |
584 | ptid_t |
585 | ravenscar_thread_target::get_ada_task_ptid (long lwp, long thread) | |
036b1ba8 JB |
586 | { |
587 | return ptid_build (ptid_get_pid (base_ptid), 0, thread); | |
588 | } | |
589 | ||
036b1ba8 JB |
590 | /* Command-list for the "set/show ravenscar" prefix command. */ |
591 | static struct cmd_list_element *set_ravenscar_list; | |
592 | static struct cmd_list_element *show_ravenscar_list; | |
593 | ||
594 | /* Implement the "set ravenscar" prefix command. */ | |
595 | ||
596 | static void | |
981a3fb3 | 597 | set_ravenscar_command (const char *arg, int from_tty) |
036b1ba8 JB |
598 | { |
599 | printf_unfiltered (_(\ | |
600 | "\"set ravenscar\" must be followed by the name of a setting.\n")); | |
635c7e8a | 601 | help_list (set_ravenscar_list, "set ravenscar ", all_commands, gdb_stdout); |
036b1ba8 JB |
602 | } |
603 | ||
604 | /* Implement the "show ravenscar" prefix command. */ | |
605 | ||
606 | static void | |
981a3fb3 | 607 | show_ravenscar_command (const char *args, int from_tty) |
036b1ba8 JB |
608 | { |
609 | cmd_show_list (show_ravenscar_list, from_tty, ""); | |
610 | } | |
611 | ||
612 | /* Implement the "show ravenscar task-switching" command. */ | |
613 | ||
614 | static void | |
615 | show_ravenscar_task_switching_command (struct ui_file *file, int from_tty, | |
616 | struct cmd_list_element *c, | |
617 | const char *value) | |
618 | { | |
619 | if (ravenscar_task_support) | |
620 | fprintf_filtered (file, _("\ | |
b64edec4 | 621 | Support for Ravenscar task/thread switching is enabled\n")); |
036b1ba8 JB |
622 | else |
623 | fprintf_filtered (file, _("\ | |
b64edec4 | 624 | Support for Ravenscar task/thread switching is disabled\n")); |
036b1ba8 JB |
625 | } |
626 | ||
627 | /* Module startup initialization function, automagically called by | |
628 | init.c. */ | |
629 | ||
630 | void | |
631 | _initialize_ravenscar (void) | |
632 | { | |
036b1ba8 JB |
633 | base_ptid = null_ptid; |
634 | ||
635 | /* Notice when the inferior is created in order to push the | |
636 | ravenscar ops if needed. */ | |
76727919 | 637 | gdb::observers::inferior_created.attach (ravenscar_inferior_created); |
036b1ba8 | 638 | |
036b1ba8 JB |
639 | add_prefix_cmd ("ravenscar", no_class, set_ravenscar_command, |
640 | _("Prefix command for changing Ravenscar-specific settings"), | |
641 | &set_ravenscar_list, "set ravenscar ", 0, &setlist); | |
642 | ||
643 | add_prefix_cmd ("ravenscar", no_class, show_ravenscar_command, | |
644 | _("Prefix command for showing Ravenscar-specific settings"), | |
04f9d4d0 | 645 | &show_ravenscar_list, "show ravenscar ", 0, &showlist); |
036b1ba8 JB |
646 | |
647 | add_setshow_boolean_cmd ("task-switching", class_obscure, | |
648 | &ravenscar_task_support, _("\ | |
649 | Enable or disable support for GNAT Ravenscar tasks"), _("\ | |
650 | Show whether support for GNAT Ravenscar tasks is enabled"), | |
651 | _("\ | |
652 | Enable or disable support for task/thread switching with the GNAT\n\ | |
653 | Ravenscar run-time library for bareboard configuration."), | |
654 | NULL, show_ravenscar_task_switching_command, | |
655 | &set_ravenscar_list, &show_ravenscar_list); | |
656 | } |