From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 50395 invoked by alias); 9 Sep 2018 11:04:29 -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 50380 invoked by uid 89); 9 Sep 2018 11:04:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Sep 2018 11:04:27 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w89B4K1Y003395 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 9 Sep 2018 07:04:25 -0400 Received: by simark.ca (Postfix, from userid 112) id 8FF621E76F; Sun, 9 Sep 2018 07:04:20 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id DA5681E4B5; Sun, 9 Sep 2018 07:04:17 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 09 Sep 2018 11:04:00 -0000 From: Simon Marchi To: Xavier Roirand Cc: gdb-patches@sourceware.org, brobecker@adacore.com, Tom Tromey Subject: Re: [RFA 3/5 v2] Darwin: set startup-with-shell to off on Sierra and later. In-Reply-To: <1536488268-8535-1-git-send-email-roirand@adacore.com> References: <1536488268-8535-1-git-send-email-roirand@adacore.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00227.txt.bz2 Thanks for the update! CCing Tom, because he had a similar patch that was unfortunately not looked at yet... so maybe he has an opinion about this. On 2018-09-09 11:17, 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. This disabling is done temporary before forking > inferior and restored after the fork. > > gdb/ChangeLog: > > * darwin-nat.c (should_disable_startup_with_shell): > New function. > (darwin_nat_target::create_inferior): Add call. > > Change-Id: Ie4d9090f65fdf2e83ecf7a0f9d0647fb1c27cdcc > --- > gdb/darwin-nat.c | 32 ++++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c > index be80163d22e..d23706d79fd 100644 > --- a/gdb/darwin-nat.c > +++ b/gdb/darwin-nat.c > @@ -1854,15 +1854,47 @@ darwin_execvp (const char *file, char * const > argv[], char * const env[]) > posix_spawnp (NULL, argv[0], NULL, &attr, argv, env); > } > > +/* Read kernel version, and return false on Sierra or later. */ I think this is the other way around (return trun on Sierra or later). > + > +static int > +should_disable_startup_with_shell () > +{ > + char str[16]; > + size_t sz = sizeof (str); > + int ret; > + > + ret = sysctlbyname ("kern.osrelease", str, &sz, NULL, 0); > + if (ret == 0 && sz < sizeof (str)) > + { > + unsigned long ver = strtoul (str, NULL, 10); > + if (ver >= 16) > + return TRUE; > + } > + return FALSE; > +} > + > void > darwin_nat_target::create_inferior (const char *exec_file, > const std::string &allargs, > char **env, int from_tty) > { > + gdb::optional> restore_startup_with_shell; > + int startup_shell_disabled = 0; > + > + 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); > + startup_shell_disabled = 1; > + } > + > /* Do the hard work. */ > fork_inferior (exec_file, allargs, env, darwin_ptrace_me, > darwin_ptrace_him, darwin_pre_ptrace, NULL, > darwin_execvp); > + > + if (startup_shell_disabled) > + restore_startup_with_shell.emplace (&startup_with_shell, 1); You shouldn't need this last bit, nor the startup_shell_disabled variable. When it gets destroyed, the restore_startup_with_shell object takes care of restoring the value of the startup_with_shell variable to the value it had when it was constructed (the first emplace call). In other words, this call: restore_startup_with_shell.emplace (&startup_with_shell, 0); means "save the current value of startup_with_shell, then put 0 in it". When the destructor of restore_startup_with_shell is called, it restores the saved value. With that fixed, it would LGTM, although I did not try it because I don't have access to a Mac at the moment. Simon