Skip to content

Commit 6d8eadb

Browse files
author
Joel Brobecker
committed
Signal unwinder for mips-irix N32.
* mips-irix-tdep.c: #include mips-tdep.h, trad-frame.h, and tramp-frame.h. (SIGTRAMP_FRAME_SIZE, SIGCONTEXT_PC_OFF, SIGCONTEXT_REGS_OFF) (SIGCONTEXT_FPREGS_OFF, SIGCONTEXT_FPCSR_OFF, SIGCONTEXT_HI_OFF) (SIGCONTEXT_LO_OFF): New macros. (mips_irix_n32_tramp_frame_init): New function. (mips_irix_n32_tramp_frame): New static constant. (mips_irix_init_abi): Prepend the mips_irix_n32_tramp_frame unwinder.
1 parent 27087a3 commit 6d8eadb

File tree

2 files changed

+164
-1
lines changed

2 files changed

+164
-1
lines changed

gdb/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2010-01-09 Joel Brobecker <[email protected]>
2+
3+
Signal unwinder for mips-irix N32.
4+
* mips-irix-tdep.c: #include mips-tdep.h, trad-frame.h, and
5+
tramp-frame.h.
6+
(SIGTRAMP_FRAME_SIZE, SIGCONTEXT_PC_OFF, SIGCONTEXT_REGS_OFF)
7+
(SIGCONTEXT_FPREGS_OFF, SIGCONTEXT_FPCSR_OFF, SIGCONTEXT_HI_OFF)
8+
(SIGCONTEXT_LO_OFF): New macros.
9+
(mips_irix_n32_tramp_frame_init): New function.
10+
(mips_irix_n32_tramp_frame): New static constant.
11+
(mips_irix_init_abi): Prepend the mips_irix_n32_tramp_frame unwinder.
12+
113
2010-01-09 Joel Brobecker <[email protected]>
214

315
Breakpoint in shared library does not work on mips-irix.

gdb/mips-irix-tdep.c

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
#include "gdb_string.h"
2424
#include "solib.h"
2525
#include "solib-irix.h"
26-
2726
#include "elf-bfd.h"
27+
#include "mips-tdep.h"
28+
#include "trad-frame.h"
29+
#include "tramp-frame.h"
2830

2931
static void
3032
mips_irix_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
@@ -77,11 +79,160 @@ mips_irix_elf_osabi_sniffer (bfd *abfd)
7779
return osabi;
7880
}
7981

82+
/* Unwinding past the signal handler on mips-irix.
83+
84+
Note: The following has only been tested with N32, but can probably
85+
be made to work with a small number of adjustments.
86+
87+
On mips-irix, the sigcontext_t structure is stored at the base
88+
of the frame established by the _sigtramp function. The definition
89+
of this structure can be found in <sys/signal.h> (comments have been
90+
C++'ified to avoid a collision with the C-style comment delimiters
91+
used by this comment):
92+
93+
typedef struct sigcontext {
94+
__uint32_t sc_regmask; // regs to restore in sigcleanup
95+
__uint32_t sc_status; // cp0 status register
96+
__uint64_t sc_pc; // pc at time of signal
97+
// General purpose registers
98+
__uint64_t sc_regs[32]; // processor regs 0 to 31
99+
// Floating point coprocessor state
100+
__uint64_t sc_fpregs[32]; // fp regs 0 to 31
101+
__uint32_t sc_ownedfp; // fp has been used
102+
__uint32_t sc_fpc_csr; // fpu control and status reg
103+
__uint32_t sc_fpc_eir; // fpu exception instruction reg
104+
// implementation/revision
105+
__uint32_t sc_ssflags; // signal stack state to restore
106+
__uint64_t sc_mdhi; // Multiplier hi and low regs
107+
__uint64_t sc_mdlo;
108+
// System coprocessor registers at time of signal
109+
__uint64_t sc_cause; // cp0 cause register
110+
__uint64_t sc_badvaddr; // cp0 bad virtual address
111+
__uint64_t sc_triggersave; // state of graphics trigger (SGI)
112+
sigset_t sc_sigset; // signal mask to restore
113+
__uint64_t sc_fp_rounded_result; // for Ieee 754 support
114+
__uint64_t sc_pad[31];
115+
} sigcontext_t;
116+
117+
The following macros provide the offset of some of the fields
118+
used to retrieve the value of the registers before the signal
119+
was raised. */
120+
121+
/* The size of the sigtramp frame. The sigtramp frame base can then
122+
be computed by adding this size to the SP. */
123+
#define SIGTRAMP_FRAME_SIZE 48
124+
/* The offset in sigcontext_t where the PC is saved. */
125+
#define SIGCONTEXT_PC_OFF 8
126+
/* The offset in sigcontext_t where the GP registers are saved. */
127+
#define SIGCONTEXT_REGS_OFF (SIGCONTEXT_PC_OFF + 8)
128+
/* The offset in sigcontext_t where the FP regsiters are saved. */
129+
#define SIGCONTEXT_FPREGS_OFF (SIGCONTEXT_REGS_OFF + 32 * 8)
130+
/* The offset in sigcontext_t where the FP CSR register is saved. */
131+
#define SIGCONTEXT_FPCSR_OFF (SIGCONTEXT_FPREGS_OFF + 32 * 8 + 4)
132+
/* The offset in sigcontext_t where the multiplier hi register is saved. */
133+
#define SIGCONTEXT_HI_OFF (SIGCONTEXT_FPCSR_OFF + 2 * 4)
134+
/* The offset in sigcontext_t where the multiplier lo register is saved. */
135+
#define SIGCONTEXT_LO_OFF (SIGCONTEXT_HI_OFF + 4)
136+
137+
/* Implement the "init" routine in struct tramp_frame for the N32 ABI
138+
on mips-irix. */
139+
static void
140+
mips_irix_n32_tramp_frame_init (const struct tramp_frame *self,
141+
struct frame_info *this_frame,
142+
struct trad_frame_cache *this_cache,
143+
CORE_ADDR func)
144+
{
145+
struct gdbarch *gdbarch = get_frame_arch (this_frame);
146+
const int num_regs = gdbarch_num_regs (gdbarch);
147+
int sp_cooked_regno = num_regs + MIPS_SP_REGNUM;
148+
const CORE_ADDR sp = get_frame_register_signed (this_frame, sp_cooked_regno);
149+
const CORE_ADDR sigcontext_base = sp + 48;
150+
const struct mips_regnum *regs = mips_regnum (gdbarch);
151+
int ireg;
152+
153+
trad_frame_set_reg_addr (this_cache, regs->pc + gdbarch_num_regs (gdbarch),
154+
sigcontext_base + SIGCONTEXT_PC_OFF);
155+
156+
for (ireg = 1; ireg < 32; ireg++)
157+
trad_frame_set_reg_addr (this_cache, ireg + MIPS_ZERO_REGNUM + num_regs,
158+
sigcontext_base + SIGCONTEXT_REGS_OFF + ireg * 8);
159+
160+
for (ireg = 0; ireg < 32; ireg++)
161+
trad_frame_set_reg_addr (this_cache, ireg + regs->fp0 + num_regs,
162+
sigcontext_base + SIGCONTEXT_FPREGS_OFF
163+
+ ireg * 8);
164+
165+
trad_frame_set_reg_addr (this_cache, regs->fp_control_status + num_regs,
166+
sigcontext_base + SIGCONTEXT_FPCSR_OFF);
167+
168+
trad_frame_set_reg_addr (this_cache, regs->hi + num_regs,
169+
sigcontext_base + SIGCONTEXT_HI_OFF);
170+
171+
trad_frame_set_reg_addr (this_cache, regs->lo + num_regs,
172+
sigcontext_base + SIGCONTEXT_LO_OFF);
173+
174+
trad_frame_set_id (this_cache, frame_id_build (sigcontext_base, func));
175+
}
176+
177+
/* The tramp_frame structure describing sigtramp frames on mips-irix N32.
178+
179+
Note that the list of instructions below is pretty much a pure dump
180+
of function _sigtramp on mips-irix. A few instructions are actually
181+
not tested (mask set to 0), because a portion of these instructions
182+
contain an address which changes due to relocation. We could use
183+
a smarter mask that checks the instrutction code alone, but given
184+
the number of instructions already being checked, this seemed
185+
unnecessary. */
186+
187+
static const struct tramp_frame mips_irix_n32_tramp_frame =
188+
{
189+
SIGTRAMP_FRAME,
190+
4,
191+
{
192+
{ 0x3c0c8000, -1 }, /* lui t0,0x8000 */
193+
{ 0x27bdffd0, -1 }, /* addiu sp,sp,-48 */
194+
{ 0x008c6024, -1 }, /* and t0,a0,t0 */
195+
{ 0xffa40018, -1 }, /* sd a0,24(sp) */
196+
{ 0x00000000, 0 }, /* beqz t0,0xfaefcb8 <_sigtramp+40> */
197+
{ 0xffa60028, -1 }, /* sd a2,40(sp) */
198+
{ 0x01806027, -1 }, /* nor t0,t0,zero */
199+
{ 0xffa00020, -1 }, /* sd zero,32(sp) */
200+
{ 0x00000000, 0 }, /* b 0xfaefcbc <_sigtramp+44> */
201+
{ 0x008c2024, -1 }, /* and a0,a0,t0 */
202+
{ 0xffa60020, -1 }, /* sd a2,32(sp) */
203+
{ 0x03e0c025, -1 }, /* move t8,ra */
204+
{ 0x00000000, 0 }, /* bal 0xfaefcc8 <_sigtramp+56> */
205+
{ 0x00000000, -1 }, /* nop */
206+
{ 0x3c0c0007, -1 }, /* lui t0,0x7 */
207+
{ 0x00e0c825, -1 }, /* move t9,a3 */
208+
{ 0x658c80fc, -1 }, /* daddiu t0,t0,-32516 */
209+
{ 0x019f602d, -1 }, /* daddu t0,t0,ra */
210+
{ 0x0300f825, -1 }, /* move ra,t8 */
211+
{ 0x8d8c9880, -1 }, /* lw t0,-26496(t0) */
212+
{ 0x8d8c0000, -1 }, /* lw t0,0(t0) */
213+
{ 0x8d8d0000, -1 }, /* lw t1,0(t0) */
214+
{ 0xffac0008, -1 }, /* sd t0,8(sp) */
215+
{ 0x0320f809, -1 }, /* jalr t9 */
216+
{ 0xffad0010, -1 }, /* sd t1,16(sp) */
217+
{ 0xdfad0010, -1 }, /* ld t1,16(sp) */
218+
{ 0xdfac0008, -1 }, /* ld t0,8(sp) */
219+
{ 0xad8d0000, -1 }, /* sw t1,0(t0) */
220+
{ 0xdfa40020, -1 }, /* ld a0,32(sp) */
221+
{ 0xdfa50028, -1 }, /* ld a1,40(sp) */
222+
{ 0xdfa60018, -1 }, /* ld a2,24(sp) */
223+
{ 0x24020440, -1 }, /* li v0,1088 */
224+
{ 0x0000000c, -1 }, /* syscall */
225+
{ TRAMP_SENTINEL_INSN, -1 }
226+
},
227+
mips_irix_n32_tramp_frame_init
228+
};
229+
80230
static void
81231
mips_irix_init_abi (struct gdbarch_info info,
82232
struct gdbarch *gdbarch)
83233
{
84234
set_solib_ops (gdbarch, &irix_so_ops);
235+
tramp_frame_prepend_unwinder (gdbarch, &mips_irix_n32_tramp_frame);
85236
}
86237

87238
/* Provide a prototype to silence -Wmissing-prototypes. */

0 commit comments

Comments
 (0)