From patchwork Wed Aug 22 10:11:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roirand X-Patchwork-Id: 29007 Received: (qmail 60816 invoked by alias); 22 Aug 2018 10:11:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 60710 invoked by uid 89); 22 Aug 2018 10:11:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=19336 X-HELO: mail-wm0-f43.google.com Received: from mail-wm0-f43.google.com (HELO mail-wm0-f43.google.com) (74.125.82.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Aug 2018 10:11:34 +0000 Received: by mail-wm0-f43.google.com with SMTP id f21-v6so1481001wmc.5 for ; Wed, 22 Aug 2018 03:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UOkhc2axfORTE32ts5UnsBPPQtflVmEhWZ+4FMoBVlE=; b=sJk/Qro4stOr4W4WBcEauQ8O2ooN0ATPRSYrF4gJTYsxVQVA5eXi99KdglcaDqVxuE NNsgK04nMUZDkhAV81cRpr5v0zLU5bpNqkI7apLmvmWP9Sy2jG6pIl/UuDR9liqRNaJv qhJG/9TPpfDrN7JA0eyiSsAeEd4f3XEIJ0vDjTjjLNEWeWZruwRfcYJJ1YrBHbsgowvj ETLFOr4puVOqiaAr73Ate3+Plt+XKbcwpE8esxZh70dNC2/c5oJrSpa+vqOhSJidvLgQ Q7wcYv7OnImECs3vqSopaWMBk2/8DTtyR+k9fLrpxyGfkCRph5pH2rqgthT28t6+ig9F wmeQ== Return-Path: Received: from adacore.com ([46.18.100.10]) by smtp.gmail.com with ESMTPSA id e133-v6sm1583890wma.33.2018.08.22.03.11.30 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 Aug 2018 03:11:31 -0700 (PDT) Received: by adacore.com (sSMTP sendmail emulation); Wed, 22 Aug 2018 12:11:29 +0200 From: Xavier Roirand To: gdb-patches@sourceware.org Cc: brobecker@adacore.com, Xavier Roirand Subject: [RFA 4/5] Darwin: fix thread ptid started by fork_inferior Date: Wed, 22 Aug 2018 12:11:16 +0200 Message-Id: <1534932677-9496-5-git-send-email-roirand@adacore.com> In-Reply-To: <1534932677-9496-1-git-send-email-roirand@adacore.com> References: <1534932677-9496-1-git-send-email-roirand@adacore.com> X-IsSubscribed: yes When debugging a program on Mac OS X Darwin, gdb stops with: Temporary breakpoint 1 at 0x100000fb4: file /tmp/helloworld.c, line 1. Starting program: /private/tmp/helloworld [New Thread 0xb03 of process 65066] [New Thread 0xd03 of process 65066] During startup program terminated with signal SIGTRAP, Trace/breakpoint trap. When the inferior is started a thread with lwp=tid=0 is created and has to be fixed later by darwin_init_thread_list(). Because this is not done, GDB does not understand that the SIGTRAP is coming from GDB and not the program itself. gdb/ChangeLog: * darwin-nat.c (darwin_check_new_threads): Check if first silent thread case. (darwin_init_thread_list): Fixup thread ptid. (darwin_ptrace_him): Add call. (darwin_nat_target::attach): Add call. Change-Id: Ie8ad7edfff167a1f95140907c75af45ceb3fae14 --- gdb/darwin-nat.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 96f70cf..9ad4a87 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -344,8 +344,22 @@ darwin_check_new_threads (struct inferior *inf) pti->gdb_port = new_id; pti->msg_state = DARWIN_RUNNING; - /* Add the new thread. */ - add_thread_with_info (ptid_t (inf->pid, 0, new_id), pti); + if (old_nbr == 0 && new_ix == 0) + { + /* A ptid is created when the inferior is started (see + fork-child.c) with lwp=tid=0. This ptid will be renamed + later by darwin_init_thread_list (), so find this previous + thread silently added. */ + + struct thread_info *tp = find_thread_ptid (ptid_t (inf->pid, 0, 0)); + tp->priv.reset (pti); + } + else + { + /* Add the new thread. */ + add_thread_with_info (ptid_t (inf->pid, 0, new_id), pti); + } + new_thread_vec.push_back (pti); new_ix++; continue; @@ -1733,6 +1747,8 @@ thread_info_from_private_thread_info (darwin_thread_info *pti) static void darwin_init_thread_list (struct inferior *inf) { + ptid_t new_ptid; + darwin_check_new_threads (inf); darwin_inferior *priv = get_darwin_inferior (inf); @@ -1743,7 +1759,11 @@ darwin_init_thread_list (struct inferior *inf) struct thread_info *first_thread = thread_info_from_private_thread_info (first_pti); - inferior_ptid = first_thread->ptid; + /* Note: fork_inferior automatically add a thread but it uses a wrong ptid. + Fix up. */ + new_ptid = ptid_t (inf->pid, 0, first_pti->gdb_port); + thread_change_ptid (inferior_ptid, new_ptid); + inferior_ptid = new_ptid; } /* The child must synchronize with gdb: gdb must set the exception port @@ -1806,6 +1826,9 @@ darwin_ptrace_him (int pid) int traps_expected; struct inferior *inf = current_inferior (); + inferior_ptid = ptid_t (pid); + add_thread_silent (inferior_ptid); + darwin_attach_pid (inf); /* Let's the child run. */ @@ -1933,6 +1956,8 @@ darwin_nat_target::attach (const char *args, int from_tty) inferior_appeared (inf, pid); inf->attach_flag = 1; + add_thread_silent (inferior_ptid); + darwin_attach_pid (inf); darwin_suspend_inferior (inf);