From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23357 invoked by alias); 8 Aug 2008 01:35:10 -0000 Received: (qmail 23349 invoked by uid 22791); 8 Aug 2008 01:35:09 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 08 Aug 2008 01:34:35 +0000 Received: (qmail 32398 invoked from network); 8 Aug 2008 01:34:32 -0000 Received: from unknown (HELO orlando.local) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 8 Aug 2008 01:34:32 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [2/7] Add the attached-to thread in inf_ptrace_attach Date: Fri, 08 Aug 2008 01:35:00 -0000 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_RL6mImi2HFF/yQ8" Message-Id: <200808080235.13509.pedro@codesourcery.com> X-IsSubscribed: yes 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 X-SW-Source: 2008-08/txt/msg00171.txt.bz2 --Boundary-00=_RL6mImi2HFF/yQ8 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 570 This patch makes sure that the thread/task we attach to with ptrace targets is added to GDB's thread table. Targets that extend inf-ptrace (inf_ptrace_target) should then use thread_change_ptid as soon as then have more lwp or tid info, instead of just setting inferior_ptid. Targets that don't have a process_stratum target overriding inf_ptrace_attach get it for free (BSD targets). This was tested together with the rest of the series on x86_64-unknown-linux-gnu, i386-unknown-openbsd4.3, i386-unknown-freebsd6.0 and i386-unknown-freebsd7.0. OK? -- Pedro Alves --Boundary-00=_RL6mImi2HFF/yQ8 Content-Type: text/x-diff; charset="utf-8"; name="002-ptrace_bsd_attach_add_a_thread.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="002-ptrace_bsd_attach_add_a_thread.diff" Content-length: 2493 2008-08-08 Pedro Alves * inf-ptrace.c: Include "gdbthread.h". (inf_ptrace_attach): Add the main thread here. * linux-nat.c (linux_nat_attach): Don't add the main thread here. Decorate the main thread id with the lwp id. --- gdb/inf-ptrace.c | 6 ++++++ gdb/linux-nat.c | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) Index: src/gdb/inf-ptrace.c =================================================================== --- src.orig/gdb/inf-ptrace.c 2008-08-07 20:58:54.000000000 +0100 +++ src/gdb/inf-ptrace.c 2008-08-07 22:52:19.000000000 +0100 @@ -33,6 +33,7 @@ #include #include "inf-child.h" +#include "gdbthread.h" /* HACK: Save the ptrace ops returned by inf_ptrace_target. */ static struct target_ops *ptrace_ops_hack; @@ -218,6 +219,11 @@ inf_ptrace_attach (char *args, int from_ #endif inferior_ptid = pid_to_ptid (pid); + + /* Always add a main thread. If some target extends the ptrace + target, it should decorate the ptid later with more info. */ + add_thread_silent (inferior_ptid); + push_target (ptrace_ops_hack); } Index: src/gdb/linux-nat.c =================================================================== --- src.orig/gdb/linux-nat.c 2008-08-07 20:58:54.000000000 +0100 +++ src/gdb/linux-nat.c 2008-08-07 22:52:19.000000000 +0100 @@ -1348,6 +1348,7 @@ linux_nat_attach (char *args, int from_t { struct lwp_info *lp; int status; + ptid_t ptid; /* FIXME: We should probably accept a list of process id's, and attach all of them. */ @@ -1362,18 +1363,18 @@ linux_nat_attach (char *args, int from_t sigdelset (&suspend_mask, SIGCHLD); } + /* The ptrace base target adds the main thread with (pid,0,0) + format. Decorate it with lwp info. */ + ptid = BUILD_LWP (GET_PID (inferior_ptid), GET_PID (inferior_ptid)); + thread_change_ptid (inferior_ptid, ptid); + /* Add the initial process as the first LWP to the list. */ - inferior_ptid = BUILD_LWP (GET_PID (inferior_ptid), GET_PID (inferior_ptid)); - lp = add_lwp (inferior_ptid); + lp = add_lwp (ptid); status = linux_nat_post_attach_wait (lp->ptid, 1, &lp->cloned, &lp->signalled); lp->stopped = 1; - /* If this process is not using thread_db, then we still don't - detect any other threads, but add at least this one. */ - add_thread_silent (lp->ptid); - /* Save the wait status to report later. */ lp->resumed = 1; if (debug_linux_nat) --Boundary-00=_RL6mImi2HFF/yQ8--