GDB (API)
/home/stan/gdb/src/gdb/ia64-linux-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for the IA-64 for GDB, the GNU debugger.
00002 
00003    Copyright (C) 2000-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 "ia64-tdep.h"
00022 #include "arch-utils.h"
00023 #include "gdbcore.h"
00024 #include "regcache.h"
00025 #include "osabi.h"
00026 #include "solib-svr4.h"
00027 #include "symtab.h"
00028 #include "linux-tdep.h"
00029 
00030 #include <ctype.h>
00031 
00032 /* The sigtramp code is in a non-readable (executable-only) region
00033    of memory called the ``gate page''.  The addresses in question
00034    were determined by examining the system headers.  They are
00035    overly generous to allow for different pages sizes.  */
00036 
00037 #define GATE_AREA_START 0xa000000000000100LL
00038 #define GATE_AREA_END   0xa000000000020000LL
00039 
00040 /* Offset to sigcontext structure from frame of handler.  */
00041 #define IA64_LINUX_SIGCONTEXT_OFFSET 192
00042 
00043 static int
00044 ia64_linux_pc_in_sigtramp (CORE_ADDR pc)
00045 {
00046   return (pc >= (CORE_ADDR) GATE_AREA_START && pc < (CORE_ADDR) GATE_AREA_END);
00047 }
00048 
00049 /* IA-64 GNU/Linux specific function which, given a frame address and
00050    a register number, returns the address at which that register may be
00051    found.  0 is returned for registers which aren't stored in the
00052    sigcontext structure.  */
00053 
00054 static CORE_ADDR
00055 ia64_linux_sigcontext_register_address (struct gdbarch *gdbarch,
00056                                         CORE_ADDR sp, int regno)
00057 {
00058   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00059   gdb_byte buf[8];
00060   CORE_ADDR sigcontext_addr = 0;
00061 
00062   /* The address of the sigcontext area is found at offset 16 in the
00063      sigframe.  */
00064   read_memory (sp + 16, buf, 8);
00065   sigcontext_addr = extract_unsigned_integer (buf, 8, byte_order);
00066 
00067   if (IA64_GR0_REGNUM <= regno && regno <= IA64_GR31_REGNUM)
00068     return sigcontext_addr + 200 + 8 * (regno - IA64_GR0_REGNUM);
00069   else if (IA64_BR0_REGNUM <= regno && regno <= IA64_BR7_REGNUM)
00070     return sigcontext_addr + 136 + 8 * (regno - IA64_BR0_REGNUM);
00071   else if (IA64_FR0_REGNUM <= regno && regno <= IA64_FR127_REGNUM)
00072     return sigcontext_addr + 464 + 16 * (regno - IA64_FR0_REGNUM);
00073   else
00074     switch (regno)
00075       {
00076       case IA64_IP_REGNUM :
00077         return sigcontext_addr + 40;
00078       case IA64_CFM_REGNUM :
00079         return sigcontext_addr + 48;
00080       case IA64_PSR_REGNUM :
00081         return sigcontext_addr + 56;            /* user mask only */
00082       /* sc_ar_rsc is provided, from which we could compute bspstore, but
00083          I don't think it's worth it.  Anyway, if we want it, it's at offset
00084          64.  */
00085       case IA64_BSP_REGNUM :
00086         return sigcontext_addr + 72;
00087       case IA64_RNAT_REGNUM :
00088         return sigcontext_addr + 80;
00089       case IA64_CCV_REGNUM :
00090         return sigcontext_addr + 88;
00091       case IA64_UNAT_REGNUM :
00092         return sigcontext_addr + 96;
00093       case IA64_FPSR_REGNUM :
00094         return sigcontext_addr + 104;
00095       case IA64_PFS_REGNUM :
00096         return sigcontext_addr + 112;
00097       case IA64_LC_REGNUM :
00098         return sigcontext_addr + 120;
00099       case IA64_PR_REGNUM :
00100         return sigcontext_addr + 128;
00101       default :
00102         return 0;
00103       }
00104 }
00105 
00106 static void
00107 ia64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
00108 {
00109   ia64_write_pc (regcache, pc);
00110 
00111   /* We must be careful with modifying the instruction-pointer: if we
00112      just interrupt a system call, the kernel would ordinarily try to
00113      restart it when we resume the inferior, which typically results
00114      in SIGSEGV or SIGILL.  We prevent this by clearing r10, which
00115      will tell the kernel that r8 does NOT contain a valid error code
00116      and hence it will skip system-call restart.
00117 
00118      The clearing of r10 is safe as long as ia64_write_pc() is only
00119      called as part of setting up an inferior call.  */
00120   regcache_cooked_write_unsigned (regcache, IA64_GR10_REGNUM, 0);
00121 }
00122 
00123 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
00124    gdbarch.h.  */
00125 
00126 static int
00127 ia64_linux_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
00128 {
00129   return ((isdigit (*s) && s[1] == '[' && s[2] == 'r') /* Displacement.  */
00130           || *s == 'r' /* Register value.  */
00131           || isdigit (*s));  /* Literal number.  */
00132 }
00133 
00134 static void
00135 ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00136 {
00137   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00138 
00139   linux_init_abi (info, gdbarch);
00140 
00141   /* Set the method of obtaining the sigcontext addresses at which
00142      registers are saved.  */
00143   tdep->sigcontext_register_address = ia64_linux_sigcontext_register_address;
00144 
00145   /* Set the pc_in_sigtramp method.  */
00146   tdep->pc_in_sigtramp = ia64_linux_pc_in_sigtramp;
00147 
00148   set_gdbarch_write_pc (gdbarch, ia64_linux_write_pc);
00149 
00150   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
00151 
00152   set_solib_svr4_fetch_link_map_offsets
00153     (gdbarch, svr4_lp64_fetch_link_map_offsets);
00154 
00155   /* Enable TLS support.  */
00156   set_gdbarch_fetch_tls_load_module_address (gdbarch,
00157                                              svr4_fetch_objfile_link_map);
00158 
00159   /* SystemTap related.  */
00160   set_gdbarch_stap_register_prefix (gdbarch, "r");
00161   set_gdbarch_stap_register_indirection_prefix (gdbarch, "[");
00162   set_gdbarch_stap_register_indirection_suffix (gdbarch, "]");
00163   set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
00164   set_gdbarch_stap_is_single_operand (gdbarch,
00165                                       ia64_linux_stap_is_single_operand);
00166 }
00167 
00168 /* Provide a prototype to silence -Wmissing-prototypes.  */
00169 extern initialize_file_ftype _initialize_ia64_linux_tdep;
00170 
00171 void
00172 _initialize_ia64_linux_tdep (void)
00173 {
00174   gdbarch_register_osabi (bfd_arch_ia64, 0, GDB_OSABI_LINUX,
00175                           ia64_linux_init_abi);
00176 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines