From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7655 invoked by alias); 3 Sep 2018 13:23:40 -0000 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 Received: (qmail 7641 invoked by uid 89); 3 Sep 2018 13:23:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:sk:static-, H*RU:sk:static-, H*r:sk:static-, restore X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Sep 2018 13:23:38 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 9E25081850; Mon, 3 Sep 2018 15:23:36 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4-u3I7PUbNDx; Mon, 3 Sep 2018 15:23:36 +0200 (CEST) Received: from Xaviers-MacBook-Pro.local (static-css-csd-010062.business.bouyguestelecom.com [176.162.10.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 35ACF815A8; Mon, 3 Sep 2018 15:23:36 +0200 (CEST) Subject: Re: [RFA 3/5] Darwin: set startup-with-shell to off on Sierra and later. To: Simon Marchi Cc: gdb-patches@sourceware.org, brobecker@adacore.com References: <1534932677-9496-1-git-send-email-roirand@adacore.com> <1534932677-9496-4-git-send-email-roirand@adacore.com> <9a64f5298b404c3be126333b4287e390@polymtl.ca> From: Xavier Roirand Message-ID: <5f840a36-05ea-7804-b51d-01e9120dc947@adacore.com> Date: Mon, 03 Sep 2018 13:23:00 -0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <9a64f5298b404c3be126333b4287e390@polymtl.ca> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00018.txt.bz2 Hello, Le 8/22/18 à 4:20 PM, Simon Marchi a écrit : > On 2018-08-22 06:11, Xavier Roirand wrote: >> On Mac OS X Sierra and later, the shell is not allowed to be >> debug so add a check and disable startup with shell in that >> case. > > Ah, that's a really good idea to do it automatically, instead of asking > the user to do it. > >> gdb/ChangeLog: >>     * darwin-nat.c (disable_startup_with_shell): New function. >>     (_initialize_darwin_inferior): Add call. >> >> Change-Id: Ia3cbeaa89b2b44a173b93ee22cce0d3884a16924 >> --- >>  gdb/darwin-nat.c | 22 ++++++++++++++++++++++ >>  1 file changed, 22 insertions(+) >> >> diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c >> index be80163..96f70cf 100644 >> --- a/gdb/darwin-nat.c >> +++ b/gdb/darwin-nat.c >> @@ -2362,6 +2362,26 @@ darwin_nat_target::supports_multi_process () >>    return true; >>  } >> >> +/* Read kernel version, and set startup-with-shell to false on Sierra or >> +   later.  */ >> + >> +void >> +disable_startup_with_shell () > > This function should be static. > >> +{ >> +  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; >> +      } >> +} > > The indentation is not quite right.  You can also declare variables when > they are used/initialized. > >> + >>  void >>  _initialize_darwin_nat () >>  { >> @@ -2396,4 +2416,6 @@ When this mode is on, all low level exceptions >> are reported before being\n\ >>  reported by the kernel."), >>                 &set_enable_mach_exceptions, NULL, >>                 &setlist, &showlist); >> + >> +  disable_startup_with_shell (); >>  } > > I don't think we should do that in _initialize_darwin_nat.  Since > startup-with-shell is supported with remote debugging, you could still > use it when starting a Linux remote program from a macOS host. > > Instead, we should probably only disable it at the moment we create a > new inferior in the darwin_nat target, so in > darwin_nat_target::create_inferior.  We also don't want to permanently > change the setting, so we should restore the value.  Presumably, putting > something like this in darwin_nat_target::create_inferior should work (I > haven't tested it, and sorry for the potential formatting mess my email > client will do): > >   gdb::optional> restore_startup_with_shell; >   if (startup_with_shell && should_disable_startup_with_shell ()) >     { >       warning (_("startup-with-shell not supported on this macOS > version, disabling it.")); >       restore_startup_with_shell.emplace (&startup_with_shell, 0); >     } > Thanks for the remarks, I'll update my patch accordingly. Regards. > Instead of setting/restoring startup_with_shell, it might be better if > its value was passed as a parameter all the way down instead of having > functions read the global variable, but that's a bigger job. > > Simon