gdb/amd64-darwin-tdep.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Darwin support for GDB, the GNU debugger.
  2.    Copyright (C) 1997-2015 Free Software Foundation, Inc.

  3.    Contributed by Apple Computer, Inc.

  4.    This file is part of GDB.

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

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

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

  15. #include "defs.h"
  16. #include "frame.h"
  17. #include "inferior.h"
  18. #include "gdbcore.h"
  19. #include "target.h"
  20. #include "floatformat.h"
  21. #include "symtab.h"
  22. #include "regcache.h"
  23. #include "libbfd.h"
  24. #include "objfiles.h"

  25. #include "i387-tdep.h"
  26. #include "amd64-tdep.h"
  27. #include "osabi.h"
  28. #include "ui-out.h"
  29. #include "amd64-darwin-tdep.h"
  30. #include "i386-darwin-tdep.h"
  31. #include "solib.h"
  32. #include "solib-darwin.h"
  33. #include "dwarf2-frame.h"

  34. /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
  35.    From <mach/i386/thread_status.h> and amd64-tdep.h.  */
  36. int amd64_darwin_thread_state_reg_offset[] =
  37. {
  38.   0 * 8,                        /* %rax */
  39.   1 * 8,                        /* %rbx */
  40.   2 * 8,                        /* %rcx */
  41.   3 * 8,                        /* %rdx */
  42.   5 * 8,                        /* %rsi */
  43.   4 * 8,                        /* %rdi */
  44.   6 * 8,                        /* %rbp */
  45.   7 * 8,                        /* %rsp */
  46.   8 * 8,                        /* %r8 ...  */
  47.   9 * 8,
  48.   10 * 8,
  49.   11 * 8,
  50.   12 * 8,
  51.   13 * 8,
  52.   14 * 8,
  53.   15 * 8,                        /* ... %r15 */
  54.   16 * 8,                        /* %rip */
  55.   17 * 8,                        /* %rflags */
  56.   18 * 8,                        /* %cs */
  57.   -1,                                /* %ss */
  58.   -1,                                /* %ds */
  59.   -1,                                /* %es */
  60.   19 * 8,                        /* %fs */
  61.   20 * 8                        /* %gs */
  62. };

  63. const int amd64_darwin_thread_state_num_regs =
  64.   ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);

  65. /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
  66.    address of the associated sigcontext structure.  */

  67. static CORE_ADDR
  68. amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
  69. {
  70.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  71.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  72.   CORE_ADDR rbx;
  73.   gdb_byte buf[8];

  74.   /* A pointer to the ucontext is passed as the fourth argument
  75.      to the signal handler, which is saved in rbx.  */
  76.   get_frame_register (this_frame, AMD64_RBX_REGNUM, buf);
  77.   rbx = extract_unsigned_integer (buf, 8, byte_order);

  78.   /* The pointer to mcontext is at offset 48.  */
  79.   read_memory (rbx + 48, buf, 8);

  80.   /* First register (rax) is at offset 16.  */
  81.   return extract_unsigned_integer (buf, 8, byte_order) + 16;
  82. }

  83. static void
  84. x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
  85. {
  86.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  87.   amd64_init_abi (info, gdbarch);

  88.   tdep->struct_return = reg_struct_return;

  89.   dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p);

  90.   tdep->sigtramp_p = i386_sigtramp_p;
  91.   tdep->sigcontext_addr = amd64_darwin_sigcontext_addr;
  92.   tdep->sc_reg_offset = amd64_darwin_thread_state_reg_offset;
  93.   tdep->sc_num_regs = amd64_darwin_thread_state_num_regs;

  94.   tdep->jb_pc_offset = 56;

  95.   set_solib_ops (gdbarch, &darwin_so_ops);
  96. }

  97. /* -Wmissing-prototypes */
  98. extern initialize_file_ftype _initialize_amd64_darwin_tdep;

  99. void
  100. _initialize_amd64_darwin_tdep (void)
  101. {
  102.   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
  103.                           GDB_OSABI_DARWIN, x86_darwin_init_abi_64);
  104. }