This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Improve ptrace-error detection on Linux targets
- From: Pedro Alves <palves at redhat dot com>
- To: Sergio Durigan Junior <sergiodj at redhat dot com>, GDB Patches <gdb-patches at sourceware dot org>
- Date: Mon, 19 Aug 2019 19:26:21 +0100
- Subject: Re: [PATCH] Improve ptrace-error detection on Linux targets
- References: <20190819032918.3536-1-sergiodj@redhat.com>
Two comments on implementation, that I think apply
equally to the new version you're working on as well:
#1 - A target method (target_ptrace_me_fail_reason) looks like the
wrong place to put this, to me. As I understand it, the core of
gdb isn't ever calling the target_ptrace_me_fail_reason. This is
all code that is implementation detail of the Linux target
implementation.
I'd prefer some other way to address this. An idea would be to have
a function pointer in inf-ptrace.c that defaults to an implementation
that returns the empty string:
// in inf-ptrace.c
static std::string
default_inf_ptrace_me_fail_reason (int err)
{
return {};
}
std::string (*inf_ptrace_me_fail_reason) (int err) = default_inf_ptrace_me_fail_reason;
// in inf-ptrace.h
extern std::string (*inf_ptrace_me_fail_reason) (int err);
And then in linux-nat.c:_initialize_linux_nat, you'd override the
implementation, like:
std::string
linux_ptrace_me_fail_reason (int err)
{
...
}
void
_initialize_linux_nat ()
{
...
inf_ptrace_me_fail_reason = linux_ptrace_me_fail_reason;
}
Note I'm not suggesting anything with virtual methods before
of the next point.
#2 - What about gdbserver? Don't we want the same nice error
messages in gdbserver?
See gdbserver/linux-low.c:linux_ptrace_fun.
This would suggest putting that linux_ptrace_me_fail_reason
function in gdb/nat/ so that it would be used by gdbserver too.
Thanks,
Pedro Alves