Commit d9f88628 authored by Ben Gamari's avatar Ben Gamari 🐢

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
```
parent 159a1a2b
......@@ -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)
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment