Here is the diffs that will build a native arm64 gdb that is mostly
functional. Single stepping is not working, however that is suspected
to be a kernel issue more than a gdb issue. gdb will recognize and
load coredumps as well as inspect live programs. register contents appear
to be correct. breakpoints do work on running programs.

The new code below is a shuffling of various files already found in the gdb
distribution, mostly various openbsd support files and linux aarch64.
It has not been clean up or tested beyond basic functionality.

Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/gdb/Makefile,v
retrieving revision 1.54
diff -u -p -r1.54 Makefile
--- Makefile    18 Jun 2018 14:53:12 -0000      1.54
+++ Makefile    23 Jun 2018 20:26:20 -0000
@@ -1,13 +1,12 @@
 # $OpenBSD: Makefile,v 1.54 2018/06/18 14:53:12 kettenis Exp $
 
 # adjust lang/ocaml if gdb is ported to aarch64
-NOT_FOR_ARCHS= aarch64
 
 COMMENT=       GNU debugger
 CATEGORIES=    devel
 
 DISTNAME=      gdb-7.12.1
-REVISION=      2
+REVISION=      3
 
 HOMEPAGE=      https://www.gnu.org/software/gdb/
 
Index: patches/patch-bfd_config_bfd
===================================================================
RCS file: patches/patch-bfd_config_bfd
diff -N patches/patch-bfd_config_bfd
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-bfd_config_bfd        23 Jun 2018 20:26:20 -0000
@@ -0,0 +1,15 @@
+$OpenBSD$
+--- bfd/config.bfd.orig        Sat Jan 21 05:48:42 2017
++++ bfd/config.bfd     Tue Mar  7 22:55:11 2017
+@@ -202,6 +202,11 @@ case "${targ}" in
+     targ_selvecs="aarch64_elf64_be_vec aarch64_elf32_le_vec 
aarch64_elf32_be_vec arm_elf32_le_vec arm_elf32_be_vec"
+     want64=true
+     ;;
++  aarch64-*-openbsd*)
++    targ_defvec=aarch64_elf64_le_vec
++    targ_selvecs="aarch64_elf32_le_vec arm_elf32_le_vec"
++    want64=true
++    ;;
+   aarch64_be-*-linux*)
+     targ_defvec=aarch64_elf64_be_vec
+     targ_selvecs="aarch64_elf64_le_vec aarch64_elf32_le_vec 
aarch64_elf32_be_vec arm_elf32_be_vec arm_elf32_le_vec"
Index: patches/patch-gdb_Makefile_in
===================================================================
RCS file: patches/patch-gdb_Makefile_in
diff -N patches/patch-gdb_Makefile_in
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_Makefile_in       23 Jun 2018 20:26:20 -0000
@@ -0,0 +1,29 @@
+$OpenBSD$
+--- gdb/Makefile.in.orig       Sat Jan 21 05:48:42 2017
++++ gdb/Makefile.in    Tue Mar  7 23:40:17 2017
+@@ -644,7 +644,8 @@ TARGET_OBS = @TARGET_OBS@
+ # All target-dependent objects files that require 64-bit CORE_ADDR
+ # (used with --enable-targets=all --enable-64-bit-bfd).
+ ALL_64_TARGET_OBS = \
+-      aarch64-tdep.o aarch64-linux-tdep.o aarch64-newlib-tdep.o 
aarch64-insn.o \
++      aarch64-tdep.o aarch64obsd-tdep.o aarch64-linux-tdep.o \
++      aarch64-newlib-tdep.o aarch64-insn.o \
+       alphabsd-tdep.o alphafbsd-tdep.o alpha-linux-tdep.o alpha-mdebug-tdep.o 
\
+       alphanbsd-tdep.o alphaobsd-tdep.o alpha-tdep.o \
+       amd64fbsd-tdep.o amd64-darwin-tdep.o amd64-dicos-tdep.o \
+@@ -657,6 +658,7 @@ ALL_64_TARGET_OBS = \
+ 
+ # All other target-dependent objects files (used with --enable-targets=all).
+ ALL_TARGET_OBS = \
++      aarch64obsd-tdep.o \
+       armbsd-tdep.o arm.o arm-linux.o arm-linux-tdep.o \
+       arm-get-next-pcs.o arm-symbian-tdep.o \
+       armnbsd-tdep.o armobsd-tdep.o \
+@@ -1664,6 +1666,7 @@ MAKEOVERRIDES=
+ ALLDEPFILES = \
+       aarch64-tdep.c aarch64-linux-tdep.c aarch64-newlib-tdep.c \
+       aarch64-linux-nat.c \
++      aarch64-obsd-nat.c \
+       aix-thread.c \
+       alphabsd-nat.c alpha-linux-nat.c \
+       alpha-tdep.c alpha-mdebug-tdep.c \
Index: patches/patch-gdb_aarch64-obsd-tdep_h
===================================================================
RCS file: patches/patch-gdb_aarch64-obsd-tdep_h
diff -N patches/patch-gdb_aarch64-obsd-tdep_h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_aarch64-obsd-tdep_h       23 Jun 2018 20:26:20 -0000
@@ -0,0 +1,39 @@
+$OpenBSD$
+Index: gdb/aarch64-obsd-tdep.h
+--- gdb/aarch64-obsd-tdep.h.orig
++++ gdb/aarch64-obsd-tdep.h
+@@ -0,0 +1,34 @@
++/* OpenBSD on AArch64 target support, prototypes.
++
++   Copyright (C) 2012-2017 Free Software Foundation, Inc.
++   Contributed by ARM Ltd.
++
++   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 "regset.h"
++
++/* The general-purpose regset consists of 31 X registers, plus SP, PC,
++   and PSTATE registers, as defined in the AArch64 port of the Linux
++   kernel.  */
++#define AARCH64_OBSD_SIZEOF_GREGSET  (35 * X_REGISTER_SIZE)
++
++/* The fp regset consists of 32 V registers, plus FPCR and FPSR 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)
++
++extern const struct regset aarch64_obsd_gregset;
++extern const struct regset aarch64_obsd_fpregset;
Index: patches/patch-gdb_aarch64obsd-nat_c
===================================================================
RCS file: patches/patch-gdb_aarch64obsd-nat_c
diff -N patches/patch-gdb_aarch64obsd-nat_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_aarch64obsd-nat_c 23 Jun 2018 20:26:20 -0000
@@ -0,0 +1,721 @@
+$OpenBSD$
+Index: gdb/aarch64obsd-nat.c
+--- gdb/aarch64obsd-nat.c.orig
++++ gdb/aarch64obsd-nat.c
+@@ -0,0 +1,716 @@
++/* Native-dependent code for OpenBSD/arm64 (AArch64)
++
++   Copyright (C) 2011-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 "inferior.h"
++#include "gdbcore.h"
++#include "regcache.h"
++#include "obsd-nat.h"
++#include "target-descriptions.h"
++#include "auxv.h"
++#include "gdbcmd.h"
++#include "aarch64-tdep.h"
++
++#include "elf/external.h"
++#include "elf/common.h"
++
++#include "nat/gdb_ptrace.h"
++#include <sys/utsname.h>
++#include <inf-ptrace.h>
++#include <sys/ptrace.h>
++
++#include <machine/reg.h>
++
++
++#ifndef TRAP_HWBKPT
++#define TRAP_HWBKPT 0x0004
++#endif
++
++/* Per-process data.  We don't bind this to a per-inferior registry
++   because of targets like x86 GNU/Linux that need to keep track of
++   processes that aren't bound to any inferior (e.g., fork children,
++   checkpoints).  */
++
++struct aarch64_process_info
++{
++  /* Linked list.  */
++  struct aarch64_process_info *next;
++
++  /* The process identifier.  */
++  pid_t pid;
++
++};
++
++static struct aarch64_process_info *aarch64_process_list = NULL;
++
++/* Find process data for process PID.  */
++
++static struct aarch64_process_info *
++aarch64_find_process_pid (pid_t pid)
++{
++  struct aarch64_process_info *proc;
++
++  for (proc = aarch64_process_list; proc; proc = proc->next)
++    if (proc->pid == pid)
++      return proc;
++
++  return NULL;
++}
++
++/* Add process data for process PID.  Returns newly allocated info
++   object.  */
++
++static struct aarch64_process_info *
++aarch64_add_process (pid_t pid)
++{
++  struct aarch64_process_info *proc;
++
++  proc = XCNEW (struct aarch64_process_info);
++  proc->pid = pid;
++
++  proc->next = aarch64_process_list;
++  aarch64_process_list = proc;
++
++  return proc;
++}
++
++/* Get data specific info for process PID, creating it if necessary.
++   Never returns NULL.  */
++
++static struct aarch64_process_info *
++aarch64_process_info_get (pid_t pid)
++{
++  struct aarch64_process_info *proc;
++
++  proc = aarch64_find_process_pid (pid);
++  if (proc == NULL)
++    proc = aarch64_add_process (pid);
++
++  return proc;
++}
++
++/* Called whenever GDB is no longer debugging process PID.  It deletes
++   data structures that keep track of debug register state.  */
++
++static void
++aarch64_forget_process (pid_t pid)
++{
++  struct aarch64_process_info *proc, **proc_link;
++
++  proc = aarch64_process_list;
++  proc_link = &aarch64_process_list;
++
++  while (proc != NULL)
++    {
++      if (proc->pid == pid)
++      {
++        *proc_link = proc->next;
++
++        xfree (proc);
++        return;
++      }
++
++      proc_link = &proc->next;
++      proc = *proc_link;
++    }
++}
++
++#if 0
++/* Get debug registers state for process PID.  */
++
++struct aarch64_debug_reg_state *
++aarch64_get_debug_reg_state (pid_t pid)
++{
++  return &aarch64_process_info_get (pid)->state;
++}
++#endif
++
++/* Fill GDB's register array with the general-purpose register values
++   from the current thread.  */
++
++static uint64_t aarch64_obsd_tpidr;
++
++static void
++fetch_gregs_from_thread (struct regcache *regcache)
++{
++  struct reg regs;
++  pid_t pid;
++  int regno;
++  int ret;
++
++  pid = ptid_get_pid (inferior_ptid);
++
++  ret = ptrace(PT_GETREGS, pid, (caddr_t)&regs, 0);
++  if (ret < 0)
++    perror_with_name (_("Unable to fetch general registers."));
++
++  for (regno = AARCH64_X0_REGNUM; regno <= AARCH64_FP_REGNUM; regno++)
++    regcache_raw_supply (regcache, regno, &regs.r_reg[regno]);
++  regcache_raw_supply (regcache, AARCH64_LR_REGNUM, &regs.r_lr);
++  regcache_raw_supply (regcache, AARCH64_SP_REGNUM, &regs.r_sp);
++  regcache_raw_supply (regcache, AARCH64_PC_REGNUM, &regs.r_pc);
++  regcache_raw_supply (regcache, AARCH64_CPSR_REGNUM, &regs.r_spsr);
++  aarch64_obsd_tpidr = regs.r_tpidr;
++}
++
++/* Store to the current thread the valid general-purpose register
++   values in the GDB's register array.  */
++
++static void
++store_gregs_to_thread (const struct regcache *regcache)
++{
++  struct reg regs;
++  pid_t pid;
++  int regno;
++  int ret;
++
++  pid = ptid_get_pid (inferior_ptid);
++
++  // fetch old values as only 'valid' entries will be replaced.
++  ret = ptrace(PT_GETREGS, pid, (caddr_t)&regs, 0);
++  if (ret < 0) {
++    perror_with_name (_("Unable to store general registers."));
++    return;
++  }
++
++  for (regno = AARCH64_X0_REGNUM; regno <= AARCH64_FP_REGNUM; regno++)
++    if (REG_VALID == regcache_register_status (regcache, regno))
++      regcache_raw_collect (regcache, regno, &regs.r_reg[regno]);
++  if (REG_VALID == regcache_register_status (regcache, AARCH64_LR_REGNUM))
++    regcache_raw_collect (regcache, AARCH64_LR_REGNUM, &regs.r_lr);
++  if (REG_VALID == regcache_register_status (regcache, AARCH64_SP_REGNUM))
++    regcache_raw_collect (regcache, AARCH64_SP_REGNUM, &regs.r_sp);
++  if (REG_VALID == regcache_register_status (regcache, AARCH64_PC_REGNUM))
++    regcache_raw_collect (regcache, AARCH64_PC_REGNUM, &regs.r_pc);
++  if (REG_VALID == regcache_register_status (regcache, AARCH64_CPSR_REGNUM))
++    regcache_raw_collect (regcache, AARCH64_CPSR_REGNUM, &regs.r_spsr);
++
++  ret = ptrace(PT_SETREGS, pid, (caddr_t)&regs, 0);
++  if (ret < 0)
++    perror_with_name (_("Unable to store general registers."));
++}
++
++/* Fill GDB's register array with the fp/simd register values
++   from the current thread.  */
++
++static void
++fetch_fpregs_from_thread (struct regcache *regcache)
++{
++  int ret;
++  pid_t pid;
++  int regno;
++  struct fpreg fpregs;
++
++  pid = ptid_get_pid (inferior_ptid);
++
++  ret = ptrace(PT_GETFPREGS, pid, (caddr_t)&fpregs, 0);
++  if (ret < 0) {
++    perror_with_name (_("Unable to fetch general registers."));
++    return;
++  }
++
++  for (regno = AARCH64_V0_REGNUM; regno <= AARCH64_V31_REGNUM; regno++)
++    regcache_raw_supply (regcache, regno, &fpregs.fp_reg[regno]);
++
++  regcache_raw_supply (regcache, AARCH64_FPSR_REGNUM, &fpregs.fp_sr);
++  regcache_raw_supply (regcache, AARCH64_FPCR_REGNUM, &fpregs.fp_cr);
++}
++
++/* Store to the current thread the valid fp/simd register
++   values in the GDB's register array.  */
++
++static void
++store_fpregs_to_thread (const struct regcache *regcache)
++{
++  int ret;
++  pid_t pid;
++  int regno;
++  struct fpreg fpregs;
++
++  pid = ptid_get_pid (inferior_ptid);
++
++  ret = ptrace(PT_GETFPREGS, pid, (caddr_t)&fpregs, 0);
++  if (ret < 0) {
++    perror_with_name (_("Unable to store general registers."));
++    return;
++  }
++
++  for (regno = AARCH64_V0_REGNUM; regno <= AARCH64_V31_REGNUM; regno++)
++    if (REG_VALID == regcache_register_status (regcache, regno))
++      regcache_raw_collect (regcache, regno, &fpregs.fp_reg[regno]);
++
++  if (REG_VALID == regcache_register_status (regcache, AARCH64_FPSR_REGNUM))
++    regcache_raw_collect (regcache, AARCH64_FPSR_REGNUM, &fpregs.fp_sr);
++  if (REG_VALID == regcache_register_status (regcache, AARCH64_FPCR_REGNUM))
++    regcache_raw_collect (regcache, AARCH64_FPCR_REGNUM, &fpregs.fp_cr);
++
++  ret = ptrace(PT_SETFPREGS, pid, (caddr_t)&fpregs, 0);
++  if (ret < 0)
++    perror_with_name (_("Unable to store general registers."));
++}
++
++/* Implement the "to_fetch_register" target_ops method.  */
++
++static void
++aarch64_obsd_fetch_inferior_registers (struct target_ops *ops,
++                                      struct regcache *regcache,
++                                      int regno)
++{
++  if (regno == -1)
++    {
++      fetch_gregs_from_thread (regcache);
++      fetch_fpregs_from_thread (regcache);
++    }
++  else if (regno < AARCH64_V0_REGNUM)
++    fetch_gregs_from_thread (regcache);
++  else
++    fetch_fpregs_from_thread (regcache);
++}
++
++/* Implement the "to_store_register" target_ops method.  */
++
++static void
++aarch64_obsd_store_inferior_registers (struct target_ops *ops,
++                                      struct regcache *regcache,
++                                      int regno)
++{
++  if (regno == -1)
++    {
++      store_gregs_to_thread (regcache);
++      store_fpregs_to_thread (regcache);
++    }
++  else if (regno < AARCH64_V0_REGNUM)
++    store_gregs_to_thread (regcache);
++  else
++    store_fpregs_to_thread (regcache);
++}
++
++#if 0 
++/* Fill register REGNO (if it is a general-purpose register) in
++   *GREGSETPS with the value in GDB's register array.  If REGNO is -1,
++   do this for all registers.  */
++
++void
++fill_gregset (const struct regcache *regcache,
++            gdb_gregset_t *gregsetp, int regno)
++{
++  regcache_collect_regset (&aarch64_obsd_gregset, regcache,
++                         regno, (gdb_byte *) gregsetp,
++                         AARCH64_OBSD_SIZEOF_GREGSET);
++}
++
++/* Fill GDB's register array with the general-purpose register values
++   in *GREGSETP.  */
++
++void
++supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
++{
++  regcache_supply_regset (&aarch64_obsd_gregset, regcache, -1,
++                        (const gdb_byte *) gregsetp,
++                        AARCH64_OBSD_SIZEOF_GREGSET);
++}
++
++/* Fill register REGNO (if it is a floating-point register) in
++   *FPREGSETP with the value in GDB's register array.  If REGNO is -1,
++   do this for all registers.  */
++
++void
++fill_fpregset (const struct regcache *regcache,
++             gdb_fpregset_t *fpregsetp, int regno)
++{
++  regcache_collect_regset (&aarch64_obsd_fpregset, regcache,
++                         regno, (gdb_byte *) fpregsetp,
++                         AARCH64_OBSD_SIZEOF_FPREGSET);
++}
++
++/* Fill GDB's register array with the floating-point register values
++   in *FPREGSETP.  */
++
++void
++supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
++{
++  regcache_supply_regset (&aarch64_obsd_fpregset, regcache, -1,
++                        (const gdb_byte *) fpregsetp,
++                        AARCH64_OBSD_SIZEOF_FPREGSET);
++}
++
++#endif
++
++/* linux_nat_new_fork hook.   */
++
++#if 0
++static void
++aarch64_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
++{
++  pid_t parent_pid;
++  struct aarch64_debug_reg_state *parent_state;
++  struct aarch64_debug_reg_state *child_state;
++
++  /* NULL means no watchpoint has ever been set in the parent.  In
++     that case, there's nothing to do.  */
++  if (parent->arch_private == NULL)
++    return;
++}
++
++
++/* Called by libthread_db.  Returns a pointer to the thread local
++   storage (or its descriptor).  */
++
++ps_err_e
++ps_get_thread_area (struct ps_prochandle *ph,
++                  lwpid_t lwpid, int idx, void **base)
++{
++  int is_64bit_p
++    = (gdbarch_bfd_arch_info (target_gdbarch ())->bits_per_word == 64);
++
++  return aarch64_ps_get_thread_area (ph, lwpid, idx, base, is_64bit_p);
++}
++#endif
++
++
++extern struct target_desc *tdesc_arm_with_neon;
++
++/* Implement the "to_read_description" target_ops method.  */
++
++static const struct target_desc *
++aarch64_obsd_read_description (struct target_ops *ops)
++{
++    return tdesc_aarch64;
++}
++
++/* Returns the number of hardware watchpoints of type TYPE that we can
++   set.  Value is positive if we can set CNT watchpoints, zero if
++   setting watchpoints of type TYPE is not supported, and negative if
++   CNT is more than the maximum number of watchpoints of type TYPE
++   that we can support.  TYPE is one of bp_hardware_watchpoint,
++   bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
++   CNT is the number of such watchpoints used so far (including this
++   one).  OTHERTYPE is non-zero if other types of watchpoints are
++   currently enabled.  */
++
++static int
++aarch64_linux_can_use_hw_breakpoint (struct target_ops *self,
++                                   enum bptype type,
++                                   int cnt, int othertype)
++{
++#if 0
++  if (type == bp_hardware_watchpoint || type == bp_read_watchpoint
++      || type == bp_access_watchpoint || type == bp_watchpoint)
++    {
++      if (aarch64_num_wp_regs == 0)
++      return 0;
++    }
++  else if (type == bp_hardware_breakpoint)
++    {
++      if (aarch64_num_bp_regs == 0)
++      return 0;
++    }
++  else
++    gdb_assert_not_reached ("unexpected breakpoint type");
++
++  /* We always return 1 here because we don't have enough information
++     about possible overlap of addresses that they want to watch.  As an
++     extreme example, consider the case where all the watchpoints watch
++     the same address and the same region length: then we can handle a
++     virtually unlimited number of watchpoints, due to debug register
++     sharing implemented via reference counts.  */
++  return 1;
++#else
++  return 0;
++#endif
++}
++
++#if 0
++/* Insert a hardware-assisted breakpoint at BP_TGT->reqstd_address.
++   Return 0 on success, -1 on failure.  */
++
++static int
++aarch64_linux_insert_hw_breakpoint (struct target_ops *self,
++                                  struct gdbarch *gdbarch,
++                                  struct bp_target_info *bp_tgt)
++{
++  int ret;
++  CORE_ADDR addr = bp_tgt->placed_address = bp_tgt->reqstd_address;
++  int len;
++  const enum target_hw_bp_type type = hw_execute;
++
++  gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
++
++  if (show_debug_regs)
++    fprintf_unfiltered
++      (gdb_stdlog,
++       "insert_hw_breakpoint on entry (addr=0x%08lx, len=%d))\n",
++       (unsigned long) addr, len);
++
++  ret = aarch64_handle_breakpoint (type, addr, len, 1 /* is_insert */, state);
++
++  if (show_debug_regs)
++    {
++      aarch64_show_debug_reg_state (state,
++                                  "insert_hw_breakpoint", addr, len, type);
++    }
++
++  return ret;
++}
++
++/* Remove a hardware-assisted breakpoint at BP_TGT->placed_address.
++   Return 0 on success, -1 on failure.  */
++
++static int
++aarch64_linux_remove_hw_breakpoint (struct target_ops *self,
++                                  struct gdbarch *gdbarch,
++                                  struct bp_target_info *bp_tgt)
++{
++  int ret;
++  CORE_ADDR addr = bp_tgt->placed_address;
++  int len = 4;
++  const enum target_hw_bp_type type = hw_execute;
++  struct aarch64_debug_reg_state *state
++    = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
++
++  gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
++
++  if (show_debug_regs)
++    fprintf_unfiltered
++      (gdb_stdlog, "remove_hw_breakpoint on entry (addr=0x%08lx, len=%d))\n",
++       (unsigned long) addr, len);
++
++  ret = aarch64_handle_breakpoint (type, addr, len, 0 /* is_insert */, state);
++
++  if (show_debug_regs)
++    {
++      aarch64_show_debug_reg_state (state,
++                                  "remove_hw_watchpoint", addr, len, type);
++    }
++
++  return ret;
++}
++
++/* Implement the "to_insert_watchpoint" target_ops method.
++
++   Insert a watchpoint to watch a memory region which starts at
++   address ADDR and whose length is LEN bytes.  Watch memory accesses
++   of the type TYPE.  Return 0 on success, -1 on failure.  */
++
++static int
++aarch64_linux_insert_watchpoint (struct target_ops *self,
++                               CORE_ADDR addr, int len,
++                               enum target_hw_bp_type type,
++                               struct expression *cond)
++{
++  int ret;
++  struct aarch64_debug_reg_state *state
++    = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
++
++  if (show_debug_regs)
++    fprintf_unfiltered (gdb_stdlog,
++                      "insert_watchpoint on entry (addr=0x%08lx, len=%d)\n",
++                      (unsigned long) addr, len);
++
++  gdb_assert (type != hw_execute);
++
++  ret = aarch64_handle_watchpoint (type, addr, len, 1 /* is_insert */, state);
++
++  if (show_debug_regs)
++    {
++      aarch64_show_debug_reg_state (state,
++                                  "insert_watchpoint", addr, len, type);
++    }
++
++  return ret;
++}
++
++/* Implement the "to_remove_watchpoint" target_ops method.
++   Remove a watchpoint that watched the memory region which starts at
++   address ADDR, whose length is LEN bytes, and for accesses of the
++   type TYPE.  Return 0 on success, -1 on failure.  */
++
++static int
++aarch64_linux_remove_watchpoint (struct target_ops *self,
++                               CORE_ADDR addr, int len,
++                               enum target_hw_bp_type type,
++                               struct expression *cond)
++{
++  int ret;
++  struct aarch64_debug_reg_state *state
++    = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
++
++  if (show_debug_regs)
++    fprintf_unfiltered (gdb_stdlog,
++                      "remove_watchpoint on entry (addr=0x%08lx, len=%d)\n",
++                      (unsigned long) addr, len);
++
++  gdb_assert (type != hw_execute);
++
++  ret = aarch64_handle_watchpoint (type, addr, len, 0 /* is_insert */, state);
++
++  if (show_debug_regs)
++    {
++      aarch64_show_debug_reg_state (state,
++                                  "remove_watchpoint", addr, len, type);
++    }
++
++  return ret;
++}
++
++/* Implement the "to_region_ok_for_hw_watchpoint" target_ops method.  */
++
++static int
++aarch64_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
++                                         CORE_ADDR addr, int len)
++{
++  return aarch64_linux_region_ok_for_watchpoint (addr, len);
++}
++
++/* Implement the "to_stopped_data_address" target_ops method.  */
++
++static int
++aarch64_linux_stopped_data_address (struct target_ops *target,
++                                  CORE_ADDR *addr_p)
++{
++  siginfo_t siginfo;
++  int i, tid;
++  struct aarch64_debug_reg_state *state;
++
++  if (!linux_nat_get_siginfo (inferior_ptid, &siginfo))
++    return 0;
++
++  /* This must be a hardware breakpoint.  */
++  if (siginfo.si_signo != SIGTRAP
++      || (siginfo.si_code & 0xffff) != TRAP_HWBKPT)
++    return 0;
++
++  /* Check if the address matches any watched address.  */
++  state = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
++  for (i = aarch64_num_wp_regs - 1; i >= 0; --i)
++    {
++      const unsigned int len = aarch64_watchpoint_length 
(state->dr_ctrl_wp[i]);
++      const CORE_ADDR addr_trap = (CORE_ADDR) siginfo.si_addr;
++      const CORE_ADDR addr_watch = state->dr_addr_wp[i];
++
++      if (state->dr_ref_count_wp[i]
++        && DR_CONTROL_ENABLED (state->dr_ctrl_wp[i])
++        && addr_trap >= addr_watch
++        && addr_trap < addr_watch + len)
++      {
++        *addr_p = addr_trap;
++        return 1;
++      }
++    }
++
++  return 0;
++}
++
++/* Implement the "to_stopped_by_watchpoint" target_ops method.  */
++
++static int
++aarch64_linux_stopped_by_watchpoint (struct target_ops *ops)
++{
++  CORE_ADDR addr;
++
++  return aarch64_linux_stopped_data_address (ops, &addr);
++}
++
++/* Implement the "to_watchpoint_addr_within_range" target_ops method.  */
++
++static int
++aarch64_linux_watchpoint_addr_within_range (struct target_ops *target,
++                                          CORE_ADDR addr,
++                                          CORE_ADDR start, int length)
++{
++  return start <= addr && start + length - 1 >= addr;
++}
++#endif
++
++/* Implement the "to_can_do_single_step" target_ops method.  */
++
++static int
++aarch64_obsd_can_do_single_step (struct target_ops *target)
++{
++  return 1;
++}
++
++/* Define AArch64 maintenance commands.  */
++
++static void
++add_show_debug_regs_command (void)
++{
++#if 0
++  /* A maintenance command to enable printing the internal DRi mirror
++     variables.  */
++  add_setshow_boolean_cmd ("show-debug-regs", class_maintenance,
++                         &show_debug_regs, _("\
++Set whether to show variables that mirror the AArch64 debug registers."), _("\
++Show whether to show variables that mirror the AArch64 debug registers."), 
_("\
++Use \"on\" to enable, \"off\" to disable.\n\
++If enabled, the debug registers values are shown when GDB inserts\n\
++or removes a hardware breakpoint or watchpoint, and when the inferior\n\
++triggers a breakpoint or watchpoint."),
++                         NULL,
++                         NULL,
++                         &maintenance_set_cmdlist,
++                         &maintenance_show_cmdlist);
++#endif
++}
++
++/* -Wmissing-prototypes.  */
++void _initialize_aarch64_obsd_nat (void);
++
++void
++_initialize_aarch64_obsd_nat (void)
++{
++  struct target_ops *t;
++
++  t = inf_ptrace_target ();
++
++  add_show_debug_regs_command ();
++
++  /* Add our register access methods.  */
++  t->to_fetch_registers = aarch64_obsd_fetch_inferior_registers;
++  t->to_store_registers = aarch64_obsd_store_inferior_registers;
++  t->to_read_description = aarch64_obsd_read_description;
++
++// ABOVEDONE
++
++#if 0
++  t->to_can_use_hw_breakpoint = aarch64_linux_can_use_hw_breakpoint;
++  t->to_insert_hw_breakpoint = aarch64_linux_insert_hw_breakpoint;
++  t->to_remove_hw_breakpoint = aarch64_linux_remove_hw_breakpoint;
++  t->to_region_ok_for_hw_watchpoint =
++    aarch64_linux_region_ok_for_hw_watchpoint;
++  t->to_insert_watchpoint = aarch64_linux_insert_watchpoint;
++  t->to_remove_watchpoint = aarch64_linux_remove_watchpoint;
++  t->to_stopped_by_watchpoint = aarch64_linux_stopped_by_watchpoint;
++  t->to_stopped_data_address = aarch64_linux_stopped_data_address;
++  t->to_watchpoint_addr_within_range =
++    aarch64_linux_watchpoint_addr_within_range;
++#endif
++  t->to_can_do_single_step = aarch64_obsd_can_do_single_step;
++
++  /* Register the target.  */
++  add_target (t);
++
++#if 0
++  linux_nat_set_new_thread (t, aarch64_linux_new_thread);
++  linux_nat_set_new_fork (t, aarch64_linux_new_fork);
++  linux_nat_set_forget_process (t, aarch64_forget_process);
++  linux_nat_set_prepare_to_resume (t, aarch64_linux_prepare_to_resume);
++#endif
++}
Index: patches/patch-gdb_aarch64obsd-tdep_c
===================================================================
RCS file: patches/patch-gdb_aarch64obsd-tdep_c
diff -N patches/patch-gdb_aarch64obsd-tdep_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_aarch64obsd-tdep_c        23 Jun 2018 20:26:20 -0000
@@ -0,0 +1,171 @@
+$OpenBSD$
+Index: gdb/aarch64obsd-tdep.c
+--- gdb/aarch64obsd-tdep.c.orig
++++ gdb/aarch64obsd-tdep.c
+@@ -0,0 +1,166 @@
++/* 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 "trad-frame.h"
++#include "tramp-frame.h"
++
++#include "obsd-tdep.h"
++#include "aarch64-tdep.h"
++#include "aarch64-obsd-tdep.h"
++#include "solib-svr4.h"
++
++/* Signal trampolines.  */
++
++#if 0
++static void
++aarch64_obsd_sigframe_init (const struct tramp_frame *self,
++                           struct frame_info *this_frame,
++                           struct trad_frame_cache *this_cache,
++                           CORE_ADDR func)
++{
++  CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
++  CORE_ADDR sigcontext_addr =
++    sp
++    + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
++    + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET;
++  int i;
++
++  for (i = 0; i < 31; i++)
++    {
++      trad_frame_set_reg_addr (this_cache,
++                             AARCH64_X0_REGNUM + i,
++                             sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
++                             + i * AARCH64_SIGCONTEXT_REG_SIZE);
++    }
++  trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM,
++                         sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
++                           + 31 * AARCH64_SIGCONTEXT_REG_SIZE);
++  trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM,
++                         sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
++                           + 32 * AARCH64_SIGCONTEXT_REG_SIZE);
++
++  trad_frame_set_id (this_cache, frame_id_build (sp, func));
++}
++
++static const struct tramp_frame aarch64_obsd_rt_sigframe =
++{
++  SIGTRAMP_FRAME,
++  4,
++  {
++    /* movz x8, 0x8b (S=1,o=10,h=0,i=0x8b,r=8)
++       Soo1 0010 1hhi iiii iiii iiii iiir rrrr  */
++    {0xd2801168, -1},
++
++    /* svc  0x0      (o=0, l=1)
++       1101 0100 oooi iiii iiii iiii iii0 00ll  */
++    {0xd4000001, -1},
++    {TRAMP_SENTINEL_INSN, -1}
++  },
++  aarch64_obsd_sigframe_init
++};
++#endif
++
++/* 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);
++}
++
++
++
++
++extern initialize_file_ftype _initialize_aarch64_tdep;
++
++static void
++aarch64obsd_init_abi (struct gdbarch_info info,
++                struct gdbarch *gdbarch)
++{
++  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
++
++#if 0
++  tramp_frame_prepend_unwinder (gdbarch, &aarch64obsd_sigframe);
++#endif
++
++  /* 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);
++
++  tdep->jb_pc = 24; /* XXX */
++  tdep->jb_elt_size = 4; /* XXX */
++
++  set_gdbarch_iterate_over_regset_sections
++    (gdbarch, aarch64_obsd_iterate_over_regset_sections);
++
++//_initialize_aarch64_tdep();
++}
++
++
++
++/* 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);
++}
Index: patches/patch-gdb_config_aarch64_obsd_mh
===================================================================
RCS file: patches/patch-gdb_config_aarch64_obsd_mh
diff -N patches/patch-gdb_config_aarch64_obsd_mh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_config_aarch64_obsd_mh    23 Jun 2018 20:26:20 -0000
@@ -0,0 +1,10 @@
+$OpenBSD$
+Index: gdb/config/aarch64/obsd.mh
+--- gdb/config/aarch64/obsd.mh.orig
++++ gdb/config/aarch64/obsd.mh
+@@ -0,0 +1,5 @@
++# Host: OpenBSD/arm64 ELF
++NATDEPFILES= fork-child.o inf-ptrace.o obsd-nat.o \
++      aarch64obsd-nat.o bsd-kvm.o
++
++LOADLIBES= -lkvm
Index: patches/patch-gdb_configure_host
===================================================================
RCS file: patches/patch-gdb_configure_host
diff -N patches/patch-gdb_configure_host
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_configure_host    23 Jun 2018 20:26:20 -0000
@@ -0,0 +1,11 @@
+$OpenBSD$
+--- gdb/configure.host.orig    Sat Jan 21 05:48:42 2017
++++ gdb/configure.host Tue Mar  7 23:52:43 2017
+@@ -82,6 +82,7 @@ case "${host}" in
+ *-*-darwin*)          gdb_host=darwin ;;
+ 
+ aarch64*-*-linux*)    gdb_host=linux ;;
++aarch64*-*-openbsd*)  gdb_host=obsd ;;
+ 
+ alpha*-*-linux*)      gdb_host=alpha-linux ;;
+ alpha*-*-freebsd* | alpha*-*-kfreebsd*-gnu)
Index: patches/patch-gdb_configure_tgt
===================================================================
RCS file: patches/patch-gdb_configure_tgt
diff -N patches/patch-gdb_configure_tgt
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_configure_tgt     23 Jun 2018 20:26:20 -0000
@@ -0,0 +1,18 @@
+$OpenBSD$
+Index: gdb/configure.tgt
+--- gdb/configure.tgt.orig
++++ gdb/configure.tgt
+@@ -51,6 +51,13 @@ aarch64*-*-linux*)
+       build_gdbserver=yes
+       ;;
+ 
++aarch64*-*-openbsd*)
++      # Target: AArch64 linux
++      gdb_target_obs="aarch64-tdep.o aarch64obsd-tdep.o \
++                      obsd-tdep.o solib.o \
++                      solib-svr4.o symfile-mem.o aarch64-insn.o"
++      ;;
++
+ alpha*-*-linux*)
+       # Target: Little-endian Alpha running Linux
+       gdb_target_obs="alpha-tdep.o alpha-mdebug-tdep.o alpha-linux-tdep.o \

Reply via email to