diff options
author | Luis Machado <luis.machado@linaro.org> | 2020-12-10 16:51:20 -0300 |
---|---|---|
committer | Luis Machado <luis.machado@linaro.org> | 2020-12-16 10:05:56 -0300 |
commit | 19007d955670a183fdf79408301d403b43eb7db1 (patch) | |
tree | 4792181fe8ae0bf0fb897646fe30ed98937e100e /gdbserver | |
parent | c410035d37d8237c641155c4e51e7ccf53decb29 (diff) | |
download | gdb-19007d955670a183fdf79408301d403b43eb7db1.zip gdb-19007d955670a183fdf79408301d403b43eb7db1.tar.gz gdb-19007d955670a183fdf79408301d403b43eb7db1.tar.bz2 |
Fix TBI handling for watchpoints
When inserting hw watchpoints, we take care of masking off the top byte
of the address (and sign-extending it if needed). This guarantees we won't
pass tagged addresses to the kernel via ptrace.
However, from the kernel documentation on tagged pointers...
"Non-zero tags are not preserved when delivering signals. This means that
signal handlers in applications making use of tags cannot rely on the tag
information for user virtual addresses being maintained for fields inside
siginfo_t.
One exception to this rule is for signals raised in response to watchpoint
debug exceptions, where the tag information will be preserved."
So the stopped data address after a hw watchpoint hit can be potentially
tagged, and we don't handle this in GDB at the moment. This results in
GDB missing a hw watchpoint hit and attempting to step over an unsteppable
hw watchpoint, causing it to spin endlessly.
The following patch fixes this by adjusting the stopped data address and adds
some tests to expose the problem.
gdb/ChangeLog:
2020-12-16 Luis Machado <luis.machado@linaro.org>
* aarch64-linux-nat.c
(aarch64_linux_nat_target::stopped_data_address): Handle the TBI.
gdbserver/ChangeLog:
2020-12-16 Luis Machado <luis.machado@linaro.org>
* linux-aarch64-low.cc (address_significant): New function.
(aarch64_target::low_stopped_data_address): Handle the TBI.
gdb/testsuite/ChangeLog:
2020-12-16 Luis Machado <luis.machado@linaro.org>
* gdb.arch/aarch64-tagged-pointer.c (main): Add a few more
pointer-based memory accesses.
* gdb.arch/aarch64-tagged-pointer.exp: Exercise additional
hw watchpoint cases.
Diffstat (limited to 'gdbserver')
-rw-r--r-- | gdbserver/ChangeLog | 5 | ||||
-rw-r--r-- | gdbserver/linux-aarch64-low.cc | 24 |
2 files changed, 28 insertions, 1 deletions
diff --git a/gdbserver/ChangeLog b/gdbserver/ChangeLog index 9756d4c..16a9609 100644 --- a/gdbserver/ChangeLog +++ b/gdbserver/ChangeLog @@ -1,3 +1,8 @@ +2020-12-16 Luis Machado <luis.machado@linaro.org> + + * linux-aarch64-low.cc (address_significant): New function. + (aarch64_target::low_stopped_data_address): Handle the TBI. + 2020-12-11 Andrew Burgess <andrew.burgess@embecosm.com> * Makefile.in (IPA_LIB): Include libiberty library. diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index 08208ae..f39d7c2 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -458,6 +458,23 @@ aarch64_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr, return ret; } +/* Return the address only having significant bits. This is used to ignore + the top byte (TBI). */ + +static CORE_ADDR +address_significant (CORE_ADDR addr) +{ + /* Clear insignificant bits of a target address and sign extend resulting + address. */ + int addr_bit = 56; + + CORE_ADDR sign = (CORE_ADDR) 1 << (addr_bit - 1); + addr &= ((CORE_ADDR) 1 << addr_bit) - 1; + addr = (addr ^ sign) - sign; + + return addr; +} + /* Implementation of linux target ops method "low_stopped_data_address". */ CORE_ADDR @@ -478,6 +495,12 @@ aarch64_target::low_stopped_data_address () || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */) return (CORE_ADDR) 0; + /* Make sure to ignore the top byte, otherwise we may not recognize a + hardware watchpoint hit. The stopped data addresses coming from the + kernel can potentially be tagged addresses. */ + const CORE_ADDR addr_trap + = address_significant ((CORE_ADDR) siginfo.si_addr); + /* Check if the address matches any watched address. */ state = aarch64_get_debug_reg_state (pid_of (current_thread)); for (i = aarch64_num_wp_regs - 1; i >= 0; --i) @@ -485,7 +508,6 @@ aarch64_target::low_stopped_data_address () const unsigned int offset = aarch64_watchpoint_offset (state->dr_ctrl_wp[i]); const unsigned int len = aarch64_watchpoint_length (state->dr_ctrl_wp[i]); - const CORE_ADDR addr_trap = (CORE_ADDR) siginfo.si_addr; const CORE_ADDR addr_watch = state->dr_addr_wp[i] + offset; const CORE_ADDR addr_watch_aligned = align_down (state->dr_addr_wp[i], 8); const CORE_ADDR addr_orig = state->dr_addr_orig_wp[i]; |