1 /* Target-dependent code for Solaris SPARC.
3 Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "frame-unwind.h"
30 #include "trad-frame.h"
32 #include "gdb_assert.h"
33 #include "gdb_string.h"
35 #include "sol2-tdep.h"
36 #include "sparc-tdep.h"
37 #include "solib-svr4.h"
39 /* From <sys/regset.h>. */
40 const struct sparc_gregset sparc32_sol2_gregset
=
53 /* The Solaris signal trampolines reside in libc. For normal signals,
54 the function `sigacthandler' is used. This signal trampoline will
55 call the signal handler using the System V calling convention,
56 where the third argument is a pointer to an instance of
57 `ucontext_t', which has a member `uc_mcontext' that contains the
58 saved registers. Incidentally, the kernel passes the `ucontext_t'
59 pointer as the third argument of the signal trampoline too, and
60 `sigacthandler' simply passes it on. However, if you link your
61 program with "-L/usr/ucblib -R/usr/ucblib -lucb", the function
62 `ucbsigvechandler' will be used, which invokes the using the BSD
63 convention, where the third argument is a pointer to an instance of
64 `struct sigcontext'. It is the `ucbsigvechandler' function that
65 converts the `ucontext_t' to a `sigcontext', and back. Unless the
66 signal handler modifies the `struct sigcontext' we can safely
70 sparc_sol2_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
72 return (name
&& (strcmp (name
, "sigacthandler") == 0
73 || strcmp (name
, "ucbsigvechandler") == 0
74 || strcmp (name
, "__sighndlr") == 0));
77 static struct sparc_frame_cache
*
78 sparc32_sol2_sigtramp_frame_cache (struct frame_info
*this_frame
,
81 struct sparc_frame_cache
*cache
;
82 CORE_ADDR mcontext_addr
, addr
;
88 cache
= sparc_frame_cache (this_frame
, this_cache
);
89 gdb_assert (cache
== *this_cache
);
91 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
93 /* The third argument is a pointer to an instance of `ucontext_t',
94 which has a member `uc_mcontext' that contains the saved
96 regnum
= (cache
->frameless_p
? SPARC_O2_REGNUM
: SPARC_I2_REGNUM
);
97 mcontext_addr
= get_frame_register_unsigned (this_frame
, regnum
) + 40;
99 cache
->saved_regs
[SPARC32_PSR_REGNUM
].addr
= mcontext_addr
+ 0 * 4;
100 cache
->saved_regs
[SPARC32_PC_REGNUM
].addr
= mcontext_addr
+ 1 * 4;
101 cache
->saved_regs
[SPARC32_NPC_REGNUM
].addr
= mcontext_addr
+ 2 * 4;
102 cache
->saved_regs
[SPARC32_Y_REGNUM
].addr
= mcontext_addr
+ 3 * 4;
104 /* Since %g0 is always zero, keep the identity encoding. */
105 for (regnum
= SPARC_G1_REGNUM
, addr
= mcontext_addr
+ 4 * 4;
106 regnum
<= SPARC_O7_REGNUM
; regnum
++, addr
+= 4)
107 cache
->saved_regs
[regnum
].addr
= addr
;
109 if (get_frame_memory_unsigned (this_frame
, mcontext_addr
+ 19 * 4, 4))
111 /* The register windows haven't been flushed. */
112 for (regnum
= SPARC_L0_REGNUM
; regnum
<= SPARC_I7_REGNUM
; regnum
++)
113 trad_frame_set_unknown (cache
->saved_regs
, regnum
);
117 addr
= cache
->saved_regs
[SPARC_SP_REGNUM
].addr
;
118 addr
= get_frame_memory_unsigned (this_frame
, addr
, 4);
119 for (regnum
= SPARC_L0_REGNUM
;
120 regnum
<= SPARC_I7_REGNUM
; regnum
++, addr
+= 4)
121 cache
->saved_regs
[regnum
].addr
= addr
;
128 sparc32_sol2_sigtramp_frame_this_id (struct frame_info
*this_frame
,
130 struct frame_id
*this_id
)
132 struct sparc_frame_cache
*cache
=
133 sparc32_sol2_sigtramp_frame_cache (this_frame
, this_cache
);
135 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
138 static struct value
*
139 sparc32_sol2_sigtramp_frame_prev_register (struct frame_info
*this_frame
,
143 struct sparc_frame_cache
*cache
=
144 sparc32_sol2_sigtramp_frame_cache (this_frame
, this_cache
);
146 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
, regnum
);
150 sparc32_sol2_sigtramp_frame_sniffer (const struct frame_unwind
*self
,
151 struct frame_info
*this_frame
,
154 CORE_ADDR pc
= get_frame_pc (this_frame
);
157 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
158 if (sparc_sol2_pc_in_sigtramp (pc
, name
))
164 static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind
=
167 sparc32_sol2_sigtramp_frame_this_id
,
168 sparc32_sol2_sigtramp_frame_prev_register
,
170 sparc32_sol2_sigtramp_frame_sniffer
173 /* Unglobalize NAME. */
176 sparc_sol2_static_transform_name (char *name
)
178 /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop,
179 SunPRO) convert file static variables into global values, a
180 process known as globalization. In order to do this, the
181 compiler will create a unique prefix and prepend it to each file
182 static variable. For static variables within a function, this
183 globalization prefix is followed by the function name (nested
184 static variables within a function are supposed to generate a
185 warning message, and are left alone). The procedure is
186 documented in the Stabs Interface Manual, which is distrubuted
187 with the compilers, although version 4.0 of the manual seems to
188 be incorrect in some places, at least for SPARC. The
189 globalization prefix is encoded into an N_OPT stab, with the form
190 "G=<prefix>". The globalization prefix always seems to start
191 with a dollar sign '$'; a dot '.' is used as a seperator. So we
192 simply strip everything up until the last dot. */
196 char *p
= strrchr (name
, '.');
206 sparc32_sol2_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
208 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
210 /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop, SunPRO)
211 compiler puts out 0 instead of the address in N_SO stabs. Starting with
212 SunPRO 3.0, the compiler does this for N_FUN stabs too. */
213 set_gdbarch_sofun_address_maybe_missing (gdbarch
, 1);
215 /* The Sun compilers also do "globalization"; see the comment in
216 sparc_sol2_static_transform_name for more information. */
217 set_gdbarch_static_transform_name
218 (gdbarch
, sparc_sol2_static_transform_name
);
220 /* Solaris has SVR4-style shared libraries... */
221 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
222 set_gdbarch_skip_solib_resolver (gdbarch
, sol2_skip_solib_resolver
);
223 set_solib_svr4_fetch_link_map_offsets
224 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
226 /* ...which means that we need some special handling when doing
227 prologue analysis. */
228 tdep
->plt_entry_size
= 12;
230 /* Solaris has kernel-assisted single-stepping support. */
231 set_gdbarch_software_single_step (gdbarch
, NULL
);
233 frame_unwind_append_unwinder (gdbarch
, &sparc32_sol2_sigtramp_frame_unwind
);
235 /* How to print LWP PTIDs from core files. */
236 set_gdbarch_core_pid_to_str (gdbarch
, sol2_core_pid_to_str
);
240 /* Provide a prototype to silence -Wmissing-prototypes. */
241 void _initialize_sparc_sol2_tdep (void);
244 _initialize_sparc_sol2_tdep (void)
246 gdbarch_register_osabi (bfd_arch_sparc
, 0,
247 GDB_OSABI_SOLARIS
, sparc32_sol2_init_abi
);