From patchwork Sun Sep 9 13:46:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roirand X-Patchwork-Id: 29274 Received: (qmail 1887 invoked by alias); 9 Sep 2018 13:46:35 -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 1875 invoked by uid 89); 9 Sep 2018 13:46:35 -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=HX-Received:sk:w12-v6m X-HELO: mail-wm0-f66.google.com Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Sep 2018 13:46:33 +0000 Received: by mail-wm0-f66.google.com with SMTP id j25-v6so3269387wmc.1 for ; Sun, 09 Sep 2018 06:46:33 -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=8vX7sRTNrbSiitV12/NGx0m/PNZd63WQhZEpcvja4sE=; b=zisT7Zj7Lc4DS3+V7vgHb7/GsyvF8v5qNd+2Y31w3K9+T+E/KN+xs1fd72arCyl+gC Vli4uIYuDfCfQ90KmgOUIej2/1PcrvWF9dp3IkbaSgGIhbKiNG/sPYIVjzlQ2ySGXxmg YMT2wztlnSrpZYkQkwnqf1zurxv/zPUaksgFv5yDdir2qjqXQ6Db3cc8SC2VXdvQDj6M 7+hKWjyEkh3iEVxqc+Z5nbCyME5y5d1rEI3A9erN7Qenyhba6hbJhPiYu+9ZPE7P7vYa IyE+q4T6lYiFlhbv61jO/50OvUTSAqFT/U/vQjJvb+noaBKRTH+e/FmwONrgN2o9ZPqq K8iA== Return-Path: Received: from adacore.com ([192.150.182.225]) by smtp.gmail.com with ESMTPSA id 132-v6sm12055096wmd.13.2018.09.09.06.46.28 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 09 Sep 2018 06:46:30 -0700 (PDT) Received: by adacore.com (sSMTP sendmail emulation); Sun, 09 Sep 2018 15:46:28 +0200 From: Xavier Roirand To: gdb-patches@sourceware.org Cc: brobecker@adacore.com, simon.marchi@polymtl.ca, tom@tromey.com, Xavier Roirand Subject: [RFA 3/5 v4] Darwin: set startup-with-shell to off on Sierra and later. Date: Sun, 9 Sep 2018 15:46:25 +0200 Message-Id: <1536500785-10409-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 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index be80163d22e..c83c5854da6 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -1854,11 +1854,38 @@ 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 TRUE on Sierra or later. */ + +static bool +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; + + 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); + } + /* Do the hard work. */ fork_inferior (exec_file, allargs, env, darwin_ptrace_me, darwin_ptrace_him, darwin_pre_ptrace, NULL,