From: Pedro Alves <palves@redhat.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [patch] aarch64: PR 19806: watchpoints: false negatives -> false positives
Date: Tue, 07 Jun 2016 16:04:00 -0000 [thread overview]
Message-ID: <7fabd183-eb46-e916-77f2-f62d5c4e4ce7@redhat.com> (raw)
In-Reply-To: <86a8ixvx5k.fsf@gmail.com>
On 06/07/2016 04:25 PM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
>> A gdbarch method poses problems for remote stubs that are actually emulators,
>> and thus can support hardware watchpoints without these restrictions.
>
> Then, the address reported by the target should fall in the range of
> loc->address,+loc->length.
Isn't that what Jan's patch did?
In any case, with the gdbarch method, if the target supports watching all
kinds of unaligned addresses/ranges, and reports the correct address in
"T05 watch" stop replies, it then faces the problem that gdb has hardcoded
knowledge of watch region alignment restrictions, and then e.g., watchpoints
on consecutive addresses are misinterpreted, even though there's
no reason for that.
E.g., say gdb believes the machine only supports watching 32-bit-aligned
words. Then with:
union
{
char buf[4];
uint32_t force_align;
} global;
(gdb) watch global.buf[1];
Hardware watchpoint 1 ...
(gdb) watch global.buf[3];
Hardware watchpoint 2 ...
... if the program writes to global.buf[1], and the target reports
a memory access to 'global.buf + 1', gdb will believe that
watchpoint 2 _also_ triggered, when it did not. That's a false positive you
can't help with with real machines, but there's no reason a
simulator/emulator has to suffer from that.
>
>> I think it's actually problematic for real machines, as the restrictions
>> will often depend on process revisions/models. So a gdbarch approach
>> would be undesirable, IMO.
>
> On the real machine, nowadays, the restriction is that address must be
> 8-byte-aligned on linux.
I think we need to consider all architectures, and the design going
forward, not just Aarch64. For example, PPC has:
static int
ppc_linux_watchpoint_addr_within_range (struct target_ops *target,
CORE_ADDR addr,
CORE_ADDR start, int length)
{
int mask;
if (have_ptrace_hwdebug_interface ()
&& ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
return start <= addr && start + length >= addr;
else if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
mask = 3;
else
mask = 7;
So e.g., here, the alignment restrictions depend on both
the processor model and kernel.
(I'll guess that other embedded architectures that gdb supports probably
have similar restrictions that gdb was never taught about.)
> The restriction can only be relaxed and
> may be removed finally in the future, IOW, the restriction won't become
> 16-byte aligned, so we can write the gdbarch method for aarch64-linux
> like this,
How can gdb determine whether the restriction has been lifted?
The way to do it is probably either by checking kernel version or having the
ptrace code that "inserts" the watchpoint to first try watching the unaligned
region exactly as gdb requested, and if that doesn't work, try a wider,
aligned region. Only that target-side ptrace code is aware of these finer details
and the correct restrictions in effect for the running system. If we put this
in a gdbarch method, how can the gdbarch method maintain compatibility with
older kernels and at the same time reflect that newer kernels no longer
impose the restriction?
It's actually not just simulators/emulators that can have different
watchpoint restrictions from the machine architecture's debug hardware
limitations. This is in good part a debug API issue as well --
a target may well support watchpoints implemented in a totally different
way -- for example, I believe Solaris supports "unlimited" watchpoints and
address ranges by implementing watchpoints not by using debug registers, but
instead by changing memory page protections and trapping faults internally,
all invisibly to userspace.
All this is why I believe that hardcoding this knowledge in gdb, which is
what a gdbarch method does, is not the best approach.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2016-06-07 16:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-06 8:00 Jan Kratochvil
2016-06-07 13:23 ` Yao Qi
2016-06-07 13:41 ` Pedro Alves
2016-06-07 15:25 ` Yao Qi
2016-06-07 16:04 ` Pedro Alves [this message]
2016-06-08 16:42 ` Yao Qi
2016-06-08 17:54 ` Pedro Alves
2016-06-08 18:46 ` Pedro Alves
2016-06-10 8:11 ` Yao Qi
2016-06-19 18:29 ` Jan Kratochvil
2016-06-20 11:47 ` Pedro Alves
2016-06-20 14:12 ` Jan Kratochvil
2016-06-20 14:40 ` Pedro Alves
2017-03-27 21:11 ` obsolete: " Jan Kratochvil
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=7fabd183-eb46-e916-77f2-f62d5c4e4ce7@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=qiyaoltc@gmail.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