Home | History | Annotate | Line # | Download | only in gdb
      1   1.1  christos /* Darwin support for GDB, the GNU debugger.
      2  1.11  christos    Copyright (C) 1997-2024 Free Software Foundation, Inc.
      3   1.1  christos 
      4   1.1  christos    Contributed by Apple Computer, Inc.
      5   1.1  christos 
      6   1.1  christos    This file is part of GDB.
      7   1.1  christos 
      8   1.1  christos    This program is free software; you can redistribute it and/or modify
      9   1.1  christos    it under the terms of the GNU General Public License as published by
     10   1.1  christos    the Free Software Foundation; either version 3 of the License, or
     11   1.1  christos    (at your option) any later version.
     12   1.1  christos 
     13   1.1  christos    This program is distributed in the hope that it will be useful,
     14   1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15   1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16   1.1  christos    GNU General Public License for more details.
     17   1.1  christos 
     18   1.1  christos    You should have received a copy of the GNU General Public License
     19   1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     20   1.1  christos 
     21  1.11  christos #include "extract-store-integer.h"
     22   1.1  christos #include "frame.h"
     23   1.1  christos #include "inferior.h"
     24   1.1  christos #include "gdbcore.h"
     25   1.1  christos #include "target.h"
     26   1.1  christos #include "symtab.h"
     27   1.1  christos #include "regcache.h"
     28   1.1  christos #include "objfiles.h"
     29   1.1  christos 
     30   1.1  christos #include "i387-tdep.h"
     31   1.9  christos #include "gdbsupport/x86-xstate.h"
     32   1.1  christos #include "amd64-tdep.h"
     33   1.1  christos #include "osabi.h"
     34   1.1  christos #include "ui-out.h"
     35   1.1  christos #include "amd64-darwin-tdep.h"
     36   1.1  christos #include "i386-darwin-tdep.h"
     37   1.1  christos #include "solib.h"
     38   1.1  christos #include "solib-darwin.h"
     39   1.9  christos #include "dwarf2/frame.h"
     40   1.1  christos 
     41   1.1  christos /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
     42   1.1  christos    From <mach/i386/thread_status.h> and amd64-tdep.h.  */
     43   1.1  christos int amd64_darwin_thread_state_reg_offset[] =
     44   1.1  christos {
     45   1.1  christos   0 * 8,			/* %rax */
     46   1.1  christos   1 * 8,			/* %rbx */
     47   1.1  christos   2 * 8,			/* %rcx */
     48   1.1  christos   3 * 8,			/* %rdx */
     49   1.1  christos   5 * 8,			/* %rsi */
     50   1.1  christos   4 * 8,			/* %rdi */
     51   1.1  christos   6 * 8,			/* %rbp */
     52   1.1  christos   7 * 8,			/* %rsp */
     53   1.1  christos   8 * 8,			/* %r8 ...  */
     54   1.1  christos   9 * 8,
     55   1.1  christos   10 * 8,
     56   1.1  christos   11 * 8,
     57   1.1  christos   12 * 8,
     58   1.1  christos   13 * 8,
     59   1.1  christos   14 * 8,
     60   1.1  christos   15 * 8,			/* ... %r15 */
     61   1.1  christos   16 * 8,			/* %rip */
     62   1.1  christos   17 * 8,			/* %rflags */
     63   1.1  christos   18 * 8,			/* %cs */
     64   1.1  christos   -1,				/* %ss */
     65   1.1  christos   -1,				/* %ds */
     66   1.1  christos   -1,				/* %es */
     67   1.1  christos   19 * 8,			/* %fs */
     68   1.1  christos   20 * 8			/* %gs */
     69   1.1  christos };
     70   1.1  christos 
     71   1.1  christos const int amd64_darwin_thread_state_num_regs =
     72   1.1  christos   ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);
     73   1.1  christos 
     74   1.1  christos /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
     75   1.1  christos    address of the associated sigcontext structure.  */
     76   1.1  christos 
     77   1.1  christos static CORE_ADDR
     78  1.11  christos amd64_darwin_sigcontext_addr (const frame_info_ptr &this_frame)
     79   1.1  christos {
     80   1.1  christos   struct gdbarch *gdbarch = get_frame_arch (this_frame);
     81   1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
     82   1.1  christos   CORE_ADDR rbx;
     83   1.1  christos   gdb_byte buf[8];
     84   1.1  christos 
     85   1.1  christos   /* A pointer to the ucontext is passed as the fourth argument
     86   1.1  christos      to the signal handler, which is saved in rbx.  */
     87   1.1  christos   get_frame_register (this_frame, AMD64_RBX_REGNUM, buf);
     88   1.1  christos   rbx = extract_unsigned_integer (buf, 8, byte_order);
     89   1.1  christos 
     90   1.1  christos   /* The pointer to mcontext is at offset 48.  */
     91   1.1  christos   read_memory (rbx + 48, buf, 8);
     92   1.1  christos 
     93   1.1  christos   /* First register (rax) is at offset 16.  */
     94   1.1  christos   return extract_unsigned_integer (buf, 8, byte_order) + 16;
     95   1.1  christos }
     96   1.1  christos 
     97   1.1  christos static void
     98   1.1  christos x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
     99   1.1  christos {
    100  1.10  christos   i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
    101   1.1  christos 
    102   1.8  christos   amd64_init_abi (info, gdbarch,
    103   1.8  christos 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
    104   1.1  christos 
    105   1.1  christos   tdep->struct_return = reg_struct_return;
    106   1.1  christos 
    107   1.1  christos   dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p);
    108   1.1  christos 
    109   1.1  christos   tdep->sigtramp_p = i386_sigtramp_p;
    110   1.1  christos   tdep->sigcontext_addr = amd64_darwin_sigcontext_addr;
    111   1.1  christos   tdep->sc_reg_offset = amd64_darwin_thread_state_reg_offset;
    112   1.1  christos   tdep->sc_num_regs = amd64_darwin_thread_state_num_regs;
    113   1.1  christos 
    114   1.1  christos   tdep->jb_pc_offset = 56;
    115   1.1  christos 
    116  1.10  christos   set_gdbarch_so_ops (gdbarch, &darwin_so_ops);
    117   1.1  christos }
    118   1.1  christos 
    119   1.9  christos void _initialize_amd64_darwin_tdep ();
    120   1.1  christos void
    121   1.9  christos _initialize_amd64_darwin_tdep ()
    122   1.1  christos {
    123   1.1  christos   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
    124  1.10  christos 			  GDB_OSABI_DARWIN, x86_darwin_init_abi_64);
    125   1.1  christos }
    126