GDB (API)
/home/stan/gdb/src/gdb/i386-sol2-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for Solaris x86.
00002 
00003    Copyright (C) 2002-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 "value.h"
00022 #include "osabi.h"
00023 
00024 #include "gdb_string.h"
00025 
00026 #include "sol2-tdep.h"
00027 #include "i386-tdep.h"
00028 #include "solib-svr4.h"
00029 
00030 /* From <ia32/sys/reg.h>.  */
00031 static int i386_sol2_gregset_reg_offset[] =
00032 {
00033   11 * 4,                       /* %eax */
00034   10 * 4,                       /* %ecx */
00035   9 * 4,                        /* %edx */
00036   8 * 4,                        /* %ebx */
00037   17 * 4,                       /* %esp */
00038   6 * 4,                        /* %ebp */
00039   5 * 4,                        /* %esi */
00040   4 * 4,                        /* %edi */
00041   14 * 4,                       /* %eip */
00042   16 * 4,                       /* %eflags */
00043   15 * 4,                       /* %cs */
00044   18 * 4,                       /* %ss */
00045   3 * 4,                        /* %ds */
00046   2 * 4,                        /* %es */
00047   1 * 4,                        /* %fs */
00048   0 * 4                         /* %gs */
00049 };
00050 
00051 /* Return whether THIS_FRAME corresponds to a Solaris sigtramp
00052    routine.  */
00053 
00054 static int
00055 i386_sol2_sigtramp_p (struct frame_info *this_frame)
00056 {
00057   CORE_ADDR pc = get_frame_pc (this_frame);
00058   const char *name;
00059 
00060   find_pc_partial_function (pc, &name, NULL, NULL);
00061   return (name && (strcmp ("sigacthandler", name) == 0
00062                    || strcmp (name, "ucbsigvechandler") == 0));
00063 }
00064 
00065 /* Solaris doesn't have a `struct sigcontext', but it does have a
00066    `mcontext_t' that contains the saved set of machine registers.  */
00067 
00068 static CORE_ADDR
00069 i386_sol2_mcontext_addr (struct frame_info *this_frame)
00070 {
00071   CORE_ADDR sp, ucontext_addr;
00072 
00073   sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
00074   ucontext_addr = get_frame_memory_unsigned (this_frame, sp + 8, 4);
00075 
00076   return ucontext_addr + 36;
00077 }
00078 
00079 /* SunPRO encodes the static variables.  This is not related to C++
00080    mangling, it is done for C too.  */
00081 
00082 static const char *
00083 i386_sol2_static_transform_name (const char *name)
00084 {
00085   char *p;
00086   if (name[0] == '.')
00087     {
00088       /* For file-local statics there will be a period, a bunch of
00089          junk (the contents of which match a string given in the
00090          N_OPT), a period and the name.  For function-local statics
00091          there will be a bunch of junk (which seems to change the
00092          second character from 'A' to 'B'), a period, the name of the
00093          function, and the name.  So just skip everything before the
00094          last period.  */
00095       p = strrchr (name, '.');
00096       if (p != NULL)
00097         name = p + 1;
00098     }
00099   return name;
00100 }
00101 
00102 /* Solaris 2.  */
00103 
00104 static void
00105 i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00106 {
00107   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00108 
00109   /* Solaris is SVR4-based.  */
00110   i386_svr4_init_abi (info, gdbarch);
00111 
00112   /* The SunPRO compiler puts out 0 instead of the address in N_SO symbols,
00113      and for SunPRO 3.0, N_FUN symbols too.  */
00114   set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
00115 
00116   /* Handle SunPRO encoding of static symbols.  */
00117   set_gdbarch_static_transform_name (gdbarch, i386_sol2_static_transform_name);
00118 
00119   /* Solaris reserves space for its FPU emulator in `fpregset_t'.
00120      There is also some space reserved for the registers of a Weitek
00121      math coprocessor.  */
00122   tdep->gregset_reg_offset = i386_sol2_gregset_reg_offset;
00123   tdep->gregset_num_regs = ARRAY_SIZE (i386_sol2_gregset_reg_offset);
00124   tdep->sizeof_gregset = 19 * 4;
00125   tdep->sizeof_fpregset = 380;
00126 
00127   /* Signal trampolines are slightly different from SVR4.  */
00128   tdep->sigtramp_p = i386_sol2_sigtramp_p;
00129   tdep->sigcontext_addr = i386_sol2_mcontext_addr;
00130   tdep->sc_reg_offset = tdep->gregset_reg_offset;
00131   tdep->sc_num_regs = tdep->gregset_num_regs;
00132 
00133   /* Solaris has SVR4-style shared libraries.  */
00134   set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
00135   set_solib_svr4_fetch_link_map_offsets
00136     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
00137 
00138   /* How to print LWP PTIDs from core files.  */
00139   set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);
00140 }
00141 
00142 
00143 static enum gdb_osabi
00144 i386_sol2_osabi_sniffer (bfd *abfd)
00145 {
00146   /* If we have a section named .SUNW_version, then it is almost
00147      certainly Solaris 2.  */
00148   if (bfd_get_section_by_name (abfd, ".SUNW_version"))
00149     return GDB_OSABI_SOLARIS;
00150 
00151   return GDB_OSABI_UNKNOWN;
00152 }
00153 
00154 /* Provide a prototype to silence -Wmissing-prototypes.  */
00155 void _initialize_i386_sol2_tdep (void);
00156 
00157 void
00158 _initialize_i386_sol2_tdep (void)
00159 {
00160   /* Register an ELF OS ABI sniffer for Solaris 2 binaries.  */
00161   gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
00162                                   i386_sol2_osabi_sniffer);
00163 
00164   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SOLARIS,
00165                           i386_sol2_init_abi);
00166 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines