runtime: restore correct m in gtraceback

If gtraceback is used to get a stack trace of a g running in the same m,
as can happen if we collect a stack trace from a g0, then restore the
old m value, don't clear it.

Change-Id: I950a3c182d0b79dd84204c59530c57edb1e100e1
Reviewed-on: https://go-review.googlesource.com/41138
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c
index 23cfb73..5febe0c 100644
--- a/libgo/runtime/proc.c
+++ b/libgo/runtime/proc.c
@@ -441,21 +441,23 @@
 }
 
 // Do a stack trace of gp, and then restore the context to
-// gp->dotraceback.
+// gp->traceback->gp.
 
 void
 gtraceback(G* gp)
 {
 	Traceback* traceback;
+	M* holdm;
 
 	traceback = gp->traceback;
 	gp->traceback = nil;
-	if(gp->m != nil && gp->m != g->m)
+	holdm = gp->m;
+	if(holdm != nil && holdm != g->m)
 		runtime_throw("gtraceback: m is not nil");
 	gp->m = traceback->gp->m;
 	traceback->c = runtime_callers(1, traceback->locbuf,
 		sizeof traceback->locbuf / sizeof traceback->locbuf[0], false);
-	gp->m = nil;
+	gp->m = holdm;
 	runtime_gogo(traceback->gp);
 }