From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9614 invoked by alias); 1 Oct 2013 09:50:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 9604 invoked by uid 89); 1 Oct 2013 09:50:51 -0000 Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 01 Oct 2013 09:50:51 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,RDNS_NONE,TO_NO_BRKTS_NORDNS autolearn=no version=3.3.2 X-HELO: rock.gnat.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 1A06C116517 for ; Tue, 1 Oct 2013 05:51:07 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 1LLEAN3bU1iX for ; Tue, 1 Oct 2013 05:51:07 -0400 (EDT) Received: from kwai.gnat.com (unknown [IPv6:2620:20:4000:0:a6ba:dbff:fe26:1f63]) by rock.gnat.com (Postfix) with ESMTP id 0B6581164EF for ; Tue, 1 Oct 2013 05:51:07 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4233) id B4D313FB31; Tue, 1 Oct 2013 05:50:48 -0400 (EDT) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA/gdbserver/LynxOS]: Incomplete thread list after --attach Date: Tue, 01 Oct 2013 09:50:00 -0000 Message-Id: <1380621039-25204-1-git-send-email-brobecker@adacore.com> X-SW-Source: 2013-10/txt/msg00021.txt.bz2 Hello, 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. This method was actually inspired by looking at old code which did exactly that. 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. Tested on various LynxOS platforms. OK to commit? Thanks, -- Joel --- gdb/gdbserver/lynx-low.c | 38 +++++++++++++++++++++++++++++++++++++- 1 files changed, 37 insertions(+), 1 deletions(-) diff --git a/gdb/gdbserver/lynx-low.c b/gdb/gdbserver/lynx-low.c index 3c75b62..09c214e 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 runnnig 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; } -- 1.7.0.4