(Ada) problem printing renaming which references a subprogram parameter
[binutils-gdb.git] / gdb / aarch64-linux-nat.c
blob9385659f14072c8040c4c9befc5d6df8b378058c
1 /* Native-dependent code for GNU/Linux AArch64.
3 Copyright (C) 2011-2018 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/>. */
21 #include "defs.h"
23 #include "inferior.h"
24 #include "gdbcore.h"
25 #include "regcache.h"
26 #include "linux-nat.h"
27 #include "target-descriptions.h"
28 #include "auxv.h"
29 #include "gdbcmd.h"
30 #include "aarch64-tdep.h"
31 #include "aarch64-linux-tdep.h"
32 #include "aarch32-linux-nat.h"
33 #include "nat/aarch64-linux.h"
34 #include "nat/aarch64-linux-hw-point.h"
36 #include "elf/external.h"
37 #include "elf/common.h"
39 #include "nat/gdb_ptrace.h"
40 #include <sys/utsname.h>
41 #include <asm/ptrace.h>
43 #include "gregset.h"
45 /* Defines ps_err_e, struct ps_prochandle. */
46 #include "gdb_proc_service.h"
48 #ifndef TRAP_HWBKPT
49 #define TRAP_HWBKPT 0x0004
50 #endif
52 /* Per-process data. We don't bind this to a per-inferior registry
53 because of targets like x86 GNU/Linux that need to keep track of
54 processes that aren't bound to any inferior (e.g., fork children,
55 checkpoints). */
57 struct aarch64_process_info
59 /* Linked list. */
60 struct aarch64_process_info *next;
62 /* The process identifier. */
63 pid_t pid;
65 /* Copy of aarch64 hardware debug registers. */
66 struct aarch64_debug_reg_state state;
69 static struct aarch64_process_info *aarch64_process_list = NULL;
71 /* Find process data for process PID. */
73 static struct aarch64_process_info *
74 aarch64_find_process_pid (pid_t pid)
76 struct aarch64_process_info *proc;
78 for (proc = aarch64_process_list; proc; proc = proc->next)
79 if (proc->pid == pid)
80 return proc;
82 return NULL;
85 /* Add process data for process PID. Returns newly allocated info
86 object. */
88 static struct aarch64_process_info *
89 aarch64_add_process (pid_t pid)
91 struct aarch64_process_info *proc;
93 proc = XCNEW (struct aarch64_process_info);
94 proc->pid = pid;
96 proc->next = aarch64_process_list;
97 aarch64_process_list = proc;
99 return proc;
102 /* Get data specific info for process PID, creating it if necessary.
103 Never returns NULL. */
105 static struct aarch64_process_info *
106 aarch64_process_info_get (pid_t pid)
108 struct aarch64_process_info *proc;
110 proc = aarch64_find_process_pid (pid);
111 if (proc == NULL)
112 proc = aarch64_add_process (pid);
114 return proc;
117 /* Called whenever GDB is no longer debugging process PID. It deletes
118 data structures that keep track of debug register state. */
120 static void
121 aarch64_forget_process (pid_t pid)
123 struct aarch64_process_info *proc, **proc_link;
125 proc = aarch64_process_list;
126 proc_link = &aarch64_process_list;
128 while (proc != NULL)
130 if (proc->pid == pid)
132 *proc_link = proc->next;
134 xfree (proc);
135 return;
138 proc_link = &proc->next;
139 proc = *proc_link;
143 /* Get debug registers state for process PID. */
145 struct aarch64_debug_reg_state *
146 aarch64_get_debug_reg_state (pid_t pid)
148 return &aarch64_process_info_get (pid)->state;
151 /* Fill GDB's register array with the general-purpose register values
152 from the current thread. */
154 static void
155 fetch_gregs_from_thread (struct regcache *regcache)
157 int ret, tid;
158 struct gdbarch *gdbarch = regcache->arch ();
159 elf_gregset_t regs;
160 struct iovec iovec;
162 /* Make sure REGS can hold all registers contents on both aarch64
163 and arm. */
164 gdb_static_assert (sizeof (regs) >= 18 * 4);
166 tid = ptid_get_lwp (regcache_get_ptid (regcache));
168 iovec.iov_base = &regs;
169 if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
170 iovec.iov_len = 18 * 4;
171 else
172 iovec.iov_len = sizeof (regs);
174 ret = ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iovec);
175 if (ret < 0)
176 perror_with_name (_("Unable to fetch general registers."));
178 if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
179 aarch32_gp_regcache_supply (regcache, (uint32_t *) regs, 1);
180 else
182 int regno;
184 for (regno = AARCH64_X0_REGNUM; regno <= AARCH64_CPSR_REGNUM; regno++)
185 regcache_raw_supply (regcache, regno, &regs[regno - AARCH64_X0_REGNUM]);
189 /* Store to the current thread the valid general-purpose register
190 values in the GDB's register array. */
192 static void
193 store_gregs_to_thread (const struct regcache *regcache)
195 int ret, tid;
196 elf_gregset_t regs;
197 struct iovec iovec;
198 struct gdbarch *gdbarch = regcache->arch ();
200 /* Make sure REGS can hold all registers contents on both aarch64
201 and arm. */
202 gdb_static_assert (sizeof (regs) >= 18 * 4);
203 tid = ptid_get_lwp (regcache_get_ptid (regcache));
205 iovec.iov_base = &regs;
206 if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
207 iovec.iov_len = 18 * 4;
208 else
209 iovec.iov_len = sizeof (regs);
211 ret = ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iovec);
212 if (ret < 0)
213 perror_with_name (_("Unable to fetch general registers."));
215 if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
216 aarch32_gp_regcache_collect (regcache, (uint32_t *) regs, 1);
217 else
219 int regno;
221 for (regno = AARCH64_X0_REGNUM; regno <= AARCH64_CPSR_REGNUM; regno++)
222 if (REG_VALID == regcache_register_status (regcache, regno))
223 regcache_raw_collect (regcache, regno,
224 &regs[regno - AARCH64_X0_REGNUM]);
227 ret = ptrace (PTRACE_SETREGSET, tid, NT_PRSTATUS, &iovec);
228 if (ret < 0)
229 perror_with_name (_("Unable to store general registers."));
232 /* Fill GDB's register array with the fp/simd register values
233 from the current thread. */
235 static void
236 fetch_fpregs_from_thread (struct regcache *regcache)
238 int ret, tid;
239 elf_fpregset_t regs;
240 struct iovec iovec;
241 struct gdbarch *gdbarch = regcache->arch ();
243 /* Make sure REGS can hold all VFP registers contents on both aarch64
244 and arm. */
245 gdb_static_assert (sizeof regs >= VFP_REGS_SIZE);
247 tid = ptid_get_lwp (regcache_get_ptid (regcache));
249 iovec.iov_base = &regs;
251 if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
253 iovec.iov_len = VFP_REGS_SIZE;
255 ret = ptrace (PTRACE_GETREGSET, tid, NT_ARM_VFP, &iovec);
256 if (ret < 0)
257 perror_with_name (_("Unable to fetch VFP registers."));
259 aarch32_vfp_regcache_supply (regcache, (gdb_byte *) &regs, 32);
261 else
263 int regno;
265 iovec.iov_len = sizeof (regs);
267 ret = ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, &iovec);
268 if (ret < 0)
269 perror_with_name (_("Unable to fetch vFP/SIMD registers."));
271 for (regno = AARCH64_V0_REGNUM; regno <= AARCH64_V31_REGNUM; regno++)
272 regcache_raw_supply (regcache, regno,
273 &regs.vregs[regno - AARCH64_V0_REGNUM]);
275 regcache_raw_supply (regcache, AARCH64_FPSR_REGNUM, &regs.fpsr);
276 regcache_raw_supply (regcache, AARCH64_FPCR_REGNUM, &regs.fpcr);
280 /* Store to the current thread the valid fp/simd register
281 values in the GDB's register array. */
283 static void
284 store_fpregs_to_thread (const struct regcache *regcache)
286 int ret, tid;
287 elf_fpregset_t regs;
288 struct iovec iovec;
289 struct gdbarch *gdbarch = regcache->arch ();
291 /* Make sure REGS can hold all VFP registers contents on both aarch64
292 and arm. */
293 gdb_static_assert (sizeof regs >= VFP_REGS_SIZE);
294 tid = ptid_get_lwp (regcache_get_ptid (regcache));
296 iovec.iov_base = &regs;
298 if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
300 iovec.iov_len = VFP_REGS_SIZE;
302 ret = ptrace (PTRACE_GETREGSET, tid, NT_ARM_VFP, &iovec);
303 if (ret < 0)
304 perror_with_name (_("Unable to fetch VFP registers."));
306 aarch32_vfp_regcache_collect (regcache, (gdb_byte *) &regs, 32);
308 else
310 int regno;
312 iovec.iov_len = sizeof (regs);
314 ret = ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, &iovec);
315 if (ret < 0)
316 perror_with_name (_("Unable to fetch FP/SIMD registers."));
318 for (regno = AARCH64_V0_REGNUM; regno <= AARCH64_V31_REGNUM; regno++)
319 if (REG_VALID == regcache_register_status (regcache, regno))
320 regcache_raw_collect (regcache, regno,
321 (char *) &regs.vregs[regno - AARCH64_V0_REGNUM]);
323 if (REG_VALID == regcache_register_status (regcache, AARCH64_FPSR_REGNUM))
324 regcache_raw_collect (regcache, AARCH64_FPSR_REGNUM,
325 (char *) &regs.fpsr);
326 if (REG_VALID == regcache_register_status (regcache, AARCH64_FPCR_REGNUM))
327 regcache_raw_collect (regcache, AARCH64_FPCR_REGNUM,
328 (char *) &regs.fpcr);
331 if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
333 ret = ptrace (PTRACE_SETREGSET, tid, NT_ARM_VFP, &iovec);
334 if (ret < 0)
335 perror_with_name (_("Unable to store VFP registers."));
337 else
339 ret = ptrace (PTRACE_SETREGSET, tid, NT_FPREGSET, &iovec);
340 if (ret < 0)
341 perror_with_name (_("Unable to store FP/SIMD registers."));
345 /* Implement the "to_fetch_register" target_ops method. */
347 static void
348 aarch64_linux_fetch_inferior_registers (struct target_ops *ops,
349 struct regcache *regcache,
350 int regno)
352 if (regno == -1)
354 fetch_gregs_from_thread (regcache);
355 fetch_fpregs_from_thread (regcache);
357 else if (regno < AARCH64_V0_REGNUM)
358 fetch_gregs_from_thread (regcache);
359 else
360 fetch_fpregs_from_thread (regcache);
363 /* Implement the "to_store_register" target_ops method. */
365 static void
366 aarch64_linux_store_inferior_registers (struct target_ops *ops,
367 struct regcache *regcache,
368 int regno)
370 if (regno == -1)
372 store_gregs_to_thread (regcache);
373 store_fpregs_to_thread (regcache);
375 else if (regno < AARCH64_V0_REGNUM)
376 store_gregs_to_thread (regcache);
377 else
378 store_fpregs_to_thread (regcache);
381 /* Fill register REGNO (if it is a general-purpose register) in
382 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
383 do this for all registers. */
385 void
386 fill_gregset (const struct regcache *regcache,
387 gdb_gregset_t *gregsetp, int regno)
389 regcache_collect_regset (&aarch64_linux_gregset, regcache,
390 regno, (gdb_byte *) gregsetp,
391 AARCH64_LINUX_SIZEOF_GREGSET);
394 /* Fill GDB's register array with the general-purpose register values
395 in *GREGSETP. */
397 void
398 supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
400 regcache_supply_regset (&aarch64_linux_gregset, regcache, -1,
401 (const gdb_byte *) gregsetp,
402 AARCH64_LINUX_SIZEOF_GREGSET);
405 /* Fill register REGNO (if it is a floating-point register) in
406 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
407 do this for all registers. */
409 void
410 fill_fpregset (const struct regcache *regcache,
411 gdb_fpregset_t *fpregsetp, int regno)
413 regcache_collect_regset (&aarch64_linux_fpregset, regcache,
414 regno, (gdb_byte *) fpregsetp,
415 AARCH64_LINUX_SIZEOF_FPREGSET);
418 /* Fill GDB's register array with the floating-point register values
419 in *FPREGSETP. */
421 void
422 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
424 regcache_supply_regset (&aarch64_linux_fpregset, regcache, -1,
425 (const gdb_byte *) fpregsetp,
426 AARCH64_LINUX_SIZEOF_FPREGSET);
429 /* linux_nat_new_fork hook. */
431 static void
432 aarch64_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
434 pid_t parent_pid;
435 struct aarch64_debug_reg_state *parent_state;
436 struct aarch64_debug_reg_state *child_state;
438 /* NULL means no watchpoint has ever been set in the parent. In
439 that case, there's nothing to do. */
440 if (parent->arch_private == NULL)
441 return;
443 /* GDB core assumes the child inherits the watchpoints/hw
444 breakpoints of the parent, and will remove them all from the
445 forked off process. Copy the debug registers mirrors into the
446 new process so that all breakpoints and watchpoints can be
447 removed together. */
449 parent_pid = ptid_get_pid (parent->ptid);
450 parent_state = aarch64_get_debug_reg_state (parent_pid);
451 child_state = aarch64_get_debug_reg_state (child_pid);
452 *child_state = *parent_state;
456 /* Called by libthread_db. Returns a pointer to the thread local
457 storage (or its descriptor). */
459 ps_err_e
460 ps_get_thread_area (struct ps_prochandle *ph,
461 lwpid_t lwpid, int idx, void **base)
463 int is_64bit_p
464 = (gdbarch_bfd_arch_info (target_gdbarch ())->bits_per_word == 64);
466 return aarch64_ps_get_thread_area (ph, lwpid, idx, base, is_64bit_p);
470 static void (*super_post_startup_inferior) (struct target_ops *self,
471 ptid_t ptid);
473 /* Implement the "to_post_startup_inferior" target_ops method. */
475 static void
476 aarch64_linux_child_post_startup_inferior (struct target_ops *self,
477 ptid_t ptid)
479 aarch64_forget_process (ptid_get_pid (ptid));
480 aarch64_linux_get_debug_reg_capacity (ptid_get_pid (ptid));
481 super_post_startup_inferior (self, ptid);
484 extern struct target_desc *tdesc_arm_with_neon;
486 /* Implement the "to_read_description" target_ops method. */
488 static const struct target_desc *
489 aarch64_linux_read_description (struct target_ops *ops)
491 int ret, tid;
492 gdb_byte regbuf[VFP_REGS_SIZE];
493 struct iovec iovec;
495 tid = ptid_get_lwp (inferior_ptid);
497 iovec.iov_base = regbuf;
498 iovec.iov_len = VFP_REGS_SIZE;
500 ret = ptrace (PTRACE_GETREGSET, tid, NT_ARM_VFP, &iovec);
501 if (ret == 0)
502 return tdesc_arm_with_neon;
503 else
504 return aarch64_read_description ();
507 /* Convert a native/host siginfo object, into/from the siginfo in the
508 layout of the inferiors' architecture. Returns true if any
509 conversion was done; false otherwise. If DIRECTION is 1, then copy
510 from INF to NATIVE. If DIRECTION is 0, copy from NATIVE to
511 INF. */
513 static int
514 aarch64_linux_siginfo_fixup (siginfo_t *native, gdb_byte *inf, int direction)
516 struct gdbarch *gdbarch = get_frame_arch (get_current_frame ());
518 /* Is the inferior 32-bit? If so, then do fixup the siginfo
519 object. */
520 if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
522 if (direction == 0)
523 aarch64_compat_siginfo_from_siginfo ((struct compat_siginfo *) inf,
524 native);
525 else
526 aarch64_siginfo_from_compat_siginfo (native,
527 (struct compat_siginfo *) inf);
529 return 1;
532 return 0;
535 /* Returns the number of hardware watchpoints of type TYPE that we can
536 set. Value is positive if we can set CNT watchpoints, zero if
537 setting watchpoints of type TYPE is not supported, and negative if
538 CNT is more than the maximum number of watchpoints of type TYPE
539 that we can support. TYPE is one of bp_hardware_watchpoint,
540 bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
541 CNT is the number of such watchpoints used so far (including this
542 one). OTHERTYPE is non-zero if other types of watchpoints are
543 currently enabled. */
545 static int
546 aarch64_linux_can_use_hw_breakpoint (struct target_ops *self,
547 enum bptype type,
548 int cnt, int othertype)
550 if (type == bp_hardware_watchpoint || type == bp_read_watchpoint
551 || type == bp_access_watchpoint || type == bp_watchpoint)
553 if (aarch64_num_wp_regs == 0)
554 return 0;
556 else if (type == bp_hardware_breakpoint)
558 if (aarch64_num_bp_regs == 0)
559 return 0;
561 else
562 gdb_assert_not_reached ("unexpected breakpoint type");
564 /* We always return 1 here because we don't have enough information
565 about possible overlap of addresses that they want to watch. As an
566 extreme example, consider the case where all the watchpoints watch
567 the same address and the same region length: then we can handle a
568 virtually unlimited number of watchpoints, due to debug register
569 sharing implemented via reference counts. */
570 return 1;
573 /* Insert a hardware-assisted breakpoint at BP_TGT->reqstd_address.
574 Return 0 on success, -1 on failure. */
576 static int
577 aarch64_linux_insert_hw_breakpoint (struct target_ops *self,
578 struct gdbarch *gdbarch,
579 struct bp_target_info *bp_tgt)
581 int ret;
582 CORE_ADDR addr = bp_tgt->placed_address = bp_tgt->reqstd_address;
583 int len;
584 const enum target_hw_bp_type type = hw_execute;
585 struct aarch64_debug_reg_state *state
586 = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
588 gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
590 if (show_debug_regs)
591 fprintf_unfiltered
592 (gdb_stdlog,
593 "insert_hw_breakpoint on entry (addr=0x%08lx, len=%d))\n",
594 (unsigned long) addr, len);
596 ret = aarch64_handle_breakpoint (type, addr, len, 1 /* is_insert */, state);
598 if (show_debug_regs)
600 aarch64_show_debug_reg_state (state,
601 "insert_hw_breakpoint", addr, len, type);
604 return ret;
607 /* Remove a hardware-assisted breakpoint at BP_TGT->placed_address.
608 Return 0 on success, -1 on failure. */
610 static int
611 aarch64_linux_remove_hw_breakpoint (struct target_ops *self,
612 struct gdbarch *gdbarch,
613 struct bp_target_info *bp_tgt)
615 int ret;
616 CORE_ADDR addr = bp_tgt->placed_address;
617 int len = 4;
618 const enum target_hw_bp_type type = hw_execute;
619 struct aarch64_debug_reg_state *state
620 = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
622 gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
624 if (show_debug_regs)
625 fprintf_unfiltered
626 (gdb_stdlog, "remove_hw_breakpoint on entry (addr=0x%08lx, len=%d))\n",
627 (unsigned long) addr, len);
629 ret = aarch64_handle_breakpoint (type, addr, len, 0 /* is_insert */, state);
631 if (show_debug_regs)
633 aarch64_show_debug_reg_state (state,
634 "remove_hw_watchpoint", addr, len, type);
637 return ret;
640 /* Implement the "to_insert_watchpoint" target_ops method.
642 Insert a watchpoint to watch a memory region which starts at
643 address ADDR and whose length is LEN bytes. Watch memory accesses
644 of the type TYPE. Return 0 on success, -1 on failure. */
646 static int
647 aarch64_linux_insert_watchpoint (struct target_ops *self,
648 CORE_ADDR addr, int len,
649 enum target_hw_bp_type type,
650 struct expression *cond)
652 int ret;
653 struct aarch64_debug_reg_state *state
654 = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
656 if (show_debug_regs)
657 fprintf_unfiltered (gdb_stdlog,
658 "insert_watchpoint on entry (addr=0x%08lx, len=%d)\n",
659 (unsigned long) addr, len);
661 gdb_assert (type != hw_execute);
663 ret = aarch64_handle_watchpoint (type, addr, len, 1 /* is_insert */, state);
665 if (show_debug_regs)
667 aarch64_show_debug_reg_state (state,
668 "insert_watchpoint", addr, len, type);
671 return ret;
674 /* Implement the "to_remove_watchpoint" target_ops method.
675 Remove a watchpoint that watched the memory region which starts at
676 address ADDR, whose length is LEN bytes, and for accesses of the
677 type TYPE. Return 0 on success, -1 on failure. */
679 static int
680 aarch64_linux_remove_watchpoint (struct target_ops *self,
681 CORE_ADDR addr, int len,
682 enum target_hw_bp_type type,
683 struct expression *cond)
685 int ret;
686 struct aarch64_debug_reg_state *state
687 = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
689 if (show_debug_regs)
690 fprintf_unfiltered (gdb_stdlog,
691 "remove_watchpoint on entry (addr=0x%08lx, len=%d)\n",
692 (unsigned long) addr, len);
694 gdb_assert (type != hw_execute);
696 ret = aarch64_handle_watchpoint (type, addr, len, 0 /* is_insert */, state);
698 if (show_debug_regs)
700 aarch64_show_debug_reg_state (state,
701 "remove_watchpoint", addr, len, type);
704 return ret;
707 /* Implement the "to_region_ok_for_hw_watchpoint" target_ops method. */
709 static int
710 aarch64_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
711 CORE_ADDR addr, int len)
713 return aarch64_linux_region_ok_for_watchpoint (addr, len);
716 /* Implement the "to_stopped_data_address" target_ops method. */
718 static int
719 aarch64_linux_stopped_data_address (struct target_ops *target,
720 CORE_ADDR *addr_p)
722 siginfo_t siginfo;
723 int i, tid;
724 struct aarch64_debug_reg_state *state;
726 if (!linux_nat_get_siginfo (inferior_ptid, &siginfo))
727 return 0;
729 /* This must be a hardware breakpoint. */
730 if (siginfo.si_signo != SIGTRAP
731 || (siginfo.si_code & 0xffff) != TRAP_HWBKPT)
732 return 0;
734 /* Check if the address matches any watched address. */
735 state = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
736 for (i = aarch64_num_wp_regs - 1; i >= 0; --i)
738 const unsigned int len = aarch64_watchpoint_length (state->dr_ctrl_wp[i]);
739 const CORE_ADDR addr_trap = (CORE_ADDR) siginfo.si_addr;
740 const CORE_ADDR addr_watch = state->dr_addr_wp[i];
742 if (state->dr_ref_count_wp[i]
743 && DR_CONTROL_ENABLED (state->dr_ctrl_wp[i])
744 && addr_trap >= addr_watch
745 && addr_trap < addr_watch + len)
747 *addr_p = addr_trap;
748 return 1;
752 return 0;
755 /* Implement the "to_stopped_by_watchpoint" target_ops method. */
757 static int
758 aarch64_linux_stopped_by_watchpoint (struct target_ops *ops)
760 CORE_ADDR addr;
762 return aarch64_linux_stopped_data_address (ops, &addr);
765 /* Implement the "to_watchpoint_addr_within_range" target_ops method. */
767 static int
768 aarch64_linux_watchpoint_addr_within_range (struct target_ops *target,
769 CORE_ADDR addr,
770 CORE_ADDR start, int length)
772 return start <= addr && start + length - 1 >= addr;
775 /* Implement the "to_can_do_single_step" target_ops method. */
777 static int
778 aarch64_linux_can_do_single_step (struct target_ops *target)
780 return 1;
783 /* Define AArch64 maintenance commands. */
785 static void
786 add_show_debug_regs_command (void)
788 /* A maintenance command to enable printing the internal DRi mirror
789 variables. */
790 add_setshow_boolean_cmd ("show-debug-regs", class_maintenance,
791 &show_debug_regs, _("\
792 Set whether to show variables that mirror the AArch64 debug registers."), _("\
793 Show whether to show variables that mirror the AArch64 debug registers."), _("\
794 Use \"on\" to enable, \"off\" to disable.\n\
795 If enabled, the debug registers values are shown when GDB inserts\n\
796 or removes a hardware breakpoint or watchpoint, and when the inferior\n\
797 triggers a breakpoint or watchpoint."),
798 NULL,
799 NULL,
800 &maintenance_set_cmdlist,
801 &maintenance_show_cmdlist);
804 void
805 _initialize_aarch64_linux_nat (void)
807 struct target_ops *t;
809 /* Fill in the generic GNU/Linux methods. */
810 t = linux_target ();
812 add_show_debug_regs_command ();
814 /* Add our register access methods. */
815 t->to_fetch_registers = aarch64_linux_fetch_inferior_registers;
816 t->to_store_registers = aarch64_linux_store_inferior_registers;
818 t->to_read_description = aarch64_linux_read_description;
820 t->to_can_use_hw_breakpoint = aarch64_linux_can_use_hw_breakpoint;
821 t->to_insert_hw_breakpoint = aarch64_linux_insert_hw_breakpoint;
822 t->to_remove_hw_breakpoint = aarch64_linux_remove_hw_breakpoint;
823 t->to_region_ok_for_hw_watchpoint =
824 aarch64_linux_region_ok_for_hw_watchpoint;
825 t->to_insert_watchpoint = aarch64_linux_insert_watchpoint;
826 t->to_remove_watchpoint = aarch64_linux_remove_watchpoint;
827 t->to_stopped_by_watchpoint = aarch64_linux_stopped_by_watchpoint;
828 t->to_stopped_data_address = aarch64_linux_stopped_data_address;
829 t->to_watchpoint_addr_within_range =
830 aarch64_linux_watchpoint_addr_within_range;
831 t->to_can_do_single_step = aarch64_linux_can_do_single_step;
833 /* Override the GNU/Linux inferior startup hook. */
834 super_post_startup_inferior = t->to_post_startup_inferior;
835 t->to_post_startup_inferior = aarch64_linux_child_post_startup_inferior;
837 /* Register the target. */
838 linux_nat_add_target (t);
839 linux_nat_set_new_thread (t, aarch64_linux_new_thread);
840 linux_nat_set_delete_thread (t, aarch64_linux_delete_thread);
841 linux_nat_set_new_fork (t, aarch64_linux_new_fork);
842 linux_nat_set_forget_process (t, aarch64_forget_process);
843 linux_nat_set_prepare_to_resume (t, aarch64_linux_prepare_to_resume);
845 /* Add our siginfo layout converter. */
846 linux_nat_set_siginfo_fixup (t, aarch64_linux_siginfo_fixup);