1 /* Target-dependent code for Solaris x86.
3 Copyright (C) 2002-2004, 2006-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
26 #include "sol2-tdep.h"
27 #include "i386-tdep.h"
28 #include "solib-svr4.h"
30 /* From <ia32/sys/reg.h>. */
31 static int i386_sol2_gregset_reg_offset[] =
51 /* Return whether THIS_FRAME corresponds to a Solaris sigtramp
55 i386_sol2_sigtramp_p (struct frame_info *this_frame)
57 CORE_ADDR pc = get_frame_pc (this_frame);
60 find_pc_partial_function (pc, &name, NULL, NULL);
61 return (name && (strcmp ("sigacthandler", name) == 0
62 || strcmp (name, "ucbsigvechandler") == 0));
65 /* Solaris doesn't have a `struct sigcontext', but it does have a
66 `mcontext_t' that contains the saved set of machine registers. */
69 i386_sol2_mcontext_addr (struct frame_info *this_frame)
71 CORE_ADDR sp, ucontext_addr;
73 sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
74 ucontext_addr = get_frame_memory_unsigned (this_frame, sp + 8, 4);
76 return ucontext_addr + 36;
79 /* SunPRO encodes the static variables. This is not related to C++
80 mangling, it is done for C too. */
83 i386_sol2_static_transform_name (const char *name)
88 /* For file-local statics there will be a period, a bunch of
89 junk (the contents of which match a string given in the
90 N_OPT), a period and the name. For function-local statics
91 there will be a bunch of junk (which seems to change the
92 second character from 'A' to 'B'), a period, the name of the
93 function, and the name. So just skip everything before the
95 p = strrchr (name, '.');
105 i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
107 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
109 /* Solaris is SVR4-based. */
110 i386_svr4_init_abi (info, gdbarch);
112 /* The SunPRO compiler puts out 0 instead of the address in N_SO symbols,
113 and for SunPRO 3.0, N_FUN symbols too. */
114 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
116 /* Handle SunPRO encoding of static symbols. */
117 set_gdbarch_static_transform_name (gdbarch, i386_sol2_static_transform_name);
119 /* Solaris reserves space for its FPU emulator in `fpregset_t'.
120 There is also some space reserved for the registers of a Weitek
122 tdep->gregset_reg_offset = i386_sol2_gregset_reg_offset;
123 tdep->gregset_num_regs = ARRAY_SIZE (i386_sol2_gregset_reg_offset);
124 tdep->sizeof_gregset = 19 * 4;
125 tdep->sizeof_fpregset = 380;
127 /* Signal trampolines are slightly different from SVR4. */
128 tdep->sigtramp_p = i386_sol2_sigtramp_p;
129 tdep->sigcontext_addr = i386_sol2_mcontext_addr;
130 tdep->sc_reg_offset = tdep->gregset_reg_offset;
131 tdep->sc_num_regs = tdep->gregset_num_regs;
133 /* Solaris has SVR4-style shared libraries. */
134 set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
135 set_solib_svr4_fetch_link_map_offsets
136 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
138 /* How to print LWP PTIDs from core files. */
139 set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);
143 static enum gdb_osabi
144 i386_sol2_osabi_sniffer (bfd *abfd)
146 /* If we have a section named .SUNW_version, then it is almost
147 certainly Solaris 2. */
148 if (bfd_get_section_by_name (abfd, ".SUNW_version"))
149 return GDB_OSABI_SOLARIS;
151 return GDB_OSABI_UNKNOWN;
154 /* Provide a prototype to silence -Wmissing-prototypes. */
155 void _initialize_i386_sol2_tdep (void);
158 _initialize_i386_sol2_tdep (void)
160 /* Register an ELF OS ABI sniffer for Solaris 2 binaries. */
161 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
162 i386_sol2_osabi_sniffer);
164 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SOLARIS,