PR gdb/16188: Verify PTRACE_TRACEME succeeded
This patch fixes PR gdb/16188, which is about the fact that
fork_inferior doesn't verify the return value of the "traceme_fun"
callback. On most targets, this callback is actually a wrapper to a
ptrace call that does a PTRACE_TRACEME on the forked GDB process that
will eventually become the inferior.
Thanks to Pedro, this second version of the patch is simpler and more
more logical. Basically, two helper functions are added:
trace_start_error and trace_start_error_with_name. The former can be
used when there is a customized error message to be printed to the
user. The latter works like perror_with_name, so you just need to
pass the function that error'd.
Both helper functions mentioned above do basically the same thing:
print the error message to stderr and call _exit, properly terminating
the forked inferior.
Most of the patch takes care of guarding the necessary system calls
against errors on the "traceme_fun" callbacks. It is not right to
call error on these situations, so I've replaced these calls with the
proper helper function call.
Regression-tested on BuildBot.
Thanks,
gdb/ChangeLog:
2017-02-20 Sergio Durigan Junior <sergiodj@redhat.com>
Pedro Alves <palves@redhat.com>
PR gdb/16188
* darwin-nat.c (darwin_ptrace_me): Check if calls to system
calls succeeded.
* fork-child.c (trace_start_error): New function.
(trace_start_error_with_name): Likewise.
* gnu-nat.c (gnu_ptrace_me): Check if call to PTRACE succeeded.
* inf-ptrace.c (inf_ptrace_me): Likewise.
* inferior.h (trace_start_error): New prototype.
(trace_start_error_with_name): Likewise.