$OpenBSD: patch-gdb_aarch64obsd-tdep_c,v 1.1 2018/07/10 11:03:46 kettenis Exp $
Index: gdb/aarch64obsd-tdep.c
--- gdb/aarch64obsd-tdep.c.orig
+++ gdb/aarch64obsd-tdep.c
@@ -0,0 +1,111 @@
+/* Target-dependent code for OpenBSD/aarch64.
+
+   Copyright (C) 2006-2017 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 "osabi.h"
+#include "regset.h"
+#include "trad-frame.h"
+#include "tramp-frame.h"
+
+#include "aarch64-tdep.h"
+#include "obsd-tdep.h"
+#include "solib-svr4.h"
+
+/* The general-purpose regset consists of 31 X registers, plus SP, PC,
+   and SPSR and TPIDR registers.  */
+#define AARCH64_OBSD_SIZEOF_GREGSET  (35 * X_REGISTER_SIZE)
+
+/* The fp regset consists of 32 V registers, plus FPSR and FPCR which
+   are 4 bytes wide each, and the whole structure is padded to 128 bit
+   alignment.  */
+#define AARCH64_OBSD_SIZEOF_FPREGSET (33 * V_REGISTER_SIZE)
+
+/* Register maps.  */
+
+static const struct regcache_map_entry aarch64_obsd_gregmap[] =
+  {
+    { 31, AARCH64_X0_REGNUM, 8 }, /* x0 ... x30 */
+    { 1, AARCH64_SP_REGNUM, 8 },
+    { 1, AARCH64_PC_REGNUM, 8 },
+    { 1, AARCH64_CPSR_REGNUM, 8 },
+    { 0 }
+  };
+
+static const struct regcache_map_entry aarch64_obsd_fpregmap[] =
+  {
+    { 32, AARCH64_V0_REGNUM, 16 }, /* v0 ... v31 */
+    { 1, AARCH64_FPSR_REGNUM, 4 },
+    { 1, AARCH64_FPCR_REGNUM, 4 },
+    { 0 }
+  };
+
+/* Register set definitions.  */
+
+const struct regset aarch64_obsd_gregset =
+  {
+    aarch64_obsd_gregmap,
+    regcache_supply_regset, regcache_collect_regset
+  };
+
+const struct regset aarch64_obsd_fpregset =
+  {
+    aarch64_obsd_fpregmap,
+    regcache_supply_regset, regcache_collect_regset
+  };
+
+static void
+aarch64_obsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					   iterate_over_regset_sections_cb *cb,
+					   void *cb_data,
+					   const struct regcache *regcache)
+{
+  cb (".reg", AARCH64_OBSD_SIZEOF_GREGSET, &aarch64_obsd_gregset,
+      NULL, cb_data);
+  cb (".reg2", AARCH64_OBSD_SIZEOF_FPREGSET, &aarch64_obsd_fpregset,
+      NULL, cb_data);
+}
+
+
+static void
+aarch64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  /* OpenBSD/aarch64 uses SVR4-style shared libraries.  */
+  set_solib_svr4_fetch_link_map_offsets
+    (gdbarch, svr4_lp64_fetch_link_map_offsets);
+  set_gdbarch_skip_solib_resolver (gdbarch, obsd_skip_solib_resolver);
+
+  /* Enable longjmp. */
+  tdep->jb_pc = 13;
+
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, aarch64_obsd_iterate_over_regset_sections);
+}
+
+
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_aarch64obsd_tdep;
+
+void
+_initialize_aarch64obsd_tdep (void)
+{
+  gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_OPENBSD_ELF,
+			  aarch64obsd_init_abi);
+}
