From patchwork Sun Sep 9 11:12:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roirand X-Patchwork-Id: 29272 Received: (qmail 103071 invoked by alias); 9 Sep 2018 11:43:15 -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 103059 invoked by uid 89); 9 Sep 2018 11:43:15 -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=H*Ad:D*ca, HX-Received:sk:p10-v6m X-HELO: mail-wr1-f49.google.com Received: from mail-wr1-f49.google.com (HELO mail-wr1-f49.google.com) (209.85.221.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Sep 2018 11:43:13 +0000 Received: by mail-wr1-f49.google.com with SMTP id g33-v6so19038205wrd.1 for ; Sun, 09 Sep 2018 04:43:13 -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=qc3EcIsjauDWiuMbPIoBk6iZyiC/AxzBvJPyZTqfhwE=; b=nPVjMe3FxH8oVxFXm/8MSGI3rGdWfhsaopjewpdNj7zazRLPQ32uisDLEH8+wUOaFH vzSes8bBDiezNZEsXOQrjj2xZjzUVe+XD0F8l2Gd1roNLvygySZtJvyAAH5+zX5hwdet e206FlA1pIFD9+CQEQNNjMQrfKyE7tepOK25MuBdndIC36Pc5vv+gA1CTIY7+5h9AILo VQrE9g9S+2hSzeSlE2mYvdu5iwBSA4xdx6rBhqt657JhdNLE67yEXDVaq6dymay6sImw nqL0RueJ7ROWLbeWnGwWwKgLc0r5a+a3YtyHTOoMw0H8krCp7FckDAMqiIy50LxtTtEe 3jQg== Return-Path: Received: from adacore.com ([192.150.182.225]) by smtp.gmail.com with ESMTPSA id z101-v6sm20377002wrb.55.2018.09.09.04.43.09 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 09 Sep 2018 04:43:10 -0700 (PDT) Received: by adacore.com (sSMTP sendmail emulation); Sun, 09 Sep 2018 13:12:52 +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 v3] Darwin: set startup-with-shell to off on Sierra and later. Date: Sun, 9 Sep 2018 13:12:33 +0200 Message-Id: <1536491553-9311-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..c4fc942b02e 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 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; + + 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,