[RFA] h8300-sim: detect exit

Michael Snyder msnyder@redhat.com
Mon Apr 14 15:17:00 GMT 2003


[re-sending]
Hi folks, 

This is a method that is used by some other targets to distinguish
a syscall trap from a breakpoint trap.  The change is already in place
in newlib/libc/sys/h8300hms/_exit.c -- exit will store a magic number
in r1/r2 which the simulator will recognize.  This allows us to return
an actual exit value to gdb, which in turn makes a lot of gdb's 
testsuites run a lot better.




2003-04-13  Michael Snyder  <msnyder@redhat.com>

        * compile.c (sim_resume): Use LIBC_MAGIC method to distinguish
        exit from trap.

Index: compile.c
===================================================================
RCS file: /cvs/src/src/sim/h8300/compile.c,v
retrieving revision 1.26
diff -p -r1.26 compile.c
*** compile.c   13 Apr 2003 17:06:29 -0000      1.26
--- compile.c   13 Apr 2003 17:36:18 -0000
*************** sim_resume (SIM_DESC sd, int step, int s
*** 1949,1965 ****
          cpu.exception = SIGILL;
          goto end;
        case O (O_SLEEP, SN):
!         /* FIXME: Doesn't this break for breakpoints when r0
!            contains just the right (er, wrong) value?  */
!         cpu.state = SIM_STATE_STOPPED;
!         /* The format of r0 is defined by target newlib.  Expand
!              the macros here instead of looking for .../sys/wait.h.  */
! #define SIM_WIFEXITED(v) (((v) & 0xff) == 0)
! #define SIM_WIFSIGNALED(v) (((v) & 0x7f) > 0 && (((v) & 0x7f) < 0x7f))
!         if (! SIM_WIFEXITED (cpu.regs[0]) && SIM_WIFSIGNALED (cpu.regs[0]))
!           cpu.exception = SIGILL;
          else
!           cpu.exception = SIGTRAP;
          goto end;
        case O (O_BPT, SN):
          cpu.state = SIM_STATE_STOPPED;
--- 1949,1981 ----
          cpu.exception = SIGILL;
          goto end;
        case O (O_SLEEP, SN):
!         /* The format of r0 is defined by target newlib.  Libc will
!            supply a magic number in r1 and r2 to distinguish exit
!            from trap.  
! 
!            Expand the macros here instead of looking for .../sys/wait.h.
!         */
! #define SIM_WIFEXITED(V)   (((V) & 0xff) == 0)
! #define SIM_WIFSIGNALED(V) (((V) & 0x7f) > 0 && (((V) & 0x7f) < 0x7f))
! #define SIM_WEXITSTATUS(V) (((V) >> 8))
!         if (SIM_WIFEXITED (cpu.regs[R0_REGNUM])
!             && cpu.regs[R1_REGNUM] == 0xDEAD
!             && cpu.regs[R2_REGNUM] == 0xBEEF)
!           {
!             cpu.state = SIM_STATE_EXITED;
!             cpu.exception = SIM_WEXITSTATUS (cpu.regs[R0_REGNUM]);
!           }
!         else if (SIM_WIFSIGNALED (cpu.regs[R0_REGNUM]))
!           {
!             cpu.state = SIM_STATE_STOPPED;
!             cpu.exception = SIGTRAP;
!           }
          else
!           {
!             cpu.state = SIM_STATE_STOPPED;
!             cpu.exception = SIGILL;
!           }
! 
          goto end;
        case O (O_BPT, SN):
          cpu.state = SIM_STATE_STOPPED;



More information about the Gdb-patches mailing list