gdb/sparc64-sol2-tdep.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Target-dependent code for Solaris UltraSPARC.

  2.    Copyright (C) 2003-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "frame.h"
  16. #include "frame-unwind.h"
  17. #include "gdbarch.h"
  18. #include "symtab.h"
  19. #include "objfiles.h"
  20. #include "osabi.h"
  21. #include "trad-frame.h"
  22. #include "regset.h"

  23. #include "sol2-tdep.h"
  24. #include "sparc64-tdep.h"
  25. #include "solib-svr4.h"

  26. /* From <sys/regset.h>.  */
  27. const struct sparc_gregmap sparc64_sol2_gregmap =
  28. {
  29.   32 * 8,                        /* "tstate" */
  30.   33 * 8,                        /* %pc */
  31.   34 * 8,                        /* %npc */
  32.   35 * 8,                        /* %y */
  33.   -1,                                /* %wim */
  34.   -1,                                /* %tbr */
  35.   1 * 8,                        /* %g1 */
  36.   16 * 8,                        /* %l0 */
  37.   8                                /* sizeof (%y) */
  38. };

  39. const struct sparc_fpregmap sparc64_sol2_fpregmap =
  40. {
  41.   0 * 8,                        /* %f0 */
  42.   33 * 8,                        /* %fsr */
  43. };

  44. static void
  45. sparc64_sol2_supply_core_gregset (const struct regset *regset,
  46.                                   struct regcache *regcache,
  47.                                   int regnum, const void *gregs, size_t len)
  48. {
  49.   sparc64_supply_gregset (&sparc64_sol2_gregmap, regcache, regnum, gregs);
  50. }

  51. static void
  52. sparc64_sol2_collect_core_gregset (const struct regset *regset,
  53.                                    const struct regcache *regcache,
  54.                                    int regnum, void *gregs, size_t len)
  55. {
  56.   sparc64_collect_gregset (&sparc64_sol2_gregmap, regcache, regnum, gregs);
  57. }

  58. static void
  59. sparc64_sol2_supply_core_fpregset (const struct regset *regset,
  60.                                    struct regcache *regcache,
  61.                                    int regnum, const void *fpregs, size_t len)
  62. {
  63.   sparc64_supply_fpregset (&sparc64_sol2_fpregmap, regcache, regnum, fpregs);
  64. }

  65. static void
  66. sparc64_sol2_collect_core_fpregset (const struct regset *regset,
  67.                                     const struct regcache *regcache,
  68.                                     int regnum, void *fpregs, size_t len)
  69. {
  70.   sparc64_collect_fpregset (&sparc64_sol2_fpregmap, regcache, regnum, fpregs);
  71. }

  72. static const struct regset sparc64_sol2_gregset =
  73.   {
  74.     NULL,
  75.     sparc64_sol2_supply_core_gregset,
  76.     sparc64_sol2_collect_core_gregset
  77.   };

  78. static const struct regset sparc64_sol2_fpregset =
  79.   {
  80.     NULL,
  81.     sparc64_sol2_supply_core_fpregset,
  82.     sparc64_sol2_collect_core_fpregset
  83.   };


  84. static struct sparc_frame_cache *
  85. sparc64_sol2_sigtramp_frame_cache (struct frame_info *this_frame,
  86.                                    void **this_cache)
  87. {
  88.   struct sparc_frame_cache *cache;
  89.   CORE_ADDR mcontext_addr, addr;
  90.   int regnum;

  91.   if (*this_cache)
  92.     return *this_cache;

  93.   cache = sparc_frame_cache (this_frame, this_cache);
  94.   gdb_assert (cache == *this_cache);

  95.   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);

  96.   /* The third argument is a pointer to an instance of `ucontext_t',
  97.      which has a member `uc_mcontext' that contains the saved
  98.      registers.  */
  99.   regnum =
  100.     (cache->copied_regs_mask & 0x04) ? SPARC_I2_REGNUM : SPARC_O2_REGNUM;
  101.   mcontext_addr = get_frame_register_unsigned (this_frame, regnum) + 64;

  102.   cache->saved_regs[SPARC64_CCR_REGNUM].addr = mcontext_addr + 0 * 8;
  103.   cache->saved_regs[SPARC64_PC_REGNUM].addr = mcontext_addr + 1 * 8;
  104.   cache->saved_regs[SPARC64_NPC_REGNUM].addr = mcontext_addr + 2 * 8;
  105.   cache->saved_regs[SPARC64_Y_REGNUM].addr = mcontext_addr + 3 * 8;
  106.   cache->saved_regs[SPARC64_ASI_REGNUM].addr = mcontext_addr + 19 * 8;
  107.   cache->saved_regs[SPARC64_FPRS_REGNUM].addr = mcontext_addr + 20 * 8;

  108.   /* Since %g0 is always zero, keep the identity encoding.  */
  109.   for (regnum = SPARC_G1_REGNUM, addr = mcontext_addr + 4 * 8;
  110.        regnum <= SPARC_O7_REGNUM; regnum++, addr += 8)
  111.     cache->saved_regs[regnum].addr = addr;

  112.   if (get_frame_memory_unsigned (this_frame, mcontext_addr + 21 * 8, 8))
  113.     {
  114.       /* The register windows haven't been flushed.  */
  115.       for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++)
  116.         trad_frame_set_unknown (cache->saved_regs, regnum);
  117.     }
  118.   else
  119.     {
  120.       CORE_ADDR sp;

  121.       addr = cache->saved_regs[SPARC_SP_REGNUM].addr;
  122.       sp = get_frame_memory_unsigned (this_frame, addr, 8);
  123.       for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS;
  124.            regnum <= SPARC_I7_REGNUM; regnum++, addr += 8)
  125.         cache->saved_regs[regnum].addr = addr;
  126.     }

  127.   return cache;
  128. }

  129. static void
  130. sparc64_sol2_sigtramp_frame_this_id (struct frame_info *this_frame,
  131.                                      void **this_cache,
  132.                                      struct frame_id *this_id)
  133. {
  134.   struct sparc_frame_cache *cache =
  135.     sparc64_sol2_sigtramp_frame_cache (this_frame, this_cache);

  136.   (*this_id) = frame_id_build (cache->base, cache->pc);
  137. }

  138. static struct value *
  139. sparc64_sol2_sigtramp_frame_prev_register (struct frame_info *this_frame,
  140.                                            void **this_cache,
  141.                                            int regnum)
  142. {
  143.   struct sparc_frame_cache *cache =
  144.     sparc64_sol2_sigtramp_frame_cache (this_frame, this_cache);

  145.   return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
  146. }

  147. static int
  148. sparc64_sol2_sigtramp_frame_sniffer (const struct frame_unwind *self,
  149.                                      struct frame_info *this_frame,
  150.                                      void **this_cache)
  151. {
  152.   CORE_ADDR pc = get_frame_pc (this_frame);
  153.   const char *name;

  154.   find_pc_partial_function (pc, &name, NULL, NULL);
  155.   if (sparc_sol2_pc_in_sigtramp (pc, name))
  156.     return 1;

  157.   return 0;
  158. }
  159. static const struct frame_unwind sparc64_sol2_sigtramp_frame_unwind =
  160. {
  161.   SIGTRAMP_FRAME,
  162.   default_frame_unwind_stop_reason,
  163.   sparc64_sol2_sigtramp_frame_this_id,
  164.   sparc64_sol2_sigtramp_frame_prev_register,
  165.   NULL,
  166.   sparc64_sol2_sigtramp_frame_sniffer
  167. };



  168. void
  169. sparc64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  170. {
  171.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  172.   tdep->gregset = &sparc64_sol2_gregset;
  173.   tdep->sizeof_gregset = 304;

  174.   tdep->fpregset = &sparc64_sol2_fpregset;
  175.   tdep->sizeof_fpregset = 544;

  176.   frame_unwind_append_unwinder (gdbarch, &sparc64_sol2_sigtramp_frame_unwind);

  177.   sparc64_init_abi (info, gdbarch);

  178.   /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop, SunPRO)
  179.      compiler puts out 0 instead of the address in N_SO stabs.  Starting with
  180.      SunPRO 3.0, the compiler does this for N_FUN stabs too.  */
  181.   set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);

  182.   /* The Sun compilers also do "globalization"; see the comment in
  183.      sparc_sol2_static_transform_name for more information.  */
  184.   set_gdbarch_static_transform_name
  185.     (gdbarch, sparc_sol2_static_transform_name);

  186.   /* Solaris has SVR4-style shared libraries...  */
  187.   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
  188.   set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
  189.   set_solib_svr4_fetch_link_map_offsets
  190.     (gdbarch, svr4_lp64_fetch_link_map_offsets);

  191.   /* ...which means that we need some special handling when doing
  192.      prologue analysis.  */
  193.   tdep->plt_entry_size = 16;

  194.   /* Solaris has kernel-assisted single-stepping support.  */
  195.   set_gdbarch_software_single_step (gdbarch, NULL);

  196.   /* How to print LWP PTIDs from core files.  */
  197.   set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);
  198. }


  199. /* Provide a prototype to silence -Wmissing-prototypes.  */
  200. void _initialize_sparc64_sol2_tdep (void);

  201. void
  202. _initialize_sparc64_sol2_tdep (void)
  203. {
  204.   gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
  205.                           GDB_OSABI_SOLARIS, sparc64_sol2_init_abi);
  206. }