1 /* Target-dependent code for GNU/Linux AArch64.
3 Copyright (C) 2009-2019 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/>. */
24 #include "arch-utils.h"
25 #include "glibc-tdep.h"
26 #include "linux-tdep.h"
27 #include "aarch64-tdep.h"
28 #include "aarch64-linux-tdep.h"
30 #include "solib-svr4.h"
32 #include "tramp-frame.h"
33 #include "trad-frame.h"
39 #include "cli/cli-utils.h"
40 #include "stap-probe.h"
41 #include "parser-defs.h"
42 #include "user-regs.h"
43 #include "xml-syscall.h"
46 #include "record-full.h"
47 #include "linux-record.h"
49 #include "elf/common.h"
51 /* Signal frame handling.
66 | | | SIGTRAMP_FRAME (struct rt_sigframe)
68 +--| saved sp |--> interrupted_sp
69 | | saved pc |--> interrupted_pc
72 | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0)
78 On signal delivery, the kernel will create a signal handler stack
79 frame and setup the return address in LR to point at restorer stub.
80 The signal stack frame is defined by:
88 The ucontext has the following form:
91 unsigned long uc_flags;
92 struct ucontext *uc_link;
95 struct sigcontext uc_mcontext;
100 unsigned long fault_address;
101 unsigned long regs[31];
102 unsigned long sp; / * 31 * /
103 unsigned long pc; / * 32 * /
104 unsigned long pstate; / * 33 * /
105 __u8 __reserved[4096]
108 The reserved space in sigcontext contains additional structures, each starting
109 with a aarch64_ctx, which specifies a unique identifier and the total size of
110 the structure. The final structure in reserved will start will a null
111 aarch64_ctx. The penultimate entry in reserved may be a extra_context which
112 then points to a further block of reserved space.
119 The restorer stub will always have the form:
121 d28015a8 movz x8, #0xad
124 This is a system call sys_rt_sigreturn.
126 We detect signal frames by snooping the return code for the restorer
127 instruction sequence.
129 The handler then needs to recover the saved register set from
130 ucontext.uc_mcontext. */
132 /* These magic numbers need to reflect the layout of the kernel
133 defined struct rt_sigframe and ucontext. */
134 #define AARCH64_SIGCONTEXT_REG_SIZE 8
135 #define AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET 128
136 #define AARCH64_UCONTEXT_SIGCONTEXT_OFFSET 176
137 #define AARCH64_SIGCONTEXT_XO_OFFSET 8
138 #define AARCH64_SIGCONTEXT_RESERVED_OFFSET 288
140 #define AARCH64_SIGCONTEXT_RESERVED_SIZE 4096
142 /* Unique identifiers that may be used for aarch64_ctx.magic. */
143 #define AARCH64_EXTRA_MAGIC 0x45585401
144 #define AARCH64_FPSIMD_MAGIC 0x46508001
145 #define AARCH64_SVE_MAGIC 0x53564501
147 /* Defines for the extra_context that follows an AARCH64_EXTRA_MAGIC. */
148 #define AARCH64_EXTRA_DATAP_OFFSET 8
150 /* Defines for the fpsimd that follows an AARCH64_FPSIMD_MAGIC. */
151 #define AARCH64_FPSIMD_FPSR_OFFSET 8
152 #define AARCH64_FPSIMD_FPCR_OFFSET 12
153 #define AARCH64_FPSIMD_V0_OFFSET 16
154 #define AARCH64_FPSIMD_VREG_SIZE 16
156 /* Defines for the sve structure that follows an AARCH64_SVE_MAGIC. */
157 #define AARCH64_SVE_CONTEXT_VL_OFFSET 8
158 #define AARCH64_SVE_CONTEXT_REGS_OFFSET 16
159 #define AARCH64_SVE_CONTEXT_P_REGS_OFFSET(vq) (32 * vq * 16)
160 #define AARCH64_SVE_CONTEXT_FFR_OFFSET(vq) \
161 (AARCH64_SVE_CONTEXT_P_REGS_OFFSET (vq) + (16 * vq * 2))
162 #define AARCH64_SVE_CONTEXT_SIZE(vq) \
163 (AARCH64_SVE_CONTEXT_FFR_OFFSET (vq) + (vq * 2))
166 /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the
167 size, or return 0 on error. */
170 read_aarch64_ctx (CORE_ADDR ctx_addr, enum bfd_endian byte_order,
176 if (target_read_memory (ctx_addr, buf, 4) != 0)
178 magic = extract_unsigned_integer (buf, 4, byte_order);
180 if (target_read_memory (ctx_addr + 4, buf, 4) != 0)
182 *size = extract_unsigned_integer (buf, 4, byte_order);
187 /* Implement the "init" method of struct tramp_frame. */
190 aarch64_linux_sigframe_init (const struct tramp_frame *self,
191 struct frame_info *this_frame,
192 struct trad_frame_cache *this_cache,
195 struct gdbarch *gdbarch = get_frame_arch (this_frame);
196 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
197 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
198 CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
199 CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
200 + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
201 CORE_ADDR section = sigcontext_addr + AARCH64_SIGCONTEXT_RESERVED_OFFSET;
202 CORE_ADDR section_end = section + AARCH64_SIGCONTEXT_RESERVED_SIZE;
203 CORE_ADDR fpsimd = 0;
204 CORE_ADDR sve_regs = 0;
205 uint32_t size, magic;
206 bool extra_found = false;
207 int num_regs = gdbarch_num_regs (gdbarch);
209 /* Read in the integer registers. */
211 for (int i = 0; i < 31; i++)
213 trad_frame_set_reg_addr (this_cache,
214 AARCH64_X0_REGNUM + i,
215 sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
216 + i * AARCH64_SIGCONTEXT_REG_SIZE);
218 trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM,
219 sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
220 + 31 * AARCH64_SIGCONTEXT_REG_SIZE);
221 trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM,
222 sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
223 + 32 * AARCH64_SIGCONTEXT_REG_SIZE);
225 /* Search for the FP and SVE sections, stopping at null. */
226 while ((magic = read_aarch64_ctx (section, byte_order, &size)) != 0
231 case AARCH64_FPSIMD_MAGIC:
236 case AARCH64_SVE_MAGIC:
238 /* Check if the section is followed by a full SVE dump, and set
239 sve_regs if it is. */
243 if (!tdep->has_sve ())
246 if (target_read_memory (section + AARCH64_SVE_CONTEXT_VL_OFFSET,
252 vq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, byte_order));
255 error (_("Invalid vector length in signal frame %d vs %s."), vq,
256 pulongest (tdep->vq));
258 if (size >= AARCH64_SVE_CONTEXT_SIZE (vq))
259 sve_regs = section + AARCH64_SVE_CONTEXT_REGS_OFFSET;
265 case AARCH64_EXTRA_MAGIC:
267 /* Extra is always the last valid section in reserved and points to
268 an additional block of memory filled with more sections. Reset
269 the address to the extra section and continue looking for more
273 if (target_read_memory (section + AARCH64_EXTRA_DATAP_OFFSET,
280 section = extract_unsigned_integer (buf, 8, byte_order);
290 /* Prevent searching past the end of the reserved section. The extra
291 section does not have a hard coded limit - we have to rely on it ending
293 if (!extra_found && section > section_end)
301 for (int i = 0; i < 32; i++)
303 offset = sve_regs + (i * tdep->vq * 16);
304 trad_frame_set_reg_addr (this_cache, AARCH64_SVE_Z0_REGNUM + i,
306 trad_frame_set_reg_addr (this_cache,
307 num_regs + AARCH64_SVE_V0_REGNUM + i,
309 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_Q0_REGNUM + i,
311 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_D0_REGNUM + i,
313 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_S0_REGNUM + i,
315 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_H0_REGNUM + i,
317 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_B0_REGNUM + i,
321 offset = sve_regs + AARCH64_SVE_CONTEXT_P_REGS_OFFSET (tdep->vq);
322 for (int i = 0; i < 16; i++)
323 trad_frame_set_reg_addr (this_cache, AARCH64_SVE_P0_REGNUM + i,
324 offset + (i * tdep->vq * 2));
326 offset = sve_regs + AARCH64_SVE_CONTEXT_FFR_OFFSET (tdep->vq);
327 trad_frame_set_reg_addr (this_cache, AARCH64_SVE_FFR_REGNUM, offset);
332 trad_frame_set_reg_addr (this_cache, AARCH64_FPSR_REGNUM,
333 fpsimd + AARCH64_FPSIMD_FPSR_OFFSET);
334 trad_frame_set_reg_addr (this_cache, AARCH64_FPCR_REGNUM,
335 fpsimd + AARCH64_FPSIMD_FPCR_OFFSET);
337 /* If there was no SVE section then set up the V registers. */
339 for (int i = 0; i < 32; i++)
341 CORE_ADDR offset = (fpsimd + AARCH64_FPSIMD_V0_OFFSET
342 + (i * AARCH64_FPSIMD_VREG_SIZE));
344 trad_frame_set_reg_addr (this_cache, AARCH64_V0_REGNUM + i, offset);
345 trad_frame_set_reg_addr (this_cache,
346 num_regs + AARCH64_Q0_REGNUM + i, offset);
347 trad_frame_set_reg_addr (this_cache,
348 num_regs + AARCH64_D0_REGNUM + i, offset);
349 trad_frame_set_reg_addr (this_cache,
350 num_regs + AARCH64_S0_REGNUM + i, offset);
351 trad_frame_set_reg_addr (this_cache,
352 num_regs + AARCH64_H0_REGNUM + i, offset);
353 trad_frame_set_reg_addr (this_cache,
354 num_regs + AARCH64_B0_REGNUM + i, offset);
355 if (tdep->has_sve ())
356 trad_frame_set_reg_addr (this_cache,
357 num_regs + AARCH64_SVE_V0_REGNUM + i,
362 trad_frame_set_id (this_cache, frame_id_build (sp, func));
365 static const struct tramp_frame aarch64_linux_rt_sigframe =
370 /* movz x8, 0x8b (S=1,o=10,h=0,i=0x8b,r=8)
371 Soo1 0010 1hhi iiii iiii iiii iiir rrrr */
372 {0xd2801168, ULONGEST_MAX},
374 /* svc 0x0 (o=0, l=1)
375 1101 0100 oooi iiii iiii iiii iii0 00ll */
376 {0xd4000001, ULONGEST_MAX},
377 {TRAMP_SENTINEL_INSN, ULONGEST_MAX}
379 aarch64_linux_sigframe_init
384 static const struct regcache_map_entry aarch64_linux_gregmap[] =
386 { 31, AARCH64_X0_REGNUM, 8 }, /* x0 ... x30 */
387 { 1, AARCH64_SP_REGNUM, 8 },
388 { 1, AARCH64_PC_REGNUM, 8 },
389 { 1, AARCH64_CPSR_REGNUM, 8 },
393 static const struct regcache_map_entry aarch64_linux_fpregmap[] =
395 { 32, AARCH64_V0_REGNUM, 16 }, /* v0 ... v31 */
396 { 1, AARCH64_FPSR_REGNUM, 4 },
397 { 1, AARCH64_FPCR_REGNUM, 4 },
401 /* Register set definitions. */
403 const struct regset aarch64_linux_gregset =
405 aarch64_linux_gregmap,
406 regcache_supply_regset, regcache_collect_regset
409 const struct regset aarch64_linux_fpregset =
411 aarch64_linux_fpregmap,
412 regcache_supply_regset, regcache_collect_regset
415 /* The fields in an SVE header at the start of a SVE regset. */
417 #define SVE_HEADER_SIZE_LENGTH 4
418 #define SVE_HEADER_MAX_SIZE_LENGTH 4
419 #define SVE_HEADER_VL_LENGTH 2
420 #define SVE_HEADER_MAX_VL_LENGTH 2
421 #define SVE_HEADER_FLAGS_LENGTH 2
422 #define SVE_HEADER_RESERVED_LENGTH 2
424 #define SVE_HEADER_SIZE_OFFSET 0
425 #define SVE_HEADER_MAX_SIZE_OFFSET \
426 (SVE_HEADER_SIZE_OFFSET + SVE_HEADER_SIZE_LENGTH)
427 #define SVE_HEADER_VL_OFFSET \
428 (SVE_HEADER_MAX_SIZE_OFFSET + SVE_HEADER_MAX_SIZE_LENGTH)
429 #define SVE_HEADER_MAX_VL_OFFSET \
430 (SVE_HEADER_VL_OFFSET + SVE_HEADER_VL_LENGTH)
431 #define SVE_HEADER_FLAGS_OFFSET \
432 (SVE_HEADER_MAX_VL_OFFSET + SVE_HEADER_MAX_VL_LENGTH)
433 #define SVE_HEADER_RESERVED_OFFSET \
434 (SVE_HEADER_FLAGS_OFFSET + SVE_HEADER_FLAGS_LENGTH)
435 #define SVE_HEADER_SIZE \
436 (SVE_HEADER_RESERVED_OFFSET + SVE_HEADER_RESERVED_LENGTH)
438 #define SVE_HEADER_FLAG_SVE 1
440 /* Get VQ value from SVE section in the core dump. */
443 aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd)
445 gdb_byte header[SVE_HEADER_SIZE];
446 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
447 asection *sve_section = bfd_get_section_by_name (abfd, ".reg-aarch-sve");
449 if (sve_section == nullptr)
455 size_t size = bfd_section_size (abfd, sve_section);
457 /* Check extended state size. */
458 if (size < SVE_HEADER_SIZE)
460 warning (_("'.reg-aarch-sve' section in core file too small."));
464 if (!bfd_get_section_contents (abfd, sve_section, header, 0, SVE_HEADER_SIZE))
466 warning (_("Couldn't read sve header from "
467 "'.reg-aarch-sve' section in core file."));
471 uint64_t vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET,
472 SVE_HEADER_VL_LENGTH, byte_order);
473 uint64_t vq = sve_vq_from_vl (vl);
475 if (vq > AARCH64_MAX_SVE_VQ)
477 warning (_("SVE Vector length in core file not supported by this version"
478 " of GDB. (VQ=%s)"), pulongest (vq));
483 warning (_("SVE Vector length in core file is invalid. (VQ=%s"),
491 /* Supply register REGNUM from BUF to REGCACHE, using the register map
492 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
493 If BUF is NULL, set the registers to "unavailable" status. */
496 aarch64_linux_supply_sve_regset (const struct regset *regset,
497 struct regcache *regcache,
498 int regnum, const void *buf, size_t size)
500 gdb_byte *header = (gdb_byte *) buf;
501 struct gdbarch *gdbarch = regcache->arch ();
502 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
505 return regcache->supply_regset (regset, regnum, nullptr, size);
506 gdb_assert (size > SVE_HEADER_SIZE);
508 /* BUF contains an SVE header followed by a register dump of either the
509 passed in SVE regset or a NEON fpregset. */
511 /* Extract required fields from the header. */
512 ULONGEST vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET,
513 SVE_HEADER_VL_LENGTH, byte_order);
514 uint16_t flags = extract_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET,
515 SVE_HEADER_FLAGS_LENGTH,
518 if (regnum == -1 || regnum == AARCH64_SVE_VG_REGNUM)
520 gdb_byte vg_target[8];
521 store_integer ((gdb_byte *)&vg_target, sizeof (uint64_t), byte_order,
522 sve_vg_from_vl (vl));
523 regcache->raw_supply (AARCH64_SVE_VG_REGNUM, &vg_target);
526 if (flags & SVE_HEADER_FLAG_SVE)
528 /* Register dump is a SVE structure. */
529 regcache->supply_regset (regset, regnum,
530 (gdb_byte *) buf + SVE_HEADER_SIZE,
531 size - SVE_HEADER_SIZE);
535 /* Register dump is a fpsimd structure. First clear the SVE
537 for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++)
538 regcache->raw_supply_zeroed (AARCH64_SVE_Z0_REGNUM + i);
539 for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++)
540 regcache->raw_supply_zeroed (AARCH64_SVE_P0_REGNUM + i);
541 regcache->raw_supply_zeroed (AARCH64_SVE_FFR_REGNUM);
543 /* Then supply the fpsimd registers. */
544 regcache->supply_regset (&aarch64_linux_fpregset, regnum,
545 (gdb_byte *) buf + SVE_HEADER_SIZE,
546 size - SVE_HEADER_SIZE);
550 /* Collect register REGNUM from REGCACHE to BUF, using the register
551 map in REGSET. If REGNUM is -1, do this for all registers in
555 aarch64_linux_collect_sve_regset (const struct regset *regset,
556 const struct regcache *regcache,
557 int regnum, void *buf, size_t size)
559 gdb_byte *header = (gdb_byte *) buf;
560 struct gdbarch *gdbarch = regcache->arch ();
561 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
562 uint64_t vq = gdbarch_tdep (gdbarch)->vq;
564 gdb_assert (buf != NULL);
565 gdb_assert (size > SVE_HEADER_SIZE);
567 /* BUF starts with a SVE header prior to the register dump. */
569 store_unsigned_integer (header + SVE_HEADER_SIZE_OFFSET,
570 SVE_HEADER_SIZE_LENGTH, byte_order, size);
571 store_unsigned_integer (header + SVE_HEADER_MAX_SIZE_OFFSET,
572 SVE_HEADER_MAX_SIZE_LENGTH, byte_order, size);
573 store_unsigned_integer (header + SVE_HEADER_VL_OFFSET, SVE_HEADER_VL_LENGTH,
574 byte_order, sve_vl_from_vq (vq));
575 store_unsigned_integer (header + SVE_HEADER_MAX_VL_OFFSET,
576 SVE_HEADER_MAX_VL_LENGTH, byte_order,
577 sve_vl_from_vq (vq));
578 store_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET,
579 SVE_HEADER_FLAGS_LENGTH, byte_order,
580 SVE_HEADER_FLAG_SVE);
581 store_unsigned_integer (header + SVE_HEADER_RESERVED_OFFSET,
582 SVE_HEADER_RESERVED_LENGTH, byte_order, 0);
584 /* The SVE register dump follows. */
585 regcache->collect_regset (regset, regnum, (gdb_byte *) buf + SVE_HEADER_SIZE,
586 size - SVE_HEADER_SIZE);
589 /* Implement the "regset_from_core_section" gdbarch method. */
592 aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
593 iterate_over_regset_sections_cb *cb,
595 const struct regcache *regcache)
597 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
599 cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
600 &aarch64_linux_gregset, NULL, cb_data);
602 if (tdep->has_sve ())
604 /* Create this on the fly in order to handle vector register sizes. */
605 const struct regcache_map_entry sve_regmap[] =
607 { 32, AARCH64_SVE_Z0_REGNUM, (int) (tdep->vq * 16) },
608 { 16, AARCH64_SVE_P0_REGNUM, (int) (tdep->vq * 16 / 8) },
609 { 1, AARCH64_SVE_FFR_REGNUM, 4 },
610 { 1, AARCH64_FPSR_REGNUM, 4 },
611 { 1, AARCH64_FPCR_REGNUM, 4 },
615 const struct regset aarch64_linux_sve_regset =
618 aarch64_linux_supply_sve_regset, aarch64_linux_collect_sve_regset,
622 cb (".reg-aarch-sve",
623 SVE_HEADER_SIZE + regcache_map_entry_size (aarch64_linux_fpregmap),
624 SVE_HEADER_SIZE + regcache_map_entry_size (sve_regmap),
625 &aarch64_linux_sve_regset, "SVE registers", cb_data);
628 cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET, AARCH64_LINUX_SIZEOF_FPREGSET,
629 &aarch64_linux_fpregset, NULL, cb_data);
632 if (tdep->has_pauth ())
634 /* Create this on the fly in order to handle the variable location. */
635 const struct regcache_map_entry pauth_regmap[] =
637 { 2, AARCH64_PAUTH_DMASK_REGNUM (tdep->pauth_reg_base), 8},
641 const struct regset aarch64_linux_pauth_regset =
643 pauth_regmap, regcache_supply_regset, regcache_collect_regset
646 cb (".reg-aarch-pauth", AARCH64_LINUX_SIZEOF_PAUTH,
647 AARCH64_LINUX_SIZEOF_PAUTH, &aarch64_linux_pauth_regset,
648 "pauth registers", cb_data);
652 /* Implement the "core_read_description" gdbarch method. */
654 static const struct target_desc *
655 aarch64_linux_core_read_description (struct gdbarch *gdbarch,
656 struct target_ops *target, bfd *abfd)
658 CORE_ADDR hwcap = linux_get_hwcap (target);
660 return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd),
661 hwcap & AARCH64_HWCAP_PACA);
664 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
668 aarch64_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
670 return (*s == '#' || isdigit (*s) /* Literal number. */
671 || *s == '[' /* Register indirection. */
672 || isalpha (*s)); /* Register value. */
675 /* This routine is used to parse a special token in AArch64's assembly.
677 The special tokens parsed by it are:
679 - Register displacement (e.g, [fp, #-8])
681 It returns one if the special token has been parsed successfully,
682 or zero if the current token is not considered special. */
685 aarch64_stap_parse_special_token (struct gdbarch *gdbarch,
686 struct stap_parse_info *p)
690 /* Temporary holder for lookahead. */
691 const char *tmp = p->arg;
693 /* Used to save the register name. */
705 while (isalnum (*tmp))
712 regname = (char *) alloca (len + 2);
714 strncpy (regname, start, len);
717 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
718 error (_("Invalid register name `%s' on expression `%s'."),
719 regname, p->saved_arg);
722 tmp = skip_spaces (tmp);
723 /* Now we expect a number. It can begin with '#' or simply
733 else if (*tmp == '+')
739 displacement = strtol (tmp, &endp, 10);
742 /* Skipping last `]'. */
746 /* The displacement. */
747 write_exp_elt_opcode (&p->pstate, OP_LONG);
748 write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long);
749 write_exp_elt_longcst (&p->pstate, displacement);
750 write_exp_elt_opcode (&p->pstate, OP_LONG);
752 write_exp_elt_opcode (&p->pstate, UNOP_NEG);
754 /* The register name. */
755 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
758 write_exp_string (&p->pstate, str);
759 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
761 write_exp_elt_opcode (&p->pstate, BINOP_ADD);
763 /* Casting to the expected type. */
764 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
765 write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type));
766 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
768 write_exp_elt_opcode (&p->pstate, UNOP_IND);
778 /* AArch64 process record-replay constructs: syscall, signal etc. */
780 struct linux_record_tdep aarch64_linux_record_tdep;
782 /* Enum that defines the AArch64 linux specific syscall identifiers used for
783 process record/replay. */
785 enum aarch64_syscall {
786 aarch64_sys_io_setup = 0,
787 aarch64_sys_io_destroy = 1,
788 aarch64_sys_io_submit = 2,
789 aarch64_sys_io_cancel = 3,
790 aarch64_sys_io_getevents = 4,
791 aarch64_sys_setxattr = 5,
792 aarch64_sys_lsetxattr = 6,
793 aarch64_sys_fsetxattr = 7,
794 aarch64_sys_getxattr = 8,
795 aarch64_sys_lgetxattr = 9,
796 aarch64_sys_fgetxattr = 10,
797 aarch64_sys_listxattr = 11,
798 aarch64_sys_llistxattr = 12,
799 aarch64_sys_flistxattr = 13,
800 aarch64_sys_removexattr = 14,
801 aarch64_sys_lremovexattr = 15,
802 aarch64_sys_fremovexattr = 16,
803 aarch64_sys_getcwd = 17,
804 aarch64_sys_lookup_dcookie = 18,
805 aarch64_sys_eventfd2 = 19,
806 aarch64_sys_epoll_create1 = 20,
807 aarch64_sys_epoll_ctl = 21,
808 aarch64_sys_epoll_pwait = 22,
809 aarch64_sys_dup = 23,
810 aarch64_sys_dup3 = 24,
811 aarch64_sys_fcntl = 25,
812 aarch64_sys_inotify_init1 = 26,
813 aarch64_sys_inotify_add_watch = 27,
814 aarch64_sys_inotify_rm_watch = 28,
815 aarch64_sys_ioctl = 29,
816 aarch64_sys_ioprio_set = 30,
817 aarch64_sys_ioprio_get = 31,
818 aarch64_sys_flock = 32,
819 aarch64_sys_mknodat = 33,
820 aarch64_sys_mkdirat = 34,
821 aarch64_sys_unlinkat = 35,
822 aarch64_sys_symlinkat = 36,
823 aarch64_sys_linkat = 37,
824 aarch64_sys_renameat = 38,
825 aarch64_sys_umount2 = 39,
826 aarch64_sys_mount = 40,
827 aarch64_sys_pivot_root = 41,
828 aarch64_sys_nfsservctl = 42,
829 aarch64_sys_statfs = 43,
830 aarch64_sys_fstatfs = 44,
831 aarch64_sys_truncate = 45,
832 aarch64_sys_ftruncate = 46,
833 aarch64_sys_fallocate = 47,
834 aarch64_sys_faccessat = 48,
835 aarch64_sys_chdir = 49,
836 aarch64_sys_fchdir = 50,
837 aarch64_sys_chroot = 51,
838 aarch64_sys_fchmod = 52,
839 aarch64_sys_fchmodat = 53,
840 aarch64_sys_fchownat = 54,
841 aarch64_sys_fchown = 55,
842 aarch64_sys_openat = 56,
843 aarch64_sys_close = 57,
844 aarch64_sys_vhangup = 58,
845 aarch64_sys_pipe2 = 59,
846 aarch64_sys_quotactl = 60,
847 aarch64_sys_getdents64 = 61,
848 aarch64_sys_lseek = 62,
849 aarch64_sys_read = 63,
850 aarch64_sys_write = 64,
851 aarch64_sys_readv = 65,
852 aarch64_sys_writev = 66,
853 aarch64_sys_pread64 = 67,
854 aarch64_sys_pwrite64 = 68,
855 aarch64_sys_preadv = 69,
856 aarch64_sys_pwritev = 70,
857 aarch64_sys_sendfile = 71,
858 aarch64_sys_pselect6 = 72,
859 aarch64_sys_ppoll = 73,
860 aarch64_sys_signalfd4 = 74,
861 aarch64_sys_vmsplice = 75,
862 aarch64_sys_splice = 76,
863 aarch64_sys_tee = 77,
864 aarch64_sys_readlinkat = 78,
865 aarch64_sys_newfstatat = 79,
866 aarch64_sys_fstat = 80,
867 aarch64_sys_sync = 81,
868 aarch64_sys_fsync = 82,
869 aarch64_sys_fdatasync = 83,
870 aarch64_sys_sync_file_range2 = 84,
871 aarch64_sys_sync_file_range = 84,
872 aarch64_sys_timerfd_create = 85,
873 aarch64_sys_timerfd_settime = 86,
874 aarch64_sys_timerfd_gettime = 87,
875 aarch64_sys_utimensat = 88,
876 aarch64_sys_acct = 89,
877 aarch64_sys_capget = 90,
878 aarch64_sys_capset = 91,
879 aarch64_sys_personality = 92,
880 aarch64_sys_exit = 93,
881 aarch64_sys_exit_group = 94,
882 aarch64_sys_waitid = 95,
883 aarch64_sys_set_tid_address = 96,
884 aarch64_sys_unshare = 97,
885 aarch64_sys_futex = 98,
886 aarch64_sys_set_robust_list = 99,
887 aarch64_sys_get_robust_list = 100,
888 aarch64_sys_nanosleep = 101,
889 aarch64_sys_getitimer = 102,
890 aarch64_sys_setitimer = 103,
891 aarch64_sys_kexec_load = 104,
892 aarch64_sys_init_module = 105,
893 aarch64_sys_delete_module = 106,
894 aarch64_sys_timer_create = 107,
895 aarch64_sys_timer_gettime = 108,
896 aarch64_sys_timer_getoverrun = 109,
897 aarch64_sys_timer_settime = 110,
898 aarch64_sys_timer_delete = 111,
899 aarch64_sys_clock_settime = 112,
900 aarch64_sys_clock_gettime = 113,
901 aarch64_sys_clock_getres = 114,
902 aarch64_sys_clock_nanosleep = 115,
903 aarch64_sys_syslog = 116,
904 aarch64_sys_ptrace = 117,
905 aarch64_sys_sched_setparam = 118,
906 aarch64_sys_sched_setscheduler = 119,
907 aarch64_sys_sched_getscheduler = 120,
908 aarch64_sys_sched_getparam = 121,
909 aarch64_sys_sched_setaffinity = 122,
910 aarch64_sys_sched_getaffinity = 123,
911 aarch64_sys_sched_yield = 124,
912 aarch64_sys_sched_get_priority_max = 125,
913 aarch64_sys_sched_get_priority_min = 126,
914 aarch64_sys_sched_rr_get_interval = 127,
915 aarch64_sys_kill = 129,
916 aarch64_sys_tkill = 130,
917 aarch64_sys_tgkill = 131,
918 aarch64_sys_sigaltstack = 132,
919 aarch64_sys_rt_sigsuspend = 133,
920 aarch64_sys_rt_sigaction = 134,
921 aarch64_sys_rt_sigprocmask = 135,
922 aarch64_sys_rt_sigpending = 136,
923 aarch64_sys_rt_sigtimedwait = 137,
924 aarch64_sys_rt_sigqueueinfo = 138,
925 aarch64_sys_rt_sigreturn = 139,
926 aarch64_sys_setpriority = 140,
927 aarch64_sys_getpriority = 141,
928 aarch64_sys_reboot = 142,
929 aarch64_sys_setregid = 143,
930 aarch64_sys_setgid = 144,
931 aarch64_sys_setreuid = 145,
932 aarch64_sys_setuid = 146,
933 aarch64_sys_setresuid = 147,
934 aarch64_sys_getresuid = 148,
935 aarch64_sys_setresgid = 149,
936 aarch64_sys_getresgid = 150,
937 aarch64_sys_setfsuid = 151,
938 aarch64_sys_setfsgid = 152,
939 aarch64_sys_times = 153,
940 aarch64_sys_setpgid = 154,
941 aarch64_sys_getpgid = 155,
942 aarch64_sys_getsid = 156,
943 aarch64_sys_setsid = 157,
944 aarch64_sys_getgroups = 158,
945 aarch64_sys_setgroups = 159,
946 aarch64_sys_uname = 160,
947 aarch64_sys_sethostname = 161,
948 aarch64_sys_setdomainname = 162,
949 aarch64_sys_getrlimit = 163,
950 aarch64_sys_setrlimit = 164,
951 aarch64_sys_getrusage = 165,
952 aarch64_sys_umask = 166,
953 aarch64_sys_prctl = 167,
954 aarch64_sys_getcpu = 168,
955 aarch64_sys_gettimeofday = 169,
956 aarch64_sys_settimeofday = 170,
957 aarch64_sys_adjtimex = 171,
958 aarch64_sys_getpid = 172,
959 aarch64_sys_getppid = 173,
960 aarch64_sys_getuid = 174,
961 aarch64_sys_geteuid = 175,
962 aarch64_sys_getgid = 176,
963 aarch64_sys_getegid = 177,
964 aarch64_sys_gettid = 178,
965 aarch64_sys_sysinfo = 179,
966 aarch64_sys_mq_open = 180,
967 aarch64_sys_mq_unlink = 181,
968 aarch64_sys_mq_timedsend = 182,
969 aarch64_sys_mq_timedreceive = 183,
970 aarch64_sys_mq_notify = 184,
971 aarch64_sys_mq_getsetattr = 185,
972 aarch64_sys_msgget = 186,
973 aarch64_sys_msgctl = 187,
974 aarch64_sys_msgrcv = 188,
975 aarch64_sys_msgsnd = 189,
976 aarch64_sys_semget = 190,
977 aarch64_sys_semctl = 191,
978 aarch64_sys_semtimedop = 192,
979 aarch64_sys_semop = 193,
980 aarch64_sys_shmget = 194,
981 aarch64_sys_shmctl = 195,
982 aarch64_sys_shmat = 196,
983 aarch64_sys_shmdt = 197,
984 aarch64_sys_socket = 198,
985 aarch64_sys_socketpair = 199,
986 aarch64_sys_bind = 200,
987 aarch64_sys_listen = 201,
988 aarch64_sys_accept = 202,
989 aarch64_sys_connect = 203,
990 aarch64_sys_getsockname = 204,
991 aarch64_sys_getpeername = 205,
992 aarch64_sys_sendto = 206,
993 aarch64_sys_recvfrom = 207,
994 aarch64_sys_setsockopt = 208,
995 aarch64_sys_getsockopt = 209,
996 aarch64_sys_shutdown = 210,
997 aarch64_sys_sendmsg = 211,
998 aarch64_sys_recvmsg = 212,
999 aarch64_sys_readahead = 213,
1000 aarch64_sys_brk = 214,
1001 aarch64_sys_munmap = 215,
1002 aarch64_sys_mremap = 216,
1003 aarch64_sys_add_key = 217,
1004 aarch64_sys_request_key = 218,
1005 aarch64_sys_keyctl = 219,
1006 aarch64_sys_clone = 220,
1007 aarch64_sys_execve = 221,
1008 aarch64_sys_mmap = 222,
1009 aarch64_sys_fadvise64 = 223,
1010 aarch64_sys_swapon = 224,
1011 aarch64_sys_swapoff = 225,
1012 aarch64_sys_mprotect = 226,
1013 aarch64_sys_msync = 227,
1014 aarch64_sys_mlock = 228,
1015 aarch64_sys_munlock = 229,
1016 aarch64_sys_mlockall = 230,
1017 aarch64_sys_munlockall = 231,
1018 aarch64_sys_mincore = 232,
1019 aarch64_sys_madvise = 233,
1020 aarch64_sys_remap_file_pages = 234,
1021 aarch64_sys_mbind = 235,
1022 aarch64_sys_get_mempolicy = 236,
1023 aarch64_sys_set_mempolicy = 237,
1024 aarch64_sys_migrate_pages = 238,
1025 aarch64_sys_move_pages = 239,
1026 aarch64_sys_rt_tgsigqueueinfo = 240,
1027 aarch64_sys_perf_event_open = 241,
1028 aarch64_sys_accept4 = 242,
1029 aarch64_sys_recvmmsg = 243,
1030 aarch64_sys_wait4 = 260,
1031 aarch64_sys_prlimit64 = 261,
1032 aarch64_sys_fanotify_init = 262,
1033 aarch64_sys_fanotify_mark = 263,
1034 aarch64_sys_name_to_handle_at = 264,
1035 aarch64_sys_open_by_handle_at = 265,
1036 aarch64_sys_clock_adjtime = 266,
1037 aarch64_sys_syncfs = 267,
1038 aarch64_sys_setns = 268,
1039 aarch64_sys_sendmmsg = 269,
1040 aarch64_sys_process_vm_readv = 270,
1041 aarch64_sys_process_vm_writev = 271,
1042 aarch64_sys_kcmp = 272,
1043 aarch64_sys_finit_module = 273,
1044 aarch64_sys_sched_setattr = 274,
1045 aarch64_sys_sched_getattr = 275,
1048 /* aarch64_canonicalize_syscall maps syscall ids from the native AArch64
1049 linux set of syscall ids into a canonical set of syscall ids used by
1052 static enum gdb_syscall
1053 aarch64_canonicalize_syscall (enum aarch64_syscall syscall_number)
1055 #define SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
1056 return gdb_sys_##SYSCALL
1058 #define UNSUPPORTED_SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
1059 return gdb_sys_no_syscall
1061 switch (syscall_number)
1063 SYSCALL_MAP (io_setup);
1064 SYSCALL_MAP (io_destroy);
1065 SYSCALL_MAP (io_submit);
1066 SYSCALL_MAP (io_cancel);
1067 SYSCALL_MAP (io_getevents);
1069 SYSCALL_MAP (setxattr);
1070 SYSCALL_MAP (lsetxattr);
1071 SYSCALL_MAP (fsetxattr);
1072 SYSCALL_MAP (getxattr);
1073 SYSCALL_MAP (lgetxattr);
1074 SYSCALL_MAP (fgetxattr);
1075 SYSCALL_MAP (listxattr);
1076 SYSCALL_MAP (llistxattr);
1077 SYSCALL_MAP (flistxattr);
1078 SYSCALL_MAP (removexattr);
1079 SYSCALL_MAP (lremovexattr);
1080 SYSCALL_MAP (fremovexattr);
1081 SYSCALL_MAP (getcwd);
1082 SYSCALL_MAP (lookup_dcookie);
1083 SYSCALL_MAP (eventfd2);
1084 SYSCALL_MAP (epoll_create1);
1085 SYSCALL_MAP (epoll_ctl);
1086 SYSCALL_MAP (epoll_pwait);
1089 SYSCALL_MAP (fcntl);
1090 SYSCALL_MAP (inotify_init1);
1091 SYSCALL_MAP (inotify_add_watch);
1092 SYSCALL_MAP (inotify_rm_watch);
1093 SYSCALL_MAP (ioctl);
1094 SYSCALL_MAP (ioprio_set);
1095 SYSCALL_MAP (ioprio_get);
1096 SYSCALL_MAP (flock);
1097 SYSCALL_MAP (mknodat);
1098 SYSCALL_MAP (mkdirat);
1099 SYSCALL_MAP (unlinkat);
1100 SYSCALL_MAP (symlinkat);
1101 SYSCALL_MAP (linkat);
1102 SYSCALL_MAP (renameat);
1103 UNSUPPORTED_SYSCALL_MAP (umount2);
1104 SYSCALL_MAP (mount);
1105 SYSCALL_MAP (pivot_root);
1106 SYSCALL_MAP (nfsservctl);
1107 SYSCALL_MAP (statfs);
1108 SYSCALL_MAP (truncate);
1109 SYSCALL_MAP (ftruncate);
1110 SYSCALL_MAP (fallocate);
1111 SYSCALL_MAP (faccessat);
1112 SYSCALL_MAP (fchdir);
1113 SYSCALL_MAP (chroot);
1114 SYSCALL_MAP (fchmod);
1115 SYSCALL_MAP (fchmodat);
1116 SYSCALL_MAP (fchownat);
1117 SYSCALL_MAP (fchown);
1118 SYSCALL_MAP (openat);
1119 SYSCALL_MAP (close);
1120 SYSCALL_MAP (vhangup);
1121 SYSCALL_MAP (pipe2);
1122 SYSCALL_MAP (quotactl);
1123 SYSCALL_MAP (getdents64);
1124 SYSCALL_MAP (lseek);
1126 SYSCALL_MAP (write);
1127 SYSCALL_MAP (readv);
1128 SYSCALL_MAP (writev);
1129 SYSCALL_MAP (pread64);
1130 SYSCALL_MAP (pwrite64);
1131 UNSUPPORTED_SYSCALL_MAP (preadv);
1132 UNSUPPORTED_SYSCALL_MAP (pwritev);
1133 SYSCALL_MAP (sendfile);
1134 SYSCALL_MAP (pselect6);
1135 SYSCALL_MAP (ppoll);
1136 UNSUPPORTED_SYSCALL_MAP (signalfd4);
1137 SYSCALL_MAP (vmsplice);
1138 SYSCALL_MAP (splice);
1140 SYSCALL_MAP (readlinkat);
1141 SYSCALL_MAP (newfstatat);
1143 SYSCALL_MAP (fstat);
1145 SYSCALL_MAP (fsync);
1146 SYSCALL_MAP (fdatasync);
1147 SYSCALL_MAP (sync_file_range);
1148 UNSUPPORTED_SYSCALL_MAP (timerfd_create);
1149 UNSUPPORTED_SYSCALL_MAP (timerfd_settime);
1150 UNSUPPORTED_SYSCALL_MAP (timerfd_gettime);
1151 UNSUPPORTED_SYSCALL_MAP (utimensat);
1153 SYSCALL_MAP (capget);
1154 SYSCALL_MAP (capset);
1155 SYSCALL_MAP (personality);
1157 SYSCALL_MAP (exit_group);
1158 SYSCALL_MAP (waitid);
1159 SYSCALL_MAP (set_tid_address);
1160 SYSCALL_MAP (unshare);
1161 SYSCALL_MAP (futex);
1162 SYSCALL_MAP (set_robust_list);
1163 SYSCALL_MAP (get_robust_list);
1164 SYSCALL_MAP (nanosleep);
1166 SYSCALL_MAP (getitimer);
1167 SYSCALL_MAP (setitimer);
1168 SYSCALL_MAP (kexec_load);
1169 SYSCALL_MAP (init_module);
1170 SYSCALL_MAP (delete_module);
1171 SYSCALL_MAP (timer_create);
1172 SYSCALL_MAP (timer_settime);
1173 SYSCALL_MAP (timer_gettime);
1174 SYSCALL_MAP (timer_getoverrun);
1175 SYSCALL_MAP (timer_delete);
1176 SYSCALL_MAP (clock_settime);
1177 SYSCALL_MAP (clock_gettime);
1178 SYSCALL_MAP (clock_getres);
1179 SYSCALL_MAP (clock_nanosleep);
1180 SYSCALL_MAP (syslog);
1181 SYSCALL_MAP (ptrace);
1182 SYSCALL_MAP (sched_setparam);
1183 SYSCALL_MAP (sched_setscheduler);
1184 SYSCALL_MAP (sched_getscheduler);
1185 SYSCALL_MAP (sched_getparam);
1186 SYSCALL_MAP (sched_setaffinity);
1187 SYSCALL_MAP (sched_getaffinity);
1188 SYSCALL_MAP (sched_yield);
1189 SYSCALL_MAP (sched_get_priority_max);
1190 SYSCALL_MAP (sched_get_priority_min);
1191 SYSCALL_MAP (sched_rr_get_interval);
1193 SYSCALL_MAP (tkill);
1194 SYSCALL_MAP (tgkill);
1195 SYSCALL_MAP (sigaltstack);
1196 SYSCALL_MAP (rt_sigsuspend);
1197 SYSCALL_MAP (rt_sigaction);
1198 SYSCALL_MAP (rt_sigprocmask);
1199 SYSCALL_MAP (rt_sigpending);
1200 SYSCALL_MAP (rt_sigtimedwait);
1201 SYSCALL_MAP (rt_sigqueueinfo);
1202 SYSCALL_MAP (rt_sigreturn);
1203 SYSCALL_MAP (setpriority);
1204 SYSCALL_MAP (getpriority);
1205 SYSCALL_MAP (reboot);
1206 SYSCALL_MAP (setregid);
1207 SYSCALL_MAP (setgid);
1208 SYSCALL_MAP (setreuid);
1209 SYSCALL_MAP (setuid);
1210 SYSCALL_MAP (setresuid);
1211 SYSCALL_MAP (getresuid);
1212 SYSCALL_MAP (setresgid);
1213 SYSCALL_MAP (getresgid);
1214 SYSCALL_MAP (setfsuid);
1215 SYSCALL_MAP (setfsgid);
1216 SYSCALL_MAP (times);
1217 SYSCALL_MAP (setpgid);
1218 SYSCALL_MAP (getpgid);
1219 SYSCALL_MAP (getsid);
1220 SYSCALL_MAP (setsid);
1221 SYSCALL_MAP (getgroups);
1222 SYSCALL_MAP (setgroups);
1223 SYSCALL_MAP (uname);
1224 SYSCALL_MAP (sethostname);
1225 SYSCALL_MAP (setdomainname);
1226 SYSCALL_MAP (getrlimit);
1227 SYSCALL_MAP (setrlimit);
1228 SYSCALL_MAP (getrusage);
1229 SYSCALL_MAP (umask);
1230 SYSCALL_MAP (prctl);
1231 SYSCALL_MAP (getcpu);
1232 SYSCALL_MAP (gettimeofday);
1233 SYSCALL_MAP (settimeofday);
1234 SYSCALL_MAP (adjtimex);
1235 SYSCALL_MAP (getpid);
1236 SYSCALL_MAP (getppid);
1237 SYSCALL_MAP (getuid);
1238 SYSCALL_MAP (geteuid);
1239 SYSCALL_MAP (getgid);
1240 SYSCALL_MAP (getegid);
1241 SYSCALL_MAP (gettid);
1242 SYSCALL_MAP (sysinfo);
1243 SYSCALL_MAP (mq_open);
1244 SYSCALL_MAP (mq_unlink);
1245 SYSCALL_MAP (mq_timedsend);
1246 SYSCALL_MAP (mq_timedreceive);
1247 SYSCALL_MAP (mq_notify);
1248 SYSCALL_MAP (mq_getsetattr);
1249 SYSCALL_MAP (msgget);
1250 SYSCALL_MAP (msgctl);
1251 SYSCALL_MAP (msgrcv);
1252 SYSCALL_MAP (msgsnd);
1253 SYSCALL_MAP (semget);
1254 SYSCALL_MAP (semctl);
1255 SYSCALL_MAP (semtimedop);
1256 SYSCALL_MAP (semop);
1257 SYSCALL_MAP (shmget);
1258 SYSCALL_MAP (shmctl);
1259 SYSCALL_MAP (shmat);
1260 SYSCALL_MAP (shmdt);
1261 SYSCALL_MAP (socket);
1262 SYSCALL_MAP (socketpair);
1264 SYSCALL_MAP (listen);
1265 SYSCALL_MAP (accept);
1266 SYSCALL_MAP (connect);
1267 SYSCALL_MAP (getsockname);
1268 SYSCALL_MAP (getpeername);
1269 SYSCALL_MAP (sendto);
1270 SYSCALL_MAP (recvfrom);
1271 SYSCALL_MAP (setsockopt);
1272 SYSCALL_MAP (getsockopt);
1273 SYSCALL_MAP (shutdown);
1274 SYSCALL_MAP (sendmsg);
1275 SYSCALL_MAP (recvmsg);
1276 SYSCALL_MAP (readahead);
1278 SYSCALL_MAP (munmap);
1279 SYSCALL_MAP (mremap);
1280 SYSCALL_MAP (add_key);
1281 SYSCALL_MAP (request_key);
1282 SYSCALL_MAP (keyctl);
1283 SYSCALL_MAP (clone);
1284 SYSCALL_MAP (execve);
1286 case aarch64_sys_mmap:
1287 return gdb_sys_mmap2;
1289 SYSCALL_MAP (fadvise64);
1290 SYSCALL_MAP (swapon);
1291 SYSCALL_MAP (swapoff);
1292 SYSCALL_MAP (mprotect);
1293 SYSCALL_MAP (msync);
1294 SYSCALL_MAP (mlock);
1295 SYSCALL_MAP (munlock);
1296 SYSCALL_MAP (mlockall);
1297 SYSCALL_MAP (munlockall);
1298 SYSCALL_MAP (mincore);
1299 SYSCALL_MAP (madvise);
1300 SYSCALL_MAP (remap_file_pages);
1301 SYSCALL_MAP (mbind);
1302 SYSCALL_MAP (get_mempolicy);
1303 SYSCALL_MAP (set_mempolicy);
1304 SYSCALL_MAP (migrate_pages);
1305 SYSCALL_MAP (move_pages);
1306 UNSUPPORTED_SYSCALL_MAP (rt_tgsigqueueinfo);
1307 UNSUPPORTED_SYSCALL_MAP (perf_event_open);
1308 UNSUPPORTED_SYSCALL_MAP (accept4);
1309 UNSUPPORTED_SYSCALL_MAP (recvmmsg);
1311 SYSCALL_MAP (wait4);
1313 UNSUPPORTED_SYSCALL_MAP (prlimit64);
1314 UNSUPPORTED_SYSCALL_MAP (fanotify_init);
1315 UNSUPPORTED_SYSCALL_MAP (fanotify_mark);
1316 UNSUPPORTED_SYSCALL_MAP (name_to_handle_at);
1317 UNSUPPORTED_SYSCALL_MAP (open_by_handle_at);
1318 UNSUPPORTED_SYSCALL_MAP (clock_adjtime);
1319 UNSUPPORTED_SYSCALL_MAP (syncfs);
1320 UNSUPPORTED_SYSCALL_MAP (setns);
1321 UNSUPPORTED_SYSCALL_MAP (sendmmsg);
1322 UNSUPPORTED_SYSCALL_MAP (process_vm_readv);
1323 UNSUPPORTED_SYSCALL_MAP (process_vm_writev);
1324 UNSUPPORTED_SYSCALL_MAP (kcmp);
1325 UNSUPPORTED_SYSCALL_MAP (finit_module);
1326 UNSUPPORTED_SYSCALL_MAP (sched_setattr);
1327 UNSUPPORTED_SYSCALL_MAP (sched_getattr);
1329 return gdb_sys_no_syscall;
1333 /* Retrieve the syscall number at a ptrace syscall-stop, either on syscall entry
1334 or exit. Return -1 upon error. */
1337 aarch64_linux_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
1339 struct regcache *regs = get_thread_regcache (thread);
1342 /* Get the system call number from register x8. */
1343 regs->cooked_read (AARCH64_X0_REGNUM + 8, &ret);
1345 /* On exit from a successful execve, we will be in a new process and all the
1346 registers will be cleared - x0 to x30 will be 0, except for a 1 in x7.
1347 This function will only ever get called when stopped at the entry or exit
1348 of a syscall, so by checking for 0 in x0 (arg0/retval), x1 (arg1), x8
1349 (syscall), x29 (FP) and x30 (LR) we can infer:
1350 1) Either inferior is at exit from sucessful execve.
1351 2) Or inferior is at entry to a call to io_setup with invalid arguments and
1352 a corrupted FP and LR.
1353 It should be safe enough to assume case 1. */
1356 LONGEST x1 = -1, fp = -1, lr = -1;
1357 regs->cooked_read (AARCH64_X0_REGNUM + 1, &x1);
1358 regs->cooked_read (AARCH64_FP_REGNUM, &fp);
1359 regs->cooked_read (AARCH64_LR_REGNUM, &lr);
1360 if (x1 == 0 && fp ==0 && lr == 0)
1361 return aarch64_sys_execve;
1367 /* Record all registers but PC register for process-record. */
1370 aarch64_all_but_pc_registers_record (struct regcache *regcache)
1374 for (i = AARCH64_X0_REGNUM; i < AARCH64_PC_REGNUM; i++)
1375 if (record_full_arch_list_add_reg (regcache, i))
1378 if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM))
1384 /* Handler for aarch64 system call instruction recording. */
1387 aarch64_linux_syscall_record (struct regcache *regcache,
1388 unsigned long svc_number)
1391 enum gdb_syscall syscall_gdb;
1394 aarch64_canonicalize_syscall ((enum aarch64_syscall) svc_number);
1396 if (syscall_gdb < 0)
1398 printf_unfiltered (_("Process record and replay target doesn't "
1399 "support syscall number %s\n"),
1400 plongest (svc_number));
1404 if (syscall_gdb == gdb_sys_sigreturn
1405 || syscall_gdb == gdb_sys_rt_sigreturn)
1407 if (aarch64_all_but_pc_registers_record (regcache))
1412 ret = record_linux_system_call (syscall_gdb, regcache,
1413 &aarch64_linux_record_tdep);
1417 /* Record the return value of the system call. */
1418 if (record_full_arch_list_add_reg (regcache, AARCH64_X0_REGNUM))
1421 if (record_full_arch_list_add_reg (regcache, AARCH64_LR_REGNUM))
1424 if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM))
1430 /* Implement the "gcc_target_options" gdbarch method. */
1433 aarch64_linux_gcc_target_options (struct gdbarch *gdbarch)
1435 /* GCC doesn't know "-m64". */
1440 aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1442 static const char *const stap_integer_prefixes[] = { "#", "", NULL };
1443 static const char *const stap_register_prefixes[] = { "", NULL };
1444 static const char *const stap_register_indirection_prefixes[] = { "[",
1446 static const char *const stap_register_indirection_suffixes[] = { "]",
1448 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1450 tdep->lowest_pc = 0x8000;
1452 linux_init_abi (info, gdbarch);
1454 set_solib_svr4_fetch_link_map_offsets (gdbarch,
1455 svr4_lp64_fetch_link_map_offsets);
1457 /* Enable TLS support. */
1458 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1459 svr4_fetch_objfile_link_map);
1461 /* Shared library handling. */
1462 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
1463 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1465 tramp_frame_prepend_unwinder (gdbarch, &aarch64_linux_rt_sigframe);
1467 /* Enable longjmp. */
1470 set_gdbarch_iterate_over_regset_sections
1471 (gdbarch, aarch64_linux_iterate_over_regset_sections);
1472 set_gdbarch_core_read_description
1473 (gdbarch, aarch64_linux_core_read_description);
1475 /* SystemTap related. */
1476 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
1477 set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
1478 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
1479 stap_register_indirection_prefixes);
1480 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
1481 stap_register_indirection_suffixes);
1482 set_gdbarch_stap_is_single_operand (gdbarch, aarch64_stap_is_single_operand);
1483 set_gdbarch_stap_parse_special_token (gdbarch,
1484 aarch64_stap_parse_special_token);
1486 /* Reversible debugging, process record. */
1487 set_gdbarch_process_record (gdbarch, aarch64_process_record);
1488 /* Syscall record. */
1489 tdep->aarch64_syscall_record = aarch64_linux_syscall_record;
1491 /* The top byte of a user space address known as the "tag",
1492 is ignored by the kernel and can be regarded as additional
1493 data associated with the address. */
1494 set_gdbarch_significant_addr_bit (gdbarch, 56);
1496 /* Initialize the aarch64_linux_record_tdep. */
1497 /* These values are the size of the type that will be used in a system
1498 call. They are obtained from Linux Kernel source. */
1499 aarch64_linux_record_tdep.size_pointer
1500 = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
1501 aarch64_linux_record_tdep.size__old_kernel_stat = 32;
1502 aarch64_linux_record_tdep.size_tms = 32;
1503 aarch64_linux_record_tdep.size_loff_t = 8;
1504 aarch64_linux_record_tdep.size_flock = 32;
1505 aarch64_linux_record_tdep.size_oldold_utsname = 45;
1506 aarch64_linux_record_tdep.size_ustat = 32;
1507 aarch64_linux_record_tdep.size_old_sigaction = 32;
1508 aarch64_linux_record_tdep.size_old_sigset_t = 8;
1509 aarch64_linux_record_tdep.size_rlimit = 16;
1510 aarch64_linux_record_tdep.size_rusage = 144;
1511 aarch64_linux_record_tdep.size_timeval = 16;
1512 aarch64_linux_record_tdep.size_timezone = 8;
1513 aarch64_linux_record_tdep.size_old_gid_t = 2;
1514 aarch64_linux_record_tdep.size_old_uid_t = 2;
1515 aarch64_linux_record_tdep.size_fd_set = 128;
1516 aarch64_linux_record_tdep.size_old_dirent = 280;
1517 aarch64_linux_record_tdep.size_statfs = 120;
1518 aarch64_linux_record_tdep.size_statfs64 = 120;
1519 aarch64_linux_record_tdep.size_sockaddr = 16;
1520 aarch64_linux_record_tdep.size_int
1521 = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
1522 aarch64_linux_record_tdep.size_long
1523 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
1524 aarch64_linux_record_tdep.size_ulong
1525 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
1526 aarch64_linux_record_tdep.size_msghdr = 56;
1527 aarch64_linux_record_tdep.size_itimerval = 32;
1528 aarch64_linux_record_tdep.size_stat = 144;
1529 aarch64_linux_record_tdep.size_old_utsname = 325;
1530 aarch64_linux_record_tdep.size_sysinfo = 112;
1531 aarch64_linux_record_tdep.size_msqid_ds = 120;
1532 aarch64_linux_record_tdep.size_shmid_ds = 112;
1533 aarch64_linux_record_tdep.size_new_utsname = 390;
1534 aarch64_linux_record_tdep.size_timex = 208;
1535 aarch64_linux_record_tdep.size_mem_dqinfo = 24;
1536 aarch64_linux_record_tdep.size_if_dqblk = 72;
1537 aarch64_linux_record_tdep.size_fs_quota_stat = 80;
1538 aarch64_linux_record_tdep.size_timespec = 16;
1539 aarch64_linux_record_tdep.size_pollfd = 8;
1540 aarch64_linux_record_tdep.size_NFS_FHSIZE = 32;
1541 aarch64_linux_record_tdep.size_knfsd_fh = 132;
1542 aarch64_linux_record_tdep.size_TASK_COMM_LEN = 16;
1543 aarch64_linux_record_tdep.size_sigaction = 32;
1544 aarch64_linux_record_tdep.size_sigset_t = 8;
1545 aarch64_linux_record_tdep.size_siginfo_t = 128;
1546 aarch64_linux_record_tdep.size_cap_user_data_t = 8;
1547 aarch64_linux_record_tdep.size_stack_t = 24;
1548 aarch64_linux_record_tdep.size_off_t = 8;
1549 aarch64_linux_record_tdep.size_stat64 = 144;
1550 aarch64_linux_record_tdep.size_gid_t = 4;
1551 aarch64_linux_record_tdep.size_uid_t = 4;
1552 aarch64_linux_record_tdep.size_PAGE_SIZE = 4096;
1553 aarch64_linux_record_tdep.size_flock64 = 32;
1554 aarch64_linux_record_tdep.size_user_desc = 16;
1555 aarch64_linux_record_tdep.size_io_event = 32;
1556 aarch64_linux_record_tdep.size_iocb = 64;
1557 aarch64_linux_record_tdep.size_epoll_event = 12;
1558 aarch64_linux_record_tdep.size_itimerspec = 32;
1559 aarch64_linux_record_tdep.size_mq_attr = 64;
1560 aarch64_linux_record_tdep.size_termios = 36;
1561 aarch64_linux_record_tdep.size_termios2 = 44;
1562 aarch64_linux_record_tdep.size_pid_t = 4;
1563 aarch64_linux_record_tdep.size_winsize = 8;
1564 aarch64_linux_record_tdep.size_serial_struct = 72;
1565 aarch64_linux_record_tdep.size_serial_icounter_struct = 80;
1566 aarch64_linux_record_tdep.size_hayes_esp_config = 12;
1567 aarch64_linux_record_tdep.size_size_t = 8;
1568 aarch64_linux_record_tdep.size_iovec = 16;
1569 aarch64_linux_record_tdep.size_time_t = 8;
1571 /* These values are the second argument of system call "sys_ioctl".
1572 They are obtained from Linux Kernel source. */
1573 aarch64_linux_record_tdep.ioctl_TCGETS = 0x5401;
1574 aarch64_linux_record_tdep.ioctl_TCSETS = 0x5402;
1575 aarch64_linux_record_tdep.ioctl_TCSETSW = 0x5403;
1576 aarch64_linux_record_tdep.ioctl_TCSETSF = 0x5404;
1577 aarch64_linux_record_tdep.ioctl_TCGETA = 0x5405;
1578 aarch64_linux_record_tdep.ioctl_TCSETA = 0x5406;
1579 aarch64_linux_record_tdep.ioctl_TCSETAW = 0x5407;
1580 aarch64_linux_record_tdep.ioctl_TCSETAF = 0x5408;
1581 aarch64_linux_record_tdep.ioctl_TCSBRK = 0x5409;
1582 aarch64_linux_record_tdep.ioctl_TCXONC = 0x540a;
1583 aarch64_linux_record_tdep.ioctl_TCFLSH = 0x540b;
1584 aarch64_linux_record_tdep.ioctl_TIOCEXCL = 0x540c;
1585 aarch64_linux_record_tdep.ioctl_TIOCNXCL = 0x540d;
1586 aarch64_linux_record_tdep.ioctl_TIOCSCTTY = 0x540e;
1587 aarch64_linux_record_tdep.ioctl_TIOCGPGRP = 0x540f;
1588 aarch64_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
1589 aarch64_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
1590 aarch64_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
1591 aarch64_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
1592 aarch64_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
1593 aarch64_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
1594 aarch64_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
1595 aarch64_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
1596 aarch64_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
1597 aarch64_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
1598 aarch64_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541a;
1599 aarch64_linux_record_tdep.ioctl_FIONREAD = 0x541b;
1600 aarch64_linux_record_tdep.ioctl_TIOCINQ = 0x541b;
1601 aarch64_linux_record_tdep.ioctl_TIOCLINUX = 0x541c;
1602 aarch64_linux_record_tdep.ioctl_TIOCCONS = 0x541d;
1603 aarch64_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541e;
1604 aarch64_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541f;
1605 aarch64_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
1606 aarch64_linux_record_tdep.ioctl_FIONBIO = 0x5421;
1607 aarch64_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
1608 aarch64_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
1609 aarch64_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
1610 aarch64_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
1611 aarch64_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
1612 aarch64_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
1613 aarch64_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
1614 aarch64_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
1615 aarch64_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
1616 aarch64_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
1617 aarch64_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
1618 aarch64_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
1619 aarch64_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
1620 aarch64_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
1621 aarch64_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
1622 aarch64_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
1623 aarch64_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
1624 aarch64_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
1625 aarch64_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
1626 aarch64_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
1627 aarch64_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
1628 aarch64_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
1629 aarch64_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
1630 aarch64_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
1631 aarch64_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545a;
1632 aarch64_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545b;
1633 aarch64_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545c;
1634 aarch64_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545d;
1635 aarch64_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545e;
1636 aarch64_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545f;
1637 aarch64_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
1639 /* These values are the second argument of system call "sys_fcntl"
1640 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1641 aarch64_linux_record_tdep.fcntl_F_GETLK = 5;
1642 aarch64_linux_record_tdep.fcntl_F_GETLK64 = 12;
1643 aarch64_linux_record_tdep.fcntl_F_SETLK64 = 13;
1644 aarch64_linux_record_tdep.fcntl_F_SETLKW64 = 14;
1646 /* The AArch64 syscall calling convention: reg x0-x6 for arguments,
1647 reg x8 for syscall number and return value in reg x0. */
1648 aarch64_linux_record_tdep.arg1 = AARCH64_X0_REGNUM + 0;
1649 aarch64_linux_record_tdep.arg2 = AARCH64_X0_REGNUM + 1;
1650 aarch64_linux_record_tdep.arg3 = AARCH64_X0_REGNUM + 2;
1651 aarch64_linux_record_tdep.arg4 = AARCH64_X0_REGNUM + 3;
1652 aarch64_linux_record_tdep.arg5 = AARCH64_X0_REGNUM + 4;
1653 aarch64_linux_record_tdep.arg6 = AARCH64_X0_REGNUM + 5;
1654 aarch64_linux_record_tdep.arg7 = AARCH64_X0_REGNUM + 6;
1656 /* `catch syscall' */
1657 set_xml_syscall_file_name (gdbarch, "syscalls/aarch64-linux.xml");
1658 set_gdbarch_get_syscall_number (gdbarch, aarch64_linux_get_syscall_number);
1660 /* Displaced stepping. */
1661 set_gdbarch_max_insn_length (gdbarch, 4 * DISPLACED_MODIFIED_INSNS);
1662 set_gdbarch_displaced_step_copy_insn (gdbarch,
1663 aarch64_displaced_step_copy_insn);
1664 set_gdbarch_displaced_step_fixup (gdbarch, aarch64_displaced_step_fixup);
1665 set_gdbarch_displaced_step_location (gdbarch, linux_displaced_step_location);
1666 set_gdbarch_displaced_step_hw_singlestep (gdbarch,
1667 aarch64_displaced_step_hw_singlestep);
1669 set_gdbarch_gcc_target_options (gdbarch, aarch64_linux_gcc_target_options);
1673 _initialize_aarch64_linux_tdep (void)
1675 gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_LINUX,
1676 aarch64_linux_init_abi);