aboutsummaryrefslogtreecommitdiff
path: root/src/internal/trace
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2025-06-27 00:59:49 +0000
committerMichael Knyszek <mknyszek@google.com>2025-06-27 10:59:23 -0700
commit742fda95246958076e439bbcf71fedda43a894bb (patch)
tree67370b38e66d647ea22f1959f231aaf15f328c82 /src/internal/trace
parentfdc076ce762326fc19ef1b6de01da6ce50f55926 (diff)
downloadgo-742fda95246958076e439bbcf71fedda43a894bb.tar.xz
runtime: account for missing frame pointer in preamble
If a goroutine is synchronously preempted, then taking a frame-pointer-based stack trace at that preemption will skip PC of the caller of the function which called into morestack. This happens because the frame pointer is pushed to the stack after the preamble, leaving the stack in an odd state for frame pointer unwinding. Deal with this by marking a goroutine as synchronously preempted and using that signal to load the missing PC from the stack. On LR platforms this is available in gp.sched.lr. On non-LR platforms like x86, it's at gp.sched.sp, because there are no args, no locals, and no frame pointer pushed to the SP yet. For #68090. Change-Id: I73a1206d8b84eecb8a96dbe727195da30088f288 Reviewed-on: https://go-review.googlesource.com/c/go/+/684435 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nick Ripley <nick.ripley@datadoghq.com>
Diffstat (limited to 'src/internal/trace')
-rw-r--r--src/internal/trace/testdata/testprog/stacks.go14
-rw-r--r--src/internal/trace/trace_test.go15
2 files changed, 24 insertions, 5 deletions
diff --git a/src/internal/trace/testdata/testprog/stacks.go b/src/internal/trace/testdata/testprog/stacks.go
index e64bc86844..478daa0d94 100644
--- a/src/internal/trace/testdata/testprog/stacks.go
+++ b/src/internal/trace/testdata/testprog/stacks.go
@@ -97,6 +97,11 @@ func main() {
rp.Read(data[:])
pipeReadDone <- true
}()
+ go func() { // func12
+ for {
+ syncPreemptPoint()
+ }
+ }()
time.Sleep(100 * time.Millisecond)
runtime.GC()
@@ -127,3 +132,12 @@ func main() {
runtime.GOMAXPROCS(oldGoMaxProcs)
}
+
+//go:noinline
+func syncPreemptPoint() {
+ if never {
+ syncPreemptPoint()
+ }
+}
+
+var never bool
diff --git a/src/internal/trace/trace_test.go b/src/internal/trace/trace_test.go
index eaf194cf07..44b7055344 100644
--- a/src/internal/trace/trace_test.go
+++ b/src/internal/trace/trace_test.go
@@ -326,7 +326,8 @@ func TestTraceStacks(t *testing.T) {
const mainLine = 21
want := []evDesc{
{trace.EventStateTransition, "Goroutine Running->Runnable", []frame{
- {"main.main", mainLine + 82},
+ {"runtime.Gosched", 0},
+ {"main.main", mainLine + 87},
}},
{trace.EventStateTransition, "Goroutine NotExist->Runnable", []frame{
{"main.main", mainLine + 11},
@@ -349,7 +350,7 @@ func TestTraceStacks(t *testing.T) {
}},
{trace.EventStateTransition, "Goroutine Waiting->Runnable", []frame{
{"runtime.chansend1", 0},
- {"main.main", mainLine + 84},
+ {"main.main", mainLine + 89},
}},
{trace.EventStateTransition, "Goroutine Running->Waiting", []frame{
{"runtime.chansend1", 0},
@@ -357,7 +358,7 @@ func TestTraceStacks(t *testing.T) {
}},
{trace.EventStateTransition, "Goroutine Waiting->Runnable", []frame{
{"runtime.chanrecv1", 0},
- {"main.main", mainLine + 85},
+ {"main.main", mainLine + 90},
}},
{trace.EventStateTransition, "Goroutine Running->Waiting", []frame{
{"runtime.selectgo", 0},
@@ -365,7 +366,7 @@ func TestTraceStacks(t *testing.T) {
}},
{trace.EventStateTransition, "Goroutine Waiting->Runnable", []frame{
{"runtime.selectgo", 0},
- {"main.main", mainLine + 86},
+ {"main.main", mainLine + 91},
}},
{trace.EventStateTransition, "Goroutine Running->Waiting", []frame{
{"sync.(*Mutex).Lock", 0},
@@ -382,7 +383,7 @@ func TestTraceStacks(t *testing.T) {
{trace.EventStateTransition, "Goroutine Waiting->Runnable", []frame{
{"sync.(*WaitGroup).Add", 0},
{"sync.(*WaitGroup).Done", 0},
- {"main.main", mainLine + 91},
+ {"main.main", mainLine + 96},
}},
{trace.EventStateTransition, "Goroutine Running->Waiting", []frame{
{"sync.(*Cond).Wait", 0},
@@ -402,6 +403,10 @@ func TestTraceStacks(t *testing.T) {
{"runtime.GOMAXPROCS", 0},
{"main.main", 0},
}},
+ {trace.EventStateTransition, "Goroutine Running->Runnable", []frame{
+ {"main.syncPreemptPoint", 0},
+ {"main.main.func12", 0},
+ }},
}
if !stress {
// Only check for this stack if !stress because traceAdvance alone could