GDB (API)
/home/stan/gdb/src/gdb/sparc64-sol2-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for Solaris UltraSPARC.
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 "frame.h"
00022 #include "frame-unwind.h"
00023 #include "gdbarch.h"
00024 #include "symtab.h"
00025 #include "objfiles.h"
00026 #include "osabi.h"
00027 #include "trad-frame.h"
00028 
00029 #include "gdb_assert.h"
00030 
00031 #include "sol2-tdep.h"
00032 #include "sparc64-tdep.h"
00033 #include "solib-svr4.h"
00034 
00035 /* From <sys/regset.h>.  */
00036 const struct sparc_gregset sparc64_sol2_gregset =
00037 {
00038   32 * 8,                       /* "tstate" */
00039   33 * 8,                       /* %pc */
00040   34 * 8,                       /* %npc */
00041   35 * 8,                       /* %y */
00042   -1,                           /* %wim */
00043   -1,                           /* %tbr */
00044   1 * 8,                        /* %g1 */
00045   16 * 8,                       /* %l0 */
00046   8                             /* sizeof (%y) */
00047 };
00048 
00049 const struct sparc_fpregset sparc64_sol2_fpregset =
00050 {
00051   0 * 8,                        /* %f0 */
00052   33 * 8,                       /* %fsr */
00053 };
00054 
00055 
00056 static struct sparc_frame_cache *
00057 sparc64_sol2_sigtramp_frame_cache (struct frame_info *this_frame,
00058                                    void **this_cache)
00059 {
00060   struct sparc_frame_cache *cache;
00061   CORE_ADDR mcontext_addr, addr;
00062   int regnum;
00063 
00064   if (*this_cache)
00065     return *this_cache;
00066 
00067   cache = sparc_frame_cache (this_frame, this_cache);
00068   gdb_assert (cache == *this_cache);
00069 
00070   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
00071 
00072   /* The third argument is a pointer to an instance of `ucontext_t',
00073      which has a member `uc_mcontext' that contains the saved
00074      registers.  */
00075   regnum =
00076     (cache->copied_regs_mask & 0x04) ? SPARC_I2_REGNUM : SPARC_O2_REGNUM;
00077   mcontext_addr = get_frame_register_unsigned (this_frame, regnum) + 64;
00078 
00079   cache->saved_regs[SPARC64_CCR_REGNUM].addr = mcontext_addr + 0 * 8;
00080   cache->saved_regs[SPARC64_PC_REGNUM].addr = mcontext_addr + 1 * 8;
00081   cache->saved_regs[SPARC64_NPC_REGNUM].addr = mcontext_addr + 2 * 8;
00082   cache->saved_regs[SPARC64_Y_REGNUM].addr = mcontext_addr + 3 * 8;
00083   cache->saved_regs[SPARC64_ASI_REGNUM].addr = mcontext_addr + 19 * 8; 
00084   cache->saved_regs[SPARC64_FPRS_REGNUM].addr = mcontext_addr + 20 * 8;
00085 
00086   /* Since %g0 is always zero, keep the identity encoding.  */
00087   for (regnum = SPARC_G1_REGNUM, addr = mcontext_addr + 4 * 8;
00088        regnum <= SPARC_O7_REGNUM; regnum++, addr += 8)
00089     cache->saved_regs[regnum].addr = addr;
00090 
00091   if (get_frame_memory_unsigned (this_frame, mcontext_addr + 21 * 8, 8))
00092     {
00093       /* The register windows haven't been flushed.  */
00094       for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++)
00095         trad_frame_set_unknown (cache->saved_regs, regnum);
00096     }
00097   else
00098     {
00099       CORE_ADDR sp;
00100 
00101       addr = cache->saved_regs[SPARC_SP_REGNUM].addr;
00102       sp = get_frame_memory_unsigned (this_frame, addr, 8);
00103       for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS;
00104            regnum <= SPARC_I7_REGNUM; regnum++, addr += 8)
00105         cache->saved_regs[regnum].addr = addr;
00106     }
00107 
00108   return cache;
00109 }
00110 
00111 static void
00112 sparc64_sol2_sigtramp_frame_this_id (struct frame_info *this_frame,
00113                                      void **this_cache,
00114                                      struct frame_id *this_id)
00115 {
00116   struct sparc_frame_cache *cache =
00117     sparc64_sol2_sigtramp_frame_cache (this_frame, this_cache);
00118 
00119   (*this_id) = frame_id_build (cache->base, cache->pc);
00120 }
00121 
00122 static struct value *
00123 sparc64_sol2_sigtramp_frame_prev_register (struct frame_info *this_frame,
00124                                            void **this_cache,
00125                                            int regnum)
00126 {
00127   struct sparc_frame_cache *cache =
00128     sparc64_sol2_sigtramp_frame_cache (this_frame, this_cache);
00129 
00130   return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
00131 }
00132 
00133 static int
00134 sparc64_sol2_sigtramp_frame_sniffer (const struct frame_unwind *self,
00135                                      struct frame_info *this_frame,
00136                                      void **this_cache)
00137 {
00138   CORE_ADDR pc = get_frame_pc (this_frame);
00139   const char *name;
00140 
00141   find_pc_partial_function (pc, &name, NULL, NULL);
00142   if (sparc_sol2_pc_in_sigtramp (pc, name))
00143     return 1;
00144 
00145   return 0;
00146 }
00147 static const struct frame_unwind sparc64_sol2_sigtramp_frame_unwind =
00148 {
00149   SIGTRAMP_FRAME,
00150   default_frame_unwind_stop_reason,
00151   sparc64_sol2_sigtramp_frame_this_id,
00152   sparc64_sol2_sigtramp_frame_prev_register,
00153   NULL,
00154   sparc64_sol2_sigtramp_frame_sniffer
00155 };
00156 
00157 
00158 
00159 void
00160 sparc64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00161 {
00162   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00163 
00164   frame_unwind_append_unwinder (gdbarch, &sparc64_sol2_sigtramp_frame_unwind);
00165 
00166   sparc64_init_abi (info, gdbarch);
00167 
00168   /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop, SunPRO)
00169      compiler puts out 0 instead of the address in N_SO stabs.  Starting with
00170      SunPRO 3.0, the compiler does this for N_FUN stabs too.  */
00171   set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
00172 
00173   /* The Sun compilers also do "globalization"; see the comment in
00174      sparc_sol2_static_transform_name for more information.  */
00175   set_gdbarch_static_transform_name
00176     (gdbarch, sparc_sol2_static_transform_name);
00177 
00178   /* Solaris has SVR4-style shared libraries...  */
00179   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
00180   set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
00181   set_solib_svr4_fetch_link_map_offsets
00182     (gdbarch, svr4_lp64_fetch_link_map_offsets);
00183 
00184   /* ...which means that we need some special handling when doing
00185      prologue analysis.  */
00186   tdep->plt_entry_size = 16;
00187 
00188   /* Solaris has kernel-assisted single-stepping support.  */
00189   set_gdbarch_software_single_step (gdbarch, NULL);
00190 
00191   /* How to print LWP PTIDs from core files.  */
00192   set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);
00193 }
00194 
00195 
00196 /* Provide a prototype to silence -Wmissing-prototypes.  */
00197 void _initialize_sparc64_sol2_tdep (void);
00198 
00199 void
00200 _initialize_sparc64_sol2_tdep (void)
00201 {
00202   gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
00203                           GDB_OSABI_SOLARIS, sparc64_sol2_init_abi);
00204 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines