gdb/vaxobsd-tdep.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

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

  2.    Copyright (C) 2005-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 "arch-utils.h"
  16. #include "frame.h"
  17. #include "frame-unwind.h"
  18. #include "osabi.h"
  19. #include "symtab.h"
  20. #include "trad-frame.h"

  21. #include "vax-tdep.h"

  22. /* Signal trampolines.  */

  23. /* Since OpenBSD 3.2, the sigtramp routine is mapped at a random page
  24.    in virtual memory.  The randomness makes it somewhat tricky to
  25.    detect it, but fortunately we can rely on the fact that the start
  26.    of the sigtramp routine is page-aligned.  We recognize the
  27.    trampoline by looking for the code that invokes the sigreturn
  28.    system call.  The offset where we can find that code varies from
  29.    release to release.

  30.    By the way, the mapping mentioned above is read-only, so you cannot
  31.    place a breakpoint in the signal trampoline.  */

  32. /* Default page size.  */
  33. static const int vaxobsd_page_size = 4096;

  34. /* Offset for sigreturn(2).  */
  35. static const int vaxobsd_sigreturn_offset = 0x11;

  36. /* Instruction sequence for sigreturn(2).  VAX doesn't have
  37.    fixed-length instructions so we include the ensuing exit(2) to
  38.    reduce the chance of spurious matches.  */
  39. static const gdb_byte vaxobsd_sigreturn[] = {
  40.   0xbc, 0x8f, 0x67, 0x00,        /* chmk $SYS_sigreturn */
  41.   0xbc, 0x01                        /* chmk $SYS_exit */
  42. };

  43. static int
  44. vaxobsd_sigtramp_sniffer (const struct frame_unwind *self,
  45.                           struct frame_info *this_frame,
  46.                           void **this_cache)
  47. {
  48.   CORE_ADDR pc = get_frame_pc (this_frame);
  49.   CORE_ADDR start_pc = (pc & ~(vaxobsd_page_size - 1));
  50.   CORE_ADDR sigreturn_addr = start_pc + vaxobsd_sigreturn_offset;
  51.   gdb_byte *buf;
  52.   const char *name;

  53.   find_pc_partial_function (pc, &name, NULL, NULL);
  54.   if (name)
  55.     return 0;

  56.   buf = alloca(sizeof vaxobsd_sigreturn);
  57.   if (!safe_frame_unwind_memory (this_frame, sigreturn_addr,
  58.                                  buf, sizeof vaxobsd_sigreturn))
  59.     return 0;

  60.   if (memcmp(buf, vaxobsd_sigreturn, sizeof vaxobsd_sigreturn) == 0)
  61.     return 1;

  62.   return 0;
  63. }

  64. static struct trad_frame_cache *
  65. vaxobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
  66. {
  67.   struct trad_frame_cache *cache;
  68.   CORE_ADDR addr, base, func;

  69.   if (*this_cache)
  70.     return *this_cache;

  71.   cache = trad_frame_cache_zalloc (this_frame);
  72.   *this_cache = cache;

  73.   func = get_frame_pc (this_frame);
  74.   func &= ~(vaxobsd_page_size - 1);

  75.   base = get_frame_register_unsigned (this_frame, VAX_SP_REGNUM);
  76.   addr = get_frame_memory_unsigned (this_frame, base - 4, 4);

  77.   trad_frame_set_reg_addr (cache, VAX_SP_REGNUM, addr + 8);
  78.   trad_frame_set_reg_addr (cache, VAX_FP_REGNUM, addr + 12);
  79.   trad_frame_set_reg_addr (cache, VAX_AP_REGNUM, addr + 16);
  80.   trad_frame_set_reg_addr (cache, VAX_PC_REGNUM, addr + 20);
  81.   trad_frame_set_reg_addr (cache, VAX_PS_REGNUM, addr + 24);

  82.   /* Construct the frame ID using the function start.  */
  83.   trad_frame_set_id (cache, frame_id_build (base, func));

  84.   return cache;
  85. }

  86. static void
  87. vaxobsd_sigtramp_frame_this_id (struct frame_info *this_frame,
  88.                                 void **this_cache, struct frame_id *this_id)
  89. {
  90.   struct trad_frame_cache *cache =
  91.     vaxobsd_sigtramp_frame_cache (this_frame, this_cache);

  92.   trad_frame_get_id (cache, this_id);
  93. }

  94. static struct value *
  95. vaxobsd_sigtramp_frame_prev_register (struct frame_info *this_frame,
  96.                                       void **this_cache, int regnum)
  97. {
  98.   struct trad_frame_cache *cache =
  99.     vaxobsd_sigtramp_frame_cache (this_frame, this_cache);

  100.   return trad_frame_get_register (cache, this_frame, regnum);
  101. }

  102. static const struct frame_unwind vaxobsd_sigtramp_frame_unwind = {
  103.   SIGTRAMP_FRAME,
  104.   default_frame_unwind_stop_reason,
  105.   vaxobsd_sigtramp_frame_this_id,
  106.   vaxobsd_sigtramp_frame_prev_register,
  107.   NULL,
  108.   vaxobsd_sigtramp_sniffer
  109. };


  110. /* OpenBSD a.out.  */

  111. static void
  112. vaxobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  113. {
  114.   frame_unwind_append_unwinder (gdbarch, &vaxobsd_sigtramp_frame_unwind);
  115. }

  116. /* FIXME: kettenis/20050821: Since OpenBSD/vax binaries are
  117.    indistingushable from NetBSD/vax a.out binaries, building a GDB
  118.    that should support both these targets will probably not work as
  119.    expected.  */
  120. #define GDB_OSABI_OPENBSD_AOUT GDB_OSABI_NETBSD_AOUT

  121. static enum gdb_osabi
  122. vaxobsd_aout_osabi_sniffer (bfd *abfd)
  123. {
  124.   if (strcmp (bfd_get_target (abfd), "a.out-vax-netbsd") == 0)
  125.     return GDB_OSABI_OPENBSD_AOUT;

  126.   return GDB_OSABI_UNKNOWN;
  127. }


  128. /* Provide a prototype to silence -Wmissing-prototypes.  */
  129. void _initialize_vaxobsd_tdep (void);

  130. void
  131. _initialize_vaxobsd_tdep (void)
  132. {
  133.   gdbarch_register_osabi_sniffer (bfd_arch_vax, bfd_target_aout_flavour,
  134.                                   vaxobsd_aout_osabi_sniffer);

  135.   gdbarch_register_osabi (bfd_arch_vax, 0, GDB_OSABI_OPENBSD_AOUT,
  136.                           vaxobsd_init_abi);
  137. }