GDB (API)
/home/stan/gdb/src/gdb/amd64-darwin-tdep.c
Go to the documentation of this file.
00001 /* Darwin support for GDB, the GNU debugger.
00002    Copyright (C) 1997-2013 Free Software Foundation, Inc.
00003 
00004    Contributed by Apple Computer, Inc.
00005 
00006    This file is part of GDB.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 3 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00020 
00021 #include "defs.h"
00022 #include "frame.h"
00023 #include "inferior.h"
00024 #include "gdbcore.h"
00025 #include "target.h"
00026 #include "floatformat.h"
00027 #include "symtab.h"
00028 #include "regcache.h"
00029 #include "libbfd.h"
00030 #include "objfiles.h"
00031 
00032 #include "i387-tdep.h"
00033 #include "amd64-tdep.h"
00034 #include "osabi.h"
00035 #include "ui-out.h"
00036 #include "symtab.h"
00037 #include "frame.h"
00038 #include "amd64-darwin-tdep.h"
00039 #include "i386-darwin-tdep.h"
00040 #include "solib.h"
00041 #include "solib-darwin.h"
00042 #include "dwarf2-frame.h"
00043 
00044 /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
00045    From <mach/i386/thread_status.h> and amd64-tdep.h.  */
00046 int amd64_darwin_thread_state_reg_offset[] =
00047 {
00048   0 * 8,                        /* %rax */
00049   1 * 8,                        /* %rbx */
00050   2 * 8,                        /* %rcx */
00051   3 * 8,                        /* %rdx */
00052   5 * 8,                        /* %rsi */
00053   4 * 8,                        /* %rdi */
00054   6 * 8,                        /* %rbp */
00055   7 * 8,                        /* %rsp */
00056   8 * 8,                        /* %r8 ...  */
00057   9 * 8,
00058   10 * 8,
00059   11 * 8,
00060   12 * 8,
00061   13 * 8,
00062   14 * 8,
00063   15 * 8,                       /* ... %r15 */
00064   16 * 8,                       /* %rip */
00065   17 * 8,                       /* %rflags */
00066   18 * 8,                       /* %cs */
00067   -1,                           /* %ss */
00068   -1,                           /* %ds */
00069   -1,                           /* %es */
00070   19 * 8,                       /* %fs */
00071   20 * 8                        /* %gs */
00072 };
00073 
00074 const int amd64_darwin_thread_state_num_regs = 
00075   ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);
00076 
00077 /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
00078    address of the associated sigcontext structure.  */
00079 
00080 static CORE_ADDR
00081 amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
00082 {
00083   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00084   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00085   CORE_ADDR rbx;
00086   gdb_byte buf[8];
00087 
00088   /* A pointer to the ucontext is passed as the fourth argument
00089      to the signal handler, which is saved in rbx.  */
00090   get_frame_register (this_frame, AMD64_RBX_REGNUM, buf);
00091   rbx = extract_unsigned_integer (buf, 8, byte_order);
00092 
00093   /* The pointer to mcontext is at offset 48.  */
00094   read_memory (rbx + 48, buf, 8);
00095 
00096   /* First register (rax) is at offset 16.  */
00097   return extract_unsigned_integer (buf, 8, byte_order) + 16;
00098 }
00099 
00100 static void
00101 x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
00102 {
00103   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00104 
00105   amd64_init_abi (info, gdbarch);
00106 
00107   tdep->struct_return = reg_struct_return;
00108 
00109   dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p);
00110 
00111   tdep->sigtramp_p = i386_sigtramp_p;
00112   tdep->sigcontext_addr = amd64_darwin_sigcontext_addr;
00113   tdep->sc_reg_offset = amd64_darwin_thread_state_reg_offset;
00114   tdep->sc_num_regs = amd64_darwin_thread_state_num_regs;
00115 
00116   tdep->jb_pc_offset = 56;
00117 
00118   set_solib_ops (gdbarch, &darwin_so_ops);
00119 }
00120 
00121 /* -Wmissing-prototypes */
00122 extern initialize_file_ftype _initialize_amd64_darwin_tdep;
00123 
00124 void
00125 _initialize_amd64_darwin_tdep (void)
00126 {
00127   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
00128                           GDB_OSABI_DARWIN, x86_darwin_init_abi_64);
00129 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines