1 /* Native-dependent code for GNU/Linux AArch64.
3 Copyright (C) 2011-2015 Free Software Foundation, Inc.
4 Contributed by ARM Ltd.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "linux-nat.h"
27 #include "target-descriptions.h"
30 #include "aarch64-tdep.h"
31 #include "aarch64-linux-tdep.h"
32 #include "aarch32-linux-nat.h"
33 #include "nat/aarch64-linux-hw-point.h"
35 #include "elf/external.h"
36 #include "elf/common.h"
38 #include "nat/gdb_ptrace.h"
39 #include <sys/utsname.h>
40 #include <asm/ptrace.h>
44 /* Defines ps_err_e, struct ps_prochandle. */
45 #include "gdb_proc_service.h"
48 #define TRAP_HWBKPT 0x0004
51 /* Per-process data. We don't bind this to a per-inferior registry
52 because of targets like x86 GNU/Linux that need to keep track of
53 processes that aren't bound to any inferior (e.g., fork children,
56 struct aarch64_process_info
59 struct aarch64_process_info
*next
;
61 /* The process identifier. */
64 /* Copy of aarch64 hardware debug registers. */
65 struct aarch64_debug_reg_state state
;
68 static struct aarch64_process_info
*aarch64_process_list
= NULL
;
70 /* Find process data for process PID. */
72 static struct aarch64_process_info
*
73 aarch64_find_process_pid (pid_t pid
)
75 struct aarch64_process_info
*proc
;
77 for (proc
= aarch64_process_list
; proc
; proc
= proc
->next
)
84 /* Add process data for process PID. Returns newly allocated info
87 static struct aarch64_process_info
*
88 aarch64_add_process (pid_t pid
)
90 struct aarch64_process_info
*proc
;
92 proc
= xcalloc (1, sizeof (*proc
));
95 proc
->next
= aarch64_process_list
;
96 aarch64_process_list
= proc
;
101 /* Get data specific info for process PID, creating it if necessary.
102 Never returns NULL. */
104 static struct aarch64_process_info
*
105 aarch64_process_info_get (pid_t pid
)
107 struct aarch64_process_info
*proc
;
109 proc
= aarch64_find_process_pid (pid
);
111 proc
= aarch64_add_process (pid
);
116 /* Called whenever GDB is no longer debugging process PID. It deletes
117 data structures that keep track of debug register state. */
120 aarch64_forget_process (pid_t pid
)
122 struct aarch64_process_info
*proc
, **proc_link
;
124 proc
= aarch64_process_list
;
125 proc_link
= &aarch64_process_list
;
129 if (proc
->pid
== pid
)
131 *proc_link
= proc
->next
;
137 proc_link
= &proc
->next
;
142 /* Get debug registers state for process PID. */
144 static struct aarch64_debug_reg_state
*
145 aarch64_get_debug_reg_state (pid_t pid
)
147 return &aarch64_process_info_get (pid
)->state
;
150 /* Fill GDB's register array with the general-purpose register values
151 from the current thread. */
154 fetch_gregs_from_thread (struct regcache
*regcache
)
157 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
161 /* Make sure REGS can hold all registers contents on both aarch64
163 gdb_static_assert (sizeof (regs
) >= 18 * 4);
165 tid
= ptid_get_lwp (inferior_ptid
);
167 iovec
.iov_base
= ®s
;
168 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
169 iovec
.iov_len
= 18 * 4;
171 iovec
.iov_len
= sizeof (regs
);
173 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_PRSTATUS
, &iovec
);
175 perror_with_name (_("Unable to fetch general registers."));
177 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
178 aarch32_gp_regcache_supply (regcache
, (uint32_t *) regs
, 1);
183 for (regno
= AARCH64_X0_REGNUM
; regno
<= AARCH64_CPSR_REGNUM
; regno
++)
184 regcache_raw_supply (regcache
, regno
, ®s
[regno
- AARCH64_X0_REGNUM
]);
188 /* Store to the current thread the valid general-purpose register
189 values in the GDB's register array. */
192 store_gregs_to_thread (const struct regcache
*regcache
)
197 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
199 /* Make sure REGS can hold all registers contents on both aarch64
201 gdb_static_assert (sizeof (regs
) >= 18 * 4);
202 tid
= ptid_get_lwp (inferior_ptid
);
204 iovec
.iov_base
= ®s
;
205 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
206 iovec
.iov_len
= 18 * 4;
208 iovec
.iov_len
= sizeof (regs
);
210 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_PRSTATUS
, &iovec
);
212 perror_with_name (_("Unable to fetch general registers."));
214 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
215 aarch32_gp_regcache_collect (regcache
, (uint32_t *) regs
, 1);
220 for (regno
= AARCH64_X0_REGNUM
; regno
<= AARCH64_CPSR_REGNUM
; regno
++)
221 if (REG_VALID
== regcache_register_status (regcache
, regno
))
222 regcache_raw_collect (regcache
, regno
,
223 ®s
[regno
- AARCH64_X0_REGNUM
]);
226 ret
= ptrace (PTRACE_SETREGSET
, tid
, NT_PRSTATUS
, &iovec
);
228 perror_with_name (_("Unable to store general registers."));
231 /* Fill GDB's register array with the fp/simd register values
232 from the current thread. */
235 fetch_fpregs_from_thread (struct regcache
*regcache
)
240 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
242 /* Make sure REGS can hold all VFP registers contents on both aarch64
244 gdb_static_assert (sizeof regs
>= VFP_REGS_SIZE
);
246 tid
= ptid_get_lwp (inferior_ptid
);
248 iovec
.iov_base
= ®s
;
250 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
252 iovec
.iov_len
= VFP_REGS_SIZE
;
254 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_ARM_VFP
, &iovec
);
256 perror_with_name (_("Unable to fetch VFP registers."));
258 aarch32_vfp_regcache_supply (regcache
, (gdb_byte
*) ®s
, 32);
264 iovec
.iov_len
= sizeof (regs
);
266 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_FPREGSET
, &iovec
);
268 perror_with_name (_("Unable to fetch vFP/SIMD registers."));
270 for (regno
= AARCH64_V0_REGNUM
; regno
<= AARCH64_V31_REGNUM
; regno
++)
271 regcache_raw_supply (regcache
, regno
,
272 ®s
.vregs
[regno
- AARCH64_V0_REGNUM
]);
274 regcache_raw_supply (regcache
, AARCH64_FPSR_REGNUM
, ®s
.fpsr
);
275 regcache_raw_supply (regcache
, AARCH64_FPCR_REGNUM
, ®s
.fpcr
);
279 /* Store to the current thread the valid fp/simd register
280 values in the GDB's register array. */
283 store_fpregs_to_thread (const struct regcache
*regcache
)
288 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
290 /* Make sure REGS can hold all VFP registers contents on both aarch64
292 gdb_static_assert (sizeof regs
>= VFP_REGS_SIZE
);
293 tid
= ptid_get_lwp (inferior_ptid
);
295 iovec
.iov_base
= ®s
;
297 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
299 iovec
.iov_len
= VFP_REGS_SIZE
;
301 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_ARM_VFP
, &iovec
);
303 perror_with_name (_("Unable to fetch VFP registers."));
305 aarch32_vfp_regcache_collect (regcache
, (gdb_byte
*) ®s
, 32);
311 iovec
.iov_len
= sizeof (regs
);
313 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_FPREGSET
, &iovec
);
315 perror_with_name (_("Unable to fetch FP/SIMD registers."));
317 for (regno
= AARCH64_V0_REGNUM
; regno
<= AARCH64_V31_REGNUM
; regno
++)
318 if (REG_VALID
== regcache_register_status (regcache
, regno
))
319 regcache_raw_collect (regcache
, regno
,
320 (char *) ®s
.vregs
[regno
- AARCH64_V0_REGNUM
]);
322 if (REG_VALID
== regcache_register_status (regcache
, AARCH64_FPSR_REGNUM
))
323 regcache_raw_collect (regcache
, AARCH64_FPSR_REGNUM
,
324 (char *) ®s
.fpsr
);
325 if (REG_VALID
== regcache_register_status (regcache
, AARCH64_FPCR_REGNUM
))
326 regcache_raw_collect (regcache
, AARCH64_FPCR_REGNUM
,
327 (char *) ®s
.fpcr
);
330 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
332 ret
= ptrace (PTRACE_SETREGSET
, tid
, NT_ARM_VFP
, &iovec
);
334 perror_with_name (_("Unable to store VFP registers."));
338 ret
= ptrace (PTRACE_SETREGSET
, tid
, NT_FPREGSET
, &iovec
);
340 perror_with_name (_("Unable to store FP/SIMD registers."));
344 /* Implement the "to_fetch_register" target_ops method. */
347 aarch64_linux_fetch_inferior_registers (struct target_ops
*ops
,
348 struct regcache
*regcache
,
353 fetch_gregs_from_thread (regcache
);
354 fetch_fpregs_from_thread (regcache
);
356 else if (regno
< AARCH64_V0_REGNUM
)
357 fetch_gregs_from_thread (regcache
);
359 fetch_fpregs_from_thread (regcache
);
362 /* Implement the "to_store_register" target_ops method. */
365 aarch64_linux_store_inferior_registers (struct target_ops
*ops
,
366 struct regcache
*regcache
,
371 store_gregs_to_thread (regcache
);
372 store_fpregs_to_thread (regcache
);
374 else if (regno
< AARCH64_V0_REGNUM
)
375 store_gregs_to_thread (regcache
);
377 store_fpregs_to_thread (regcache
);
380 /* Fill register REGNO (if it is a general-purpose register) in
381 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
382 do this for all registers. */
385 fill_gregset (const struct regcache
*regcache
,
386 gdb_gregset_t
*gregsetp
, int regno
)
388 regcache_collect_regset (&aarch64_linux_gregset
, regcache
,
389 regno
, (gdb_byte
*) gregsetp
,
390 AARCH64_LINUX_SIZEOF_GREGSET
);
393 /* Fill GDB's register array with the general-purpose register values
397 supply_gregset (struct regcache
*regcache
, const gdb_gregset_t
*gregsetp
)
399 regcache_supply_regset (&aarch64_linux_gregset
, regcache
, -1,
400 (const gdb_byte
*) gregsetp
,
401 AARCH64_LINUX_SIZEOF_GREGSET
);
404 /* Fill register REGNO (if it is a floating-point register) in
405 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
406 do this for all registers. */
409 fill_fpregset (const struct regcache
*regcache
,
410 gdb_fpregset_t
*fpregsetp
, int regno
)
412 regcache_collect_regset (&aarch64_linux_fpregset
, regcache
,
413 regno
, (gdb_byte
*) fpregsetp
,
414 AARCH64_LINUX_SIZEOF_FPREGSET
);
417 /* Fill GDB's register array with the floating-point register values
421 supply_fpregset (struct regcache
*regcache
, const gdb_fpregset_t
*fpregsetp
)
423 regcache_supply_regset (&aarch64_linux_fpregset
, regcache
, -1,
424 (const gdb_byte
*) fpregsetp
,
425 AARCH64_LINUX_SIZEOF_FPREGSET
);
428 /* Called when resuming a thread.
429 The hardware debug registers are updated when there is any change. */
432 aarch64_linux_prepare_to_resume (struct lwp_info
*lwp
)
434 struct arch_lwp_info
*info
= lwp
->arch_private
;
436 /* NULL means this is the main thread still going through the shell,
437 or, no watchpoint has been set yet. In that case, there's
442 if (DR_HAS_CHANGED (info
->dr_changed_bp
)
443 || DR_HAS_CHANGED (info
->dr_changed_wp
))
445 int tid
= ptid_get_lwp (lwp
->ptid
);
446 struct aarch64_debug_reg_state
*state
447 = aarch64_get_debug_reg_state (ptid_get_pid (lwp
->ptid
));
450 fprintf_unfiltered (gdb_stdlog
, "prepare_to_resume thread %d\n", tid
);
453 if (DR_HAS_CHANGED (info
->dr_changed_wp
))
455 aarch64_linux_set_debug_regs (state
, tid
, 1);
456 DR_CLEAR_CHANGED (info
->dr_changed_wp
);
460 if (DR_HAS_CHANGED (info
->dr_changed_bp
))
462 aarch64_linux_set_debug_regs (state
, tid
, 0);
463 DR_CLEAR_CHANGED (info
->dr_changed_bp
);
469 aarch64_linux_new_thread (struct lwp_info
*lp
)
471 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
473 /* Mark that all the hardware breakpoint/watchpoint register pairs
474 for this thread need to be initialized. */
475 DR_MARK_ALL_CHANGED (info
->dr_changed_bp
, aarch64_num_bp_regs
);
476 DR_MARK_ALL_CHANGED (info
->dr_changed_wp
, aarch64_num_wp_regs
);
478 lp
->arch_private
= info
;
481 /* linux_nat_new_fork hook. */
484 aarch64_linux_new_fork (struct lwp_info
*parent
, pid_t child_pid
)
487 struct aarch64_debug_reg_state
*parent_state
;
488 struct aarch64_debug_reg_state
*child_state
;
490 /* NULL means no watchpoint has ever been set in the parent. In
491 that case, there's nothing to do. */
492 if (parent
->arch_private
== NULL
)
495 /* GDB core assumes the child inherits the watchpoints/hw
496 breakpoints of the parent, and will remove them all from the
497 forked off process. Copy the debug registers mirrors into the
498 new process so that all breakpoints and watchpoints can be
501 parent_pid
= ptid_get_pid (parent
->ptid
);
502 parent_state
= aarch64_get_debug_reg_state (parent_pid
);
503 child_state
= aarch64_get_debug_reg_state (child_pid
);
504 *child_state
= *parent_state
;
508 /* Called by libthread_db. Returns a pointer to the thread local
509 storage (or its descriptor). */
512 ps_get_thread_area (const struct ps_prochandle
*ph
,
513 lwpid_t lwpid
, int idx
, void **base
)
518 iovec
.iov_base
= ®
;
519 iovec
.iov_len
= sizeof (reg
);
521 if (ptrace (PTRACE_GETREGSET
, lwpid
, NT_ARM_TLS
, &iovec
) != 0)
524 /* IDX is the bias from the thread pointer to the beginning of the
525 thread descriptor. It has to be subtracted due to implementation
526 quirks in libthread_db. */
527 *base
= (void *) (reg
- idx
);
533 static void (*super_post_startup_inferior
) (struct target_ops
*self
,
536 /* Implement the "to_post_startup_inferior" target_ops method. */
539 aarch64_linux_child_post_startup_inferior (struct target_ops
*self
,
542 aarch64_forget_process (ptid_get_pid (ptid
));
543 aarch64_linux_get_debug_reg_capacity (ptid_get_pid (ptid
));
544 super_post_startup_inferior (self
, ptid
);
547 extern struct target_desc
*tdesc_arm_with_vfpv3
;
548 extern struct target_desc
*tdesc_arm_with_neon
;
550 /* Implement the "to_read_description" target_ops method. */
552 static const struct target_desc
*
553 aarch64_linux_read_description (struct target_ops
*ops
)
557 if (target_auxv_search (ops
, AT_PHENT
, &at_phent
) == 1)
559 if (at_phent
== sizeof (Elf64_External_Phdr
))
560 return tdesc_aarch64
;
563 CORE_ADDR arm_hwcap
= 0;
565 if (target_auxv_search (ops
, AT_HWCAP
, &arm_hwcap
) != 1)
566 return ops
->beneath
->to_read_description (ops
->beneath
);
568 #ifndef COMPAT_HWCAP_VFP
569 #define COMPAT_HWCAP_VFP (1 << 6)
571 #ifndef COMPAT_HWCAP_NEON
572 #define COMPAT_HWCAP_NEON (1 << 12)
574 #ifndef COMPAT_HWCAP_VFPv3
575 #define COMPAT_HWCAP_VFPv3 (1 << 13)
578 if (arm_hwcap
& COMPAT_HWCAP_VFP
)
581 const struct target_desc
*result
= NULL
;
583 if (arm_hwcap
& COMPAT_HWCAP_NEON
)
584 result
= tdesc_arm_with_neon
;
585 else if (arm_hwcap
& COMPAT_HWCAP_VFPv3
)
586 result
= tdesc_arm_with_vfpv3
;
595 return tdesc_aarch64
;
598 /* Returns the number of hardware watchpoints of type TYPE that we can
599 set. Value is positive if we can set CNT watchpoints, zero if
600 setting watchpoints of type TYPE is not supported, and negative if
601 CNT is more than the maximum number of watchpoints of type TYPE
602 that we can support. TYPE is one of bp_hardware_watchpoint,
603 bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
604 CNT is the number of such watchpoints used so far (including this
605 one). OTHERTYPE is non-zero if other types of watchpoints are
606 currently enabled. */
609 aarch64_linux_can_use_hw_breakpoint (struct target_ops
*self
,
611 int cnt
, int othertype
)
613 if (type
== bp_hardware_watchpoint
|| type
== bp_read_watchpoint
614 || type
== bp_access_watchpoint
|| type
== bp_watchpoint
)
616 if (aarch64_num_wp_regs
== 0)
619 else if (type
== bp_hardware_breakpoint
)
621 if (aarch64_num_bp_regs
== 0)
625 gdb_assert_not_reached ("unexpected breakpoint type");
627 /* We always return 1 here because we don't have enough information
628 about possible overlap of addresses that they want to watch. As an
629 extreme example, consider the case where all the watchpoints watch
630 the same address and the same region length: then we can handle a
631 virtually unlimited number of watchpoints, due to debug register
632 sharing implemented via reference counts. */
636 /* Insert a hardware-assisted breakpoint at BP_TGT->reqstd_address.
637 Return 0 on success, -1 on failure. */
640 aarch64_linux_insert_hw_breakpoint (struct target_ops
*self
,
641 struct gdbarch
*gdbarch
,
642 struct bp_target_info
*bp_tgt
)
645 CORE_ADDR addr
= bp_tgt
->placed_address
= bp_tgt
->reqstd_address
;
647 const enum target_hw_bp_type type
= hw_execute
;
648 struct aarch64_debug_reg_state
*state
649 = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid
));
654 "insert_hw_breakpoint on entry (addr=0x%08lx, len=%d))\n",
655 (unsigned long) addr
, len
);
657 ret
= aarch64_handle_breakpoint (type
, addr
, len
, 1 /* is_insert */, state
);
661 aarch64_show_debug_reg_state (state
,
662 "insert_hw_breakpoint", addr
, len
, type
);
668 /* Remove a hardware-assisted breakpoint at BP_TGT->placed_address.
669 Return 0 on success, -1 on failure. */
672 aarch64_linux_remove_hw_breakpoint (struct target_ops
*self
,
673 struct gdbarch
*gdbarch
,
674 struct bp_target_info
*bp_tgt
)
677 CORE_ADDR addr
= bp_tgt
->placed_address
;
679 const enum target_hw_bp_type type
= hw_execute
;
680 struct aarch64_debug_reg_state
*state
681 = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid
));
685 (gdb_stdlog
, "remove_hw_breakpoint on entry (addr=0x%08lx, len=%d))\n",
686 (unsigned long) addr
, len
);
688 ret
= aarch64_handle_breakpoint (type
, addr
, len
, 0 /* is_insert */, state
);
692 aarch64_show_debug_reg_state (state
,
693 "remove_hw_watchpoint", addr
, len
, type
);
699 /* Implement the "to_insert_watchpoint" target_ops method.
701 Insert a watchpoint to watch a memory region which starts at
702 address ADDR and whose length is LEN bytes. Watch memory accesses
703 of the type TYPE. Return 0 on success, -1 on failure. */
706 aarch64_linux_insert_watchpoint (struct target_ops
*self
,
707 CORE_ADDR addr
, int len
,
708 enum target_hw_bp_type type
,
709 struct expression
*cond
)
712 struct aarch64_debug_reg_state
*state
713 = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid
));
716 fprintf_unfiltered (gdb_stdlog
,
717 "insert_watchpoint on entry (addr=0x%08lx, len=%d)\n",
718 (unsigned long) addr
, len
);
720 gdb_assert (type
!= hw_execute
);
722 ret
= aarch64_handle_watchpoint (type
, addr
, len
, 1 /* is_insert */, state
);
726 aarch64_show_debug_reg_state (state
,
727 "insert_watchpoint", addr
, len
, type
);
733 /* Implement the "to_remove_watchpoint" target_ops method.
734 Remove a watchpoint that watched the memory region which starts at
735 address ADDR, whose length is LEN bytes, and for accesses of the
736 type TYPE. Return 0 on success, -1 on failure. */
739 aarch64_linux_remove_watchpoint (struct target_ops
*self
,
740 CORE_ADDR addr
, int len
,
741 enum target_hw_bp_type type
,
742 struct expression
*cond
)
745 struct aarch64_debug_reg_state
*state
746 = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid
));
749 fprintf_unfiltered (gdb_stdlog
,
750 "remove_watchpoint on entry (addr=0x%08lx, len=%d)\n",
751 (unsigned long) addr
, len
);
753 gdb_assert (type
!= hw_execute
);
755 ret
= aarch64_handle_watchpoint (type
, addr
, len
, 0 /* is_insert */, state
);
759 aarch64_show_debug_reg_state (state
,
760 "remove_watchpoint", addr
, len
, type
);
766 /* Implement the "to_region_ok_for_hw_watchpoint" target_ops method. */
769 aarch64_linux_region_ok_for_hw_watchpoint (struct target_ops
*self
,
770 CORE_ADDR addr
, int len
)
772 CORE_ADDR aligned_addr
;
774 /* Can not set watchpoints for zero or negative lengths. */
778 /* Must have hardware watchpoint debug register(s). */
779 if (aarch64_num_wp_regs
== 0)
782 /* We support unaligned watchpoint address and arbitrary length,
783 as long as the size of the whole watched area after alignment
784 doesn't exceed size of the total area that all watchpoint debug
785 registers can watch cooperatively.
787 This is a very relaxed rule, but unfortunately there are
788 limitations, e.g. false-positive hits, due to limited support of
789 hardware debug registers in the kernel. See comment above
790 aarch64_align_watchpoint for more information. */
792 aligned_addr
= addr
& ~(AARCH64_HWP_MAX_LEN_PER_REG
- 1);
793 if (aligned_addr
+ aarch64_num_wp_regs
* AARCH64_HWP_MAX_LEN_PER_REG
797 /* All tests passed so we are likely to be able to set the watchpoint.
798 The reason that it is 'likely' rather than 'must' is because
799 we don't check the current usage of the watchpoint registers, and
800 there may not be enough registers available for this watchpoint.
801 Ideally we should check the cached debug register state, however
802 the checking is costly. */
806 /* Implement the "to_stopped_data_address" target_ops method. */
809 aarch64_linux_stopped_data_address (struct target_ops
*target
,
814 struct aarch64_debug_reg_state
*state
;
816 if (!linux_nat_get_siginfo (inferior_ptid
, &siginfo
))
819 /* This must be a hardware breakpoint. */
820 if (siginfo
.si_signo
!= SIGTRAP
821 || (siginfo
.si_code
& 0xffff) != TRAP_HWBKPT
)
824 /* Check if the address matches any watched address. */
825 state
= aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid
));
826 for (i
= aarch64_num_wp_regs
- 1; i
>= 0; --i
)
828 const unsigned int len
= aarch64_watchpoint_length (state
->dr_ctrl_wp
[i
]);
829 const CORE_ADDR addr_trap
= (CORE_ADDR
) siginfo
.si_addr
;
830 const CORE_ADDR addr_watch
= state
->dr_addr_wp
[i
];
832 if (state
->dr_ref_count_wp
[i
]
833 && DR_CONTROL_ENABLED (state
->dr_ctrl_wp
[i
])
834 && addr_trap
>= addr_watch
835 && addr_trap
< addr_watch
+ len
)
845 /* Implement the "to_stopped_by_watchpoint" target_ops method. */
848 aarch64_linux_stopped_by_watchpoint (struct target_ops
*ops
)
852 return aarch64_linux_stopped_data_address (ops
, &addr
);
855 /* Implement the "to_watchpoint_addr_within_range" target_ops method. */
858 aarch64_linux_watchpoint_addr_within_range (struct target_ops
*target
,
860 CORE_ADDR start
, int length
)
862 return start
<= addr
&& start
+ length
- 1 >= addr
;
865 /* Define AArch64 maintenance commands. */
868 add_show_debug_regs_command (void)
870 /* A maintenance command to enable printing the internal DRi mirror
872 add_setshow_boolean_cmd ("show-debug-regs", class_maintenance
,
873 &show_debug_regs
, _("\
874 Set whether to show variables that mirror the AArch64 debug registers."), _("\
875 Show whether to show variables that mirror the AArch64 debug registers."), _("\
876 Use \"on\" to enable, \"off\" to disable.\n\
877 If enabled, the debug registers values are shown when GDB inserts\n\
878 or removes a hardware breakpoint or watchpoint, and when the inferior\n\
879 triggers a breakpoint or watchpoint."),
882 &maintenance_set_cmdlist
,
883 &maintenance_show_cmdlist
);
886 /* -Wmissing-prototypes. */
887 void _initialize_aarch64_linux_nat (void);
890 _initialize_aarch64_linux_nat (void)
892 struct target_ops
*t
;
894 /* Fill in the generic GNU/Linux methods. */
897 add_show_debug_regs_command ();
899 /* Add our register access methods. */
900 t
->to_fetch_registers
= aarch64_linux_fetch_inferior_registers
;
901 t
->to_store_registers
= aarch64_linux_store_inferior_registers
;
903 t
->to_read_description
= aarch64_linux_read_description
;
905 t
->to_can_use_hw_breakpoint
= aarch64_linux_can_use_hw_breakpoint
;
906 t
->to_insert_hw_breakpoint
= aarch64_linux_insert_hw_breakpoint
;
907 t
->to_remove_hw_breakpoint
= aarch64_linux_remove_hw_breakpoint
;
908 t
->to_region_ok_for_hw_watchpoint
=
909 aarch64_linux_region_ok_for_hw_watchpoint
;
910 t
->to_insert_watchpoint
= aarch64_linux_insert_watchpoint
;
911 t
->to_remove_watchpoint
= aarch64_linux_remove_watchpoint
;
912 t
->to_stopped_by_watchpoint
= aarch64_linux_stopped_by_watchpoint
;
913 t
->to_stopped_data_address
= aarch64_linux_stopped_data_address
;
914 t
->to_watchpoint_addr_within_range
=
915 aarch64_linux_watchpoint_addr_within_range
;
917 /* Override the GNU/Linux inferior startup hook. */
918 super_post_startup_inferior
= t
->to_post_startup_inferior
;
919 t
->to_post_startup_inferior
= aarch64_linux_child_post_startup_inferior
;
921 /* Register the target. */
922 linux_nat_add_target (t
);
923 linux_nat_set_new_thread (t
, aarch64_linux_new_thread
);
924 linux_nat_set_new_fork (t
, aarch64_linux_new_fork
);
925 linux_nat_set_forget_process (t
, aarch64_forget_process
);
926 linux_nat_set_prepare_to_resume (t
, aarch64_linux_prepare_to_resume
);