From patchwork Fri Jun 29 20:55:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28159 Received: (qmail 74943 invoked by alias); 29 Jun 2018 20:55:57 -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 74934 invoked by uid 89); 29 Jun 2018 20:55:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=target_gdbarch X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.152.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 29 Jun 2018 20:55:53 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 8591FD894 for ; Fri, 29 Jun 2018 15:55:51 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id Z0QYfARMCaSeyZ0QhfplLF; Fri, 29 Jun 2018 15:55:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=jSeTmxuperuHr7CJDR7DuaqzegQfF01oYkaMq7rB5Fs=; b=u4jOqs7BDQ5LEDVMoSrWF76dIf ohGncBcyNbsXFXzpUFqWNHW0ui2jbaBFL3xK8VUA8cn+SW9sbXMwXllpfv6rzaddGJeBgDiNPMrtb ZrwKbFUqH732MA2TBHn4iVOnm; Received: from 75-166-79-120.hlrn.qwest.net ([75.166.79.120]:33442 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fZ0QX-001DkF-Ps; Fri, 29 Jun 2018 15:55:33 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC] Make "run" work on macOS 10.13 Date: Fri, 29 Jun 2018 14:55:32 -0600 Message-Id: <20180629205532.25377-1-tom@tromey.com> I would like some feedback on this patch. On macOS 10.13.5, "run" does not work in gdb. There are two cases: 1. If I forget to "set startup-with-shell off", then gdb will fail due to the system integrity protection feature. I believe this happens because gdb is not allowed to debug the shell. You can find many sites advocating "set startup-with-shell off", but it seems to me that it is friendlier for gdb to simply do it by default. One option here might be to do this conditionally based on the version of the OS. 2. I found that gdb was setting the solib breakpoint incorrectly, causing a failure. Adding the load address to the notifier address makes this work for me. I suspect this would regress earlier versions of macOS, but I have no way to test that; one idea might be to only do this when gdb_dyld_all_image_infos::version == 15. gdb/ChangeLog 2018-06-29 Tom Tromey * solib-darwin.c (darwin_solib_create_inferior_hook): Create solib breakpoint later. Add load_addr to the notifier address. * darwin-nat.c (darwin_nat_target::create_inferior): Bind startup_with_shell to 0. --- gdb/ChangeLog | 7 +++++++ gdb/darwin-nat.c | 5 +++++ gdb/solib-darwin.c | 9 +++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4c04d0ba728..c6462259fe0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2018-06-29 Tom Tromey + + * solib-darwin.c (darwin_solib_create_inferior_hook): Create solib + breakpoint later. Add load_addr to the notifier address. + * darwin-nat.c (darwin_nat_target::create_inferior): Bind + startup_with_shell to 0. + 2018-06-28 Tom Tromey * NEWS: Mention --enable-codesign. diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 7dccce73926..542c8389ef0 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -1809,6 +1809,11 @@ darwin_nat_target::create_inferior (const char *exec_file, const std::string &allargs, char **env, int from_tty) { + /* Starting with Sierra, SIP prevents gdb from attaching to the + shell, so users have to disable startup-with-shell. */ + scoped_restore save_startup + = make_scoped_restore (&startup_with_shell, 0); + /* Do the hard work. */ fork_inferior (exec_file, allargs, env, darwin_ptrace_me, darwin_ptrace_him, darwin_pre_ptrace, NULL, diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c index ed8e0c13365..a4e15dc6b5b 100644 --- a/gdb/solib-darwin.c +++ b/gdb/solib-darwin.c @@ -528,10 +528,6 @@ darwin_solib_create_inferior_hook (int from_tty) return; } - /* Add the breakpoint which is hit by dyld when the list of solib is - modified. */ - create_solib_event_breakpoint (target_gdbarch (), info->all_image.notifier); - if (info->all_image.count != 0) { /* Possible relocate the main executable (PIE). */ @@ -547,6 +543,11 @@ darwin_solib_create_inferior_hook (int from_tty) load_addr = darwin_read_exec_load_addr_at_init (info); } + /* Add the breakpoint which is hit by dyld when the list of solib is + modified. */ + create_solib_event_breakpoint (target_gdbarch (), + info->all_image.notifier + load_addr); + if (load_addr != 0 && symfile_objfile != NULL) { CORE_ADDR vmaddr;