gdb/alphaobsd-tdep.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Target-dependent code for OpenBSD/alpha.

  2.    Copyright (C) 2006-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "frame.h"
  16. #include "gdbcore.h"
  17. #include "osabi.h"

  18. #include "obsd-tdep.h"
  19. #include "alpha-tdep.h"
  20. #include "alphabsd-tdep.h"
  21. #include "solib-svr4.h"

  22. /* Signal trampolines.  */

  23. /* The OpenBSD kernel maps the signal trampoline at some random
  24.    location in user space, which means that the traditional BSD way of
  25.    detecting it won't work.

  26.    The signal trampoline will be mapped at an address that is page
  27.    aligned.  We recognize the signal trampoline by looking for the
  28.    sigreturn system call.  */

  29. static const int alphaobsd_page_size = 8192;

  30. static LONGEST
  31. alphaobsd_sigtramp_offset (struct gdbarch *gdbarch, CORE_ADDR pc)
  32. {
  33.   return (pc & (alphaobsd_page_size - 1));
  34. }

  35. static int
  36. alphaobsd_pc_in_sigtramp (struct gdbarch *gdbarch,
  37.                           CORE_ADDR pc, const char *name)
  38. {
  39.   CORE_ADDR start_pc = (pc & ~(alphaobsd_page_size - 1));
  40.   unsigned insn;

  41.   if (name)
  42.     return 0;

  43.   /* Check for "".  */
  44.   insn = alpha_read_insn (gdbarch, start_pc + 5 * ALPHA_INSN_SIZE);
  45.   if (insn != 0x201f0067)
  46.     return 0;

  47.   /* Check for "".  */
  48.   insn = alpha_read_insn (gdbarch, start_pc + 6 * ALPHA_INSN_SIZE);
  49.   if (insn != 0x00000083)
  50.     return 0;

  51.   return 1;
  52. }

  53. static CORE_ADDR
  54. alphaobsd_sigcontext_addr (struct frame_info *this_frame)
  55. {
  56.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  57.   CORE_ADDR pc = get_frame_pc (this_frame);

  58.   if (alphaobsd_sigtramp_offset (gdbarch, pc) < 3 * ALPHA_INSN_SIZE)
  59.     {
  60.       /* On entry, a pointer the `struct sigcontext' is passed in %a2.  */
  61.       return get_frame_register_unsigned (this_frame, ALPHA_A0_REGNUM + 2);
  62.     }
  63.   else if (alphaobsd_sigtramp_offset (gdbarch, pc) < 4 * ALPHA_INSN_SIZE)
  64.     {
  65.       /* It is stored on the stack Before calling the signal handler.  */
  66.       CORE_ADDR sp;
  67.       sp = get_frame_register_unsigned (this_frame, ALPHA_SP_REGNUM);
  68.       return get_frame_memory_unsigned (this_frame, sp, 8);
  69.     }
  70.   else
  71.     {
  72.       /* It is reloaded into %a0 for the sigreturn(2) call.  */
  73.       return get_frame_register_unsigned (this_frame, ALPHA_A0_REGNUM);
  74.     }
  75. }


  76. static void
  77. alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
  78. {
  79.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  80.   /* Hook into the DWARF CFI frame unwinder.  */
  81.   alpha_dwarf2_init_abi (info, gdbarch);

  82.   /* Hook into the MDEBUG frame unwinder.  */
  83.   alpha_mdebug_init_abi (info, gdbarch);

  84.   /* OpenBSD/alpha 3.0 and earlier does not provide single step
  85.      support via ptrace(2); use software single-stepping for now.  */
  86.   set_gdbarch_software_single_step (gdbarch, alpha_software_single_step);

  87.   /* OpenBSD/alpha has SVR4-style shared libraries.  */
  88.   set_solib_svr4_fetch_link_map_offsets
  89.     (gdbarch, svr4_lp64_fetch_link_map_offsets);
  90.   set_gdbarch_skip_solib_resolver (gdbarch, obsd_skip_solib_resolver);

  91.   tdep->dynamic_sigtramp_offset = alphaobsd_sigtramp_offset;
  92.   tdep->pc_in_sigtramp = alphaobsd_pc_in_sigtramp;
  93.   tdep->sigcontext_addr = alphaobsd_sigcontext_addr;

  94.   tdep->jb_pc = 2;
  95.   tdep->jb_elt_size = 8;

  96.   set_gdbarch_iterate_over_regset_sections
  97.     (gdbarch, alphanbsd_iterate_over_regset_sections);
  98. }


  99. /* Provide a prototype to silence -Wmissing-prototypes.  */
  100. void _initialize_alphaobsd_tdep (void);

  101. void
  102. _initialize_alphaobsd_tdep (void)
  103. {
  104.   gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_OPENBSD_ELF,
  105.                           alphaobsd_init_abi);
  106. }