public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Unwinding on Sparc/Solaris: MD_FALLBACK_FRAME_STATE_FOR
@ 2003-01-23 20:13 Geert Bosch
  2003-01-23 22:07 ` Daniel Jacobowitz
  2003-01-24  7:32 ` Jeff Sturm
  0 siblings, 2 replies; 3+ messages in thread
From: Geert Bosch @ 2003-01-23 20:13 UTC (permalink / raw)
  To: gcc

I am trying to get GCC to correctly unwind through
SPARC/Solaris signal frames. When the GCC unwinder encounters
a frame without unwind info, it will execute the code
given by the MD_FALLBACK_FRAME_STATE_FOR macro, which
is not defined yet.

The problem however is finding out what signal frames look like
and where the information to unwind through them can be found,
such as saved stack pointer, return address etc.
Since GDB can display a correct backtrace when breaking in
a signal handler, I have looked there for inspiration.
The GDB 5.1 code to handle this are in gdb/sparc-tdep.c,
function sparc_init_extra_frame_info and sparc_frame_saved_pc.
However, most of the 3212 lines in this file seem related to tracing
through these frames without DWARF info, and it's a bit of a mess
that I have not been able to untangle.

The Sparc/Linux signal frames are quite different (no surprise)
so the code for MD_FALLBACK_FRAME_STATE_FOR of that port does
not help much.

If anyone could point me to information on how to unwind
these signal frames that would be great.

   -Geert


PS. Below follows information I extracted from the Sparc/Linux kernel
     sources, but it appears outdated/incorrect as it doesn't match
     what I see on the actual stack.

  /* A SunOS signal frame basically looks as follows.
   *
   * ---------------------------------- <-- %sp at signal time
   * Struct sigcontext
   * Signal address
   * Ptr to sigcontext area above
   * Signal code
   * The signal number itself
   * One register window
   * ---------------------------------- <-- New %sp
   */

  #define SUNOS_MAXWIN   31
  #define _NSIG_WORDS    2  /* Just a guess, is right ??? */

  struct reg_window {
    unsigned long locals[8];
    unsigned long ins[8];
  };

  struct sigcontext {
    int sigc_onstack;      /* state to restore */
    int sigc_mask;         /* sigmask to restore */
    int sigc_sp;           /* stack pointer */
    int sigc_pc;           /* program counter */
    int sigc_npc;          /* next program counter */
    int sigc_psr;          /* for condition codes etc */
    int sigc_g1;           /* User uses these two registers */
    int sigc_o0;           /* within the trampoline code. */

    /* Now comes information regarding the users window set
       at the time of the signal. */
    int sigc_oswins;       /* outstanding windows */

    /* stack ptrs for each regwin buf */
    char *sigc_spbuf[SUNOS_MAXWIN];

    /* Windows to restore after signal */
    struct reg_window sigc_wbuf[SUNOS_MAXWIN];
  };

  struct signal_sframe {
    struct reg_window    sig_window;
    int                  sig_num;
    int                  sig_code;
    struct sigcontext    *sig_scptr;
    int                   sig_address;
    struct sigcontext     sig_context;
    unsigned int         extramask[_NSIG_WORDS - 1];
  }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unwinding on Sparc/Solaris: MD_FALLBACK_FRAME_STATE_FOR
  2003-01-23 20:13 Unwinding on Sparc/Solaris: MD_FALLBACK_FRAME_STATE_FOR Geert Bosch
@ 2003-01-23 22:07 ` Daniel Jacobowitz
  2003-01-24  7:32 ` Jeff Sturm
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Jacobowitz @ 2003-01-23 22:07 UTC (permalink / raw)
  To: gcc

On Thu, Jan 23, 2003 at 01:04:42PM -0500, Geert Bosch wrote:
> I am trying to get GCC to correctly unwind through
> SPARC/Solaris signal frames. When the GCC unwinder encounters
> a frame without unwind info, it will execute the code
> given by the MD_FALLBACK_FRAME_STATE_FOR macro, which
> is not defined yet.
> 
> The problem however is finding out what signal frames look like
> and where the information to unwind through them can be found,
> such as saved stack pointer, return address etc.
> Since GDB can display a correct backtrace when breaking in
> a signal handler, I have looked there for inspiration.
> The GDB 5.1 code to handle this are in gdb/sparc-tdep.c,
> function sparc_init_extra_frame_info and sparc_frame_saved_pc.
> However, most of the 3212 lines in this file seem related to tracing
> through these frames without DWARF info, and it's a bit of a mess
> that I have not been able to untangle.

sparc_frame_saved_pc is a good place to start; what it tells me is
that generally there is a pointer in %o2 to the sigcontext structure. 
You can then look in Solaris headers to find the struct sigcontext.
The PC should be the fourth word, in 32-bit mode at least, to guess
from the comments in GDB.  I don't know what else you need to unwind in
MD_FALLBACK_FRAME_STATE_FOR but it should all be in the struct
sigcontext.


-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unwinding on Sparc/Solaris: MD_FALLBACK_FRAME_STATE_FOR
  2003-01-23 20:13 Unwinding on Sparc/Solaris: MD_FALLBACK_FRAME_STATE_FOR Geert Bosch
  2003-01-23 22:07 ` Daniel Jacobowitz
@ 2003-01-24  7:32 ` Jeff Sturm
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Sturm @ 2003-01-24  7:32 UTC (permalink / raw)
  To: Geert Bosch; +Cc: gcc

On Thu, 23 Jan 2003, Geert Bosch wrote:
> I am trying to get GCC to correctly unwind through
> SPARC/Solaris signal frames. When the GCC unwinder encounters
> a frame without unwind info, it will execute the code
> given by the MD_FALLBACK_FRAME_STATE_FOR macro, which
> is not defined yet.

Aside from signal frames, I wonder if there's not enough information
in SPARC register windows to unwind anyway.  The unwinder will always see
a DW_CFA_GNU_window_save instruction if the FDE is found.  Maybe
MD_FALLBACK_FRAME_STATE_FOR could proceed assuming the window_save area is
present, and not worry about decoding signal frames.

Also look at what's done in libjava/include/sparc-signal.h.

Jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-01-24  4:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-23 20:13 Unwinding on Sparc/Solaris: MD_FALLBACK_FRAME_STATE_FOR Geert Bosch
2003-01-23 22:07 ` Daniel Jacobowitz
2003-01-24  7:32 ` Jeff Sturm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).