From patchwork Fri Jun 29 23:04:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 28165 Received: (qmail 88060 invoked by alias); 29 Jun 2018 23:04:51 -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 85848 invoked by uid 89); 29 Jun 2018 23:04:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.5 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_PASS autolearn=ham version=3.3.2 spammy= X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 29 Jun 2018 23:04:47 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5265456136; Fri, 29 Jun 2018 19:04:46 -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 F49VtxT8rBpc; Fri, 29 Jun 2018 19:04:46 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 1E44656134; Fri, 29 Jun 2018 19:04:46 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 6D2E387940; Fri, 29 Jun 2018 16:04:44 -0700 (PDT) Date: Fri, 29 Jun 2018 16:04:44 -0700 From: Joel Brobecker To: Tom Tromey , Xavier Roirand Cc: gdb-patches@sourceware.org Subject: Re: [RFC] Make "run" work on macOS 10.13 Message-ID: <20180629230444.GI2511@adacore.com> References: <20180629205532.25377-1-tom@tromey.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180629205532.25377-1-tom@tromey.com> User-Agent: Mutt/1.9.4 (2018-02-28) Hi Tom, > 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. Attached is a patch that Tristan wrote to make that automatic. We were hoping to contribute that patch a while back, but we got busy working on other targets that needed our immediate attention. This patch has been working for us, but we wanted to review it internally before submitting it, because we wanted to make sure that changing the value of a global like that during _init was the best way to do this. > 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. Xavier, do you think you could help Tom to answer his question, please? > 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; > -- > 2.17.1 From 770848bb83d170ea2def48e02f7ea93f772124e4 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 15 Mar 2017 14:10:17 +0100 Subject: [PATCH] Darwin: set startup-with-shell to off by default on Sierra and later. ... as they aren't allowed to be debugger. gdb/ChangeLog: * darwin-nat.c (_initialize_darwin_inferior): Clear startup_with_shell on Sierra and later. --- gdb/darwin-nat.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index e3d058d15e8..013f8c08a41 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -2383,6 +2383,23 @@ _initialize_darwin_inferior (void) MACH_CHECK_ERROR (kret); } + /* Read kernel version, and set startup-with-shell to false on Sierra or + later. */ + { + char str[16]; + size_t sz = sizeof (str); + int ret; + unsigned long ver; + + ret = sysctlbyname ("kern.osrelease", str, &sz, NULL, 0); + if (ret == 0 && sz < sizeof (str)) + { + ver = strtoul (str, NULL, 10); + if (ver >= 16) + startup_with_shell = 0; + } + } + darwin_ops = inf_child_target (); darwin_ops->to_create_inferior = darwin_create_inferior; -- 2.17.1