Home | History | Annotate | Line # | Download | only in gdb
amd64-darwin-tdep.c revision 1.1
      1  1.1  christos /* Darwin support for GDB, the GNU debugger.
      2  1.1  christos    Copyright (C) 1997-2014 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.1  christos #include "defs.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 "floatformat.h"
     27  1.1  christos #include "symtab.h"
     28  1.1  christos #include "regcache.h"
     29  1.1  christos #include "libbfd.h"
     30  1.1  christos #include "objfiles.h"
     31  1.1  christos 
     32  1.1  christos #include "i387-tdep.h"
     33  1.1  christos #include "amd64-tdep.h"
     34  1.1  christos #include "osabi.h"
     35  1.1  christos #include "ui-out.h"
     36  1.1  christos #include "amd64-darwin-tdep.h"
     37  1.1  christos #include "i386-darwin-tdep.h"
     38  1.1  christos #include "solib.h"
     39  1.1  christos #include "solib-darwin.h"
     40  1.1  christos #include "dwarf2-frame.h"
     41  1.1  christos 
     42  1.1  christos /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
     43  1.1  christos    From <mach/i386/thread_status.h> and amd64-tdep.h.  */
     44  1.1  christos int amd64_darwin_thread_state_reg_offset[] =
     45  1.1  christos {
     46  1.1  christos   0 * 8,			/* %rax */
     47  1.1  christos   1 * 8,			/* %rbx */
     48  1.1  christos   2 * 8,			/* %rcx */
     49  1.1  christos   3 * 8,			/* %rdx */
     50  1.1  christos   5 * 8,			/* %rsi */
     51  1.1  christos   4 * 8,			/* %rdi */
     52  1.1  christos   6 * 8,			/* %rbp */
     53  1.1  christos   7 * 8,			/* %rsp */
     54  1.1  christos   8 * 8,			/* %r8 ...  */
     55  1.1  christos   9 * 8,
     56  1.1  christos   10 * 8,
     57  1.1  christos   11 * 8,
     58  1.1  christos   12 * 8,
     59  1.1  christos   13 * 8,
     60  1.1  christos   14 * 8,
     61  1.1  christos   15 * 8,			/* ... %r15 */
     62  1.1  christos   16 * 8,			/* %rip */
     63  1.1  christos   17 * 8,			/* %rflags */
     64  1.1  christos   18 * 8,			/* %cs */
     65  1.1  christos   -1,				/* %ss */
     66  1.1  christos   -1,				/* %ds */
     67  1.1  christos   -1,				/* %es */
     68  1.1  christos   19 * 8,			/* %fs */
     69  1.1  christos   20 * 8			/* %gs */
     70  1.1  christos };
     71  1.1  christos 
     72  1.1  christos const int amd64_darwin_thread_state_num_regs =
     73  1.1  christos   ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);
     74  1.1  christos 
     75  1.1  christos /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
     76  1.1  christos    address of the associated sigcontext structure.  */
     77  1.1  christos 
     78  1.1  christos static CORE_ADDR
     79  1.1  christos amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
     80  1.1  christos {
     81  1.1  christos   struct gdbarch *gdbarch = get_frame_arch (this_frame);
     82  1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
     83  1.1  christos   CORE_ADDR rbx;
     84  1.1  christos   gdb_byte buf[8];
     85  1.1  christos 
     86  1.1  christos   /* A pointer to the ucontext is passed as the fourth argument
     87  1.1  christos      to the signal handler, which is saved in rbx.  */
     88  1.1  christos   get_frame_register (this_frame, AMD64_RBX_REGNUM, buf);
     89  1.1  christos   rbx = extract_unsigned_integer (buf, 8, byte_order);
     90  1.1  christos 
     91  1.1  christos   /* The pointer to mcontext is at offset 48.  */
     92  1.1  christos   read_memory (rbx + 48, buf, 8);
     93  1.1  christos 
     94  1.1  christos   /* First register (rax) is at offset 16.  */
     95  1.1  christos   return extract_unsigned_integer (buf, 8, byte_order) + 16;
     96  1.1  christos }
     97  1.1  christos 
     98  1.1  christos static void
     99  1.1  christos x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
    100  1.1  christos {
    101  1.1  christos   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
    102  1.1  christos 
    103  1.1  christos   amd64_init_abi (info, gdbarch);
    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.1  christos   set_solib_ops (gdbarch, &darwin_so_ops);
    117  1.1  christos }
    118  1.1  christos 
    119  1.1  christos /* -Wmissing-prototypes */
    120  1.1  christos extern initialize_file_ftype _initialize_amd64_darwin_tdep;
    121  1.1  christos 
    122  1.1  christos void
    123  1.1  christos _initialize_amd64_darwin_tdep (void)
    124  1.1  christos {
    125  1.1  christos   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
    126  1.1  christos                           GDB_OSABI_DARWIN, x86_darwin_init_abi_64);
    127  1.1  christos }
    128