[commit: ghc] master: StgStartup: Setup unwinding for stg_stop_thread (d9f8862)

git at git.haskell.org git at git.haskell.org
Sun Nov 1 14:20:47 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/d9f886282c605e5f4b74126b3af8f23771ef03f1/ghc

>---------------------------------------------------------------

commit d9f886282c605e5f4b74126b3af8f23771ef03f1
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Sun Aug 30 14:11:56 2015 +0200

    StgStartup: Setup unwinding for stg_stop_thread
    
    This is a bit ugly as we need to assume the structure of the C stack as
    left by StgRun. Nevertheless, it allows us to unwind all the way back to
    `_start` on my machine.
    
    ```
    Stack trace:
        set_initial_registers (rts/Libdw.c:272.0)
        dwfl_thread_getframes
    
        dwfl_getthreads
        dwfl_getthread_frames
        libdw_get_backtrace (rts/Libdw.c:243.0)
        base_GHCziExecutionStack_getStackTrace1_info
    (libraries/base/GHC/ExecutionStack.hs:43.1)
        base_GHCziExecutionStack_showStackTrace1_info
    (libraries/base/GHC/ExecutionStack.hs:47.1)
        base_GHCziBase_bindIO1_info (libraries/base/GHC/Base.hs:1085.1)
        base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1)
        base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1)
        base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1)
        base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1)
        base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1)
        stg_catch_frame_info (rts/Exception.cmm:370.1)
        stg_stop_thread_info (rts/StgStartup.cmm:42.1)
        scheduleWaitThread (rts/Schedule.c:465.0)
        hs_main (rts/RtsMain.c:65.0)
    
        __libc_start_main (/tmp/buildd/glibc-2.19/csu/libc-start.c:321.0)
        _start
    ```


>---------------------------------------------------------------

d9f886282c605e5f4b74126b3af8f23771ef03f1
 rts/StgCRun.c      |  2 ++
 rts/StgStartup.cmm | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/rts/StgCRun.c b/rts/StgCRun.c
index 6448509..0a010d4 100644
--- a/rts/StgCRun.c
+++ b/rts/StgCRun.c
@@ -159,6 +159,8 @@ StgWord8 *win32AllocStack(void)
  * stack isn't aligned, and calling exitWith from Haskell invokes
  * shutdownHaskellAndExit using a C call.
  *
+ * If you edit the sequence below be sure to update the unwinding information
+ * for stg_stop_thread in StgStartup.cmm.
  */
 
 static void GNUC3_ATTRIBUTE(used)
diff --git a/rts/StgStartup.cmm b/rts/StgStartup.cmm
index 2a245b0..aad4fab 100644
--- a/rts/StgStartup.cmm
+++ b/rts/StgStartup.cmm
@@ -62,6 +62,18 @@ INFO_TABLE_RET(stg_stop_thread, STOP_FRAME,
        be an info table on top of the stack).
     */
 
+    /*
+       Here we setup the stack unwinding annotation necessary to allow
+       debuggers to find their way back to the C stack.
+
+       This is a bit fiddly as we assume the layout of the stack prepared
+       for us by StgRun.
+     */
+#ifdef x86_64_HOST_ARCH
+    unwind MachSp = MachSp + RESERVED_C_STACK_BYTES + 0x38 + 8
+    unwind UnwindReturnReg = W_[MachSp + RESERVED_C_STACK_BYTES + 0x38]
+#endif
+
     Sp = Sp + SIZEOF_StgStopFrame - WDS(2);
     Sp(1) = R1;
     Sp(0) = stg_enter_info;



More information about the ghc-commits mailing list