aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2020-06-18 21:28:20 +0100
committerPedro Alves <palves@redhat.com>2020-06-18 23:04:17 +0100
commit6155c136ccf04b1e4ae1bdc201b853ce899b8607 (patch)
tree51a93b77b05afcd0e596dd83da90f5e3b91947b3
parentc5316fc6e634858a3821e612e613342da562e0b3 (diff)
downloadgdb-6155c136ccf04b1e4ae1bdc201b853ce899b8607.zip
gdb-6155c136ccf04b1e4ae1bdc201b853ce899b8607.tar.gz
gdb-6155c136ccf04b1e4ae1bdc201b853ce899b8607.tar.bz2
Don't write to inferior_ptid in inf-ptrace.c
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * inf-ptrace.c (inf_ptrace_target::create_inferior): Switch to the added thread. (inf_ptrace_target::attach): Don't write to inferior_ptid. Switch to the added thread. (inf_ptrace_target::detach_success): Use switch_to_no_thread instead of writing to inferior_ptid.
-rw-r--r--gdb/ChangeLog9
-rw-r--r--gdb/inf-ptrace.c19
2 files changed, 18 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6854b8f..4bc9c28 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@
2020-06-18 Pedro Alves <palves@redhat.com>
+ * inf-ptrace.c (inf_ptrace_target::create_inferior): Switch to the
+ added thread.
+ (inf_ptrace_target::attach): Don't write to inferior_ptid. Switch
+ to the added thread.
+ (inf_ptrace_target::detach_success): Use switch_to_no_thread
+ instead of writing to inferior_ptid.
+
+2020-06-18 Pedro Alves <palves@redhat.com>
+
* gdbarch-selftests.c: Include "progspace-and-thread.h".
(register_to_value_test): Mock a program_space too. Heap-allocate
the address space. Don't write to inferior_ptid. Use
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index a83ffcc..d25d226 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -90,9 +90,6 @@ inf_ptrace_target::create_inferior (const char *exec_file,
const std::string &allargs,
char **env, int from_tty)
{
- pid_t pid;
- ptid_t ptid;
-
/* Do not change either targets above or the same target if already present.
The reason is the target stack is shared across multiple inferiors. */
int ops_already_pushed = target_is_pushed (this);
@@ -105,14 +102,15 @@ inf_ptrace_target::create_inferior (const char *exec_file,
unpusher.reset (this);
}
- pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
- NULL, NULL, NULL);
+ pid_t pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
+ NULL, NULL, NULL);
- ptid = ptid_t (pid);
+ ptid_t ptid (pid);
/* We have something that executes now. We'll be running through
the shell at this point (if startup-with-shell is true), but the
pid shouldn't change. */
- add_thread_silent (this, ptid);
+ thread_info *thr = add_thread_silent (this, ptid);
+ switch_to_thread (thr);
unpusher.release ();
@@ -190,11 +188,12 @@ inf_ptrace_target::attach (const char *args, int from_tty)
inf = current_inferior ();
inferior_appeared (inf, pid);
inf->attach_flag = 1;
- inferior_ptid = ptid_t (pid);
/* Always add a main thread. If some target extends the ptrace
target, it should decorate the ptid later with more info. */
- thread_info *thr = add_thread_silent (this, inferior_ptid);
+ thread_info *thr = add_thread_silent (this, ptid_t (pid));
+ switch_to_thread (thr);
+
/* Don't consider the thread stopped until we've processed its
initial SIGSTOP stop. */
set_executing (this, thr->ptid, true);
@@ -232,7 +231,7 @@ inf_ptrace_target::detach (inferior *inf, int from_tty)
void
inf_ptrace_target::detach_success (inferior *inf)
{
- inferior_ptid = null_ptid;
+ switch_to_no_thread ();
detach_inferior (inf);
maybe_unpush_target ();