aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/traceback.go
diff options
context:
space:
mode:
authorHeschi Kreinick <heschi@google.com>2018-08-17 16:32:02 -0400
committerHeschi Kreinick <heschi@google.com>2018-08-23 19:48:12 +0000
commitc9986d1452f3ef226bfd044fb0f128175a7dff03 (patch)
treeb8f78037be8e0d16aec2700255bfdd52a5e3c0b6 /src/runtime/traceback.go
parentb15a1e3cfb64aeeb90f74e0748524b38fde5ebf9 (diff)
downloadgo-c9986d1452f3ef226bfd044fb0f128175a7dff03.tar.gz
go-c9986d1452f3ef226bfd044fb0f128175a7dff03.zip
runtime: fix use of wrong g in gentraceback
gentraceback gets the currently running g to do some sanity checks, but should use gp everywhere to do its actual work. Some noncritical checks later accidentally used g instead of gp. This seems like it could be a problem in many different contexts, but I noticed in Windows profiling, where profilem calls gentraceback on a goroutine from a different thread. Change-Id: I3da27a43e833b257f6411ee6893bdece45a9323f Reviewed-on: https://go-review.googlesource.com/128895 Run-TryBot: Heschi Kreinick <heschi@google.com> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/traceback.go')
-rw-r--r--src/runtime/traceback.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go
index a1f32016b9e..78589f5ea38 100644
--- a/src/runtime/traceback.go
+++ b/src/runtime/traceback.go
@@ -99,8 +99,9 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
if skip > 0 && callback != nil {
throw("gentraceback callback cannot be used with non-zero skip")
}
- g := getg()
- if g == gp && g == g.m.curg {
+
+ // Don't call this "g"; it's too easy get "g" and "gp" confused.
+ if ourg := getg(); ourg == gp && ourg == ourg.m.curg {
// The starting sp has been passed in as a uintptr, and the caller may
// have other uintptr-typed stack references as well.
// If during one of the calls that got us here or during one of the
@@ -200,7 +201,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
// g0, this systemstack is at the top of the stack.
// if we're not on g0 or there's a no curg, then this is a regular call.
sp := frame.sp
- if flags&_TraceJumpStack != 0 && f.funcID == funcID_systemstack && gp == g.m.g0 && gp.m.curg != nil {
+ if flags&_TraceJumpStack != 0 && f.funcID == funcID_systemstack && gp == gp.m.g0 && gp.m.curg != nil {
sp = gp.m.curg.sched.sp
frame.sp = sp
cgoCtxt = gp.m.curg.cgoCtxt
@@ -425,7 +426,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
if frame.pc > f.entry {
print(" +", hex(frame.pc-f.entry))
}
- if g.m.throwing > 0 && gp == g.m.curg || level >= 2 {
+ if gp.m != nil && gp.m.throwing > 0 && gp == gp.m.curg || level >= 2 {
print(" fp=", hex(frame.fp), " sp=", hex(frame.sp), " pc=", hex(frame.pc))
}
print("\n")