GDB (API)
/home/stan/gdb/src/gdb/amd64nbsd-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for NetBSD/amd64.
00002 
00003    Copyright (C) 2003-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "arch-utils.h"
00022 #include "frame.h"
00023 #include "gdbcore.h"
00024 #include "osabi.h"
00025 #include "symtab.h"
00026 
00027 #include "gdb_assert.h"
00028 
00029 #include "amd64-tdep.h"
00030 #include "nbsd-tdep.h"
00031 #include "solib-svr4.h"
00032 
00033 /* Support for signal handlers.  */
00034 
00035 /* Return whether THIS_FRAME corresponds to a NetBSD sigtramp
00036    routine.  */
00037 
00038 static int
00039 amd64nbsd_sigtramp_p (struct frame_info *this_frame)
00040 {
00041   CORE_ADDR pc = get_frame_pc (this_frame);
00042   const char *name;
00043 
00044   find_pc_partial_function (pc, &name, NULL, NULL);
00045   return nbsd_pc_in_sigtramp (pc, name);
00046 }
00047 
00048 /* Assuming THIS_FRAME corresponds to a NetBSD sigtramp routine,
00049    return the address of the associated mcontext structure.  */
00050 
00051 static CORE_ADDR
00052 amd64nbsd_mcontext_addr (struct frame_info *this_frame)
00053 {
00054   CORE_ADDR addr;
00055 
00056   /* The register %r15 points at `struct ucontext' upon entry of a
00057      signal trampoline.  */
00058   addr = get_frame_register_unsigned (this_frame, AMD64_R15_REGNUM);
00059 
00060   /* The mcontext structure lives as offset 56 in `struct ucontext'.  */
00061   return addr + 56;
00062 }
00063 
00064 /* NetBSD 2.0 or later.  */
00065 
00066 /* Mapping between the general-purpose registers in `struct reg'
00067    format and GDB's register cache layout.  */
00068 
00069 /* From <machine/reg.h>.  */
00070 int amd64nbsd_r_reg_offset[] =
00071 {
00072   14 * 8,                       /* %rax */
00073   13 * 8,                       /* %rbx */
00074   3 * 8,                        /* %rcx */
00075   2 * 8,                        /* %rdx */
00076   1 * 8,                        /* %rsi */
00077   0 * 8,                        /* %rdi */
00078   12 * 8,                       /* %rbp */
00079   24 * 8,                       /* %rsp */
00080   4 * 8,                        /* %r8 ..  */
00081   5 * 8,
00082   6 * 8,
00083   7 * 8,
00084   8 * 8,
00085   9 * 8,
00086   10 * 8,
00087   11 * 8,                       /* ... %r15 */
00088   21 * 8,                       /* %rip */
00089   23 * 8,                       /* %eflags */
00090   22 * 8,                       /* %cs */
00091   25 * 8,                       /* %ss */
00092   18 * 8,                       /* %ds */
00093   17 * 8,                       /* %es */
00094   16 * 8,                       /* %fs */
00095   15 * 8                        /* %gs */
00096 };
00097 
00098 static void
00099 amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00100 {
00101   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00102 
00103   /* Initialize general-purpose register set details first.  */
00104   tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
00105   tdep->gregset_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
00106   tdep->sizeof_gregset = 26 * 8;
00107 
00108   amd64_init_abi (info, gdbarch);
00109 
00110   tdep->jb_pc_offset = 7 * 8;
00111 
00112   /* NetBSD has its own convention for signal trampolines.  */
00113   tdep->sigtramp_p = amd64nbsd_sigtramp_p;
00114   tdep->sigcontext_addr = amd64nbsd_mcontext_addr;
00115   tdep->sc_reg_offset = amd64nbsd_r_reg_offset;
00116   tdep->sc_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
00117 
00118   /* NetBSD uses SVR4-style shared libraries.  */
00119   set_solib_svr4_fetch_link_map_offsets
00120     (gdbarch, svr4_lp64_fetch_link_map_offsets);
00121 }
00122 
00123 
00124 /* Provide a prototype to silence -Wmissing-prototypes.  */
00125 void _initialize_amd64nbsd_tdep (void);
00126 
00127 void
00128 _initialize_amd64nbsd_tdep (void)
00129 {
00130   /* The NetBSD/amd64 native dependent code makes this assumption.  */
00131   gdb_assert (ARRAY_SIZE (amd64nbsd_r_reg_offset) == AMD64_NUM_GREGS);
00132 
00133   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
00134                           GDB_OSABI_NETBSD_ELF, amd64nbsd_init_abi);
00135 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines