Commit | Line | Data |
---|---|---|
386c036b MK |
1 | /* Target-dependent code for Solaris SPARC. |
2 | ||
6aba47ca | 3 | Copyright (C) 2003, 2004, 2006, 2007 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 | |
9 | the Free Software Foundation; either version 2 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, write to the Free Software | |
197e01b6 EZ |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. */ | |
386c036b MK |
21 | |
22 | #include "defs.h" | |
23 | #include "frame.h" | |
24 | #include "frame-unwind.h" | |
25 | #include "gdbcore.h" | |
26 | #include "symtab.h" | |
27 | #include "objfiles.h" | |
28 | #include "osabi.h" | |
29 | #include "regcache.h" | |
30 | #include "target.h" | |
31 | #include "trad-frame.h" | |
32 | ||
33 | #include "gdb_assert.h" | |
34 | #include "gdb_string.h" | |
35 | ||
081bf9da | 36 | #include "sol2-tdep.h" |
386c036b | 37 | #include "sparc-tdep.h" |
70b216c8 | 38 | #include "solib-svr4.h" |
386c036b MK |
39 | |
40 | /* From <sys/regset.h>. */ | |
41 | const struct sparc_gregset sparc32_sol2_gregset = | |
42 | { | |
43 | 32 * 4, /* %psr */ | |
44 | 33 * 4, /* %pc */ | |
45 | 34 * 4, /* %npc */ | |
46 | 35 * 4, /* %y */ | |
47 | 36 * 4, /* %wim */ | |
48 | 37 * 4, /* %tbr */ | |
49 | 1 * 4, /* %g1 */ | |
50 | 16 * 4, /* %l0 */ | |
51 | }; | |
52 | \f | |
53 | ||
54 | /* The Solaris signal trampolines reside in libc. For normal signals, | |
55 | the function `sigacthandler' is used. This signal trampoline will | |
56 | call the signal handler using the System V calling convention, | |
57 | where the third argument is a pointer to an instance of | |
58 | `ucontext_t', which has a member `uc_mcontext' that contains the | |
59 | saved registers. Incidentally, the kernel passes the `ucontext_t' | |
60 | pointer as the third argument of the signal trampoline too, and | |
61 | `sigacthandler' simply passes it on. However, if you link your | |
62 | program with "-L/usr/ucblib -R/usr/ucblib -lucb", the function | |
63 | `ucbsigvechandler' will be used, which invokes the using the BSD | |
64 | convention, where the third argument is a pointer to an instance of | |
65 | `struct sigcontext'. It is the `ucbsigvechandler' function that | |
66 | converts the `ucontext_t' to a `sigcontext', and back. Unless the | |
67 | signal handler modifies the `struct sigcontext' we can safely | |
68 | ignore this. */ | |
69 | ||
70 | int | |
71 | sparc_sol2_pc_in_sigtramp (CORE_ADDR pc, char *name) | |
72 | { | |
73 | return (name && (strcmp (name, "sigacthandler") == 0 | |
0c318c49 MK |
74 | || strcmp (name, "ucbsigvechandler") == 0 |
75 | || strcmp (name, "__sighndlr") == 0)); | |
386c036b MK |
76 | } |
77 | ||
78 | static struct sparc_frame_cache * | |
79 | sparc32_sol2_sigtramp_frame_cache (struct frame_info *next_frame, | |
80 | void **this_cache) | |
81 | { | |
82 | struct sparc_frame_cache *cache; | |
83 | CORE_ADDR mcontext_addr, addr; | |
84 | int regnum; | |
85 | ||
86 | if (*this_cache) | |
87 | return *this_cache; | |
88 | ||
89 | cache = sparc_frame_cache (next_frame, this_cache); | |
90 | gdb_assert (cache == *this_cache); | |
91 | ||
92 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
93 | ||
94 | /* The third argument is a pointer to an instance of `ucontext_t', | |
95 | which has a member `uc_mcontext' that contains the saved | |
96 | registers. */ | |
97 | regnum = (cache->frameless_p ? SPARC_O2_REGNUM : SPARC_I2_REGNUM); | |
98 | mcontext_addr = frame_unwind_register_unsigned (next_frame, regnum) + 40; | |
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 | ||
110 | if (get_frame_memory_unsigned (next_frame, mcontext_addr + 19 * 4, 4)) | |
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; | |
119 | addr = get_frame_memory_unsigned (next_frame, addr, 4); | |
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 | ||
128 | static void | |
129 | sparc32_sol2_sigtramp_frame_this_id (struct frame_info *next_frame, | |
130 | void **this_cache, | |
131 | struct frame_id *this_id) | |
132 | { | |
133 | struct sparc_frame_cache *cache = | |
134 | sparc32_sol2_sigtramp_frame_cache (next_frame, this_cache); | |
135 | ||
136 | (*this_id) = frame_id_build (cache->base, cache->pc); | |
137 | } | |
138 | ||
139 | static void | |
140 | sparc32_sol2_sigtramp_frame_prev_register (struct frame_info *next_frame, | |
141 | void **this_cache, | |
142 | int regnum, int *optimizedp, | |
143 | enum lval_type *lvalp, | |
144 | CORE_ADDR *addrp, | |
47ef841b | 145 | int *realnump, gdb_byte *valuep) |
386c036b MK |
146 | { |
147 | struct sparc_frame_cache *cache = | |
148 | sparc32_sol2_sigtramp_frame_cache (next_frame, this_cache); | |
149 | ||
1f67027d AC |
150 | trad_frame_get_prev_register (next_frame, cache->saved_regs, regnum, |
151 | optimizedp, lvalp, addrp, realnump, valuep); | |
386c036b MK |
152 | } |
153 | ||
154 | static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind = | |
155 | { | |
156 | SIGTRAMP_FRAME, | |
157 | sparc32_sol2_sigtramp_frame_this_id, | |
158 | sparc32_sol2_sigtramp_frame_prev_register | |
159 | }; | |
160 | ||
161 | static const struct frame_unwind * | |
162 | sparc32_sol2_sigtramp_frame_sniffer (struct frame_info *next_frame) | |
163 | { | |
164 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
165 | char *name; | |
166 | ||
167 | find_pc_partial_function (pc, &name, NULL, NULL); | |
168 | if (sparc_sol2_pc_in_sigtramp (pc, name)) | |
169 | return &sparc32_sol2_sigtramp_frame_unwind; | |
170 | ||
171 | return NULL; | |
172 | } | |
173 | \f | |
174 | ||
175 | void | |
176 | sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
177 | { | |
178 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
179 | ||
180 | /* Solaris has SVR4-style shared libraries... */ | |
386c036b | 181 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); |
081bf9da | 182 | set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver); |
70b216c8 MK |
183 | set_solib_svr4_fetch_link_map_offsets |
184 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); | |
386c036b MK |
185 | |
186 | /* ...which means that we need some special handling when doing | |
187 | prologue analysis. */ | |
188 | tdep->plt_entry_size = 12; | |
189 | ||
190 | /* Solaris has kernel-assisted single-stepping support. */ | |
191 | set_gdbarch_software_single_step (gdbarch, NULL); | |
192 | ||
386c036b MK |
193 | frame_unwind_append_sniffer (gdbarch, sparc32_sol2_sigtramp_frame_sniffer); |
194 | } | |
195 | \f | |
196 | ||
197 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
198 | void _initialize_sparc_sol2_tdep (void); | |
199 | ||
200 | void | |
201 | _initialize_sparc_sol2_tdep (void) | |
202 | { | |
203 | gdbarch_register_osabi (bfd_arch_sparc, 0, | |
204 | GDB_OSABI_SOLARIS, sparc32_sol2_init_abi); | |
205 | } |