summaryrefslogtreecommitdiff
path: root/gdb/gdbserver
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2013-10-01 10:56:51 +0000
committerJoel Brobecker <brobecker@gnat.com>2013-10-01 10:56:51 +0000
commit63b4d2410df203b11d23f87e042d3db8ca094f04 (patch)
tree6668048ca204739d78288b5ef6681894c80b4e14 /gdb/gdbserver
parentceda0895037ea390baa326c7ed8d7a812289dcfd (diff)
downloadgdb-63b4d2410df203b11d23f87e042d3db8ca094f04.tar.gz
[gdbserver/LynxOS]: Incomplete thread list after --attach
The current implementation is forgetting to populate the thread list when attaching to the process. This results in an incomplete list of threads when debugging a threaded program. Unfortunately, as the added comments hints, there appears to be no way of getting the list of threads via ptrace, other than by spawning the "ps" command, and parsing its output. Not great, but it appears to be the best we can do. gdb/gdbserver/ChangeLog: * lynx-low.c (lynx_add_threads_after_attach): New function. (lynx_attach): Remove call to add_thread. Add call to lynx_add_threads_after_attach instead.
Diffstat (limited to 'gdb/gdbserver')
-rw-r--r--gdb/gdbserver/ChangeLog6
-rw-r--r--gdb/gdbserver/lynx-low.c38
2 files changed, 43 insertions, 1 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 460d9a12057..469a2df1a42 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,9 @@
+2013-10-01 Joel Brobecker <brobecker@adacore.com>
+
+ * lynx-low.c (lynx_add_threads_after_attach): New function.
+ (lynx_attach): Remove call to add_thread. Add call to
+ lynx_add_threads_after_attach instead.
+
2013-09-28 Mike Frysinger <vapier@gentoo.org>
* configure.ac (AC_CHECK_HEADERS): Add sys/syscall.h
diff --git a/gdb/gdbserver/lynx-low.c b/gdb/gdbserver/lynx-low.c
index 3c75b6296b8..3c061b8f077 100644
--- a/gdb/gdbserver/lynx-low.c
+++ b/gdb/gdbserver/lynx-low.c
@@ -262,6 +262,42 @@ lynx_create_inferior (char *program, char **allargs)
return pid;
}
+/* Assuming we've just attached to a running inferior whose pid is PID,
+ add all threads running in that process. */
+
+static void
+lynx_add_threads_after_attach (int pid)
+{
+ /* Ugh! There appears to be no way to get the list of threads
+ in the program we just attached to. So get the list by calling
+ the "ps" command. This is only needed now, as we will then
+ keep the thread list up to date thanks to thread creation and
+ exit notifications. */
+ FILE *f;
+ char buf[256];
+ int thread_pid, thread_tid;
+
+ f = popen ("ps atx", "r");
+ if (f == NULL)
+ perror_with_name ("Cannot get thread list");
+
+ while (fgets (buf, sizeof (buf), f) != NULL)
+ if ((sscanf (buf, "%d %d", &thread_pid, &thread_tid) == 2
+ && thread_pid == pid))
+ {
+ ptid_t thread_ptid = lynx_ptid_build (pid, thread_tid);
+
+ if (!find_thread_ptid (thread_ptid))
+ {
+ lynx_debug ("New thread: (pid = %d, tid = %d)",
+ pid, thread_tid);
+ add_thread (thread_ptid, NULL);
+ }
+ }
+
+ pclose (f);
+}
+
/* Implement the attach target_ops method. */
static int
@@ -274,7 +310,7 @@ lynx_attach (unsigned long pid)
strerror (errno), errno);
lynx_add_process (pid, 1);
- add_thread (ptid, NULL);
+ lynx_add_threads_after_attach (pid);
return 0;
}