]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/sparc-sol2-tdep.c
remove gdb_string.h
[thirdparty/binutils-gdb.git] / gdb / sparc-sol2-tdep.c
1 /* Target-dependent code for Solaris SPARC.
2
3 Copyright (C) 2003-2013 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "frame-unwind.h"
23 #include "gdbcore.h"
24 #include "symtab.h"
25 #include "objfiles.h"
26 #include "osabi.h"
27 #include "regcache.h"
28 #include "target.h"
29 #include "trad-frame.h"
30
31 #include "gdb_assert.h"
32 #include <string.h>
33
34 #include "sol2-tdep.h"
35 #include "sparc-tdep.h"
36 #include "solib-svr4.h"
37
38 /* From <sys/regset.h>. */
39 const struct sparc_gregset sparc32_sol2_gregset =
40 {
41 32 * 4, /* %psr */
42 33 * 4, /* %pc */
43 34 * 4, /* %npc */
44 35 * 4, /* %y */
45 36 * 4, /* %wim */
46 37 * 4, /* %tbr */
47 1 * 4, /* %g1 */
48 16 * 4, /* %l0 */
49 };
50
51 const struct sparc_fpregset sparc32_sol2_fpregset =
52 {
53 0 * 4, /* %f0 */
54 33 * 4, /* %fsr */
55 };
56 \f
57
58 /* The Solaris signal trampolines reside in libc. For normal signals,
59 the function `sigacthandler' is used. This signal trampoline will
60 call the signal handler using the System V calling convention,
61 where the third argument is a pointer to an instance of
62 `ucontext_t', which has a member `uc_mcontext' that contains the
63 saved registers. Incidentally, the kernel passes the `ucontext_t'
64 pointer as the third argument of the signal trampoline too, and
65 `sigacthandler' simply passes it on. However, if you link your
66 program with "-L/usr/ucblib -R/usr/ucblib -lucb", the function
67 `ucbsigvechandler' will be used, which invokes the using the BSD
68 convention, where the third argument is a pointer to an instance of
69 `struct sigcontext'. It is the `ucbsigvechandler' function that
70 converts the `ucontext_t' to a `sigcontext', and back. Unless the
71 signal handler modifies the `struct sigcontext' we can safely
72 ignore this. */
73
74 int
75 sparc_sol2_pc_in_sigtramp (CORE_ADDR pc, const char *name)
76 {
77 return (name && (strcmp (name, "sigacthandler") == 0
78 || strcmp (name, "ucbsigvechandler") == 0
79 || strcmp (name, "__sighndlr") == 0));
80 }
81
82 static struct sparc_frame_cache *
83 sparc32_sol2_sigtramp_frame_cache (struct frame_info *this_frame,
84 void **this_cache)
85 {
86 struct sparc_frame_cache *cache;
87 CORE_ADDR mcontext_addr, addr;
88 int regnum;
89
90 if (*this_cache)
91 return *this_cache;
92
93 cache = sparc_frame_cache (this_frame, this_cache);
94 gdb_assert (cache == *this_cache);
95
96 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
97
98 /* The third argument is a pointer to an instance of `ucontext_t',
99 which has a member `uc_mcontext' that contains the saved
100 registers. */
101 regnum =
102 (cache->copied_regs_mask & 0x04) ? SPARC_I2_REGNUM : SPARC_O2_REGNUM;
103 mcontext_addr = get_frame_register_unsigned (this_frame, regnum) + 40;
104
105 cache->saved_regs[SPARC32_PSR_REGNUM].addr = mcontext_addr + 0 * 4;
106 cache->saved_regs[SPARC32_PC_REGNUM].addr = mcontext_addr + 1 * 4;
107 cache->saved_regs[SPARC32_NPC_REGNUM].addr = mcontext_addr + 2 * 4;
108 cache->saved_regs[SPARC32_Y_REGNUM].addr = mcontext_addr + 3 * 4;
109
110 /* Since %g0 is always zero, keep the identity encoding. */
111 for (regnum = SPARC_G1_REGNUM, addr = mcontext_addr + 4 * 4;
112 regnum <= SPARC_O7_REGNUM; regnum++, addr += 4)
113 cache->saved_regs[regnum].addr = addr;
114
115 if (get_frame_memory_unsigned (this_frame, mcontext_addr + 19 * 4, 4))
116 {
117 /* The register windows haven't been flushed. */
118 for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++)
119 trad_frame_set_unknown (cache->saved_regs, regnum);
120 }
121 else
122 {
123 addr = cache->saved_regs[SPARC_SP_REGNUM].addr;
124 addr = get_frame_memory_unsigned (this_frame, addr, 4);
125 for (regnum = SPARC_L0_REGNUM;
126 regnum <= SPARC_I7_REGNUM; regnum++, addr += 4)
127 cache->saved_regs[regnum].addr = addr;
128 }
129
130 return cache;
131 }
132
133 static void
134 sparc32_sol2_sigtramp_frame_this_id (struct frame_info *this_frame,
135 void **this_cache,
136 struct frame_id *this_id)
137 {
138 struct sparc_frame_cache *cache =
139 sparc32_sol2_sigtramp_frame_cache (this_frame, this_cache);
140
141 (*this_id) = frame_id_build (cache->base, cache->pc);
142 }
143
144 static struct value *
145 sparc32_sol2_sigtramp_frame_prev_register (struct frame_info *this_frame,
146 void **this_cache,
147 int regnum)
148 {
149 struct sparc_frame_cache *cache =
150 sparc32_sol2_sigtramp_frame_cache (this_frame, this_cache);
151
152 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
153 }
154
155 static int
156 sparc32_sol2_sigtramp_frame_sniffer (const struct frame_unwind *self,
157 struct frame_info *this_frame,
158 void **this_cache)
159 {
160 CORE_ADDR pc = get_frame_pc (this_frame);
161 const char *name;
162
163 find_pc_partial_function (pc, &name, NULL, NULL);
164 if (sparc_sol2_pc_in_sigtramp (pc, name))
165 return 1;
166
167 return 0;
168 }
169
170 static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
171 {
172 SIGTRAMP_FRAME,
173 default_frame_unwind_stop_reason,
174 sparc32_sol2_sigtramp_frame_this_id,
175 sparc32_sol2_sigtramp_frame_prev_register,
176 NULL,
177 sparc32_sol2_sigtramp_frame_sniffer
178 };
179
180 /* Unglobalize NAME. */
181
182 const const char *
183 sparc_sol2_static_transform_name (const char *name)
184 {
185 /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop,
186 SunPRO) convert file static variables into global values, a
187 process known as globalization. In order to do this, the
188 compiler will create a unique prefix and prepend it to each file
189 static variable. For static variables within a function, this
190 globalization prefix is followed by the function name (nested
191 static variables within a function are supposed to generate a
192 warning message, and are left alone). The procedure is
193 documented in the Stabs Interface Manual, which is distrubuted
194 with the compilers, although version 4.0 of the manual seems to
195 be incorrect in some places, at least for SPARC. The
196 globalization prefix is encoded into an N_OPT stab, with the form
197 "G=<prefix>". The globalization prefix always seems to start
198 with a dollar sign '$'; a dot '.' is used as a seperator. So we
199 simply strip everything up until the last dot. */
200
201 if (name[0] == '$')
202 {
203 char *p = strrchr (name, '.');
204 if (p)
205 return p + 1;
206 }
207
208 return name;
209 }
210 \f
211
212 void
213 sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
214 {
215 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
216
217 /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop, SunPRO)
218 compiler puts out 0 instead of the address in N_SO stabs. Starting with
219 SunPRO 3.0, the compiler does this for N_FUN stabs too. */
220 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
221
222 /* The Sun compilers also do "globalization"; see the comment in
223 sparc_sol2_static_transform_name for more information. */
224 set_gdbarch_static_transform_name
225 (gdbarch, sparc_sol2_static_transform_name);
226
227 /* Solaris has SVR4-style shared libraries... */
228 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
229 set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
230 set_solib_svr4_fetch_link_map_offsets
231 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
232
233 /* ...which means that we need some special handling when doing
234 prologue analysis. */
235 tdep->plt_entry_size = 12;
236
237 /* Solaris has kernel-assisted single-stepping support. */
238 set_gdbarch_software_single_step (gdbarch, NULL);
239
240 frame_unwind_append_unwinder (gdbarch, &sparc32_sol2_sigtramp_frame_unwind);
241
242 /* How to print LWP PTIDs from core files. */
243 set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);
244 }
245 \f
246
247 /* Provide a prototype to silence -Wmissing-prototypes. */
248 void _initialize_sparc_sol2_tdep (void);
249
250 void
251 _initialize_sparc_sol2_tdep (void)
252 {
253 gdbarch_register_osabi (bfd_arch_sparc, 0,
254 GDB_OSABI_SOLARIS, sparc32_sol2_init_abi);
255 }