gdb/sparc-sol2-tdep.c - gdb

Global variables defined

Functions defined

Source code

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

  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 "gdbcore.h"
  18. #include "symtab.h"
  19. #include "objfiles.h"
  20. #include "osabi.h"
  21. #include "regcache.h"
  22. #include "regset.h"
  23. #include "target.h"
  24. #include "trad-frame.h"

  25. #include "sol2-tdep.h"
  26. #include "sparc-tdep.h"
  27. #include "solib-svr4.h"

  28. /* From <sys/regset.h>.  */
  29. const struct sparc_gregmap sparc32_sol2_gregmap =
  30. {
  31.   32 * 4,                        /* %psr */
  32.   33 * 4,                        /* %pc */
  33.   34 * 4,                        /* %npc */
  34.   35 * 4,                        /* %y */
  35.   36 * 4,                        /* %wim */
  36.   37 * 4,                        /* %tbr */
  37.   1 * 4,                        /* %g1 */
  38.   16 * 4,                        /* %l0 */
  39. };

  40. const struct sparc_fpregmap sparc32_sol2_fpregmap =
  41. {
  42.   0 * 4,                        /* %f0 */
  43.   33 * 4,                        /* %fsr */
  44. };

  45. static void
  46. sparc32_sol2_supply_core_gregset (const struct regset *regset,
  47.                                   struct regcache *regcache,
  48.                                   int regnum, const void *gregs, size_t len)
  49. {
  50.   sparc32_supply_gregset (&sparc32_sol2_gregmap, regcache, regnum, gregs);
  51. }

  52. static void
  53. sparc32_sol2_collect_core_gregset (const struct regset *regset,
  54.                                    const struct regcache *regcache,
  55.                                    int regnum, void *gregs, size_t len)
  56. {
  57.   sparc32_collect_gregset (&sparc32_sol2_gregmap, regcache, regnum, gregs);
  58. }

  59. static void
  60. sparc32_sol2_supply_core_fpregset (const struct regset *regset,
  61.                                    struct regcache *regcache,
  62.                                    int regnum, const void *fpregs, size_t len)
  63. {
  64.   sparc32_supply_fpregset (&sparc32_sol2_fpregmap, regcache, regnum, fpregs);
  65. }

  66. static void
  67. sparc32_sol2_collect_core_fpregset (const struct regset *regset,
  68.                                     const struct regcache *regcache,
  69.                                     int regnum, void *fpregs, size_t len)
  70. {
  71.   sparc32_collect_fpregset (&sparc32_sol2_fpregmap, regcache, regnum, fpregs);
  72. }

  73. static const struct regset sparc32_sol2_gregset =
  74.   {
  75.     NULL,
  76.     sparc32_sol2_supply_core_gregset,
  77.     sparc32_sol2_collect_core_gregset
  78.   };

  79. static const struct regset sparc32_sol2_fpregset =
  80.   {
  81.     NULL,
  82.     sparc32_sol2_supply_core_fpregset,
  83.     sparc32_sol2_collect_core_fpregset
  84.   };


  85. /* The Solaris signal trampolines reside in libc.  For normal signals,
  86.    the function `sigacthandler' is used.  This signal trampoline will
  87.    call the signal handler using the System V calling convention,
  88.    where the third argument is a pointer to an instance of
  89.    `ucontext_t', which has a member `uc_mcontext' that contains the
  90.    saved registers.  Incidentally, the kernel passes the `ucontext_t'
  91.    pointer as the third argument of the signal trampoline too, and
  92.    `sigacthandler' simply passes it on.  However, if you link your
  93.    program with "-L/usr/ucblib -R/usr/ucblib -lucb", the function
  94.    `ucbsigvechandler' will be used, which invokes the using the BSD
  95.    convention, where the third argument is a pointer to an instance of
  96.    `struct sigcontext'.  It is the `ucbsigvechandler' function that
  97.    converts the `ucontext_t' to a `sigcontext', and back.  Unless the
  98.    signal handler modifies the `struct sigcontext' we can safely
  99.    ignore this.  */

  100. int
  101. sparc_sol2_pc_in_sigtramp (CORE_ADDR pc, const char *name)
  102. {
  103.   return (name && (strcmp (name, "sigacthandler") == 0
  104.                    || strcmp (name, "ucbsigvechandler") == 0
  105.                    || strcmp (name, "__sighndlr") == 0));
  106. }

  107. static struct sparc_frame_cache *
  108. sparc32_sol2_sigtramp_frame_cache (struct frame_info *this_frame,
  109.                                    void **this_cache)
  110. {
  111.   struct sparc_frame_cache *cache;
  112.   CORE_ADDR mcontext_addr, addr;
  113.   int regnum;

  114.   if (*this_cache)
  115.     return *this_cache;

  116.   cache = sparc_frame_cache (this_frame, this_cache);
  117.   gdb_assert (cache == *this_cache);

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

  119.   /* The third argument is a pointer to an instance of `ucontext_t',
  120.      which has a member `uc_mcontext' that contains the saved
  121.      registers.  */
  122.   regnum =
  123.     (cache->copied_regs_mask & 0x04) ? SPARC_I2_REGNUM : SPARC_O2_REGNUM;
  124.   mcontext_addr = get_frame_register_unsigned (this_frame, regnum) + 40;

  125.   cache->saved_regs[SPARC32_PSR_REGNUM].addr = mcontext_addr + 0 * 4;
  126.   cache->saved_regs[SPARC32_PC_REGNUM].addr = mcontext_addr + 1 * 4;
  127.   cache->saved_regs[SPARC32_NPC_REGNUM].addr = mcontext_addr + 2 * 4;
  128.   cache->saved_regs[SPARC32_Y_REGNUM].addr = mcontext_addr + 3 * 4;

  129.   /* Since %g0 is always zero, keep the identity encoding.  */
  130.   for (regnum = SPARC_G1_REGNUM, addr = mcontext_addr + 4 * 4;
  131.        regnum <= SPARC_O7_REGNUM; regnum++, addr += 4)
  132.     cache->saved_regs[regnum].addr = addr;

  133.   if (get_frame_memory_unsigned (this_frame, mcontext_addr + 19 * 4, 4))
  134.     {
  135.       /* The register windows haven't been flushed.  */
  136.       for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++)
  137.         trad_frame_set_unknown (cache->saved_regs, regnum);
  138.     }
  139.   else
  140.     {
  141.       addr = cache->saved_regs[SPARC_SP_REGNUM].addr;
  142.       addr = get_frame_memory_unsigned (this_frame, addr, 4);
  143.       for (regnum = SPARC_L0_REGNUM;
  144.            regnum <= SPARC_I7_REGNUM; regnum++, addr += 4)
  145.         cache->saved_regs[regnum].addr = addr;
  146.     }

  147.   return cache;
  148. }

  149. static void
  150. sparc32_sol2_sigtramp_frame_this_id (struct frame_info *this_frame,
  151.                                      void **this_cache,
  152.                                      struct frame_id *this_id)
  153. {
  154.   struct sparc_frame_cache *cache =
  155.     sparc32_sol2_sigtramp_frame_cache (this_frame, this_cache);

  156.   (*this_id) = frame_id_build (cache->base, cache->pc);
  157. }

  158. static struct value *
  159. sparc32_sol2_sigtramp_frame_prev_register (struct frame_info *this_frame,
  160.                                            void **this_cache,
  161.                                            int regnum)
  162. {
  163.   struct sparc_frame_cache *cache =
  164.     sparc32_sol2_sigtramp_frame_cache (this_frame, this_cache);

  165.   return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
  166. }

  167. static int
  168. sparc32_sol2_sigtramp_frame_sniffer (const struct frame_unwind *self,
  169.                                      struct frame_info *this_frame,
  170.                                      void **this_cache)
  171. {
  172.   CORE_ADDR pc = get_frame_pc (this_frame);
  173.   const char *name;

  174.   find_pc_partial_function (pc, &name, NULL, NULL);
  175.   if (sparc_sol2_pc_in_sigtramp (pc, name))
  176.     return 1;

  177.   return 0;
  178. }

  179. static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
  180. {
  181.   SIGTRAMP_FRAME,
  182.   default_frame_unwind_stop_reason,
  183.   sparc32_sol2_sigtramp_frame_this_id,
  184.   sparc32_sol2_sigtramp_frame_prev_register,
  185.   NULL,
  186.   sparc32_sol2_sigtramp_frame_sniffer
  187. };

  188. /* Unglobalize NAME.  */

  189. const const char *
  190. sparc_sol2_static_transform_name (const char *name)
  191. {
  192.   /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop,
  193.      SunPRO) convert file static variables into global values, a
  194.      process known as globalization.  In order to do this, the
  195.      compiler will create a unique prefix and prepend it to each file
  196.      static variable.  For static variables within a function, this
  197.      globalization prefix is followed by the function name (nested
  198.      static variables within a function are supposed to generate a
  199.      warning message, and are left alone).  The procedure is
  200.      documented in the Stabs Interface Manual, which is distrubuted
  201.      with the compilers, although version 4.0 of the manual seems to
  202.      be incorrect in some places, at least for SPARC.  The
  203.      globalization prefix is encoded into an N_OPT stab, with the form
  204.      "G=<prefix>".  The globalization prefix always seems to start
  205.      with a dollar sign '$'; a dot '.' is used as a seperator.  So we
  206.      simply strip everything up until the last dot.  */

  207.   if (name[0] == '$')
  208.     {
  209.       char *p = strrchr (name, '.');
  210.       if (p)
  211.         return p + 1;
  212.     }

  213.   return name;
  214. }


  215. void
  216. sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  217. {
  218.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  219.   tdep->gregset = &sparc32_sol2_gregset;
  220.   tdep->sizeof_gregset = 152;

  221.   tdep->fpregset = &sparc32_sol2_fpregset;
  222.   tdep->sizeof_fpregset = 400;

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

  227.   /* The Sun compilers also do "globalization"; see the comment in
  228.      sparc_sol2_static_transform_name for more information.  */
  229.   set_gdbarch_static_transform_name
  230.     (gdbarch, sparc_sol2_static_transform_name);

  231.   /* Solaris has SVR4-style shared libraries...  */
  232.   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
  233.   set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
  234.   set_solib_svr4_fetch_link_map_offsets
  235.     (gdbarch, svr4_ilp32_fetch_link_map_offsets);

  236.   /* ...which means that we need some special handling when doing
  237.      prologue analysis.  */
  238.   tdep->plt_entry_size = 12;

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

  241.   frame_unwind_append_unwinder (gdbarch, &sparc32_sol2_sigtramp_frame_unwind);

  242.   /* How to print LWP PTIDs from core files.  */
  243.   set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);
  244. }


  245. /* Provide a prototype to silence -Wmissing-prototypes.  */
  246. void _initialize_sparc_sol2_tdep (void);

  247. void
  248. _initialize_sparc_sol2_tdep (void)
  249. {
  250.   gdbarch_register_osabi (bfd_arch_sparc, 0,
  251.                           GDB_OSABI_SOLARIS, sparc32_sol2_init_abi);
  252. }