Re: [PATCH 02/23] Don't rely on inferior_ptid in record_full_wait

Tom Tromey
2020-07-31T03:17:27Z

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> The multi-target patch sets inferior_ptid to null_ptid before handling
Pedro> a target event, and thus before calling target_wait, in order to catch
Pedro> places in target_ops::wait implementations that are incorrectly
Pedro> relying on inferior_ptid (which could otherwise be a ptid of a
Pedro> different target, for example). That caught this instance in
Pedro> record-full.c.

I found a few target_ops::wait implementations doing "return
inferior_ptid" in error cases. Based on this comment, and the comment
for target_wait, I suspect these should actually return minus_one_ptid
instead.

I've appended the patch so you can see what it looks like. I haven't
tried it at all. Does this seem correct?

Tom

diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index ae0b0f7ff0d..2cae87023f9 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -343,7 +343,7 @@ inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
/* Claim it exited with unknown signal. */
ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
- return inferior_ptid;
+ return minus_one_ptid;
}

/* Ignore terminated detached child processes. */
diff --git a/gdb/obsd-nat.c b/gdb/obsd-nat.c
index 6667a0add7f..5414adec051 100644
--- a/gdb/obsd-nat.c
+++ b/gdb/obsd-nat.c
@@ -101,7 +101,7 @@ obsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
/* Claim it exited with unknown signal. */
ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
- return inferior_ptid;
+ return minus_one_ptid;
}

/* Ignore terminated detached child processes. */
diff --git a/gdb/rs6000-nat.c b/gdb/rs6000-nat.c
index 654e06e3e4b..f73919f055c 100644
--- a/gdb/rs6000-nat.c
+++ b/gdb/rs6000-nat.c
@@ -522,7 +522,7 @@ rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
/* Claim it exited with unknown signal. */
ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
- return inferior_ptid;
+ return minus_one_ptid;
}

/* Ignore terminated detached child processes. */