Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>,
	Xavier Roirand <roirand@adacore.com>
Cc: gdb-patches@sourceware.org, brobecker@adacore.com
Subject: Re: [RFA 3/5] Darwin: set startup-with-shell to off on Sierra and later.
Date: Wed, 22 Aug 2018 14:37:00 -0000	[thread overview]
Message-ID: <271518a7-d06a-219b-b4a0-6958e8f1dc51@redhat.com> (raw)
In-Reply-To: <9a64f5298b404c3be126333b4287e390@polymtl.ca>

On 08/22/2018 03:20 PM, Simon Marchi wrote:
> On 2018-08-22 06:11, 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.
> 
> Ah, that's a really good idea to do it automatically, instead of asking the user to do it.

See also:

  https://sourceware.org/ml/gdb-patches/2018-06/msg00734.html

BTW, on IRC, Tromey and I discussed how to make startup-with-shell
work, which led to:

  https://sourceware.org/bugzilla/show_bug.cgi?id=23364

which points at what seems like the simplest solution (copy the shell
to /tmp).  

An alternative would be to use a similar approach to
lldb's -- run a helper tool (lldb-argdumper) via the shell whose only
purpose is to return back its shell-expanded argv[0..N].  That would work
because gdb wouldn't debug that program, just run it normally, so it
wouldn't run into the SIP restrictions.  Instead of a separate helper tool, I would
imagine we could also build the helper functionality inside gdb itself -- we'd
make gdb behave in that "expand args" mode via an environment
variable, for example.

> 
>> gdb/ChangeLog:
>>     * darwin-nat.c (disable_startup_with_shell): New function.
>>     (_initialize_darwin_inferior): Add call.
>>
>> Change-Id: Ia3cbeaa89b2b44a173b93ee22cce0d3884a16924
>> ---
>>  gdb/darwin-nat.c | 22 ++++++++++++++++++++++
>>  1 file changed, 22 insertions(+)
>>
>> diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
>> index be80163..96f70cf 100644
>> --- a/gdb/darwin-nat.c
>> +++ b/gdb/darwin-nat.c
>> @@ -2362,6 +2362,26 @@ darwin_nat_target::supports_multi_process ()
>>    return true;
>>  }
>>
>> +/* Read kernel version, and set startup-with-shell to false on Sierra or
>> +   later.  */
>> +
>> +void
>> +disable_startup_with_shell ()
> 
> This function should be static.
> 
>> +{
>> +  char str[16];
>> +    size_t sz = sizeof (str);
>> +    int ret;
>> +    unsigned long ver;
>> +
>> +    ret = sysctlbyname ("kern.osrelease", str, &sz, NULL, 0);
>> +    if (ret == 0 && sz < sizeof (str))
>> +      {
>> +       ver = strtoul (str, NULL, 10);
>> +       if (ver >= 16)
>> +         startup_with_shell = 0;
>> +      }
>> +}
> 
> The indentation is not quite right.  You can also declare variables when they are used/initialized.
> 
>> +
>>  void
>>  _initialize_darwin_nat ()
>>  {
>> @@ -2396,4 +2416,6 @@ When this mode is on, all low level exceptions
>> are reported before being\n\
>>  reported by the kernel."),
>>                 &set_enable_mach_exceptions, NULL,
>>                 &setlist, &showlist);
>> +
>> +  disable_startup_with_shell ();
>>  }
> 
> I don't think we should do that in _initialize_darwin_nat.  Since startup-with-shell is supported with remote debugging, you could still use it when starting a Linux remote program from a macOS host.
> 
> Instead, we should probably only disable it at the moment we create a new inferior in the darwin_nat target, so in darwin_nat_target::create_inferior.  We also don't want to permanently change the setting, so we should restore the value.  Presumably, putting something like this in darwin_nat_target::create_inferior should work (I haven't tested it, and sorry for the potential formatting mess my email client will do):
> 
>   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);
>     }
> 
> Instead of setting/restoring startup_with_shell, it might be better if its value was passed as a parameter all the way down instead of having functions read the global variable, but that's a bigger job.
Thanks,
Pedro Alves


  reply	other threads:[~2018-08-22 14:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-22 10:11 [RFA 0/5] Fix some bugs on macOS Xavier Roirand
2018-08-22 10:11 ` [RFA 3/5] Darwin: set startup-with-shell to off on Sierra and later Xavier Roirand
2018-08-22 14:20   ` Simon Marchi
2018-08-22 14:37     ` Pedro Alves [this message]
2018-09-03 13:23     ` Xavier Roirand
2018-09-17 19:31   ` Tom Tromey
2018-08-22 10:11 ` [RFA 1/5] Darwin: fix bad loop incrementation Xavier Roirand
2018-08-22 13:14   ` Simon Marchi
2018-08-23 15:21     ` Simon Marchi
2018-08-22 10:11 ` [RFA 4/5] Darwin: fix thread ptid started by fork_inferior Xavier Roirand
2018-08-22 14:30   ` Simon Marchi
2018-08-22 16:10   ` Pedro Alves
2018-08-22 18:14     ` Simon Marchi
2018-08-22 10:11 ` [RFA 5/5] Darwin: fix SIGTRAP when debugging Xavier Roirand
2018-08-22 14:34   ` Simon Marchi
2018-08-22 10:11 ` [RFA 2/5] Darwin: Handle unrelocated dyld Xavier Roirand
2018-08-22 13:55   ` Simon Marchi
2018-09-18 21:22     ` Tom Tromey
2018-09-19 13:41       ` Joel Brobecker
2018-09-19 14:16         ` Simon Marchi
2018-09-19 14:28           ` Joel Brobecker
2018-09-19 14:36         ` Tom Tromey
2018-09-19 14:44           ` Simon Marchi
2018-09-19 15:32             ` Joel Brobecker
2018-09-19 19:15             ` Tom Tromey
2018-09-19 19:50               ` Simon Marchi
2018-09-28 13:31               ` Xavier Roirand
2018-09-28 17:22                 ` Tom Tromey
2018-08-22 13:59   ` Simon Marchi
2018-09-18 21:23     ` Tom Tromey
2018-09-17 20:57 ` [RFA 0/5] Fix some bugs on macOS Tom Tromey
2018-09-17 21:25   ` Joel Brobecker
2018-09-17 23:03     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=271518a7-d06a-219b-b4a0-6958e8f1dc51@redhat.com \
    --to=palves@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=roirand@adacore.com \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox