Add x86_64 ravenscar support
authorTom Tromey <tromey@adacore.com>
Thu, 29 Oct 2020 14:47:16 +0000 (08:47 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 2 Nov 2020 19:10:51 +0000 (12:10 -0700)
Support for x86_64 ravenscar was recently added to the Ada runtime.
This patch updates gdb to follow.

As this is Ada-specific, and was reviewed internally by Joel, I am
checking it in.

2020-11-02  Tom Tromey  <tromey@adacore.com>

* Makefile.in (ALL_64_TARGET_OBS): Add amd64-ravenscar-thread.o.
(ALLDEPFILES): Add amd64-ravenscar-thread.c.
(HFILES_NO_SRCDIR): Add amd64-ravenscar-thread.h.
* amd64-ravenscar-thread.c: New file.
* amd64-ravenscar-thread.h: New file.
* amd64-tdep.c (amd64_init_abi): Register ravenscar ops.
* configure.tgt (amd64_tobjs): Add ravenscar objects.

gdb/ChangeLog
gdb/Makefile.in
gdb/amd64-ravenscar-thread.c [new file with mode: 0644]
gdb/amd64-ravenscar-thread.h [new file with mode: 0644]
gdb/amd64-tdep.c
gdb/configure.tgt

index 4356fa75df33de8b8b3fa0f449d8e167c53c81ab..373e1527fc7a64bc5452720a210816253b3f7591 100644 (file)
@@ -1,3 +1,13 @@
+2020-11-02  Tom Tromey  <tromey@adacore.com>
+
+       * Makefile.in (ALL_64_TARGET_OBS): Add amd64-ravenscar-thread.o.
+       (ALLDEPFILES): Add amd64-ravenscar-thread.c.
+       (HFILES_NO_SRCDIR): Add amd64-ravenscar-thread.h.
+       * amd64-ravenscar-thread.c: New file.
+       * amd64-ravenscar-thread.h: New file.
+       * amd64-tdep.c (amd64_init_abi): Register ravenscar ops.
+       * configure.tgt (amd64_tobjs): Add ravenscar objects.
+
 2020-11-02  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * main.c (execute_cmdargs): New function.
index b3be21bb5a0b1c326777cc21fe3dab3ac1961097..c46935efafad9b422c98d27bc4f34af532b307ca 100644 (file)
@@ -687,6 +687,7 @@ ALL_64_TARGET_OBS = \
        amd64-linux-tdep.o \
        amd64-netbsd-tdep.o \
        amd64-obsd-tdep.o \
+       amd64-ravenscar-thread.o \
        amd64-sol2-tdep.o \
        amd64-tdep.o \
        amd64-windows-tdep.o \
@@ -1219,6 +1220,7 @@ HFILES_NO_SRCDIR = \
        amd64-darwin-tdep.h \
        amd64-linux-tdep.h \
        amd64-nat.h \
+       amd64-ravenscar-thread.h \
        amd64-tdep.h \
        annotate.h \
        arc-tdep.h \
@@ -2139,6 +2141,7 @@ ALLDEPFILES = \
        amd64-netbsd-tdep.c \
        amd64-obsd-nat.c \
        amd64-obsd-tdep.c \
+       amd64-ravenscar-thread.c \
        amd64-sol2-tdep.c \
        amd64-tdep.c \
        arc-tdep.c \
diff --git a/gdb/amd64-ravenscar-thread.c b/gdb/amd64-ravenscar-thread.c
new file mode 100644 (file)
index 0000000..656f4c4
--- /dev/null
@@ -0,0 +1,150 @@
+/* Ravenscar x86-64 target support.
+
+   Copyright (C) 2020 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "gdbarch.h"
+#include "gdbcore.h"
+#include "regcache.h"
+#include "amd64-tdep.h"
+#include "inferior.h"
+#include "ravenscar-thread.h"
+#include "amd64-ravenscar-thread.h"
+
+struct amd64_ravenscar_ops : public ravenscar_arch_ops
+{
+  void fetch_registers (struct regcache *regcache, int regnum) override;
+  void store_registers (struct regcache *regcache, int regnum) override;
+
+private:
+
+  /* Return the offset of the register in the context buffer.  */
+  int register_offset (struct gdbarch *arch, int regnum);
+};
+
+/* x86-64 Ravenscar stores registers as:
+
+   type Context_Buffer is record
+      RIP    : System.Address;
+      RFLAGS : EFLAGS;
+      RSP    : System.Address;
+
+      RBX    : System.Address;
+      RBP    : System.Address;
+      R12    : System.Address;
+      R13    : System.Address;
+      R14    : System.Address;
+      R15    : System.Address;
+   end record;
+*/
+static const int register_layout[] =
+{
+  AMD64_RIP_REGNUM,
+  AMD64_EFLAGS_REGNUM,
+  AMD64_RSP_REGNUM,
+  AMD64_RBX_REGNUM,
+  AMD64_RBP_REGNUM,
+  AMD64_R12_REGNUM,
+  AMD64_R13_REGNUM,
+  AMD64_R14_REGNUM,
+  AMD64_R15_REGNUM,
+};
+
+int
+amd64_ravenscar_ops::register_offset (struct gdbarch *arch, int regnum)
+{
+  for (int i = 0; i < ARRAY_SIZE (register_layout); ++i)
+    if (register_layout[i] == regnum)
+      return i * 8;
+  /* Not saved.  */
+  return -1;
+}
+
+/* Supply register REGNUM, which has been saved at REGISTER_ADDR, to
+   the regcache.  */
+
+static void
+supply_register_at_address (struct regcache *regcache, int regnum,
+                            CORE_ADDR register_addr)
+{
+  struct gdbarch *gdbarch = regcache->arch ();
+  int buf_size = register_size (gdbarch, regnum);
+  gdb_byte *buf;
+
+  buf = (gdb_byte *) alloca (buf_size);
+  read_memory (register_addr, buf, buf_size);
+  regcache->raw_supply (regnum, buf);
+}
+
+void
+amd64_ravenscar_ops::fetch_registers (struct regcache *regcache, int regnum)
+{
+  struct gdbarch *gdbarch = regcache->arch ();
+  const int num_regs = gdbarch_num_regs (gdbarch);
+  int current_regnum;
+  CORE_ADDR current_address;
+  CORE_ADDR thread_descriptor_address;
+
+  /* The tid is the thread_id field, which is a pointer to the thread.  */
+  thread_descriptor_address = (CORE_ADDR) inferior_ptid.tid ();
+
+  /* Read registers.  */
+  for (current_regnum = 0; current_regnum < num_regs; current_regnum++)
+    {
+      int offset = register_offset (gdbarch, current_regnum);
+
+      if (offset != -1)
+        {
+          current_address = thread_descriptor_address + offset;
+          supply_register_at_address (regcache, current_regnum,
+                                      current_address);
+        }
+    }
+}
+
+void
+amd64_ravenscar_ops::store_registers (struct regcache *regcache, int regnum)
+{
+  struct gdbarch *gdbarch = regcache->arch ();
+  int buf_size = register_size (gdbarch, regnum);
+  gdb_byte buf[buf_size];
+  CORE_ADDR register_address;
+
+  int offset = register_offset (gdbarch, regnum);
+  if (offset != -1)
+    {
+      register_address = inferior_ptid.tid () + offset;
+
+      regcache->raw_collect (regnum, buf);
+      write_memory (register_address,
+                   buf,
+                   buf_size);
+    }
+}
+
+/* The ravenscar_arch_ops vector for AMD64 targets.  */
+
+static struct amd64_ravenscar_ops amd64_ravenscar_ops;
+
+/* Register amd64_ravenscar_ops in GDBARCH.  */
+
+void
+register_amd64_ravenscar_ops (struct gdbarch *gdbarch)
+{
+  set_gdbarch_ravenscar_ops (gdbarch, &amd64_ravenscar_ops);
+}
diff --git a/gdb/amd64-ravenscar-thread.h b/gdb/amd64-ravenscar-thread.h
new file mode 100644 (file)
index 0000000..e1edcd7
--- /dev/null
@@ -0,0 +1,27 @@
+/* Ravenscar x86-64 target support.
+
+   Copyright (C) 2020 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef AMD64_RAVENSCAR_THREAD_H
+#define AMD64_RAVENSCAR_THREAD_H
+
+struct gdbarch;
+
+extern void register_amd64_ravenscar_ops (struct gdbarch *gdbarch);
+
+#endif /* AMD64_RAVENSCAR_THREAD_H */
index 975718b1de2e1fdae398c6dc6c3673dd14d379c7..31d4d3460ef2ffc28708725b8b01b4409589d201 100644 (file)
@@ -49,6 +49,7 @@
 #include "gdbsupport/byte-vector.h"
 #include "osabi.h"
 #include "x86-tdep.h"
+#include "amd64-ravenscar-thread.h"
 
 /* Note that the AMD64 architecture was previously known as x86-64.
    The latter is (forever) engraved into the canonical system name as
@@ -3256,6 +3257,8 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 
   set_gdbarch_in_indirect_branch_thunk (gdbarch,
                                        amd64_in_indirect_branch_thunk);
+
+  register_amd64_ravenscar_ops (gdbarch);
 }
 
 /* Initialize ARCH for x86-64, no osabi.  */
index d865ecdcb60055bf68553b38bfc3438cbe9f0aea..6e039838748228b2d2e5ea3141cea573e09da917 100644 (file)
@@ -39,7 +39,8 @@ esac
 
 x86_tobjs="x86-tdep.o"
 i386_tobjs="i386-tdep.o arch/i386.o i387-tdep.o ${x86_tobjs}"
-amd64_tobjs="amd64-tdep.o arch/amd64.o ${x86_tobjs}"
+amd64_tobjs="ravenscar-thread.o amd64-ravenscar-thread.o \
+    amd64-tdep.o arch/amd64.o ${x86_tobjs}"
 
 # Here are three sections to get a list of target specific object
 # files according to target triplet $TARG.
This page took 0.035023 seconds and 4 git commands to generate.