]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: do not stop traceback at onM
authorRuss Cox <rsc@golang.org>
Fri, 5 Sep 2014 02:48:08 +0000 (22:48 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 5 Sep 2014 02:48:08 +0000 (22:48 -0400)
Behavior before this CL:

1. If onM is called on a g0 stack, it just calls the given function.

2. If onM is called on a gsignal stack, it calls badonm.

3. If onM is called on a curg stack, it switches to the g0 stack
and then calls the function.

In cases 1 and 2, if the program then crashes (and badonm always does),
we want to see what called onM, but the traceback stops at onM.
In case 3, the traceback must stop at onM, because the g0
stack we are renting really does stop at onM.

The current code stops the traceback at onM to handle 3,
at the cost of making 1 and 2 crash with incomplete traces.

Change traceback to scan past onM but in case 3 make it look
like on the rented g0 stack, onM was called from mstart.
The traceback already knows that mstart is a top-of-stack function.

Alternate fix at CL 132610043 but I think this one is cleaner.
This CL makes 3 the exception, while that CL makes 1 and 2 the exception.

Submitting TBR to try to get better stack traces out of the
freebsd/amd64 builder, but happy to make changes in a
followup CL.

TBR=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/133620043

src/pkg/runtime/asm_386.s
src/pkg/runtime/asm_amd64.s
src/pkg/runtime/asm_arm.s
src/pkg/runtime/traceback.go

index 87dd1fa0f5cef51fc49c31981849e5ffd2ba4e69..40271567b0f127c9c5aa2acb3aceb9abfbe00feb 100644 (file)
@@ -233,7 +233,12 @@ oncurg:
 
        // switch to g0
        MOVL    DX, g(CX)
-       MOVL    (g_sched+gobuf_sp)(DX), SP
+       MOVL    (g_sched+gobuf_sp)(DX), BX
+       // make it look like mstart called onM on g0, to stop traceback
+       SUBL    $4, BX
+       MOVL    $runtime·mstart(SB), DX
+       MOVL    DX, 0(BX)
+       MOVL    BX, SP
 
        // call target function
        ARGSIZE(0)
index 80c2ab3c544ae77f2efdb1a7cf4a72caecbb782e..9103ef29e3c88338540ced5ca5d50c3edc620e94 100644 (file)
@@ -226,7 +226,12 @@ oncurg:
 
        // switch to g0
        MOVQ    DX, g(CX)
-       MOVQ    (g_sched+gobuf_sp)(DX), SP
+       MOVQ    (g_sched+gobuf_sp)(DX), BX
+       // make it look like mstart called onM on g0, to stop traceback
+       SUBQ    $8, BX
+       MOVQ    $runtime·mstart(SB), DX
+       MOVQ    DX, 0(BX)
+       MOVQ    BX, SP
 
        // call target function
        ARGSIZE(0)
index 54ef836211398a03eaf8a9b650987c743d211338..3869696f60b8d9842de61a362d2668caff75985b 100644 (file)
@@ -219,7 +219,12 @@ oncurg:
 
        // switch to g0
        MOVW    R2, g
-       MOVW    (g_sched+gobuf_sp)(R2), SP
+       MOVW    (g_sched+gobuf_sp)(R2), R3
+       // make it look like mstart called onM on g0, to stop traceback
+       SUB     $4, R3, R3
+       MOVW    $runtime·mstart(SB), R4
+       MOVW    R4, 0(R3)
+       MOVW    R3, SP
 
        // call target function
        ARGSIZE(0)
index adb03440b39627eef2c35176356202c47a46c9cf..ec7be28dc0e2466d59bc3194029e9443e8ccc7d1 100644 (file)
@@ -40,7 +40,6 @@ var (
        mstartPC    = funcPC(mstart)
        newprocPC   = funcPC(newproc)
        newstackPC  = funcPC(newstack)
-       onMPC       = funcPC(onM)
        rt0_goPC    = funcPC(rt0_go)
        sigpanicPC  = funcPC(sigpanic)
 
@@ -633,7 +632,6 @@ func topofstack(f *_func) bool {
        return pc == goexitPC ||
                pc == mstartPC ||
                pc == mcallPC ||
-               pc == onMPC ||
                pc == morestackPC ||
                pc == lessstackPC ||
                pc == rt0_goPC ||