runtime: print goid when throwing in gentraceback

This makes it easier to figure out where the crash is occurring.

Change-Id: Ie1f78a360367090dcd61c61b2a55c34f3e2ff2eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/390034
Trust: David Chase <drchase@google.com>
Reviewed-by: David Chase <drchase@google.com>
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Michael Pratt 2022-03-04 11:17:43 -05:00
parent 63bd6f68e6
commit cc9d3f548a
2 changed files with 3 additions and 3 deletions

View file

@ -665,7 +665,7 @@ retry:
func TestBadTraceback(t *testing.T) { func TestBadTraceback(t *testing.T) {
output := runTestProg(t, "testprog", "BadTraceback") output := runTestProg(t, "testprog", "BadTraceback")
for _, want := range []string{ for _, want := range []string{
"runtime: unexpected return pc", "unexpected return pc",
"called from 0xbad", "called from 0xbad",
"00000bad", // Smashed LR in hex dump "00000bad", // Smashed LR in hex dump
"<main.badLR", // Symbolization in hex dump (badLR1 or badLR2) "<main.badLR", // Symbolization in hex dump (badLR1 or badLR2)

View file

@ -113,7 +113,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
f := findfunc(frame.pc) f := findfunc(frame.pc)
if !f.valid() { if !f.valid() {
if callback != nil || printing { if callback != nil || printing {
print("runtime: unknown pc ", hex(frame.pc), "\n") print("runtime: g ", gp.goid, ": unknown pc ", hex(frame.pc), "\n")
tracebackHexdump(gp.stack, &frame, 0) tracebackHexdump(gp.stack, &frame, 0)
} }
if callback != nil { if callback != nil {
@ -247,7 +247,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
doPrint = false doPrint = false
} }
if callback != nil || doPrint { if callback != nil || doPrint {
print("runtime: unexpected return pc for ", funcname(f), " called from ", hex(frame.lr), "\n") print("runtime: g ", gp.goid, ": unexpected return pc for ", funcname(f), " called from ", hex(frame.lr), "\n")
tracebackHexdump(gp.stack, &frame, lrPtr) tracebackHexdump(gp.stack, &frame, lrPtr)
} }
if callback != nil { if callback != nil {