1 /* Native-dependent code for GNU/Linux AArch64.
3 Copyright (C) 2011-2023 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-nat.h"
31 #include "aarch64-tdep.h"
32 #include "aarch64-linux-tdep.h"
33 #include "aarch32-linux-nat.h"
34 #include "aarch32-tdep.h"
36 #include "nat/aarch64-linux.h"
37 #include "nat/aarch64-linux-hw-point.h"
38 #include "nat/aarch64-scalable-linux-ptrace.h"
40 #include "elf/external.h"
41 #include "elf/common.h"
43 #include "nat/gdb_ptrace.h"
44 #include <sys/utsname.h>
45 #include <asm/ptrace.h>
48 #include "linux-tdep.h"
51 /* Defines ps_err_e, struct ps_prochandle. */
52 #include "gdb_proc_service.h"
53 #include "arch-utils.h"
55 #include "arch/aarch64-mte-linux.h"
57 #include "nat/aarch64-mte-linux-ptrace.h"
62 #define TRAP_HWBKPT 0x0004
65 class aarch64_linux_nat_target final
66 : public aarch64_nat_target
<linux_nat_target
>
69 /* Add our register access methods. */
70 void fetch_registers (struct regcache
*, int) override
;
71 void store_registers (struct regcache
*, int) override
;
73 const struct target_desc
*read_description () override
;
75 /* Add our hardware breakpoint and watchpoint implementation. */
76 bool stopped_by_watchpoint () override
;
77 bool stopped_data_address (CORE_ADDR
*) override
;
79 int can_do_single_step () override
;
81 /* Override the GNU/Linux inferior startup hook. */
82 void post_startup_inferior (ptid_t
) override
;
84 /* Override the GNU/Linux post attach hook. */
85 void post_attach (int pid
) override
;
87 /* These three defer to common nat/ code. */
88 void low_new_thread (struct lwp_info
*lp
) override
89 { aarch64_linux_new_thread (lp
); }
90 void low_delete_thread (struct arch_lwp_info
*lp
) override
91 { aarch64_linux_delete_thread (lp
); }
92 void low_prepare_to_resume (struct lwp_info
*lp
) override
93 { aarch64_linux_prepare_to_resume (lp
); }
95 void low_new_fork (struct lwp_info
*parent
, pid_t child_pid
) override
;
96 void low_forget_process (pid_t pid
) override
;
98 /* Add our siginfo layout converter. */
99 bool low_siginfo_fixup (siginfo_t
*ptrace
, gdb_byte
*inf
, int direction
)
102 struct gdbarch
*thread_architecture (ptid_t
) override
;
104 bool supports_memory_tagging () override
;
106 /* Read memory allocation tags from memory via PTRACE. */
107 bool fetch_memtags (CORE_ADDR address
, size_t len
,
108 gdb::byte_vector
&tags
, int type
) override
;
110 /* Write allocation tags to memory via PTRACE. */
111 bool store_memtags (CORE_ADDR address
, size_t len
,
112 const gdb::byte_vector
&tags
, int type
) override
;
115 static aarch64_linux_nat_target the_aarch64_linux_nat_target
;
117 /* Called whenever GDB is no longer debugging process PID. It deletes
118 data structures that keep track of debug register state. */
121 aarch64_linux_nat_target::low_forget_process (pid_t pid
)
123 aarch64_remove_debug_reg_state (pid
);
126 /* Fill GDB's register array with the general-purpose register values
127 from the current thread. */
130 fetch_gregs_from_thread (struct regcache
*regcache
)
133 struct gdbarch
*gdbarch
= regcache
->arch ();
137 /* Make sure REGS can hold all registers contents on both aarch64
139 gdb_static_assert (sizeof (regs
) >= 18 * 4);
141 tid
= regcache
->ptid ().lwp ();
143 iovec
.iov_base
= ®s
;
144 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
145 iovec
.iov_len
= 18 * 4;
147 iovec
.iov_len
= sizeof (regs
);
149 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_PRSTATUS
, &iovec
);
151 perror_with_name (_("Unable to fetch general registers"));
153 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
154 aarch32_gp_regcache_supply (regcache
, (uint32_t *) regs
, 1);
159 for (regno
= AARCH64_X0_REGNUM
; regno
<= AARCH64_CPSR_REGNUM
; regno
++)
160 regcache
->raw_supply (regno
, ®s
[regno
- AARCH64_X0_REGNUM
]);
164 /* Store to the current thread the valid general-purpose register
165 values in the GDB's register array. */
168 store_gregs_to_thread (const struct regcache
*regcache
)
173 struct gdbarch
*gdbarch
= regcache
->arch ();
175 /* Make sure REGS can hold all registers contents on both aarch64
177 gdb_static_assert (sizeof (regs
) >= 18 * 4);
178 tid
= regcache
->ptid ().lwp ();
180 iovec
.iov_base
= ®s
;
181 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
182 iovec
.iov_len
= 18 * 4;
184 iovec
.iov_len
= sizeof (regs
);
186 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_PRSTATUS
, &iovec
);
188 perror_with_name (_("Unable to fetch general registers"));
190 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
191 aarch32_gp_regcache_collect (regcache
, (uint32_t *) regs
, 1);
196 for (regno
= AARCH64_X0_REGNUM
; regno
<= AARCH64_CPSR_REGNUM
; regno
++)
197 if (REG_VALID
== regcache
->get_register_status (regno
))
198 regcache
->raw_collect (regno
, ®s
[regno
- AARCH64_X0_REGNUM
]);
201 ret
= ptrace (PTRACE_SETREGSET
, tid
, NT_PRSTATUS
, &iovec
);
203 perror_with_name (_("Unable to store general registers"));
206 /* Fill GDB's register array with the fp/simd register values
207 from the current thread. */
210 fetch_fpregs_from_thread (struct regcache
*regcache
)
215 struct gdbarch
*gdbarch
= regcache
->arch ();
217 /* Make sure REGS can hold all VFP registers contents on both aarch64
219 gdb_static_assert (sizeof regs
>= ARM_VFP3_REGS_SIZE
);
221 tid
= regcache
->ptid ().lwp ();
223 iovec
.iov_base
= ®s
;
225 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
227 iovec
.iov_len
= ARM_VFP3_REGS_SIZE
;
229 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_ARM_VFP
, &iovec
);
231 perror_with_name (_("Unable to fetch VFP registers"));
233 aarch32_vfp_regcache_supply (regcache
, (gdb_byte
*) ®s
, 32);
239 iovec
.iov_len
= sizeof (regs
);
241 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_FPREGSET
, &iovec
);
243 perror_with_name (_("Unable to fetch vFP/SIMD registers"));
245 for (regno
= AARCH64_V0_REGNUM
; regno
<= AARCH64_V31_REGNUM
; regno
++)
246 regcache
->raw_supply (regno
, ®s
.vregs
[regno
- AARCH64_V0_REGNUM
]);
248 regcache
->raw_supply (AARCH64_FPSR_REGNUM
, ®s
.fpsr
);
249 regcache
->raw_supply (AARCH64_FPCR_REGNUM
, ®s
.fpcr
);
253 /* Store to the current thread the valid fp/simd register
254 values in the GDB's register array. */
257 store_fpregs_to_thread (const struct regcache
*regcache
)
262 struct gdbarch
*gdbarch
= regcache
->arch ();
264 /* Make sure REGS can hold all VFP registers contents on both aarch64
266 gdb_static_assert (sizeof regs
>= ARM_VFP3_REGS_SIZE
);
267 tid
= regcache
->ptid ().lwp ();
269 iovec
.iov_base
= ®s
;
271 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
273 iovec
.iov_len
= ARM_VFP3_REGS_SIZE
;
275 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_ARM_VFP
, &iovec
);
277 perror_with_name (_("Unable to fetch VFP registers"));
279 aarch32_vfp_regcache_collect (regcache
, (gdb_byte
*) ®s
, 32);
285 iovec
.iov_len
= sizeof (regs
);
287 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_FPREGSET
, &iovec
);
289 perror_with_name (_("Unable to fetch FP/SIMD registers"));
291 for (regno
= AARCH64_V0_REGNUM
; regno
<= AARCH64_V31_REGNUM
; regno
++)
292 if (REG_VALID
== regcache
->get_register_status (regno
))
293 regcache
->raw_collect
294 (regno
, (char *) ®s
.vregs
[regno
- AARCH64_V0_REGNUM
]);
296 if (REG_VALID
== regcache
->get_register_status (AARCH64_FPSR_REGNUM
))
297 regcache
->raw_collect (AARCH64_FPSR_REGNUM
, (char *) ®s
.fpsr
);
298 if (REG_VALID
== regcache
->get_register_status (AARCH64_FPCR_REGNUM
))
299 regcache
->raw_collect (AARCH64_FPCR_REGNUM
, (char *) ®s
.fpcr
);
302 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
304 ret
= ptrace (PTRACE_SETREGSET
, tid
, NT_ARM_VFP
, &iovec
);
306 perror_with_name (_("Unable to store VFP registers"));
310 ret
= ptrace (PTRACE_SETREGSET
, tid
, NT_FPREGSET
, &iovec
);
312 perror_with_name (_("Unable to store FP/SIMD registers"));
316 /* Fill GDB's register array with the sve register values
317 from the current thread. */
320 fetch_sveregs_from_thread (struct regcache
*regcache
)
322 /* Fetch SVE state from the thread and copy it into the register cache. */
323 aarch64_sve_regs_copy_to_reg_buf (regcache
->ptid ().lwp (), regcache
);
326 /* Store to the current thread the valid sve register
327 values in the GDB's register array. */
330 store_sveregs_to_thread (struct regcache
*regcache
)
332 /* Fetch SVE state from the register cache and update the thread TID with
334 aarch64_sve_regs_copy_from_reg_buf (regcache
->ptid ().lwp (), regcache
);
337 /* Fill GDB's register array with the pointer authentication mask values from
338 the current thread. */
341 fetch_pauth_masks_from_thread (struct regcache
*regcache
)
343 aarch64_gdbarch_tdep
*tdep
344 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
347 uint64_t pauth_regset
[2] = {0, 0};
348 int tid
= regcache
->ptid ().lwp ();
350 iovec
.iov_base
= &pauth_regset
;
351 iovec
.iov_len
= sizeof (pauth_regset
);
353 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_ARM_PAC_MASK
, &iovec
);
355 perror_with_name (_("unable to fetch pauth registers"));
357 regcache
->raw_supply (AARCH64_PAUTH_DMASK_REGNUM (tdep
->pauth_reg_base
),
359 regcache
->raw_supply (AARCH64_PAUTH_CMASK_REGNUM (tdep
->pauth_reg_base
),
363 /* Fill GDB's register array with the MTE register values from
364 the current thread. */
367 fetch_mteregs_from_thread (struct regcache
*regcache
)
369 aarch64_gdbarch_tdep
*tdep
370 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
371 int regno
= tdep
->mte_reg_base
;
373 gdb_assert (regno
!= -1);
375 uint64_t tag_ctl
= 0;
378 iovec
.iov_base
= &tag_ctl
;
379 iovec
.iov_len
= sizeof (tag_ctl
);
381 int tid
= get_ptrace_pid (regcache
->ptid ());
382 if (ptrace (PTRACE_GETREGSET
, tid
, NT_ARM_TAGGED_ADDR_CTRL
, &iovec
) != 0)
383 perror_with_name (_("unable to fetch MTE registers"));
385 regcache
->raw_supply (regno
, &tag_ctl
);
388 /* Store to the current thread the valid MTE register set in the GDB's
392 store_mteregs_to_thread (struct regcache
*regcache
)
394 aarch64_gdbarch_tdep
*tdep
395 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
396 int regno
= tdep
->mte_reg_base
;
398 gdb_assert (regno
!= -1);
400 uint64_t tag_ctl
= 0;
402 if (REG_VALID
!= regcache
->get_register_status (regno
))
405 regcache
->raw_collect (regno
, (char *) &tag_ctl
);
409 iovec
.iov_base
= &tag_ctl
;
410 iovec
.iov_len
= sizeof (tag_ctl
);
412 int tid
= get_ptrace_pid (regcache
->ptid ());
413 if (ptrace (PTRACE_SETREGSET
, tid
, NT_ARM_TAGGED_ADDR_CTRL
, &iovec
) != 0)
414 perror_with_name (_("unable to store MTE registers"));
417 /* Fill GDB's register array with the TLS register values from
418 the current thread. */
421 fetch_tlsregs_from_thread (struct regcache
*regcache
)
423 aarch64_gdbarch_tdep
*tdep
424 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
425 int regno
= tdep
->tls_regnum_base
;
427 gdb_assert (regno
!= -1);
428 gdb_assert (tdep
->tls_register_count
> 0);
430 uint64_t tpidrs
[tdep
->tls_register_count
];
431 memset(tpidrs
, 0, sizeof(tpidrs
));
434 iovec
.iov_base
= tpidrs
;
435 iovec
.iov_len
= sizeof (tpidrs
);
437 int tid
= get_ptrace_pid (regcache
->ptid ());
438 if (ptrace (PTRACE_GETREGSET
, tid
, NT_ARM_TLS
, &iovec
) != 0)
439 perror_with_name (_("unable to fetch TLS registers"));
441 for (int i
= 0; i
< tdep
->tls_register_count
; i
++)
442 regcache
->raw_supply (regno
+ i
, &tpidrs
[i
]);
445 /* Store to the current thread the valid TLS register set in GDB's
449 store_tlsregs_to_thread (struct regcache
*regcache
)
451 aarch64_gdbarch_tdep
*tdep
452 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
453 int regno
= tdep
->tls_regnum_base
;
455 gdb_assert (regno
!= -1);
456 gdb_assert (tdep
->tls_register_count
> 0);
458 uint64_t tpidrs
[tdep
->tls_register_count
];
459 memset(tpidrs
, 0, sizeof(tpidrs
));
461 for (int i
= 0; i
< tdep
->tls_register_count
; i
++)
463 if (REG_VALID
!= regcache
->get_register_status (regno
+ i
))
466 regcache
->raw_collect (regno
+ i
, (char *) &tpidrs
[i
]);
470 iovec
.iov_base
= &tpidrs
;
471 iovec
.iov_len
= sizeof (tpidrs
);
473 int tid
= get_ptrace_pid (regcache
->ptid ());
474 if (ptrace (PTRACE_SETREGSET
, tid
, NT_ARM_TLS
, &iovec
) != 0)
475 perror_with_name (_("unable to store TLS register"));
478 /* The AArch64 version of the "fetch_registers" target_ops method. Fetch
479 REGNO from the target and place the result into REGCACHE. */
482 aarch64_fetch_registers (struct regcache
*regcache
, int regno
)
484 aarch64_gdbarch_tdep
*tdep
485 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
487 /* Do we need to fetch all registers? */
490 fetch_gregs_from_thread (regcache
);
491 if (tdep
->has_sve ())
492 fetch_sveregs_from_thread (regcache
);
494 fetch_fpregs_from_thread (regcache
);
496 if (tdep
->has_pauth ())
497 fetch_pauth_masks_from_thread (regcache
);
499 if (tdep
->has_mte ())
500 fetch_mteregs_from_thread (regcache
);
502 if (tdep
->has_tls ())
503 fetch_tlsregs_from_thread (regcache
);
505 /* General purpose register? */
506 else if (regno
< AARCH64_V0_REGNUM
)
507 fetch_gregs_from_thread (regcache
);
509 else if (tdep
->has_sve () && regno
<= AARCH64_SVE_VG_REGNUM
)
510 fetch_sveregs_from_thread (regcache
);
511 /* FPSIMD register? */
512 else if (regno
<= AARCH64_FPCR_REGNUM
)
513 fetch_fpregs_from_thread (regcache
);
514 /* PAuth register? */
515 else if (tdep
->has_pauth ()
516 && (regno
== AARCH64_PAUTH_DMASK_REGNUM (tdep
->pauth_reg_base
)
517 || regno
== AARCH64_PAUTH_CMASK_REGNUM (tdep
->pauth_reg_base
)))
518 fetch_pauth_masks_from_thread (regcache
);
520 else if (tdep
->has_mte ()
521 && (regno
== tdep
->mte_reg_base
))
522 fetch_mteregs_from_thread (regcache
);
524 else if (tdep
->has_tls ()
525 && regno
>= tdep
->tls_regnum_base
526 && regno
< tdep
->tls_regnum_base
+ tdep
->tls_register_count
)
527 fetch_tlsregs_from_thread (regcache
);
530 /* A version of the "fetch_registers" target_ops method used when running
531 32-bit ARM code on an AArch64 target. Fetch REGNO from the target and
532 place the result into REGCACHE. */
535 aarch32_fetch_registers (struct regcache
*regcache
, int regno
)
537 arm_gdbarch_tdep
*tdep
538 = gdbarch_tdep
<arm_gdbarch_tdep
> (regcache
->arch ());
542 fetch_gregs_from_thread (regcache
);
543 if (tdep
->vfp_register_count
> 0)
544 fetch_fpregs_from_thread (regcache
);
546 else if (regno
< ARM_F0_REGNUM
|| regno
== ARM_PS_REGNUM
)
547 fetch_gregs_from_thread (regcache
);
548 else if (tdep
->vfp_register_count
> 0
549 && regno
>= ARM_D0_REGNUM
550 && (regno
< ARM_D0_REGNUM
+ tdep
->vfp_register_count
551 || regno
== ARM_FPSCR_REGNUM
))
552 fetch_fpregs_from_thread (regcache
);
555 /* Implement the "fetch_registers" target_ops method. */
558 aarch64_linux_nat_target::fetch_registers (struct regcache
*regcache
,
561 if (gdbarch_bfd_arch_info (regcache
->arch ())->bits_per_word
== 32)
562 aarch32_fetch_registers (regcache
, regno
);
564 aarch64_fetch_registers (regcache
, regno
);
567 /* The AArch64 version of the "store_registers" target_ops method. Copy
568 the value of register REGNO from REGCACHE into the the target. */
571 aarch64_store_registers (struct regcache
*regcache
, int regno
)
573 aarch64_gdbarch_tdep
*tdep
574 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
576 /* Do we need to store all registers? */
579 store_gregs_to_thread (regcache
);
580 if (tdep
->has_sve ())
581 store_sveregs_to_thread (regcache
);
583 store_fpregs_to_thread (regcache
);
585 if (tdep
->has_mte ())
586 store_mteregs_to_thread (regcache
);
588 if (tdep
->has_tls ())
589 store_tlsregs_to_thread (regcache
);
591 /* General purpose register? */
592 else if (regno
< AARCH64_V0_REGNUM
)
593 store_gregs_to_thread (regcache
);
595 else if (tdep
->has_sve () && regno
<= AARCH64_SVE_VG_REGNUM
)
596 store_sveregs_to_thread (regcache
);
597 /* FPSIMD register? */
598 else if (regno
<= AARCH64_FPCR_REGNUM
)
599 store_fpregs_to_thread (regcache
);
601 else if (tdep
->has_mte ()
602 && (regno
== tdep
->mte_reg_base
))
603 store_mteregs_to_thread (regcache
);
605 else if (tdep
->has_tls ()
606 && regno
>= tdep
->tls_regnum_base
607 && regno
< tdep
->tls_regnum_base
+ tdep
->tls_register_count
)
608 store_tlsregs_to_thread (regcache
);
610 /* PAuth registers are read-only. */
613 /* A version of the "store_registers" target_ops method used when running
614 32-bit ARM code on an AArch64 target. Copy the value of register REGNO
615 from REGCACHE into the the target. */
618 aarch32_store_registers (struct regcache
*regcache
, int regno
)
620 arm_gdbarch_tdep
*tdep
621 = gdbarch_tdep
<arm_gdbarch_tdep
> (regcache
->arch ());
625 store_gregs_to_thread (regcache
);
626 if (tdep
->vfp_register_count
> 0)
627 store_fpregs_to_thread (regcache
);
629 else if (regno
< ARM_F0_REGNUM
|| regno
== ARM_PS_REGNUM
)
630 store_gregs_to_thread (regcache
);
631 else if (tdep
->vfp_register_count
> 0
632 && regno
>= ARM_D0_REGNUM
633 && (regno
< ARM_D0_REGNUM
+ tdep
->vfp_register_count
634 || regno
== ARM_FPSCR_REGNUM
))
635 store_fpregs_to_thread (regcache
);
638 /* Implement the "store_registers" target_ops method. */
641 aarch64_linux_nat_target::store_registers (struct regcache
*regcache
,
644 if (gdbarch_bfd_arch_info (regcache
->arch ())->bits_per_word
== 32)
645 aarch32_store_registers (regcache
, regno
);
647 aarch64_store_registers (regcache
, regno
);
650 /* Fill register REGNO (if it is a general-purpose register) in
651 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
652 do this for all registers. */
655 fill_gregset (const struct regcache
*regcache
,
656 gdb_gregset_t
*gregsetp
, int regno
)
658 regcache_collect_regset (&aarch64_linux_gregset
, regcache
,
659 regno
, (gdb_byte
*) gregsetp
,
660 AARCH64_LINUX_SIZEOF_GREGSET
);
663 /* Fill GDB's register array with the general-purpose register values
667 supply_gregset (struct regcache
*regcache
, const gdb_gregset_t
*gregsetp
)
669 regcache_supply_regset (&aarch64_linux_gregset
, regcache
, -1,
670 (const gdb_byte
*) gregsetp
,
671 AARCH64_LINUX_SIZEOF_GREGSET
);
674 /* Fill register REGNO (if it is a floating-point register) in
675 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
676 do this for all registers. */
679 fill_fpregset (const struct regcache
*regcache
,
680 gdb_fpregset_t
*fpregsetp
, int regno
)
682 regcache_collect_regset (&aarch64_linux_fpregset
, regcache
,
683 regno
, (gdb_byte
*) fpregsetp
,
684 AARCH64_LINUX_SIZEOF_FPREGSET
);
687 /* Fill GDB's register array with the floating-point register values
691 supply_fpregset (struct regcache
*regcache
, const gdb_fpregset_t
*fpregsetp
)
693 regcache_supply_regset (&aarch64_linux_fpregset
, regcache
, -1,
694 (const gdb_byte
*) fpregsetp
,
695 AARCH64_LINUX_SIZEOF_FPREGSET
);
698 /* linux_nat_new_fork hook. */
701 aarch64_linux_nat_target::low_new_fork (struct lwp_info
*parent
,
705 struct aarch64_debug_reg_state
*parent_state
;
706 struct aarch64_debug_reg_state
*child_state
;
708 /* NULL means no watchpoint has ever been set in the parent. In
709 that case, there's nothing to do. */
710 if (parent
->arch_private
== NULL
)
713 /* GDB core assumes the child inherits the watchpoints/hw
714 breakpoints of the parent, and will remove them all from the
715 forked off process. Copy the debug registers mirrors into the
716 new process so that all breakpoints and watchpoints can be
719 parent_pid
= parent
->ptid
.pid ();
720 parent_state
= aarch64_get_debug_reg_state (parent_pid
);
721 child_state
= aarch64_get_debug_reg_state (child_pid
);
722 *child_state
= *parent_state
;
726 /* Called by libthread_db. Returns a pointer to the thread local
727 storage (or its descriptor). */
730 ps_get_thread_area (struct ps_prochandle
*ph
,
731 lwpid_t lwpid
, int idx
, void **base
)
734 = (gdbarch_bfd_arch_info (target_gdbarch ())->bits_per_word
== 64);
736 return aarch64_ps_get_thread_area (ph
, lwpid
, idx
, base
, is_64bit_p
);
740 /* Implement the virtual inf_ptrace_target::post_startup_inferior method. */
743 aarch64_linux_nat_target::post_startup_inferior (ptid_t ptid
)
745 low_forget_process (ptid
.pid ());
746 aarch64_linux_get_debug_reg_capacity (ptid
.pid ());
747 linux_nat_target::post_startup_inferior (ptid
);
750 /* Implement the "post_attach" target_ops method. */
753 aarch64_linux_nat_target::post_attach (int pid
)
755 low_forget_process (pid
);
756 /* Set the hardware debug register capacity. If
757 aarch64_linux_get_debug_reg_capacity is not called
758 (as it is in aarch64_linux_child_post_startup_inferior) then
759 software watchpoints will be used instead of hardware
760 watchpoints when attaching to a target. */
761 aarch64_linux_get_debug_reg_capacity (pid
);
762 linux_nat_target::post_attach (pid
);
765 /* Implement the "read_description" target_ops method. */
767 const struct target_desc
*
768 aarch64_linux_nat_target::read_description ()
771 gdb_byte regbuf
[ARM_VFP3_REGS_SIZE
];
774 if (inferior_ptid
== null_ptid
)
775 return this->beneath ()->read_description ();
777 tid
= inferior_ptid
.pid ();
779 iovec
.iov_base
= regbuf
;
780 iovec
.iov_len
= ARM_VFP3_REGS_SIZE
;
782 ret
= ptrace (PTRACE_GETREGSET
, tid
, NT_ARM_VFP
, &iovec
);
784 return aarch32_read_description ();
786 CORE_ADDR hwcap
= linux_get_hwcap ();
787 CORE_ADDR hwcap2
= linux_get_hwcap2 ();
789 aarch64_features features
;
790 features
.vq
= aarch64_sve_get_vq (tid
);
791 features
.pauth
= hwcap
& AARCH64_HWCAP_PACA
;
792 features
.mte
= hwcap2
& HWCAP2_MTE
;
793 features
.tls
= aarch64_tls_register_count (tid
);
795 return aarch64_read_description (features
);
798 /* Convert a native/host siginfo object, into/from the siginfo in the
799 layout of the inferiors' architecture. Returns true if any
800 conversion was done; false otherwise. If DIRECTION is 1, then copy
801 from INF to NATIVE. If DIRECTION is 0, copy from NATIVE to
805 aarch64_linux_nat_target::low_siginfo_fixup (siginfo_t
*native
, gdb_byte
*inf
,
808 struct gdbarch
*gdbarch
= get_frame_arch (get_current_frame ());
810 /* Is the inferior 32-bit? If so, then do fixup the siginfo
812 if (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
== 32)
815 aarch64_compat_siginfo_from_siginfo ((struct compat_siginfo
*) inf
,
818 aarch64_siginfo_from_compat_siginfo (native
,
819 (struct compat_siginfo
*) inf
);
827 /* Implement the "stopped_data_address" target_ops method. */
830 aarch64_linux_nat_target::stopped_data_address (CORE_ADDR
*addr_p
)
833 struct aarch64_debug_reg_state
*state
;
835 if (!linux_nat_get_siginfo (inferior_ptid
, &siginfo
))
838 /* This must be a hardware breakpoint. */
839 if (siginfo
.si_signo
!= SIGTRAP
840 || (siginfo
.si_code
& 0xffff) != TRAP_HWBKPT
)
843 /* Make sure to ignore the top byte, otherwise we may not recognize a
844 hardware watchpoint hit. The stopped data addresses coming from the
845 kernel can potentially be tagged addresses. */
846 struct gdbarch
*gdbarch
= thread_architecture (inferior_ptid
);
847 const CORE_ADDR addr_trap
848 = gdbarch_remove_non_address_bits (gdbarch
, (CORE_ADDR
) siginfo
.si_addr
);
850 /* Check if the address matches any watched address. */
851 state
= aarch64_get_debug_reg_state (inferior_ptid
.pid ());
852 return aarch64_stopped_data_address (state
, addr_trap
, addr_p
);
855 /* Implement the "stopped_by_watchpoint" target_ops method. */
858 aarch64_linux_nat_target::stopped_by_watchpoint ()
862 return stopped_data_address (&addr
);
865 /* Implement the "can_do_single_step" target_ops method. */
868 aarch64_linux_nat_target::can_do_single_step ()
873 /* Implement the "thread_architecture" target_ops method.
875 Returns the gdbarch for the thread identified by PTID. If the thread in
876 question is a 32-bit ARM thread, then the architecture returned will be
877 that of the process itself.
879 If the thread is an AArch64 thread then we need to check the current
880 vector length; if the vector length has changed then we need to lookup a
881 new gdbarch that matches the new vector length. */
884 aarch64_linux_nat_target::thread_architecture (ptid_t ptid
)
886 /* Find the current gdbarch the same way as process_stratum_target. */
887 inferior
*inf
= find_inferior_ptid (this, ptid
);
888 gdb_assert (inf
!= NULL
);
890 /* If this is a 32-bit architecture, then this is ARM, not AArch64.
891 There's no SVE vectors here, so just return the inferior
893 if (gdbarch_bfd_arch_info (inf
->gdbarch
)->bits_per_word
== 32)
896 /* Only return it if the current vector length matches the one in the tdep. */
897 aarch64_gdbarch_tdep
*tdep
898 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (inf
->gdbarch
);
899 uint64_t vq
= aarch64_sve_get_vq (ptid
.lwp ());
903 /* We reach here if the vector length for the thread is different from its
904 value at process start. Lookup gdbarch via info (potentially creating a
905 new one) by using a target description that corresponds to the new vq value
906 and the current architecture features. */
908 const struct target_desc
*tdesc
= gdbarch_target_desc (inf
->gdbarch
);
909 aarch64_features features
= aarch64_features_from_target_desc (tdesc
);
912 struct gdbarch_info info
;
913 info
.bfd_arch_info
= bfd_lookup_arch (bfd_arch_aarch64
, bfd_mach_aarch64
);
914 info
.target_desc
= aarch64_read_description (features
);
915 return gdbarch_find_by_info (info
);
918 /* Implement the "supports_memory_tagging" target_ops method. */
921 aarch64_linux_nat_target::supports_memory_tagging ()
923 return (linux_get_hwcap2 () & HWCAP2_MTE
) != 0;
926 /* Implement the "fetch_memtags" target_ops method. */
929 aarch64_linux_nat_target::fetch_memtags (CORE_ADDR address
, size_t len
,
930 gdb::byte_vector
&tags
, int type
)
932 int tid
= get_ptrace_pid (inferior_ptid
);
934 /* Allocation tags? */
935 if (type
== static_cast<int> (aarch64_memtag_type::mte_allocation
))
936 return aarch64_mte_fetch_memtags (tid
, address
, len
, tags
);
941 /* Implement the "store_memtags" target_ops method. */
944 aarch64_linux_nat_target::store_memtags (CORE_ADDR address
, size_t len
,
945 const gdb::byte_vector
&tags
, int type
)
947 int tid
= get_ptrace_pid (inferior_ptid
);
949 /* Allocation tags? */
950 if (type
== static_cast<int> (aarch64_memtag_type::mte_allocation
))
951 return aarch64_mte_store_memtags (tid
, address
, len
, tags
);
956 void _initialize_aarch64_linux_nat ();
958 _initialize_aarch64_linux_nat ()
960 aarch64_initialize_hw_point ();
962 /* Register the target. */
963 linux_target
= &the_aarch64_linux_nat_target
;
964 add_inf_child_target (&the_aarch64_linux_nat_target
);