gdb/amd64nbsd-tdep.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Target-dependent code for NetBSD/amd64.

  2.    Copyright (C) 2003-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 "gdbcore.h"
  18. #include "osabi.h"
  19. #include "symtab.h"

  20. #include "amd64-tdep.h"
  21. #include "nbsd-tdep.h"
  22. #include "solib-svr4.h"

  23. /* Support for signal handlers.  */

  24. /* Return whether THIS_FRAME corresponds to a NetBSD sigtramp
  25.    routine.  */

  26. static int
  27. amd64nbsd_sigtramp_p (struct frame_info *this_frame)
  28. {
  29.   CORE_ADDR pc = get_frame_pc (this_frame);
  30.   const char *name;

  31.   find_pc_partial_function (pc, &name, NULL, NULL);
  32.   return nbsd_pc_in_sigtramp (pc, name);
  33. }

  34. /* Assuming THIS_FRAME corresponds to a NetBSD sigtramp routine,
  35.    return the address of the associated mcontext structure.  */

  36. static CORE_ADDR
  37. amd64nbsd_mcontext_addr (struct frame_info *this_frame)
  38. {
  39.   CORE_ADDR addr;

  40.   /* The register %r15 points at `struct ucontext' upon entry of a
  41.      signal trampoline.  */
  42.   addr = get_frame_register_unsigned (this_frame, AMD64_R15_REGNUM);

  43.   /* The mcontext structure lives as offset 56 in `struct ucontext'.  */
  44.   return addr + 56;
  45. }

  46. /* NetBSD 2.0 or later.  */

  47. /* Mapping between the general-purpose registers in `struct reg'
  48.    format and GDB's register cache layout.  */

  49. /* From <machine/reg.h>.  */
  50. int amd64nbsd_r_reg_offset[] =
  51. {
  52.   14 * 8,                        /* %rax */
  53.   13 * 8,                        /* %rbx */
  54.   3 * 8,                        /* %rcx */
  55.   2 * 8,                        /* %rdx */
  56.   1 * 8,                        /* %rsi */
  57.   0 * 8,                        /* %rdi */
  58.   12 * 8,                        /* %rbp */
  59.   24 * 8,                        /* %rsp */
  60.   4 * 8,                        /* %r8 ..  */
  61.   5 * 8,
  62.   6 * 8,
  63.   7 * 8,
  64.   8 * 8,
  65.   9 * 8,
  66.   10 * 8,
  67.   11 * 8,                        /* ... %r15 */
  68.   21 * 8,                        /* %rip */
  69.   23 * 8,                        /* %eflags */
  70.   22 * 8,                        /* %cs */
  71.   25 * 8,                        /* %ss */
  72.   18 * 8,                        /* %ds */
  73.   17 * 8,                        /* %es */
  74.   16 * 8,                        /* %fs */
  75.   15 * 8                        /* %gs */
  76. };

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

  81.   /* Initialize general-purpose register set details first.  */
  82.   tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
  83.   tdep->gregset_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
  84.   tdep->sizeof_gregset = 26 * 8;

  85.   amd64_init_abi (info, gdbarch);

  86.   tdep->jb_pc_offset = 7 * 8;

  87.   /* NetBSD has its own convention for signal trampolines.  */
  88.   tdep->sigtramp_p = amd64nbsd_sigtramp_p;
  89.   tdep->sigcontext_addr = amd64nbsd_mcontext_addr;
  90.   tdep->sc_reg_offset = amd64nbsd_r_reg_offset;
  91.   tdep->sc_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);

  92.   /* NetBSD uses SVR4-style shared libraries.  */
  93.   set_solib_svr4_fetch_link_map_offsets
  94.     (gdbarch, svr4_lp64_fetch_link_map_offsets);
  95. }


  96. /* Provide a prototype to silence -Wmissing-prototypes.  */
  97. void _initialize_amd64nbsd_tdep (void);

  98. void
  99. _initialize_amd64nbsd_tdep (void)
  100. {
  101.   /* The NetBSD/amd64 native dependent code makes this assumption.  */
  102.   gdb_assert (ARRAY_SIZE (amd64nbsd_r_reg_offset) == AMD64_NUM_GREGS);

  103.   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
  104.                           GDB_OSABI_NETBSD_ELF, amd64nbsd_init_abi);
  105. }