From patchwork Sun Sep 9 10:17:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roirand X-Patchwork-Id: 29271 Received: (qmail 70367 invoked by alias); 9 Sep 2018 10:18:02 -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 70357 invoked by uid 89); 9 Sep 2018 10:18:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=ver, Hx-languages-length:1986, sk:startup, HX-Received:sk:61-v6mr X-HELO: mail-wr1-f66.google.com Received: from mail-wr1-f66.google.com (HELO mail-wr1-f66.google.com) (209.85.221.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Sep 2018 10:18:00 +0000 Received: by mail-wr1-f66.google.com with SMTP id s14-v6so9928421wrw.6 for ; Sun, 09 Sep 2018 03:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=d/KCvE4cjCd7CMQKvCPswkCZAJnBn0UBzXuYQqgOuaI=; b=nIaQZnD83kSqC2PN5HrYwQJ165+Kw26ZeWxwHro2JxwdYMh1luWEAdBmy40dqcKDWg 1JsEJXb7AEe08d73PXx8a9NIrSEqy64RqkqzHnt2wbJAvgyoRJO4tS6Cvn964yTN1NtN f0oFiZviXdW2f7ZD8LZm9DfdkwNwj7JZ38DFglx9JSXAsrK4Oc56bsZcFsp009gBCjbG hME8C2oKxigv1O4wpZw0rTgclnXeMl1zt36U6Ld5+NMA8cw92ydXqT4KfyS36Obw6zFY y/BaOQ2Hik+kwLWU3H5980fOsdave5SYYnTIqI2+yPQCm3blr3sA8uY5mTL4QtTFwX+m 38Jg== Return-Path: Received: from adacore.com ([192.150.182.225]) by smtp.gmail.com with ESMTPSA id t9-v6sm32881912wra.91.2018.09.09.03.17.55 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 09 Sep 2018 03:17:57 -0700 (PDT) Received: by adacore.com (sSMTP sendmail emulation); Sun, 09 Sep 2018 12:17:55 +0200 From: Xavier Roirand To: gdb-patches@sourceware.org Cc: brobecker@adacore.com, Xavier Roirand Subject: [RFA 3/5 v2] Darwin: set startup-with-shell to off on Sierra and later. Date: Sun, 9 Sep 2018 12:17:48 +0200 Message-Id: <1536488268-8535-1-git-send-email-roirand@adacore.com> X-IsSubscribed: yes 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. */ + +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); }