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