aboutsummaryrefslogtreecommitdiff
path: root/gdb/aarch64-nat.c
AgeCommit message (Collapse)AuthorFilesLines
2024-05-02Fix regression on aarch64-linux gdbserverTom Tromey1-115/+0
Commit 9a03f218 ("Fix gdb.base/watchpoint-unaligned.exp on aarch64") fixed a watchpoint bug in gdb -- but did not touch the corresponding code in gdbserver. This patch moves the gdb code into gdb/nat, so that it can be shared with gdbserver, and then changes gdbserver to use it, fixing the bug. This is yet another case where having a single back end would prevent bugs. I tested this using the AdaCore internal gdb testsuite. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29423 Approved-By: Luis Machado <luis.machado@arm.com>
2024-03-26gdb, gdbserver, gdbsupport: remove includes of early headersSimon Marchi1-1/+0
Now that defs.h, server.h and common-defs.h are included via the `-include` option, it is no longer necessary for source files to include them. Remove all the inclusions of these files I could find. Update the generation scripts where relevant. Change-Id: Ia026cff269c1b7ae7386dd3619bc9bb6a5332837 Approved-By: Pedro Alves <pedro@palves.net>
2024-03-14[gdb/tdep] Fix gdb.base/watchpoint-unaligned.exp on aarch64Tom de Vries1-3/+14
On aarch64-linux, with test-case gdb.base/watchpoint-unaligned.exp I run into: ... (gdb) watch data.u.size8twice[1]^M Hardware watchpoint 241: data.u.size8twice[1]^M (gdb) PASS: gdb.base/watchpoint-unaligned.exp: watch data.u.size8twice[1] continue^M Continuing.^M FAIL: gdb.base/watchpoint-unaligned.exp: continue (timeout) FAIL: gdb.base/watchpoint-unaligned.exp: size8twice write ... This happens as follows. We start the exec and set an 8-byte hardware watchpoint on data.u.size8twice[1] at address 0x440048: ... (gdb) p sizeof (data.u.size8twice[1]) $1 = 8 (gdb) p &data.u.size8twice[1] $2 = (uint64_t *) 0x440048 <data+16> ... We continue execution, and a 16-byte write at address 0x440040 triggers the hardware watchpoint: ... 4101c8: a9000801 stp x1, x2, [x0] ... When checking whether a watchpoint has triggered in aarch64_stopped_data_address, we check against address 0x440040 (passed in parameter addr_trap). This behaviour is documented: ... /* ADDR_TRAP reports the first address of the memory range accessed by the CPU, regardless of what was the memory range watched. ... */ ... and consequently the matching logic compares against an addr_watch_aligned: ... && addr_trap >= addr_watch_aligned && addr_trap < addr_watch + len) ... However, the comparison fails: ... (gdb) p /x addr_watch_aligned $3 = 0x440048 (gdb) p addr_trap >= addr_watch_aligned $4 = false ... Consequently, aarch64_stopped_data_address returns false, and stopped_by_watchpoint returns false, and watchpoints_triggered returns 0, which make infrun think it's looking at a delayed hardware breakpoint/watchpoint trap: ... [infrun] handle_signal_stop: stop_pc=0x4101c8 [infrun] handle_signal_stop: delayed hardware breakpoint/watchpoint trap, ignoring ... Infrun then ignores the trap and continues, but runs into the same situation again and again, causing a hang which then causes the test timeout. Fix this by allowing a match 8 bytes below addr_watch_aligned. This introduces the possibility for false positives, so we only do this for regular "value changed" watchpoints. An earlier version of this patch worked by aligning addr_watch_aligned to 16 instead of 8: ... - const CORE_ADDR addr_watch_aligned = align_down (state->dr_addr_wp[i], 8); + const CORE_ADDR addr_watch_aligned = align_down (state->dr_addr_wp[i], 16); ... but while that fixed the test-case, it didn't fix the problem completely, so extend the test-case to check more scenarios. Tested on aarch64-linux. Tested-By: Luis Machado <luis.machado@arm.com> Approved-By: Luis Machado <luis.machado@arm.com> PR tdep/29423 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29423
2024-03-12[gdb/tdep] Fix gdb.base/watch-bitfields.exp on aarch64Tom de Vries1-38/+94
On aarch64-linux, with test-case gdb.base/watch-bitfields.exp I run into: ... (gdb) continue^M Continuing.^M ^M Hardware watchpoint 2: -location q.a^M ^M Old value = 1^M New value = 0^M main () at watch-bitfields.c:42^M 42 q.h--;^M (gdb) FAIL: $exp: -location watch against bitfields: q.e: 0->5: continue ... In a minimal form, if we step past line 37 which sets q.e, and we have a watchpoint set on q.e, it triggers: ... $ gdb -q -batch watch-bitfields -ex "b 37" -ex run -ex "watch q.e" -ex step Breakpoint 1 at 0x410204: file watch-bitfields.c, line 37. Breakpoint 1, main () at watch-bitfields.c:37 37 q.e = 5; Hardware watchpoint 2: q.e Hardware watchpoint 2: q.e Old value = 0 New value = 5 main () at /home/vries/gdb/src/gdb/testsuite/gdb.base/watch-bitfields.c:38 38 q.f = 6; ... However, if we set in addition a watchpoint on q.a, the watchpoint on q.e doesn't trigger. How does this happen? Bitfield q.a is just bit 0 of byte 0, and bitfield q.e is bit 4..7 of byte 1 and bit 1 of byte 2. So, watch q.a should watch byte 0, and watch q.e should watch bytes 1 and 2. Using "maint set show-debug-regs on" (and some more detailed debug prints) we get: ... WP2: addr=0x440028 (orig=0x440029), ctrl=0x000000d5, ref.count=1 ctrl: enabled=1, offset=1, len=2 WP3: addr=0x440028 (orig=0x440028), ctrl=0x00000035, ref.count=1 ctrl: enabled=1, offset=0, len=1 ... which matches that. When executing line 37, a hardware watchpoint trap triggers and we hit aarch64_stopped_data_address with addr_trap == 0x440028: ... (gdb) p /x addr_trap $1 = 0x440028 .... and since the loop in aarch64_stopped_data_address walks backward, we check WP3 first, which matches, and consequently target_stopped_by_watchpoint returns true in watchpoints_triggered. Likewise for target_stopped_data_address, which also returns addr == 0x440028. Watchpoints_triggered matches watchpoint q.a to that address, and sets watch_triggered_yes. However, subsequently the value of q.a is checked, and it's the same value as before (becase the insn in line 37 didn't change q.a), so the watchpoint hardware trap is not reported to the user. The problem originates from that fact that aarch64_stopped_data_address picked WP3 instead of WP2. There's something we can do about this. In the example above, both target_stopped_by_watchpoint and target_stopped_data_address returned true. Instead we can return true in target_stopped_by_watchpoint but false in target_stopped_data_address. This lets watchpoints_triggered known that a watchpoint was triggered, but we don't know where, and both watchpoints get set to watch_triggered_unknown. Subsequently, the values of both q.a and q.e are checked, and since q.e is not the same value as before, the watchpoint hardware trap is reported to the user. Note that this works well for regular (write) watchpoints (watch command), but not for read watchpoints (rwatch command), because for those no value is checked. Likewise for access watchpoints (awatch command). So, fix this by: - passing a nullptr in aarch64_fbsd_nat_target::stopped_by_watchpoint and aarch64_linux_nat_target::stopped_by_watchpoint to make clear we're not interested in the stop address, - introducing a two-phase approach in aarch64_stopped_data_address, where: - phase one handles access and read watchpoints, as before, and - phase two handles write watchpoints, where multiple matches cause: - return true if addr_p == null, and - return false if addr_p != null. Tested on aarch64-linux. Approved-By: Luis Machado <luis.machado@arm.com> PR tdep/31214 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31214
2024-01-12Update copyright year range in header of all files managed by GDBAndrew Burgess1-1/+1
This commit is the result of the following actions: - Running gdb/copyright.py to update all of the copyright headers to include 2024, - Manually updating a few files the copyright.py script told me to update, these files had copyright headers embedded within the file, - Regenerating gdbsupport/Makefile.in to refresh it's copyright date, - Using grep to find other files that still mentioned 2023. If these files were updated last year from 2022 to 2023 then I've updated them this year to 2024. I'm sure I've probably missed some dates. Feel free to fix them up as you spot them.
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker1-1/+1
This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
2022-03-30Use gdb_printf and gdb_vprintf in more placesTom Tromey1-13/+12
Luis pointed out that I missed a spot in the gdb_printf conversion -- namely aarch64-nat.c. While looking at this, I found another spot in darwin-nat.c that I also missed. I can't build either of these, but I think this patch should fix the problems.
2022-03-22aarch64: Add an aarch64_nat_target mixin class.John Baldwin1-0/+302
This class includes platform-independent target methods for hardware breakpoints and watchpoints using routines from nat/aarch64-hw-point.c. stopped_data_address is not platform-independent since the FAR register holding the address for a breakpoint hit must be fetched in a platform-specific manner. However, aarch64_stopped_data_address is provided as a helper routine which performs platform-independent validation given the value of the FAR register. For tracking the per-process debug register mirror state, use an unordered_map indexed by pid as recently adopted in x86-nat.c rather than a manual linked-list.