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