Skip to content

Commit 5acd2d6

Browse files
committed
runtime: eliminate waspanic from gentraceback
gentraceback also tracks the funcID of the callee, which is more general. Fix this up to happen in all cases and eliminate waspanic in favor of checking the funcID of the caller. For #54466. Change-Id: Idc98365a6f05022db18ddcd5b3ed8684a6872a88 Reviewed-on: https://go-review.googlesource.com/c/go/+/458216 Run-TryBot: Austin Clements <[email protected]> Reviewed-by: Felix Geisendörfer <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 4f132b7 commit 5acd2d6

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/runtime/traceback.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
7676
if usesLR {
7777
frame.lr = lr0
7878
}
79-
waspanic := false
8079
cgoCtxt := gp.cgoCtxt
8180
printing := pcbuf == nil && callback == nil
8281

@@ -121,7 +120,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
121120

122121
var cache pcvalueCache
123122

124-
lastFuncID := funcID_normal
123+
calleeFuncID := funcID_normal
125124
n := 0
126125
for n < max {
127126
// Typically:
@@ -308,7 +307,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
308307
// deferproc a second time (if the corresponding deferred func recovers).
309308
// In the latter case, use a deferreturn call site as the continuation pc.
310309
frame.continpc = frame.pc
311-
if waspanic {
310+
if calleeFuncID == funcID_sigpanic {
312311
if frame.fn.deferreturn != 0 {
313312
frame.continpc = frame.fn.entry() + uintptr(frame.fn.deferreturn) + 1
314313
// Note: this may perhaps keep return variables alive longer than
@@ -346,7 +345,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
346345
// See issue 34123.
347346
// The pc can be at function entry when the frame is initialized without
348347
// actually running code, like runtime.mstart.
349-
if (n == 0 && flags&_TraceTrap != 0) || waspanic || pc == f.entry() {
348+
if (n == 0 && flags&_TraceTrap != 0) || calleeFuncID == funcID_sigpanic || pc == f.entry() {
350349
pc++
351350
} else {
352351
tracepc--
@@ -360,30 +359,29 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
360359
if ix < 0 {
361360
break
362361
}
363-
if inltree[ix].funcID == funcID_wrapper && elideWrapperCalling(lastFuncID) {
362+
if inltree[ix].funcID == funcID_wrapper && elideWrapperCalling(calleeFuncID) {
364363
// ignore wrappers
365364
} else if skip > 0 {
366365
skip--
367366
} else if n < max {
368367
(*[1 << 20]uintptr)(unsafe.Pointer(pcbuf))[n] = pc
369368
n++
370369
}
371-
lastFuncID = inltree[ix].funcID
370+
calleeFuncID = inltree[ix].funcID
372371
// Back up to an instruction in the "caller".
373372
tracepc = frame.fn.entry() + uintptr(inltree[ix].parentPc)
374373
pc = tracepc + 1
375374
}
376375
}
377376
// Record the main frame.
378-
if f.funcID == funcID_wrapper && elideWrapperCalling(lastFuncID) {
377+
if f.funcID == funcID_wrapper && elideWrapperCalling(calleeFuncID) {
379378
// Ignore wrapper functions (except when they trigger panics).
380379
} else if skip > 0 {
381380
skip--
382381
} else if n < max {
383382
(*[1 << 20]uintptr)(unsafe.Pointer(pcbuf))[n] = pc
384383
n++
385384
}
386-
lastFuncID = f.funcID
387385
n-- // offset n++ below
388386
}
389387

@@ -397,7 +395,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
397395

398396
// backup to CALL instruction to read inlining info (same logic as below)
399397
tracepc := frame.pc
400-
if (n > 0 || flags&_TraceTrap == 0) && frame.pc > f.entry() && !waspanic {
398+
if (n > 0 || flags&_TraceTrap == 0) && frame.pc > f.entry() && calleeFuncID != funcID_sigpanic {
401399
tracepc--
402400
}
403401
// If there is inlining info, print the inner frames.
@@ -417,19 +415,19 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
417415
inlFunc.funcID = inltree[ix].funcID
418416
inlFunc.startLine = inltree[ix].startLine
419417

420-
if (flags&_TraceRuntimeFrames) != 0 || showframe(inlFuncInfo, gp, nprint == 0, inlFuncInfo.funcID, lastFuncID) {
418+
if (flags&_TraceRuntimeFrames) != 0 || showframe(inlFuncInfo, gp, nprint == 0, inlFuncInfo.funcID, calleeFuncID) {
421419
name := funcname(inlFuncInfo)
422420
file, line := funcline(f, tracepc)
423421
print(name, "(...)\n")
424422
print("\t", file, ":", line, "\n")
425423
nprint++
426424
}
427-
lastFuncID = inltree[ix].funcID
425+
calleeFuncID = inltree[ix].funcID
428426
// Back up to an instruction in the "caller".
429427
tracepc = frame.fn.entry() + uintptr(inltree[ix].parentPc)
430428
}
431429
}
432-
if (flags&_TraceRuntimeFrames) != 0 || showframe(f, gp, nprint == 0, f.funcID, lastFuncID) {
430+
if (flags&_TraceRuntimeFrames) != 0 || showframe(f, gp, nprint == 0, f.funcID, calleeFuncID) {
433431
// Print during crash.
434432
// main(0x1, 0x2, 0x3)
435433
// /home/rsc/go/src/runtime/x.go:23 +0xf
@@ -453,7 +451,6 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
453451
print("\n")
454452
nprint++
455453
}
456-
lastFuncID = f.funcID
457454
}
458455
n++
459456

@@ -469,8 +466,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
469466
}
470467
}
471468

472-
waspanic = f.funcID == funcID_sigpanic
473-
injectedCall := waspanic || f.funcID == funcID_asyncPreempt || f.funcID == funcID_debugCallV2
469+
injectedCall := f.funcID == funcID_sigpanic || f.funcID == funcID_asyncPreempt || f.funcID == funcID_debugCallV2
474470

475471
// Do not unwind past the bottom of the stack.
476472
if !flr.valid() {
@@ -485,6 +481,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
485481
}
486482

487483
// Unwind to next frame.
484+
calleeFuncID = f.funcID
488485
frame.fn = flr
489486
frame.pc = frame.lr
490487
frame.lr = 0

0 commit comments

Comments
 (0)