]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Core file support (C registers)
authorLuis Machado <luis.machado@linaro.org>
Fri, 16 Apr 2021 13:43:59 +0000 (10:43 -0300)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 22:57:21 +0000 (15:57 -0700)
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.

bfd/elf-bfd.h
bfd/elf.c
gdb/aarch64-linux-tdep.c

index a84a3a7c494767b38baccd06b8fc4d59626bc28d..336e942c1a55f16221fdfc366e56eea218170ab3 100644 (file)
@@ -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
index e9148dbecab21436e1d70b4c006b30a180ab4069..1af3442d8f8697e24a914c6d62c1b3833b6fb931 100644 (file)
--- 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)
index 5edbdb61d66e23e27a7f1001a6f564fe8767b049..45d6f054fd215aab03355da42a971d216b89f290 100644 (file)
@@ -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);