gdb/i386-sol2-tdep.c - gdb

Global variables defined

Functions defined

Source code

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

  2.    Copyright (C) 2002-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 "value.h"
  16. #include "osabi.h"

  17. #include "sol2-tdep.h"
  18. #include "i386-tdep.h"
  19. #include "solib-svr4.h"

  20. /* From <ia32/sys/reg.h>.  */
  21. static int i386_sol2_gregset_reg_offset[] =
  22. {
  23.   11 * 4,                        /* %eax */
  24.   10 * 4,                        /* %ecx */
  25.   9 * 4,                        /* %edx */
  26.   8 * 4,                        /* %ebx */
  27.   17 * 4,                        /* %esp */
  28.   6 * 4,                        /* %ebp */
  29.   5 * 4,                        /* %esi */
  30.   4 * 4,                        /* %edi */
  31.   14 * 4,                        /* %eip */
  32.   16 * 4,                        /* %eflags */
  33.   15 * 4,                        /* %cs */
  34.   18 * 4,                        /* %ss */
  35.   3 * 4,                        /* %ds */
  36.   2 * 4,                        /* %es */
  37.   1 * 4,                        /* %fs */
  38.   0 * 4                                /* %gs */
  39. };

  40. /* Return whether THIS_FRAME corresponds to a Solaris sigtramp
  41.    routine.  */

  42. static int
  43. i386_sol2_sigtramp_p (struct frame_info *this_frame)
  44. {
  45.   CORE_ADDR pc = get_frame_pc (this_frame);
  46.   const char *name;

  47.   find_pc_partial_function (pc, &name, NULL, NULL);
  48.   return (name && (strcmp ("sigacthandler", name) == 0
  49.                    || strcmp (name, "ucbsigvechandler") == 0));
  50. }

  51. /* Solaris doesn't have a `struct sigcontext', but it does have a
  52.    `mcontext_t' that contains the saved set of machine registers.  */

  53. static CORE_ADDR
  54. i386_sol2_mcontext_addr (struct frame_info *this_frame)
  55. {
  56.   CORE_ADDR sp, ucontext_addr;

  57.   sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
  58.   ucontext_addr = get_frame_memory_unsigned (this_frame, sp + 8, 4);

  59.   return ucontext_addr + 36;
  60. }

  61. /* SunPRO encodes the static variables.  This is not related to C++
  62.    mangling, it is done for C too.  */

  63. static const char *
  64. i386_sol2_static_transform_name (const char *name)
  65. {
  66.   char *p;
  67.   if (name[0] == '.')
  68.     {
  69.       /* For file-local statics there will be a period, a bunch of
  70.          junk (the contents of which match a string given in the
  71.          N_OPT), a period and the name.  For function-local statics
  72.          there will be a bunch of junk (which seems to change the
  73.          second character from 'A' to 'B'), a period, the name of the
  74.          function, and the name.  So just skip everything before the
  75.          last period.  */
  76.       p = strrchr (name, '.');
  77.       if (p != NULL)
  78.         name = p + 1;
  79.     }
  80.   return name;
  81. }

  82. /* Solaris 2.  */

  83. static void
  84. i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  85. {
  86.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  87.   /* Solaris is SVR4-based.  */
  88.   i386_svr4_init_abi (info, gdbarch);

  89.   /* The SunPRO compiler puts out 0 instead of the address in N_SO symbols,
  90.      and for SunPRO 3.0, N_FUN symbols too.  */
  91.   set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);

  92.   /* Handle SunPRO encoding of static symbols.  */
  93.   set_gdbarch_static_transform_name (gdbarch, i386_sol2_static_transform_name);

  94.   /* Solaris reserves space for its FPU emulator in `fpregset_t'.
  95.      There is also some space reserved for the registers of a Weitek
  96.      math coprocessor.  */
  97.   tdep->gregset_reg_offset = i386_sol2_gregset_reg_offset;
  98.   tdep->gregset_num_regs = ARRAY_SIZE (i386_sol2_gregset_reg_offset);
  99.   tdep->sizeof_gregset = 19 * 4;
  100.   tdep->sizeof_fpregset = 380;

  101.   /* Signal trampolines are slightly different from SVR4.  */
  102.   tdep->sigtramp_p = i386_sol2_sigtramp_p;
  103.   tdep->sigcontext_addr = i386_sol2_mcontext_addr;
  104.   tdep->sc_reg_offset = tdep->gregset_reg_offset;
  105.   tdep->sc_num_regs = tdep->gregset_num_regs;

  106.   /* Solaris has SVR4-style shared libraries.  */
  107.   set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
  108.   set_solib_svr4_fetch_link_map_offsets
  109.     (gdbarch, svr4_ilp32_fetch_link_map_offsets);

  110.   /* How to print LWP PTIDs from core files.  */
  111.   set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);
  112. }


  113. static enum gdb_osabi
  114. i386_sol2_osabi_sniffer (bfd *abfd)
  115. {
  116.   /* If we have a section named .SUNW_version, then it is almost
  117.      certainly Solaris 2.  */
  118.   if (bfd_get_section_by_name (abfd, ".SUNW_version"))
  119.     return GDB_OSABI_SOLARIS;

  120.   return GDB_OSABI_UNKNOWN;
  121. }

  122. /* Provide a prototype to silence -Wmissing-prototypes.  */
  123. void _initialize_i386_sol2_tdep (void);

  124. void
  125. _initialize_i386_sol2_tdep (void)
  126. {
  127.   /* Register an ELF OS ABI sniffer for Solaris 2 binaries.  */
  128.   gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
  129.                                   i386_sol2_osabi_sniffer);

  130.   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SOLARIS,
  131.                           i386_sol2_init_abi);
  132. }