From: Xavier Roirand <roirand@adacore.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org, brobecker@adacore.com,
Tom Tromey <tom@tromey.com>
Subject: Re: [RFA 3/5 v2] Darwin: set startup-with-shell to off on Sierra and later.
Date: Sun, 09 Sep 2018 11:42:00 -0000 [thread overview]
Message-ID: <39b1e71b-a5bc-e2f0-42f7-1551651823e2@adacore.com> (raw)
In-Reply-To: <e282f17ec6ceffd809b936f236966f63@polymtl.ca>
Le 9/9/18 à 1:04 PM, Simon Marchi a écrit :
> Thanks for the update!
>
> CCing Tom, because he had a similar patch that was unfortunately not
> looked at yet... so maybe he has an opinion about this.
>
> On 2018-09-09 11:17, 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 | 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. */
>
> I think this is the other way around (return trun 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;
>> +Â 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);
>
> You shouldn't need this last bit, nor the startup_shell_disabled
> variable. When it gets destroyed, the restore_startup_with_shell object
> takes care of restoring the value of the startup_with_shell variable to
> the value it had when it was constructed (the first emplace call).
>
> In other words, this call:
>
> Â restore_startup_with_shell.emplace (&startup_with_shell, 0);
>
> means "save the current value of startup_with_shell, then put 0 in it".
>
> When the destructor of restore_startup_with_shell is called, it restores
> the saved value.
>
> With that fixed, it would LGTM, although I did not try it because I
> don't have access to a Mac at the moment.
>
> Simon
Thanks, I'll fix this.
prev parent reply other threads:[~2018-09-09 11:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-09 10:18 Xavier Roirand
2018-09-09 11:04 ` Simon Marchi
2018-09-09 11:42 ` Xavier Roirand [this message]
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=39b1e71b-a5bc-e2f0-42f7-1551651823e2@adacore.com \
--to=roirand@adacore.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
--cc=tom@tromey.com \
/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