[rfc] Fix broken i386 signal unwinding (Re: graceful unwind termination when we'd need unavailable/uncollect memory or registers to unwind further)

Ulrich Weigand
2011-03-31T13:58:15Z

Pedro Alves wrote:

> (i386_frame_prev_register): Handle unavailable SP.

> - if (regnum == I386_ESP_REGNUM && cache->saved_sp)
> - return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
> + if (regnum == I386_ESP_REGNUM)
> + {
> + /* If the SP has been saved, but we don't know where, then this
> + means that SAVED_SP_REG register was found unavailable back
> + when we built the cache. */
> + if (cache->saved_sp == 0 && cache->saved_sp_reg != -1)
> + return frame_unwind_got_register (this_frame, regnum,
> + cache->saved_sp_reg);
> + else
> + return frame_unwind_got_constant (this_frame, regnum,
> + cache->saved_sp);
> + }
>
> if (regnum < I386_NUM_SAVED_REGS && cache->saved_regs[regnum] != -1)
> return frame_unwind_got_memory (this_frame, regnum,

It seems this change broke unwinding out of signal trampoline
frames on i386 for me. In this case, neither SAVED_SP nor
SAVED_SP_REG is set; instead, SP is supposed to be unwound
from memory (the trampoline stack frame) via SAVED_REGS.

However, after your change, we now fall into the _got_constant
case and SP is always unwound as 0.

The following patch fixes this for me, and gets about 50 test
cases back to PASS.

Does this look right to you?

Tested on i386-linux (Ubuntu Lucid).

Bye,
Ulrich

ChangeLog:

* i386-tdep.c (i386_frame_prev_register): Unwind SP from memory
if neither saved value nor register available (e.g. signal frame).

Index: gdb/i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.330
diff -u -p -r1.330 i386-tdep.c
--- gdb/i386-tdep.c 18 Mar 2011 18:52:30 -0000 1.330
+++ gdb/i386-tdep.c 31 Mar 2011 13:50:07 -0000
@@ -1798,12 +1798,13 @@ i386_frame_prev_register (struct frame_i
if (regnum == I386_EIP_REGNUM && cache->pc_in_eax)
return frame_unwind_got_register (this_frame, regnum, I386_EAX_REGNUM);

- if (regnum == I386_ESP_REGNUM)
+ if (regnum == I386_ESP_REGNUM
+ && (cache->saved_sp != 0 || cache->saved_sp_reg != -1))
{
/* If the SP has been saved, but we don't know where, then this
means that SAVED_SP_REG register was found unavailable back
when we built the cache. */
- if (cache->saved_sp == 0 && cache->saved_sp_reg != -1)
+ if (cache->saved_sp == 0)
return frame_unwind_got_register (this_frame, regnum,
cache->saved_sp_reg);
else

--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com