amd64-darwin-tdep.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Darwin support for GDB, the GNU debugger.
  2. Copyright (C) 1997-2022 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 "symtab.h"
  21. #include "regcache.h"
  22. #include "objfiles.h"
  23. #include "i387-tdep.h"
  24. #include "gdbsupport/x86-xstate.h"
  25. #include "amd64-tdep.h"
  26. #include "osabi.h"
  27. #include "ui-out.h"
  28. #include "amd64-darwin-tdep.h"
  29. #include "i386-darwin-tdep.h"
  30. #include "solib.h"
  31. #include "solib-darwin.h"
  32. #include "dwarf2/frame.h"
  33. /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
  34. From <mach/i386/thread_status.h> and amd64-tdep.h. */
  35. int amd64_darwin_thread_state_reg_offset[] =
  36. {
  37. 0 * 8, /* %rax */
  38. 1 * 8, /* %rbx */
  39. 2 * 8, /* %rcx */
  40. 3 * 8, /* %rdx */
  41. 5 * 8, /* %rsi */
  42. 4 * 8, /* %rdi */
  43. 6 * 8, /* %rbp */
  44. 7 * 8, /* %rsp */
  45. 8 * 8, /* %r8 ... */
  46. 9 * 8,
  47. 10 * 8,
  48. 11 * 8,
  49. 12 * 8,
  50. 13 * 8,
  51. 14 * 8,
  52. 15 * 8, /* ... %r15 */
  53. 16 * 8, /* %rip */
  54. 17 * 8, /* %rflags */
  55. 18 * 8, /* %cs */
  56. -1, /* %ss */
  57. -1, /* %ds */
  58. -1, /* %es */
  59. 19 * 8, /* %fs */
  60. 20 * 8 /* %gs */
  61. };
  62. const int amd64_darwin_thread_state_num_regs =
  63. ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);
  64. /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
  65. address of the associated sigcontext structure. */
  66. static CORE_ADDR
  67. amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
  68. {
  69. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  70. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  71. CORE_ADDR rbx;
  72. gdb_byte buf[8];
  73. /* A pointer to the ucontext is passed as the fourth argument
  74. to the signal handler, which is saved in rbx. */
  75. get_frame_register (this_frame, AMD64_RBX_REGNUM, buf);
  76. rbx = extract_unsigned_integer (buf, 8, byte_order);
  77. /* The pointer to mcontext is at offset 48. */
  78. read_memory (rbx + 48, buf, 8);
  79. /* First register (rax) is at offset 16. */
  80. return extract_unsigned_integer (buf, 8, byte_order) + 16;
  81. }
  82. static void
  83. x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
  84. {
  85. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  86. amd64_init_abi (info, gdbarch,
  87. amd64_target_description (X86_XSTATE_SSE_MASK, true));
  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. void _initialize_amd64_darwin_tdep ();
  98. void
  99. _initialize_amd64_darwin_tdep ()
  100. {
  101. gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
  102. GDB_OSABI_DARWIN, x86_darwin_init_abi_64);
  103. }