From: Luis Machado Date: Fri, 16 Apr 2021 13:43:59 +0000 (-0300) Subject: Core file support (C registers) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7eb6c78e2b9e25eb7b2e5928a785d29fb2919815;p=thirdparty%2Fbinutils-gdb.git Core file support (C registers) Enable core file dumping through the gcore command and enable reading of kernel-generated core files for Morello. This patch enables writing and reading Morello core file containing dumps of the C register set. The C register dumps are stored in a NT_ARM_MORELLO note. Tested by writing a gcore-based core file and reading it back, and also exercised by reading a kernel-generated core file. --- diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index a84a3a7c494..336e942c1a5 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -2866,6 +2866,8 @@ extern char *elfcore_write_aarch_pauth (bfd *, char *, int *, const void *, int); extern char *elfcore_write_aarch_mte (bfd *, char *, int *, const void *, int); +extern char *elfcore_write_aarch_morello + (bfd *, char *, int *, const void *, int); extern char *elfcore_write_arc_v2 (bfd *, char *, int *, const void *, int); extern char *elfcore_write_riscv_csr diff --git a/bfd/elf.c b/bfd/elf.c index e9148dbecab..1af3442d8f8 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -10015,6 +10015,12 @@ elfcore_grok_aarch_mte (bfd *abfd, Elf_Internal_Note *note) note); } +static bool +elfcore_grok_aarch_morello (bfd *abfd, Elf_Internal_Note *note) +{ + return elfcore_make_note_pseudosection (abfd, ".reg-aarch-morello", note); +} + static bool elfcore_grok_arc_v2 (bfd *abfd, Elf_Internal_Note *note) { @@ -10770,6 +10776,13 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) else return true; + case NT_ARM_MORELLO: + if (note->namesz == 6 + && strcmp (note->namedata, "LINUX") == 0) + return elfcore_grok_aarch_morello (abfd, note); + else + return true; + case NT_PRPSINFO: case NT_PSINFO: if (bed->elf_backend_grok_psinfo) @@ -12347,6 +12360,18 @@ elfcore_write_aarch_mte (bfd *abfd, size); } +char * +elfcore_write_aarch_morello (bfd *abfd, + char *buf, + int *bufsiz, + const void *aarch_morello, + int size) +{ + char *note_name = "LINUX"; + return elfcore_write_note (abfd, buf, bufsiz, + note_name, NT_ARM_MORELLO, aarch_morello, size); +} + char * elfcore_write_arc_v2 (bfd *abfd, char *buf, @@ -12528,6 +12553,8 @@ elfcore_write_register_note (bfd *abfd, return elfcore_write_aarch_pauth (abfd, buf, bufsiz, data, size); if (strcmp (section, ".reg-aarch-mte") == 0) return elfcore_write_aarch_mte (abfd, buf, bufsiz, data, size); + if (strcmp (section, ".reg-aarch-morello") == 0) + return elfcore_write_aarch_morello (abfd, buf, bufsiz, data, size); if (strcmp (section, ".reg-arc-v2") == 0) return elfcore_write_arc_v2 (abfd, buf, bufsiz, data, size); if (strcmp (section, ".gdb-tdesc") == 0) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 5edbdb61d66..45d6f054fd2 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -560,13 +560,17 @@ static const struct regcache_map_entry aarch64_linux_fpregmap[] = placeholders so we can update the numbers later. */ static struct regcache_map_entry aarch64_linux_cregmap[] = { - /* FIXME-Morello: Need to decide if we are reading the whole 16 bytes or - just the upper 8 bytes of the capability registers. */ - { 31, -1, 8 }, /* c0 ... c30 */ - { 1, -1, 8 }, /* Stack Pointer Capability */ - { 1, -1, 8 }, /* Program Counter Capability */ - { 1, -1, 16 }, /* Default Data Capability */ - { 1, -1, 8 }, + { 31, -1, 16 }, /* c0 ... c30 */ + { 1, -1, 16 }, /* pcc */ + { 1, -1, 16 }, /* csp */ + { 1, -1, 16 }, /* ddc */ + { 1, -1, 16 }, /* ctpidr */ + { 1, -1, 16 }, /* rcsp */ + { 1, -1, 16 }, /* rddc */ + { 1, -1, 16 }, /* rctpidr */ + { 1, -1, 16 }, /* cid */ + { 1, -1, 8 }, /* tag_map */ + { 1, -1, 8 }, /* cctlr */ { 0 } }; @@ -866,11 +870,10 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, "TLS register", cb_data); } - /* FIXME-Morello: We still need to provide a valid check for the presence of - capability registers. */ + /* Morello capability registers. */ if (tdep->has_capability ()) { - cb (".reg-cap", AARCH64_LINUX_CREGS_SIZE, + cb (".reg-aarch-morello", AARCH64_LINUX_CREGS_SIZE, AARCH64_LINUX_CREGS_SIZE, &aarch64_linux_cregset, NULL, cb_data); } @@ -2395,12 +2398,21 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) if (tdep->has_capability ()) { - /* Initialize the register numbers for the core file register set. */ - /* FIXME-Morello: This needs to be updated. */ + /* Initialize the register numbers for the core file register set. + Please note the PCC/CSP position in GDB's target description is + the inverse of the position in the Linux Kernel's user_morello_state + data structure. This can cause some confusion. */ aarch64_linux_cregmap[0].regno = tdep->cap_reg_base; - aarch64_linux_cregmap[1].regno = tdep->cap_reg_base + 32; - aarch64_linux_cregmap[2].regno = tdep->cap_reg_base + 31; - aarch64_linux_cregmap[3].regno = tdep->cap_reg_base + 33; + aarch64_linux_cregmap[1].regno = tdep->cap_reg_pcc; + aarch64_linux_cregmap[2].regno = tdep->cap_reg_csp; + + /* Set the rest of the registers. */ + int next_regnum = tdep->cap_reg_base + 33; + for (int i = 3; i <= 10; i++) + { + aarch64_linux_cregmap[i].regno = next_regnum; + next_regnum++; + } set_gdbarch_report_signal_info (gdbarch, aarch64_linux_report_signal_info);