Re: [PATCH v2] Improve ptrace-error detection on Linux targets

Sergio Durigan Junior
2019-08-29T19:48:24Z

On Thursday, August 29 2019, I wrote:

> On Thursday, August 29 2019, Pedro Alves wrote:
>
>>> - It reads the contents of "/proc/sys/kernel/yama/ptrace_scope" and
>>> checks if it's different than 0.
>>>
>>> For each of these checks, if it succeeds, the user will see a message
>>> informing about the restriction in place, and how it can be disabled.
>>> For example, if "deny_ptrace" is enabled, the user will see:
>>>
>>> # gdb /bin/true
>>> ...
>>> Starting program: /usr/bin/true
>>> warning: Could not trace the inferior process.
>>> Error:
>>> warning: ptrace: Permission denied
>>
>> Curious, that:
>>
>> warning:
>> Error:
>> warning:
>>
>> looks a bit odd, specifically the "Error:" line. Do you know where is
>> that coming from?
>
> Not offhand; I'll investigate and come back with the results.

So, the problem is with nat/fork-inferior.c:trace_start_error:

void
trace_start_error (const char *fmt, ...)
{
va_list ap;

va_start (ap, fmt);
warning ("Could not trace the inferior process.\nError: ");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
vwarning (fmt, ap);
va_end (ap);

gdb_flush_out_err ();
_exit (0177);
}

/* See nat/fork-inferior.h. */

void
trace_start_error_with_name (const char *string, const char *append)
{
trace_start_error ("%s: %s%s", string, safe_strerror (errno), append);
}

You can see that we're calling "warning", which puts a newline at the
end of the string. I think it'd be best to just get rid of the
"\nError: " suffix. We'd then have something like:

Starting program: /usr/bin/true
warning: Could not trace the inferior process.
warning: ptrace: Permission denied
....

WDYT?

--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible