aboutsummaryrefslogtreecommitdiff
path: root/gdbserver
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-09-08 08:25:15 -0600
committerTom Tromey <tromey@adacore.com>2023-12-01 10:36:00 -0700
commitc6f7f9c80c3b92c6d877214d38aaef141adc5b93 (patch)
tree243638f58de9fe248d6193ffffa913a0ab25ae38 /gdbserver
parent596cd22cb10519f9baad6295fed13443d1ef86f9 (diff)
downloadgdb-c6f7f9c80c3b92c6d877214d38aaef141adc5b93.zip
gdb-c6f7f9c80c3b92c6d877214d38aaef141adc5b93.tar.gz
gdb-c6f7f9c80c3b92c6d877214d38aaef141adc5b93.tar.bz2
Bail out of "attach" if a thread cannot be traced
On Linux, threads are treated much like separate processes by the kernel. In particular, it's possible to ptrace just a single thread. If gdb tries to attach to a multi-threaded inferior, where a non-main thread is already being traced (e.g., by strace), then gdb will get into an infinite loop attempting to attach. This patch fixes this problem by having the attach fail if ptrace fails to attach to any thread of the inferior.
Diffstat (limited to 'gdbserver')
-rw-r--r--gdbserver/linux-low.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index eea2d8a..4aa011c 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -1154,7 +1154,7 @@ attach_proc_task_lwp_callback (ptid_t ptid)
std::string reason
= linux_ptrace_attach_fail_reason_string (ptid, err);
- warning (_("Cannot attach to lwp %d: %s"), lwpid, reason.c_str ());
+ error (_("Cannot attach to lwp %d: %s"), lwpid, reason.c_str ());
}
return 1;
@@ -1207,7 +1207,18 @@ linux_process_target::attach (unsigned long pid)
threads/LWPs, and those structures may well be corrupted. Note
that once thread_db is loaded, we'll still use it to list threads
and associate pthread info with each LWP. */
- linux_proc_attach_tgid_threads (pid, attach_proc_task_lwp_callback);
+ try
+ {
+ linux_proc_attach_tgid_threads (pid, attach_proc_task_lwp_callback);
+ }
+ catch (const gdb_exception_error &)
+ {
+ /* Make sure we do not deliver the SIGSTOP to the process. */
+ initial_thread->last_resume_kind = resume_continue;
+
+ this->detach (proc);
+ throw;
+ }
/* GDB will shortly read the xml target description for this
process, to figure out the process' architecture. But the target