Re: [PATCH 19/28] Don't write to inferior_ptid in btrace_fetch

Pedro Alves
2020-04-15T14:13:17Z

On 4/15/20 5:52 AM, Metzger, Markus T via Gdb-patches wrote:
> Hello Pedro,
>
>> AFAICT, this isn't required nowadays.
>
> How is this working nowadays? There are still references to inferior_ptid.

Clearly I didn't think this one through. I put a tp->ptid==inferior_ptid
assertion in place, and that regressed gdb.python/py-record-btrace-threads.exp.
This should mean that the target_read_btrace calls in btrace_fetch can hit
the wrong thread.

So here's an alternative patch. No regressions when tested with:

$ make check TESTS="gdb.btrace/*.exp */*btrace*.exp"

From 92c8fa469295b5737e6cb5e882024af2e9872c4c Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 13 Apr 2020 20:02:22 +0100
Subject: [PATCH 19/28] Don't write to inferior_ptid in btrace.c

gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>

* btrace.c (btrace_fetch): Use switch_to_thread instead of writing
to inferior_ptid.
---
gdb/btrace.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gdb/btrace.c b/gdb/btrace.c
index bbf8749649..2964455680 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1908,13 +1908,13 @@ btrace_fetch (struct thread_info *tp, const struct btrace_cpu *cpu)
if (btinfo->replay != NULL)
return;

- /* With CLI usage, TP->PTID always equals INFERIOR_PTID here. Now that we
- can store a gdb.Record object in Python referring to a different thread
- than the current one, temporarily set INFERIOR_PTID. */
- scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
- inferior_ptid = tp->ptid;
+ /* With CLI usage, TP is always the current thread when we get here.
+ However, since we can also store a gdb.Record object in Python
+ referring to a different thread than the current one, we need to
+ temporarily set the current thread. */
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (tp);

/* We should not be called on running or exited threads. */
gdb_assert (can_access_registers_thread (tp));

--
2.14.5