From patchwork Mon Jul 2 15:33:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28192 Received: (qmail 81135 invoked by alias); 2 Jul 2018 15:33:33 -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 81116 invoked by uid 89); 2 Jul 2018 15:33:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=hows X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.145.216) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 02 Jul 2018 15:33:30 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 78F2920F49 for ; Mon, 2 Jul 2018 10:33:29 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id a0pAf5F4Y79N3a0pMfUXEu; Mon, 02 Jul 2018 10:33:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=uNrficWfbvTrgWka8Mqb8JdTD13GyEuVjxGQaIenl2I=; b=ogd8B1osW4xtIBpgEaXLK3NwSc CQdaLTQEceKIP3nKz2We5blJjdsuGNSqPR/NuCf0eaoCWg0tkW8Yd+0cojjJJF/DtX5dMBKessWbB DIhXU0JatMoaylEtJIRJHZP1Q; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:44384 helo=pokyo) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fa0p9-003Ad1-R9; Mon, 02 Jul 2018 10:33:07 -0500 From: Tom Tromey To: Pedro Alves Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFA] Fix crash in "run" on macOS when gdb is not signed References: <20180628180257.29883-1-tom@tromey.com> <1d40e422-08f4-30c1-de10-bd63396acb0b@redhat.com> Date: Mon, 02 Jul 2018 09:33:07 -0600 In-Reply-To: <1d40e422-08f4-30c1-de10-bd63396acb0b@redhat.com> (Pedro Alves's message of "Fri, 29 Jun 2018 20:31:33 +0100") Message-ID: <87o9fpodos.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) MIME-Version: 1.0 >>>>> "Pedro" == Pedro Alves writes: Pedro> I'd try also with "attach", see if something else needs Pedro> cleaning up / unwinding. Thanks. This seemed to work fine. Pedro> If you try this with MI as is, I think gdb will output a Pedro> -thread-group-started notification, and then an ^error. Pedro> You may want to call exit_inferior instead so that Pedro> gdb outputs a matching -thread-group-exited. Indeed; I've changed it to use exit_inferior. Pedro> Otherwise looks fine to me. How's this? Tom commit 2697c65bdfb0078c6cd60b87f16d73b25399a32c Author: Tom Tromey Date: Thu Jun 28 11:57:39 2018 -0600 Fix crash in "run" on macOS when gdb is not signed On macOS, when gdb is not code-signed, it will throw an exception from darwin_attach_pid. However, gdb also then crashes: thread.c:93: internal-error: struct thread_info *inferior_thread(): Assertion `tp' failed. I think the problem here is that darwin_attach_pid does not clean up inferior_ptid and inf->pid on failure. This leads to a situation where gdb tries to find a thread, but cannot. In other cases, gdb would mourn the inferior at this point; but here this is not possible because the target has not been pushed. Instead this patch works by simply calling exit_inferior and then updating inferior_ptid on failure. Tested by building an unsigned gdb on macOS and trying to run an inferior. I also tried this with MI, and by attaching; as suggested by Pedro. gdb/ChangeLog 2018-06-28 Tom Tromey PR cli/23340: * darwin-nat.c (darwin_attach_pid): Reset inferior and inferior_ptid on error. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0f601bdbf07..e61d042aa63 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-07-02 Tom Tromey + + PR cli/23340: + * darwin-nat.c (darwin_attach_pid): Call exit_inferior and reset + inferior_ptid on error. + 2018-07-02 Sebastian Huber * riscv-tdep.c (riscv_register_aliases): Swap "fp" and "s0" entries. diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 7dccce73926..38b3b765159 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -1583,77 +1583,91 @@ darwin_attach_pid (struct inferior *inf) darwin_inferior *priv = new darwin_inferior; inf->priv.reset (priv); - kret = task_for_pid (gdb_task, inf->pid, &priv->task); - if (kret != KERN_SUCCESS) + TRY { - int status; - - if (!inf->attach_flag) + kret = task_for_pid (gdb_task, inf->pid, &priv->task); + if (kret != KERN_SUCCESS) { - kill (inf->pid, 9); - waitpid (inf->pid, &status, 0); - } + int status; + + if (!inf->attach_flag) + { + kill (inf->pid, 9); + waitpid (inf->pid, &status, 0); + } - error (_("Unable to find Mach task port for process-id %d: %s (0x%lx).\n" + error + (_("Unable to find Mach task port for process-id %d: %s (0x%lx).\n" " (please check gdb is codesigned - see taskgated(8))"), - inf->pid, mach_error_string (kret), (unsigned long) kret); - } + inf->pid, mach_error_string (kret), (unsigned long) kret); + } - inferior_debug (2, _("inferior task: 0x%x, pid: %d\n"), - priv->task, inf->pid); + inferior_debug (2, _("inferior task: 0x%x, pid: %d\n"), + priv->task, inf->pid); - if (darwin_ex_port == MACH_PORT_NULL) - { - /* Create a port to get exceptions. */ - kret = mach_port_allocate (gdb_task, MACH_PORT_RIGHT_RECEIVE, - &darwin_ex_port); - if (kret != KERN_SUCCESS) - error (_("Unable to create exception port, mach_port_allocate " - "returned: %d"), - kret); + if (darwin_ex_port == MACH_PORT_NULL) + { + /* Create a port to get exceptions. */ + kret = mach_port_allocate (gdb_task, MACH_PORT_RIGHT_RECEIVE, + &darwin_ex_port); + if (kret != KERN_SUCCESS) + error (_("Unable to create exception port, mach_port_allocate " + "returned: %d"), + kret); - kret = mach_port_insert_right (gdb_task, darwin_ex_port, darwin_ex_port, - MACH_MSG_TYPE_MAKE_SEND); - if (kret != KERN_SUCCESS) - error (_("Unable to create exception port, mach_port_insert_right " - "returned: %d"), - kret); + kret = mach_port_insert_right (gdb_task, darwin_ex_port, + darwin_ex_port, + MACH_MSG_TYPE_MAKE_SEND); + if (kret != KERN_SUCCESS) + error (_("Unable to create exception port, mach_port_insert_right " + "returned: %d"), + kret); - /* Create a port set and put ex_port in it. */ - kret = mach_port_allocate (gdb_task, MACH_PORT_RIGHT_PORT_SET, - &darwin_port_set); + /* Create a port set and put ex_port in it. */ + kret = mach_port_allocate (gdb_task, MACH_PORT_RIGHT_PORT_SET, + &darwin_port_set); + if (kret != KERN_SUCCESS) + error (_("Unable to create port set, mach_port_allocate " + "returned: %d"), + kret); + + kret = mach_port_move_member (gdb_task, darwin_ex_port, + darwin_port_set); + if (kret != KERN_SUCCESS) + error (_("Unable to move exception port into new port set, " + "mach_port_move_member\n" + "returned: %d"), + kret); + } + + /* Create a port to be notified when the child task terminates. */ + kret = mach_port_allocate (gdb_task, MACH_PORT_RIGHT_RECEIVE, + &priv->notify_port); if (kret != KERN_SUCCESS) - error (_("Unable to create port set, mach_port_allocate " + error (_("Unable to create notification port, mach_port_allocate " "returned: %d"), kret); - kret = mach_port_move_member (gdb_task, darwin_ex_port, darwin_port_set); + kret = mach_port_move_member (gdb_task, + priv->notify_port, darwin_port_set); if (kret != KERN_SUCCESS) - error (_("Unable to move exception port into new port set, " + error (_("Unable to move notification port into new port set, " "mach_port_move_member\n" "returned: %d"), kret); - } - - /* Create a port to be notified when the child task terminates. */ - kret = mach_port_allocate (gdb_task, MACH_PORT_RIGHT_RECEIVE, - &priv->notify_port); - if (kret != KERN_SUCCESS) - error (_("Unable to create notification port, mach_port_allocate " - "returned: %d"), - kret); - kret = mach_port_move_member (gdb_task, - priv->notify_port, darwin_port_set); - if (kret != KERN_SUCCESS) - error (_("Unable to move notification port into new port set, " - "mach_port_move_member\n" - "returned: %d"), - kret); + darwin_setup_request_notification (inf); - darwin_setup_request_notification (inf); + darwin_setup_exceptions (inf); + } + CATCH (ex, RETURN_MASK_ALL) + { + exit_inferior (inf); + inferior_ptid = null_ptid; - darwin_setup_exceptions (inf); + throw_exception (ex); + } + END_CATCH target_ops *darwin_ops = get_native_target (); if (!target_is_pushed (darwin_ops))