Skip to content

Commit 0b790b1

Browse files
committed
Make the ravenscar thread target multi-target-ready
This changes ravenscar-thread.c to make it ready for multi-target. This is done by moving globals into the target, and then arranging to allocate the target with "new" and delete the target in its "close" method. gdb/ChangeLog 2019-02-15 Tom Tromey <tromey@adacore.com> * ravenscar-thread.c (base_ptid): Remove. (struct ravenscar_thread_target) <close>: New method. <m_base_ptid>: New member. <update_inferior_ptid, active_task, task_is_currently_active, runtime_initialized>: Declare methods. <ravenscar_thread_target>: Add constructor. (ravenscar_thread_target::task_is_currently_active) (ravenscar_thread_target::update_inferior_ptid) (ravenscar_runtime_initialized): Rename. Now methods. (ravenscar_thread_target::resume, ravenscar_thread_target::wait) (ravenscar_thread_target::update_thread_list): Update. (ravenscar_thread_target::active_task): Now method. (ravenscar_thread_target::store_registers) (ravenscar_thread_target::prepare_to_store) (ravenscar_thread_target::prepare_to_store) (ravenscar_thread_target::mourn_inferior): Update. (ravenscar_inferior_created): Use "new" to create target. (ravenscar_thread_target::get_ada_task_ptid): Update. (_initialize_ravenscar): Don't initialize base_ptid. (ravenscar_ops): Remove global.
1 parent dea57a6 commit 0b790b1

File tree

2 files changed

+77
-45
lines changed

2 files changed

+77
-45
lines changed

gdb/ChangeLog

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2019-02-15 Tom Tromey <tromey@adacore.com>
2+
3+
* ravenscar-thread.c (base_ptid): Remove.
4+
(struct ravenscar_thread_target) <close>: New method.
5+
<m_base_ptid>: New member.
6+
<update_inferior_ptid, active_task, task_is_currently_active,
7+
runtime_initialized>: Declare methods.
8+
<ravenscar_thread_target>: Add constructor.
9+
(ravenscar_thread_target::task_is_currently_active)
10+
(ravenscar_thread_target::update_inferior_ptid)
11+
(ravenscar_runtime_initialized): Rename. Now methods.
12+
(ravenscar_thread_target::resume, ravenscar_thread_target::wait)
13+
(ravenscar_thread_target::update_thread_list): Update.
14+
(ravenscar_thread_target::active_task): Now method.
15+
(ravenscar_thread_target::store_registers)
16+
(ravenscar_thread_target::prepare_to_store)
17+
(ravenscar_thread_target::prepare_to_store)
18+
(ravenscar_thread_target::mourn_inferior): Update.
19+
(ravenscar_inferior_created): Use "new" to create target.
20+
(ravenscar_thread_target::get_ada_task_ptid): Update.
21+
(_initialize_ravenscar): Don't initialize base_ptid.
22+
(ravenscar_ops): Remove global.
23+
124
2019-02-15 Tom Tromey <tromey@adacore.com>
225

326
* target.h (push_target): Declare new overload.

gdb/ravenscar-thread.c

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@
6060
/* If non-null, ravenscar task support is enabled. */
6161
static int ravenscar_task_support = 1;
6262

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. */
66-
static ptid_t base_ptid;
67-
6863
static const char running_thread_name[] = "__gnat_running_thread_table";
6964

7065
static const char known_tasks_name[] = "system__tasking__debug__known_tasks";
@@ -81,6 +76,11 @@ static const target_info ravenscar_target_info = {
8176

8277
struct ravenscar_thread_target final : public target_ops
8378
{
79+
ravenscar_thread_target ()
80+
{
81+
update_inferior_ptid ();
82+
}
83+
8484
const target_info &info () const override
8585
{ return ravenscar_target_info; }
8686

@@ -115,13 +115,24 @@ struct ravenscar_thread_target final : public target_ops
115115
ptid_t get_ada_task_ptid (long lwp, long thread) override;
116116

117117
void mourn_inferior () override;
118-
};
119118

120-
/* This module's target-specific operations. */
121-
static ravenscar_thread_target ravenscar_ops;
119+
void close () override
120+
{
121+
delete this;
122+
}
123+
124+
private:
122125

123-
static ptid_t ravenscar_active_task (int cpu);
124-
static bool ravenscar_runtime_initialized ();
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+
};
125136

126137
/* Return true iff PTID corresponds to a ravenscar task. */
127138

@@ -175,11 +186,11 @@ ravenscar_get_thread_base_cpu (ptid_t ptid)
175186
that task's registers are in the CPU bank. Otherwise, the task
176187
is currently suspended, and its registers have been saved in memory. */
177188

178-
static bool
179-
ravenscar_task_is_currently_active (ptid_t ptid)
189+
bool
190+
ravenscar_thread_target::task_is_currently_active (ptid_t ptid)
180191
{
181192
ptid_t active_task_ptid
182-
= ravenscar_active_task (ravenscar_get_thread_base_cpu (ptid));
193+
= active_task (ravenscar_get_thread_base_cpu (ptid));
183194

184195
return ptid == active_task_ptid;
185196
}
@@ -205,24 +216,24 @@ get_base_thread_from_ravenscar_task (ptid_t ptid)
205216
/* Fetch the ravenscar running thread from target memory and
206217
update inferior_ptid accordingly. */
207218

208-
static void
209-
ravenscar_update_inferior_ptid ()
219+
void
220+
ravenscar_thread_target::update_inferior_ptid ()
210221
{
211222
int base_cpu;
212223

213-
base_ptid = inferior_ptid;
224+
m_base_ptid = inferior_ptid;
214225

215226
gdb_assert (!is_ravenscar_task (inferior_ptid));
216-
base_cpu = ravenscar_get_thread_base_cpu (base_ptid);
227+
base_cpu = ravenscar_get_thread_base_cpu (m_base_ptid);
217228

218229
/* If the runtime has not been initialized yet, the inferior_ptid is
219230
the only ptid that there is. */
220-
if (!ravenscar_runtime_initialized ())
231+
if (!runtime_initialized ())
221232
return;
222233

223-
/* Make sure we set base_ptid before calling ravenscar_active_task
234+
/* Make sure we set m_base_ptid before calling active_task
224235
as the latter relies on it. */
225-
inferior_ptid = ravenscar_active_task (base_cpu);
236+
inferior_ptid = active_task (base_cpu);
226237
gdb_assert (inferior_ptid != null_ptid);
227238

228239
/* The running thread may not have been added to
@@ -276,10 +287,10 @@ has_ravenscar_runtime ()
276287
/* Return True if the Ada Ravenscar run-time can be found in the
277288
application, and if it has been initialized on target. */
278289

279-
static bool
280-
ravenscar_runtime_initialized ()
290+
bool
291+
ravenscar_thread_target::runtime_initialized ()
281292
{
282-
return ravenscar_active_task (1) != null_ptid;
293+
return active_task (1) != null_ptid;
283294
}
284295

285296
/* Return the ID of the thread that is currently running.
@@ -312,8 +323,8 @@ void
312323
ravenscar_thread_target::resume (ptid_t ptid, int step,
313324
enum gdb_signal siggnal)
314325
{
315-
inferior_ptid = base_ptid;
316-
beneath ()->resume (base_ptid, step, siggnal);
326+
inferior_ptid = m_base_ptid;
327+
beneath ()->resume (m_base_ptid, step, siggnal);
317328
}
318329

319330
ptid_t
@@ -323,8 +334,8 @@ ravenscar_thread_target::wait (ptid_t ptid,
323334
{
324335
ptid_t event_ptid;
325336

326-
inferior_ptid = base_ptid;
327-
event_ptid = beneath ()->wait (base_ptid, status, 0);
337+
inferior_ptid = m_base_ptid;
338+
event_ptid = beneath ()->wait (m_base_ptid, status, 0);
328339
/* Find any new threads that might have been created, and update
329340
inferior_ptid to the active thread.
330341
@@ -337,7 +348,7 @@ ravenscar_thread_target::wait (ptid_t ptid,
337348
{
338349
inferior_ptid = event_ptid;
339350
this->update_thread_list ();
340-
ravenscar_update_inferior_ptid ();
351+
this->update_inferior_ptid ();
341352
}
342353
return inferior_ptid;
343354
}
@@ -359,21 +370,21 @@ ravenscar_thread_target::update_thread_list ()
359370

360371
/* Do not clear the thread list before adding the Ada task, to keep
361372
the thread that the process stratum has included into it
362-
(base_ptid) and the running thread, that may not have been included
373+
(m_base_ptid) and the running thread, that may not have been included
363374
to system.tasking.debug's list yet. */
364375

365376
iterate_over_live_ada_tasks (ravenscar_add_thread);
366377
}
367378

368-
static ptid_t
369-
ravenscar_active_task (int cpu)
379+
ptid_t
380+
ravenscar_thread_target::active_task (int cpu)
370381
{
371382
CORE_ADDR tid = get_running_thread_id (cpu);
372383

373384
if (tid == 0)
374385
return null_ptid;
375386
else
376-
return ptid_t (base_ptid.pid (), 0, tid);
387+
return ptid_t (m_base_ptid.pid (), 0, tid);
377388
}
378389

379390
const char *
@@ -403,9 +414,9 @@ ravenscar_thread_target::fetch_registers (struct regcache *regcache, int regnum)
403414
{
404415
ptid_t ptid = regcache->ptid ();
405416

406-
if (ravenscar_runtime_initialized ()
417+
if (runtime_initialized ()
407418
&& is_ravenscar_task (ptid)
408-
&& !ravenscar_task_is_currently_active (ptid))
419+
&& !task_is_currently_active (ptid))
409420
{
410421
struct gdbarch *gdbarch = regcache->arch ();
411422
struct ravenscar_arch_ops *arch_ops
@@ -423,9 +434,9 @@ ravenscar_thread_target::store_registers (struct regcache *regcache,
423434
{
424435
ptid_t ptid = regcache->ptid ();
425436

426-
if (ravenscar_runtime_initialized ()
437+
if (runtime_initialized ()
427438
&& is_ravenscar_task (ptid)
428-
&& !ravenscar_task_is_currently_active (ptid))
439+
&& !task_is_currently_active (ptid))
429440
{
430441
struct gdbarch *gdbarch = regcache->arch ();
431442
struct ravenscar_arch_ops *arch_ops
@@ -442,9 +453,9 @@ ravenscar_thread_target::prepare_to_store (struct regcache *regcache)
442453
{
443454
ptid_t ptid = regcache->ptid ();
444455

445-
if (ravenscar_runtime_initialized ()
456+
if (runtime_initialized ()
446457
&& is_ravenscar_task (ptid)
447-
&& !ravenscar_task_is_currently_active (ptid))
458+
&& !task_is_currently_active (ptid))
448459
{
449460
/* Nothing. */
450461
}
@@ -495,9 +506,9 @@ ravenscar_thread_target::stopped_data_address (CORE_ADDR *addr_p)
495506
void
496507
ravenscar_thread_target::mourn_inferior ()
497508
{
498-
base_ptid = null_ptid;
509+
m_base_ptid = null_ptid;
499510
beneath ()->mourn_inferior ();
500-
unpush_target (&ravenscar_ops);
511+
unpush_target (this);
501512
}
502513

503514
/* Implement the to_core_of_thread target_ops "method". */
@@ -529,14 +540,14 @@ ravenscar_inferior_created (struct target_ops *target, int from_tty)
529540
return;
530541
}
531542

532-
ravenscar_update_inferior_ptid ();
533-
push_target (&ravenscar_ops);
543+
target_ops_up target_holder (new ravenscar_thread_target ());
544+
push_target (std::move (target_holder));
534545
}
535546

536547
ptid_t
537548
ravenscar_thread_target::get_ada_task_ptid (long lwp, long thread)
538549
{
539-
return ptid_t (base_ptid.pid (), 0, thread);
550+
return ptid_t (m_base_ptid.pid (), 0, thread);
540551
}
541552

542553
/* Command-list for the "set/show ravenscar" prefix command. */
@@ -582,8 +593,6 @@ Support for Ravenscar task/thread switching is disabled\n"));
582593
void
583594
_initialize_ravenscar ()
584595
{
585-
base_ptid = null_ptid;
586-
587596
/* Notice when the inferior is created in order to push the
588597
ravenscar ops if needed. */
589598
gdb::observers::inferior_created.attach (ravenscar_inferior_created);

0 commit comments

Comments
 (0)