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