Commit | Line | Data |
---|---|---|
036b1ba8 JB |
1 | /* Ada Ravenscar thread support. |
2 | ||
b811d2c2 | 3 | Copyright (C) 2004-2020 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 | |
e397fd39 | 39 | about high-level concepts such as threads, only about some code |
9edcc12f JB |
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 | |
e397fd39 | 47 | on the list of Ada tasks, with one thread per Ada task. The convention |
9edcc12f | 48 | is that threads corresponding to the CPUs (see assumption above) |
e397fd39 | 49 | have a ptid_t of the form (PID, LWP, 0), while threads corresponding |
9edcc12f JB |
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 | ||
e397fd39 TT |
53 | Switching to a given Ada task (or its underlying thread) is performed |
54 | by fetching the registers of that task from the memory area where | |
9edcc12f JB |
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 | ||
491144b5 CB |
60 | /* If true, ravenscar task support is enabled. */ |
61 | static bool ravenscar_task_support = true; | |
036b1ba8 | 62 | |
7f39f34a | 63 | static const char running_thread_name[] = "__gnat_running_thread_table"; |
036b1ba8 JB |
64 | |
65 | static const char known_tasks_name[] = "system__tasking__debug__known_tasks"; | |
6040a59d | 66 | static const char first_task_name[] = "system__tasking__debug__first_task"; |
036b1ba8 | 67 | |
6cbcc006 TT |
68 | static const char ravenscar_runtime_initializer[] |
69 | = "system__bb__threads__initialize"; | |
036b1ba8 | 70 | |
d9f719f1 PA |
71 | static const target_info ravenscar_target_info = { |
72 | "ravenscar", | |
73 | N_("Ravenscar tasks."), | |
74 | N_("Ravenscar tasks support.") | |
75 | }; | |
76 | ||
f6ac5f3d PA |
77 | struct ravenscar_thread_target final : public target_ops |
78 | { | |
0b790b1e TT |
79 | ravenscar_thread_target () |
80 | { | |
81 | update_inferior_ptid (); | |
82 | } | |
83 | ||
d9f719f1 PA |
84 | const target_info &info () const override |
85 | { return ravenscar_target_info; } | |
f6ac5f3d | 86 | |
66b4deae PA |
87 | strata stratum () const override { return thread_stratum; } |
88 | ||
f6ac5f3d PA |
89 | ptid_t wait (ptid_t, struct target_waitstatus *, int) override; |
90 | void resume (ptid_t, int, enum gdb_signal) override; | |
91 | ||
92 | void fetch_registers (struct regcache *, int) override; | |
93 | void store_registers (struct regcache *, int) override; | |
94 | ||
95 | void prepare_to_store (struct regcache *) override; | |
96 | ||
57810aa7 | 97 | bool stopped_by_sw_breakpoint () override; |
f6ac5f3d | 98 | |
57810aa7 | 99 | bool stopped_by_hw_breakpoint () override; |
f6ac5f3d | 100 | |
57810aa7 | 101 | bool stopped_by_watchpoint () override; |
f6ac5f3d | 102 | |
57810aa7 | 103 | bool stopped_data_address (CORE_ADDR *) override; |
f6ac5f3d | 104 | |
57810aa7 | 105 | bool thread_alive (ptid_t ptid) override; |
f6ac5f3d PA |
106 | |
107 | int core_of_thread (ptid_t ptid) override; | |
108 | ||
109 | void update_thread_list () override; | |
110 | ||
111 | const char *extra_thread_info (struct thread_info *) override; | |
112 | ||
a068643d | 113 | std::string pid_to_str (ptid_t) override; |
f6ac5f3d PA |
114 | |
115 | ptid_t get_ada_task_ptid (long lwp, long thread) override; | |
116 | ||
117 | void mourn_inferior () override; | |
f6ac5f3d | 118 | |
0b790b1e TT |
119 | void close () override |
120 | { | |
121 | delete this; | |
122 | } | |
123 | ||
124 | private: | |
f6ac5f3d | 125 | |
0b790b1e TT |
126 | /* PTID of the last thread that received an event. |
127 | This can be useful to determine the associated task that received | |
128 | the event, to make it the current task. */ | |
129 | ptid_t m_base_ptid = null_ptid; | |
130 | ||
131 | void update_inferior_ptid (); | |
132 | ptid_t active_task (int cpu); | |
133 | bool task_is_currently_active (ptid_t ptid); | |
134 | bool runtime_initialized (); | |
135 | }; | |
036b1ba8 | 136 | |
989f3c58 | 137 | /* Return true iff PTID corresponds to a ravenscar task. */ |
9edcc12f | 138 | |
989f3c58 | 139 | static bool |
9edcc12f JB |
140 | is_ravenscar_task (ptid_t ptid) |
141 | { | |
54aa6c67 JB |
142 | /* By construction, ravenscar tasks have their LWP set to zero. |
143 | Also make sure that the TID is nonzero, as some remotes, when | |
144 | asked for the list of threads, will return the first thread | |
145 | as having its TID set to zero. For instance, TSIM version | |
146 | 2.0.48 for LEON3 sends 'm0' as a reply to the 'qfThreadInfo' | |
147 | query, which the remote protocol layer then treats as a thread | |
148 | whose TID is 0. This is obviously not a ravenscar task. */ | |
cc6bcb54 | 149 | return ptid.lwp () == 0 && ptid.tid () != 0; |
9edcc12f JB |
150 | } |
151 | ||
152 | /* Given PTID, which can be either a ravenscar task or a CPU thread, | |
153 | return which CPU that ptid is running on. | |
154 | ||
155 | This assume that PTID is a valid ptid_t. Otherwise, a gdb_assert | |
156 | will be triggered. */ | |
157 | ||
158 | static int | |
159 | ravenscar_get_thread_base_cpu (ptid_t ptid) | |
160 | { | |
161 | int base_cpu; | |
162 | ||
163 | if (is_ravenscar_task (ptid)) | |
164 | { | |
165 | struct ada_task_info *task_info = ada_get_task_info_from_ptid (ptid); | |
166 | ||
167 | gdb_assert (task_info != NULL); | |
168 | base_cpu = task_info->base_cpu; | |
169 | } | |
170 | else | |
171 | { | |
172 | /* We assume that the LWP of the PTID is equal to the CPU number. */ | |
e38504b3 | 173 | base_cpu = ptid.lwp (); |
9edcc12f JB |
174 | } |
175 | ||
176 | return base_cpu; | |
177 | } | |
178 | ||
989f3c58 | 179 | /* Given a ravenscar task (identified by its ptid_t PTID), return true |
9edcc12f JB |
180 | if this task is the currently active task on the cpu that task is |
181 | running on. | |
182 | ||
183 | In other words, this function determine which CPU this task is | |
184 | currently running on, and then return nonzero if the CPU in question | |
185 | is executing the code for that task. If that's the case, then | |
186 | that task's registers are in the CPU bank. Otherwise, the task | |
187 | is currently suspended, and its registers have been saved in memory. */ | |
188 | ||
0b790b1e TT |
189 | bool |
190 | ravenscar_thread_target::task_is_currently_active (ptid_t ptid) | |
9edcc12f JB |
191 | { |
192 | ptid_t active_task_ptid | |
0b790b1e | 193 | = active_task (ravenscar_get_thread_base_cpu (ptid)); |
9edcc12f | 194 | |
d7e15655 | 195 | return ptid == active_task_ptid; |
9edcc12f JB |
196 | } |
197 | ||
198 | /* Return the CPU thread (as a ptid_t) on which the given ravenscar | |
199 | task is running. | |
200 | ||
201 | This is the thread that corresponds to the CPU on which the task | |
202 | is running. */ | |
203 | ||
204 | static ptid_t | |
205 | get_base_thread_from_ravenscar_task (ptid_t ptid) | |
206 | { | |
207 | int base_cpu; | |
208 | ||
209 | if (!is_ravenscar_task (ptid)) | |
210 | return ptid; | |
211 | ||
212 | base_cpu = ravenscar_get_thread_base_cpu (ptid); | |
e99b03dc | 213 | return ptid_t (ptid.pid (), base_cpu, 0); |
9edcc12f JB |
214 | } |
215 | ||
036b1ba8 JB |
216 | /* Fetch the ravenscar running thread from target memory and |
217 | update inferior_ptid accordingly. */ | |
218 | ||
0b790b1e TT |
219 | void |
220 | ravenscar_thread_target::update_inferior_ptid () | |
036b1ba8 | 221 | { |
9edcc12f JB |
222 | int base_cpu; |
223 | ||
0b790b1e | 224 | m_base_ptid = inferior_ptid; |
036b1ba8 | 225 | |
9edcc12f | 226 | gdb_assert (!is_ravenscar_task (inferior_ptid)); |
0b790b1e | 227 | base_cpu = ravenscar_get_thread_base_cpu (m_base_ptid); |
9edcc12f | 228 | |
036b1ba8 JB |
229 | /* If the runtime has not been initialized yet, the inferior_ptid is |
230 | the only ptid that there is. */ | |
0b790b1e | 231 | if (!runtime_initialized ()) |
036b1ba8 JB |
232 | return; |
233 | ||
0b790b1e | 234 | /* Make sure we set m_base_ptid before calling active_task |
036b1ba8 | 235 | as the latter relies on it. */ |
0b790b1e | 236 | inferior_ptid = active_task (base_cpu); |
d7e15655 | 237 | gdb_assert (inferior_ptid != null_ptid); |
036b1ba8 JB |
238 | |
239 | /* The running thread may not have been added to | |
e8032dde | 240 | system.tasking.debug's list yet; so ravenscar_update_thread_list |
036b1ba8 JB |
241 | may not always add it to the thread list. Add it here. */ |
242 | if (!find_thread_ptid (inferior_ptid)) | |
243 | add_thread (inferior_ptid); | |
244 | } | |
245 | ||
7f39f34a JB |
246 | /* The Ravenscar Runtime exports a symbol which contains the ID of |
247 | the thread that is currently running. Try to locate that symbol | |
248 | and return its associated minimal symbol. | |
249 | Return NULL if not found. */ | |
250 | ||
3b7344d5 | 251 | static struct bound_minimal_symbol |
989f3c58 | 252 | get_running_thread_msymbol () |
7f39f34a | 253 | { |
3b7344d5 | 254 | struct bound_minimal_symbol msym; |
7f39f34a JB |
255 | |
256 | msym = lookup_minimal_symbol (running_thread_name, NULL, NULL); | |
3b7344d5 | 257 | if (!msym.minsym) |
7f39f34a JB |
258 | /* Older versions of the GNAT runtime were using a different |
259 | (less ideal) name for the symbol where the active thread ID | |
260 | is stored. If we couldn't find the symbol using the latest | |
261 | name, then try the old one. */ | |
262 | msym = lookup_minimal_symbol ("running_thread", NULL, NULL); | |
263 | ||
264 | return msym; | |
265 | } | |
266 | ||
036b1ba8 JB |
267 | /* Return True if the Ada Ravenscar run-time can be found in the |
268 | application. */ | |
269 | ||
989f3c58 TT |
270 | static bool |
271 | has_ravenscar_runtime () | |
036b1ba8 | 272 | { |
6cbcc006 TT |
273 | struct bound_minimal_symbol msym_ravenscar_runtime_initializer |
274 | = lookup_minimal_symbol (ravenscar_runtime_initializer, NULL, NULL); | |
275 | struct bound_minimal_symbol msym_known_tasks | |
276 | = lookup_minimal_symbol (known_tasks_name, NULL, NULL); | |
277 | struct bound_minimal_symbol msym_first_task | |
278 | = lookup_minimal_symbol (first_task_name, NULL, NULL); | |
3b7344d5 TT |
279 | struct bound_minimal_symbol msym_running_thread |
280 | = get_running_thread_msymbol (); | |
036b1ba8 | 281 | |
3b7344d5 TT |
282 | return (msym_ravenscar_runtime_initializer.minsym |
283 | && (msym_known_tasks.minsym || msym_first_task.minsym) | |
284 | && msym_running_thread.minsym); | |
036b1ba8 JB |
285 | } |
286 | ||
287 | /* Return True if the Ada Ravenscar run-time can be found in the | |
288 | application, and if it has been initialized on target. */ | |
289 | ||
0b790b1e TT |
290 | bool |
291 | ravenscar_thread_target::runtime_initialized () | |
036b1ba8 | 292 | { |
0b790b1e | 293 | return active_task (1) != null_ptid; |
036b1ba8 JB |
294 | } |
295 | ||
7f39f34a JB |
296 | /* Return the ID of the thread that is currently running. |
297 | Return 0 if the ID could not be determined. */ | |
036b1ba8 JB |
298 | |
299 | static CORE_ADDR | |
9edcc12f | 300 | get_running_thread_id (int cpu) |
036b1ba8 | 301 | { |
3b7344d5 | 302 | struct bound_minimal_symbol object_msym = get_running_thread_msymbol (); |
036b1ba8 JB |
303 | int object_size; |
304 | int buf_size; | |
948f8e3d | 305 | gdb_byte *buf; |
036b1ba8 | 306 | CORE_ADDR object_addr; |
6cbcc006 TT |
307 | struct type *builtin_type_void_data_ptr |
308 | = builtin_type (target_gdbarch ())->builtin_data_ptr; | |
036b1ba8 | 309 | |
3b7344d5 | 310 | if (!object_msym.minsym) |
036b1ba8 JB |
311 | return 0; |
312 | ||
036b1ba8 | 313 | object_size = TYPE_LENGTH (builtin_type_void_data_ptr); |
9edcc12f JB |
314 | object_addr = (BMSYMBOL_VALUE_ADDRESS (object_msym) |
315 | + (cpu - 1) * object_size); | |
036b1ba8 | 316 | buf_size = object_size; |
224c3ddb | 317 | buf = (gdb_byte *) alloca (buf_size); |
036b1ba8 JB |
318 | read_memory (object_addr, buf, buf_size); |
319 | return extract_typed_address (buf, builtin_type_void_data_ptr); | |
320 | } | |
321 | ||
f6ac5f3d | 322 | void |
6cbcc006 TT |
323 | ravenscar_thread_target::resume (ptid_t ptid, int step, |
324 | enum gdb_signal siggnal) | |
036b1ba8 | 325 | { |
485b851b TT |
326 | /* If we see a wildcard resume, we simply pass that on. Otherwise, |
327 | arrange to resume the base ptid. */ | |
0b790b1e | 328 | inferior_ptid = m_base_ptid; |
485b851b TT |
329 | if (ptid != minus_one_ptid) |
330 | ptid = m_base_ptid; | |
331 | beneath ()->resume (ptid, step, siggnal); | |
036b1ba8 JB |
332 | } |
333 | ||
f6ac5f3d PA |
334 | ptid_t |
335 | ravenscar_thread_target::wait (ptid_t ptid, | |
336 | struct target_waitstatus *status, | |
337 | int options) | |
036b1ba8 | 338 | { |
3b1b69bf | 339 | ptid_t event_ptid; |
036b1ba8 | 340 | |
0b790b1e | 341 | inferior_ptid = m_base_ptid; |
485b851b TT |
342 | if (ptid != minus_one_ptid) |
343 | ptid = m_base_ptid; | |
344 | event_ptid = beneath ()->wait (ptid, status, 0); | |
bed0c243 JB |
345 | /* Find any new threads that might have been created, and update |
346 | inferior_ptid to the active thread. | |
347 | ||
348 | Only do it if the program is still alive, though. Otherwise, | |
349 | this causes problems when debugging through the remote protocol, | |
350 | because we might try switching threads (and thus sending packets) | |
351 | after the remote has disconnected. */ | |
352 | if (status->kind != TARGET_WAITKIND_EXITED | |
353 | && status->kind != TARGET_WAITKIND_SIGNALLED) | |
354 | { | |
3b1b69bf | 355 | inferior_ptid = event_ptid; |
f6ac5f3d | 356 | this->update_thread_list (); |
0b790b1e | 357 | this->update_inferior_ptid (); |
bed0c243 | 358 | } |
485b851b TT |
359 | else |
360 | inferior_ptid = m_base_ptid; | |
036b1ba8 JB |
361 | return inferior_ptid; |
362 | } | |
363 | ||
364 | /* Add the thread associated to the given TASK to the thread list | |
365 | (if the thread has already been added, this is a no-op). */ | |
366 | ||
367 | static void | |
368 | ravenscar_add_thread (struct ada_task_info *task) | |
369 | { | |
370 | if (find_thread_ptid (task->ptid) == NULL) | |
371 | add_thread (task->ptid); | |
372 | } | |
373 | ||
f6ac5f3d PA |
374 | void |
375 | ravenscar_thread_target::update_thread_list () | |
036b1ba8 | 376 | { |
036b1ba8 JB |
377 | /* Do not clear the thread list before adding the Ada task, to keep |
378 | the thread that the process stratum has included into it | |
0b790b1e | 379 | (m_base_ptid) and the running thread, that may not have been included |
036b1ba8 JB |
380 | to system.tasking.debug's list yet. */ |
381 | ||
382 | iterate_over_live_ada_tasks (ravenscar_add_thread); | |
383 | } | |
384 | ||
0b790b1e TT |
385 | ptid_t |
386 | ravenscar_thread_target::active_task (int cpu) | |
036b1ba8 | 387 | { |
9edcc12f | 388 | CORE_ADDR tid = get_running_thread_id (cpu); |
036b1ba8 JB |
389 | |
390 | if (tid == 0) | |
391 | return null_ptid; | |
392 | else | |
0b790b1e | 393 | return ptid_t (m_base_ptid.pid (), 0, tid); |
036b1ba8 JB |
394 | } |
395 | ||
f6ac5f3d PA |
396 | const char * |
397 | ravenscar_thread_target::extra_thread_info (thread_info *tp) | |
036b1ba8 JB |
398 | { |
399 | return "Ravenscar task"; | |
400 | } | |
401 | ||
57810aa7 | 402 | bool |
f6ac5f3d | 403 | ravenscar_thread_target::thread_alive (ptid_t ptid) |
036b1ba8 JB |
404 | { |
405 | /* Ravenscar tasks are non-terminating. */ | |
57810aa7 | 406 | return true; |
036b1ba8 JB |
407 | } |
408 | ||
a068643d | 409 | std::string |
f6ac5f3d | 410 | ravenscar_thread_target::pid_to_str (ptid_t ptid) |
036b1ba8 | 411 | { |
a068643d | 412 | return string_printf ("Thread %#x", (int) ptid.tid ()); |
036b1ba8 JB |
413 | } |
414 | ||
f6ac5f3d PA |
415 | void |
416 | ravenscar_thread_target::fetch_registers (struct regcache *regcache, int regnum) | |
036b1ba8 | 417 | { |
222312d3 | 418 | ptid_t ptid = regcache->ptid (); |
036b1ba8 | 419 | |
0b790b1e | 420 | if (runtime_initialized () |
9edcc12f | 421 | && is_ravenscar_task (ptid) |
0b790b1e | 422 | && !task_is_currently_active (ptid)) |
7e35103a | 423 | { |
ac7936df | 424 | struct gdbarch *gdbarch = regcache->arch (); |
7e35103a JB |
425 | struct ravenscar_arch_ops *arch_ops |
426 | = gdbarch_ravenscar_ops (gdbarch); | |
427 | ||
7657f14d | 428 | arch_ops->fetch_registers (regcache, regnum); |
7e35103a | 429 | } |
9edcc12f | 430 | else |
d6ca69cd | 431 | beneath ()->fetch_registers (regcache, regnum); |
036b1ba8 JB |
432 | } |
433 | ||
f6ac5f3d PA |
434 | void |
435 | ravenscar_thread_target::store_registers (struct regcache *regcache, | |
436 | int regnum) | |
036b1ba8 | 437 | { |
222312d3 | 438 | ptid_t ptid = regcache->ptid (); |
036b1ba8 | 439 | |
0b790b1e | 440 | if (runtime_initialized () |
9edcc12f | 441 | && is_ravenscar_task (ptid) |
0b790b1e | 442 | && !task_is_currently_active (ptid)) |
7e35103a | 443 | { |
ac7936df | 444 | struct gdbarch *gdbarch = regcache->arch (); |
7e35103a JB |
445 | struct ravenscar_arch_ops *arch_ops |
446 | = gdbarch_ravenscar_ops (gdbarch); | |
447 | ||
7657f14d | 448 | arch_ops->store_registers (regcache, regnum); |
7e35103a | 449 | } |
9edcc12f | 450 | else |
d6ca69cd | 451 | beneath ()->store_registers (regcache, regnum); |
036b1ba8 JB |
452 | } |
453 | ||
f6ac5f3d PA |
454 | void |
455 | ravenscar_thread_target::prepare_to_store (struct regcache *regcache) | |
036b1ba8 | 456 | { |
222312d3 | 457 | ptid_t ptid = regcache->ptid (); |
036b1ba8 | 458 | |
0b790b1e | 459 | if (runtime_initialized () |
9edcc12f | 460 | && is_ravenscar_task (ptid) |
0b790b1e | 461 | && !task_is_currently_active (ptid)) |
7e35103a | 462 | { |
7657f14d | 463 | /* Nothing. */ |
7e35103a | 464 | } |
9edcc12f | 465 | else |
d6ca69cd | 466 | beneath ()->prepare_to_store (regcache); |
036b1ba8 JB |
467 | } |
468 | ||
e02544b2 JB |
469 | /* Implement the to_stopped_by_sw_breakpoint target_ops "method". */ |
470 | ||
57810aa7 | 471 | bool |
f6ac5f3d | 472 | ravenscar_thread_target::stopped_by_sw_breakpoint () |
e02544b2 | 473 | { |
5b6ea500 TT |
474 | scoped_restore save_ptid = make_scoped_restore (&inferior_ptid); |
475 | inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid); | |
476 | return beneath ()->stopped_by_sw_breakpoint (); | |
e02544b2 JB |
477 | } |
478 | ||
479 | /* Implement the to_stopped_by_hw_breakpoint target_ops "method". */ | |
480 | ||
57810aa7 | 481 | bool |
f6ac5f3d | 482 | ravenscar_thread_target::stopped_by_hw_breakpoint () |
e02544b2 | 483 | { |
5b6ea500 TT |
484 | scoped_restore save_ptid = make_scoped_restore (&inferior_ptid); |
485 | inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid); | |
486 | return beneath ()->stopped_by_hw_breakpoint (); | |
e02544b2 JB |
487 | } |
488 | ||
489 | /* Implement the to_stopped_by_watchpoint target_ops "method". */ | |
490 | ||
57810aa7 | 491 | bool |
f6ac5f3d | 492 | ravenscar_thread_target::stopped_by_watchpoint () |
e02544b2 | 493 | { |
5b6ea500 TT |
494 | scoped_restore save_ptid = make_scoped_restore (&inferior_ptid); |
495 | inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid); | |
496 | return beneath ()->stopped_by_watchpoint (); | |
e02544b2 JB |
497 | } |
498 | ||
499 | /* Implement the to_stopped_data_address target_ops "method". */ | |
500 | ||
57810aa7 | 501 | bool |
f6ac5f3d | 502 | ravenscar_thread_target::stopped_data_address (CORE_ADDR *addr_p) |
e02544b2 | 503 | { |
5b6ea500 TT |
504 | scoped_restore save_ptid = make_scoped_restore (&inferior_ptid); |
505 | inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid); | |
506 | return beneath ()->stopped_data_address (addr_p); | |
e02544b2 JB |
507 | } |
508 | ||
f6ac5f3d PA |
509 | void |
510 | ravenscar_thread_target::mourn_inferior () | |
036b1ba8 | 511 | { |
0b790b1e | 512 | m_base_ptid = null_ptid; |
d6ca69cd | 513 | beneath ()->mourn_inferior (); |
0b790b1e | 514 | unpush_target (this); |
036b1ba8 JB |
515 | } |
516 | ||
e02544b2 JB |
517 | /* Implement the to_core_of_thread target_ops "method". */ |
518 | ||
f6ac5f3d PA |
519 | int |
520 | ravenscar_thread_target::core_of_thread (ptid_t ptid) | |
e02544b2 | 521 | { |
5b6ea500 TT |
522 | scoped_restore save_ptid = make_scoped_restore (&inferior_ptid); |
523 | inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid); | |
524 | return beneath ()->core_of_thread (inferior_ptid); | |
e02544b2 JB |
525 | } |
526 | ||
036b1ba8 JB |
527 | /* Observer on inferior_created: push ravenscar thread stratum if needed. */ |
528 | ||
529 | static void | |
530 | ravenscar_inferior_created (struct target_ops *target, int from_tty) | |
531 | { | |
cf3fbed4 | 532 | const char *err_msg; |
7e35103a JB |
533 | |
534 | if (!ravenscar_task_support | |
7dc7c195 | 535 | || gdbarch_ravenscar_ops (target_gdbarch ()) == NULL |
7e35103a | 536 | || !has_ravenscar_runtime ()) |
25abf4de JB |
537 | return; |
538 | ||
cf3fbed4 JB |
539 | err_msg = ada_get_tcb_types_info (); |
540 | if (err_msg != NULL) | |
541 | { | |
8f6cb6c3 | 542 | warning (_("%s. Task/thread support disabled."), err_msg); |
cf3fbed4 JB |
543 | return; |
544 | } | |
545 | ||
0b790b1e TT |
546 | target_ops_up target_holder (new ravenscar_thread_target ()); |
547 | push_target (std::move (target_holder)); | |
036b1ba8 JB |
548 | } |
549 | ||
f6ac5f3d PA |
550 | ptid_t |
551 | ravenscar_thread_target::get_ada_task_ptid (long lwp, long thread) | |
036b1ba8 | 552 | { |
0b790b1e | 553 | return ptid_t (m_base_ptid.pid (), 0, thread); |
036b1ba8 JB |
554 | } |
555 | ||
036b1ba8 JB |
556 | /* Command-list for the "set/show ravenscar" prefix command. */ |
557 | static struct cmd_list_element *set_ravenscar_list; | |
558 | static struct cmd_list_element *show_ravenscar_list; | |
559 | ||
560 | /* Implement the "set ravenscar" prefix command. */ | |
561 | ||
562 | static void | |
981a3fb3 | 563 | set_ravenscar_command (const char *arg, int from_tty) |
036b1ba8 JB |
564 | { |
565 | printf_unfiltered (_(\ | |
566 | "\"set ravenscar\" must be followed by the name of a setting.\n")); | |
635c7e8a | 567 | help_list (set_ravenscar_list, "set ravenscar ", all_commands, gdb_stdout); |
036b1ba8 JB |
568 | } |
569 | ||
570 | /* Implement the "show ravenscar" prefix command. */ | |
571 | ||
572 | static void | |
981a3fb3 | 573 | show_ravenscar_command (const char *args, int from_tty) |
036b1ba8 JB |
574 | { |
575 | cmd_show_list (show_ravenscar_list, from_tty, ""); | |
576 | } | |
577 | ||
578 | /* Implement the "show ravenscar task-switching" command. */ | |
579 | ||
580 | static void | |
581 | show_ravenscar_task_switching_command (struct ui_file *file, int from_tty, | |
582 | struct cmd_list_element *c, | |
583 | const char *value) | |
584 | { | |
585 | if (ravenscar_task_support) | |
586 | fprintf_filtered (file, _("\ | |
b64edec4 | 587 | Support for Ravenscar task/thread switching is enabled\n")); |
036b1ba8 JB |
588 | else |
589 | fprintf_filtered (file, _("\ | |
b64edec4 | 590 | Support for Ravenscar task/thread switching is disabled\n")); |
036b1ba8 JB |
591 | } |
592 | ||
593 | /* Module startup initialization function, automagically called by | |
594 | init.c. */ | |
595 | ||
596 | void | |
989f3c58 | 597 | _initialize_ravenscar () |
036b1ba8 | 598 | { |
036b1ba8 JB |
599 | /* Notice when the inferior is created in order to push the |
600 | ravenscar ops if needed. */ | |
76727919 | 601 | gdb::observers::inferior_created.attach (ravenscar_inferior_created); |
036b1ba8 | 602 | |
036b1ba8 | 603 | add_prefix_cmd ("ravenscar", no_class, set_ravenscar_command, |
590042fc | 604 | _("Prefix command for changing Ravenscar-specific settings."), |
036b1ba8 JB |
605 | &set_ravenscar_list, "set ravenscar ", 0, &setlist); |
606 | ||
607 | add_prefix_cmd ("ravenscar", no_class, show_ravenscar_command, | |
590042fc | 608 | _("Prefix command for showing Ravenscar-specific settings."), |
04f9d4d0 | 609 | &show_ravenscar_list, "show ravenscar ", 0, &showlist); |
036b1ba8 JB |
610 | |
611 | add_setshow_boolean_cmd ("task-switching", class_obscure, | |
612 | &ravenscar_task_support, _("\ | |
590042fc PW |
613 | Enable or disable support for GNAT Ravenscar tasks."), _("\ |
614 | Show whether support for GNAT Ravenscar tasks is enabled."), | |
036b1ba8 JB |
615 | _("\ |
616 | Enable or disable support for task/thread switching with the GNAT\n\ | |
617 | Ravenscar run-time library for bareboard configuration."), | |
618 | NULL, show_ravenscar_task_switching_command, | |
619 | &set_ravenscar_list, &show_ravenscar_list); | |
620 | } |