Skip to content

Commit 97ad458

Browse files
author
Joel Brobecker
committed
[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.
1 parent e39462c commit 97ad458

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

gdb/gdbserver/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2013-10-01 Joel Brobecker <[email protected]>
2+
3+
* lynx-low.c (lynx_add_threads_after_attach): New function.
4+
(lynx_attach): Remove call to add_thread. Add call to
5+
lynx_add_threads_after_attach instead.
6+
17
2013-09-28 Mike Frysinger <[email protected]>
28

39
* configure.ac (AC_CHECK_HEADERS): Add sys/syscall.h

gdb/gdbserver/lynx-low.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,42 @@ lynx_create_inferior (char *program, char **allargs)
262262
return pid;
263263
}
264264

265+
/* Assuming we've just attached to a running inferior whose pid is PID,
266+
add all threads running in that process. */
267+
268+
static void
269+
lynx_add_threads_after_attach (int pid)
270+
{
271+
/* Ugh! There appears to be no way to get the list of threads
272+
in the program we just attached to. So get the list by calling
273+
the "ps" command. This is only needed now, as we will then
274+
keep the thread list up to date thanks to thread creation and
275+
exit notifications. */
276+
FILE *f;
277+
char buf[256];
278+
int thread_pid, thread_tid;
279+
280+
f = popen ("ps atx", "r");
281+
if (f == NULL)
282+
perror_with_name ("Cannot get thread list");
283+
284+
while (fgets (buf, sizeof (buf), f) != NULL)
285+
if ((sscanf (buf, "%d %d", &thread_pid, &thread_tid) == 2
286+
&& thread_pid == pid))
287+
{
288+
ptid_t thread_ptid = lynx_ptid_build (pid, thread_tid);
289+
290+
if (!find_thread_ptid (thread_ptid))
291+
{
292+
lynx_debug ("New thread: (pid = %d, tid = %d)",
293+
pid, thread_tid);
294+
add_thread (thread_ptid, NULL);
295+
}
296+
}
297+
298+
pclose (f);
299+
}
300+
265301
/* Implement the attach target_ops method. */
266302

267303
static int
@@ -274,7 +310,7 @@ lynx_attach (unsigned long pid)
274310
strerror (errno), errno);
275311

276312
lynx_add_process (pid, 1);
277-
add_thread (ptid, NULL);
313+
lynx_add_threads_after_attach (pid);
278314

279315
return 0;
280316
}

0 commit comments

Comments
 (0)