Skip to content

Commit d829b62

Browse files
committed
runtime: use srcFunc for showframe
Since srcFunc can represent information for either an real text function or an inlined function, this means we no longer have to synthesize a fake _func just to call showframe on an inlined frame. This is cleaner and also eliminates the one case where _func values live in the heap. This will let us mark them NotInHeap, which will in turn eliminate pesky write barriers in the traceback rewrite. For #54466. Change-Id: Ibf5e24d01ee4bf384c825e1a4e2922ef444a438e Reviewed-on: https://go-review.googlesource.com/c/go/+/466097 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent f52bede commit d829b62

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

src/runtime/traceback.go

+12-25
Original file line numberDiff line numberDiff line change
@@ -376,22 +376,16 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
376376
// If there is inlining info, print the inner frames.
377377
if inldata := funcdata(f, _FUNCDATA_InlTree); inldata != nil {
378378
inltree := (*[1 << 20]inlinedCall)(inldata)
379-
var inlFunc _func
380-
inlFuncInfo := funcInfo{&inlFunc, f.datap}
381379
for {
382380
ix := pcdatavalue(f, _PCDATA_InlTreeIndex, tracepc, nil)
383381
if ix < 0 {
384382
break
385383
}
386384

387-
// Create a fake _func for the
388-
// inlined function.
389-
inlFunc.nameOff = inltree[ix].nameOff
390-
inlFunc.funcID = inltree[ix].funcID
391-
inlFunc.startLine = inltree[ix].startLine
385+
sf := srcFunc{f.datap, inltree[ix].nameOff, inltree[ix].startLine, inltree[ix].funcID}
392386

393-
if (flags&_TraceRuntimeFrames) != 0 || showframe(inlFuncInfo, gp, nprint == 0, inlFuncInfo.funcID, calleeFuncID) {
394-
name := funcname(inlFuncInfo)
387+
if (flags&_TraceRuntimeFrames) != 0 || showframe(sf, gp, nprint == 0, calleeFuncID) {
388+
name := sf.name()
395389
file, line := funcline(f, tracepc)
396390
print(name, "(...)\n")
397391
print("\t", file, ":", line, "\n")
@@ -402,7 +396,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
402396
tracepc = frame.fn.entry() + uintptr(inltree[ix].parentPc)
403397
}
404398
}
405-
if (flags&_TraceRuntimeFrames) != 0 || showframe(f, gp, nprint == 0, f.funcID, calleeFuncID) {
399+
if (flags&_TraceRuntimeFrames) != 0 || showframe(f.srcFunc(), gp, nprint == 0, calleeFuncID) {
406400
// Print during crash.
407401
// main(0x1, 0x2, 0x3)
408402
// /home/rsc/go/src/runtime/x.go:23 +0xf
@@ -692,7 +686,7 @@ func printcreatedby(gp *g) {
692686
// Show what created goroutine, except main goroutine (goid 1).
693687
pc := gp.gopc
694688
f := findfunc(pc)
695-
if f.valid() && showframe(f, gp, false, funcID_normal, funcID_normal) && gp.goid != 1 {
689+
if f.valid() && showframe(f.srcFunc(), gp, false, funcID_normal) && gp.goid != 1 {
696690
printcreatedby1(f, pc, gp.parentGoid)
697691
}
698692
}
@@ -792,7 +786,7 @@ func printAncestorTraceback(ancestor ancestorInfo) {
792786
print("[originating from goroutine ", ancestor.goid, "]:\n")
793787
for fidx, pc := range ancestor.pcs {
794788
f := findfunc(pc) // f previously validated
795-
if showfuncinfo(f, fidx == 0, funcID_normal, funcID_normal) {
789+
if showfuncinfo(f.srcFunc(), fidx == 0, funcID_normal) {
796790
printAncestorTracebackFuncInfo(f, pc)
797791
}
798792
}
@@ -801,7 +795,7 @@ func printAncestorTraceback(ancestor ancestorInfo) {
801795
}
802796
// Show what created goroutine, except main goroutine (goid 1).
803797
f := findfunc(ancestor.gopc)
804-
if f.valid() && showfuncinfo(f, false, funcID_normal, funcID_normal) && ancestor.goid != 1 {
798+
if f.valid() && showfuncinfo(f.srcFunc(), false, funcID_normal) && ancestor.goid != 1 {
805799
// In ancestor mode, we'll already print the goroutine ancestor.
806800
// Pass 0 for the goid parameter so we don't print it again.
807801
printcreatedby1(f, ancestor.gopc, 0)
@@ -850,35 +844,28 @@ func gcallers(gp *g, skip int, pcbuf []uintptr) int {
850844

851845
// showframe reports whether the frame with the given characteristics should
852846
// be printed during a traceback.
853-
func showframe(f funcInfo, gp *g, firstFrame bool, funcID, childID funcID) bool {
847+
func showframe(sf srcFunc, gp *g, firstFrame bool, calleeID funcID) bool {
854848
mp := getg().m
855849
if mp.throwing >= throwTypeRuntime && gp != nil && (gp == mp.curg || gp == mp.caughtsig.ptr()) {
856850
return true
857851
}
858-
return showfuncinfo(f, firstFrame, funcID, childID)
852+
return showfuncinfo(sf, firstFrame, calleeID)
859853
}
860854

861855
// showfuncinfo reports whether a function with the given characteristics should
862856
// be printed during a traceback.
863-
func showfuncinfo(f funcInfo, firstFrame bool, funcID, childID funcID) bool {
864-
// Note that f may be a synthesized funcInfo for an inlined
865-
// function, in which case only nameOff and funcID are set.
866-
857+
func showfuncinfo(sf srcFunc, firstFrame bool, calleeID funcID) bool {
867858
level, _, _ := gotraceback()
868859
if level > 1 {
869860
// Show all frames.
870861
return true
871862
}
872863

873-
if !f.valid() {
874-
return false
875-
}
876-
877-
if funcID == funcID_wrapper && elideWrapperCalling(childID) {
864+
if sf.funcID == funcID_wrapper && elideWrapperCalling(calleeID) {
878865
return false
879866
}
880867

881-
name := funcname(f)
868+
name := sf.name()
882869

883870
// Special case: always show runtime.gopanic frame
884871
// in the middle of a stack trace, so that we can

0 commit comments

Comments
 (0)