aarch64: PR 19806: watchpoints: false negatives + PR 20207 contiguous ones
authorJan Kratochvil <jan.kratochvil@redhat.com>
Fri, 4 May 2018 20:22:04 +0000 (22:22 +0200)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Fri, 4 May 2018 20:26:46 +0000 (22:26 +0200)
commita3b60e4588606354b93508a0008a5ca04b68fad8
tree87962568d24528162603c7fd5f3be6a63f25f174
parent45fe4a03b495f778013f0a0deb06512913e1955b
aarch64: PR 19806: watchpoints: false negatives + PR 20207 contiguous ones

Some unaligned watchpoints were currently missed.

On old kernels as specified in
kernel RFE: aarch64: ptrace: BAS: Support any contiguous range (edit)
https://sourceware.org/bugzilla/show_bug.cgi?id=20207
after this patch some other unaligned watchpoints will get reported as false
positives.

With new kernels all the watchpoints should work exactly.

There may be a regresion that it now less merges watchpoints so that with
multiple overlapping watchpoints it may run out of the 4 hardware watchpoint
registers.  But as discussed in the original thread GDB needs some generic
watchpoints merging framework to be used by all the target specific code.
Even current FSF GDB code does not merge it perfectly.  Also with the more
precise watchpoints one can technically merge them less.  And I do not think
it matters too much to improve mergeability only for old kernels.
Still even on new kernels some better merging logic would make sense.

There remains one issue:
kernel-4.15.14-300.fc27.armv7hl
FAIL: gdb.base/watchpoint-unaligned.exp: continue
FAIL: gdb.base/watchpoint-unaligned.exp: continue
(gdb) continue
Continuing.
Unexpected error setting watchpoint: Invalid argument.
(gdb) FAIL: gdb.base/watchpoint-unaligned.exp: continue
But that looks as a kernel bug to me.
(1) It is not a regression by this patch.
(2) It is unrelated to this patch.

gdb/ChangeLog
2018-05-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
    Pedro Alves <palves@redhat.com>

PR breakpoints/19806 and support for PR external/20207.
* NEWS: Mention Aarch64 watchpoint improvements.
* aarch64-linux-nat.c (aarch64_linux_stopped_data_address): Fix missed
watchpoints and PR external/20207 watchpoints.
* nat/aarch64-linux-hw-point.c
(kernel_supports_any_contiguous_range): New.
(aarch64_watchpoint_offset): New.
(aarch64_watchpoint_length): Support PR external/20207 watchpoints.
(aarch64_point_encode_ctrl_reg): New parameter offset, new asserts.
(aarch64_point_is_aligned): Support PR external/20207 watchpoints.
(aarch64_align_watchpoint): New parameters aligned_offset_p and
next_addr_orig_p.  Support PR external/20207 watchpoints.
(aarch64_downgrade_regs): New.
(aarch64_dr_state_insert_one_point): New parameters offset and
addr_orig.
(aarch64_dr_state_remove_one_point): Likewise.
(aarch64_handle_breakpoint): Update caller.
(aarch64_handle_aligned_watchpoint): Likewise.
(aarch64_handle_unaligned_watchpoint): Support addr_orig and
aligned_offset.
(aarch64_linux_set_debug_regs): Remove const from state.  Call
aarch64_downgrade_regs.
(aarch64_show_debug_reg_state): Print also dr_addr_orig_wp.
* nat/aarch64-linux-hw-point.h (DR_CONTROL_LENGTH): Rename to ...
(DR_CONTROL_MASK): ... this.
(struct aarch64_debug_reg_state): New field dr_addr_orig_wp.
(unsigned int aarch64_watchpoint_offset): New prototype.
(aarch64_linux_set_debug_regs): Remove const from state.
* utils.c (align_up, align_down): Move to ...
* common/common-utils.c (align_up, align_down): ... here.
* utils.h (align_up, align_down): Move to ...
* common/common-utils.h (align_up, align_down): ... here.

gdb/gdbserver/ChangeLog
2018-05-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
    Pedro Alves <palves@redhat.com>

* linux-aarch64-low.c (aarch64_stopped_data_address):
Likewise.

gdb/testsuite/ChangeLog
2018-05-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
    Pedro Alves <palves@redhat.com>

PR breakpoints/19806 and support for PR external/20207.
* gdb.base/watchpoint-unaligned.c: New file.
* gdb.base/watchpoint-unaligned.exp: New file.
14 files changed:
gdb/ChangeLog
gdb/NEWS
gdb/aarch64-linux-nat.c
gdb/common/common-utils.c
gdb/common/common-utils.h
gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-aarch64-low.c
gdb/nat/aarch64-linux-hw-point.c
gdb/nat/aarch64-linux-hw-point.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/watchpoint-unaligned.c [new file with mode: 0644]
gdb/testsuite/gdb.base/watchpoint-unaligned.exp [new file with mode: 0644]
gdb/utils.c
gdb/utils.h