[RFA,3/5,v3] Darwin: set startup-with-shell to off on Sierra and later.

Message ID 1536491553-9311-1-git-send-email-roirand@adacore.com
State New, archived
Headers

Commit Message

Xavier Roirand Sept. 9, 2018, 11:12 a.m. UTC
  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(+)
  

Comments

Simon Marchi Sept. 9, 2018, 1:41 p.m. UTC | #1
On 2018-09-09 12:12, 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 | 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 ()

Ah, forgot to mention this previously.  Please use return a bool, and 
use small-case true/false.  The patch is fine to push with that fixed.

Simon
  
Joel Brobecker Sept. 10, 2018, 7:25 a.m. UTC | #2
> gdb/ChangeLog:
> 
>         * darwin-nat.c (should_disable_startup_with_shell):
>         New function.
>         (darwin_nat_target::create_inferior): Add call.

One minor nit:

> +  gdb::optional<scoped_restore_tmpl<int>> 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."));

Can you split this line to fit in 80 characters, please?
  

Patch

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<scoped_restore_tmpl<int>> 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,