}
}
+func TestMainGoroutineId(t *testing.T) {
+ output := executeTest(t, mainGoroutineIdSource, nil)
+ want := "panic: test\n\ngoroutine 1 [running]:\n"
+ if !strings.HasPrefix(output, want) {
+ t.Fatalf("output does not start with %q:\n%s", want, output)
+ }
+}
+
const crashSource = `
package main
select{}
}
`
+
+const mainGoroutineIdSource = `
+package main
+func main() {
+ panic("test")
+}
+`
newg->gopc = (uintptr)callerpc;
newg->status = Grunnable;
if(p->goidcache == p->goidcacheend) {
+ // Sched.goidgen is the last allocated id,
+ // this batch must be [sched.goidgen+1, sched.goidgen+GoidCacheBatch].
+ // At startup sched.goidgen=0, so main goroutine receives goid=1.
p->goidcache = runtime·xadd64(&runtime·sched.goidgen, GoidCacheBatch);
+ p->goidcache -= GoidCacheBatch - 1;
p->goidcacheend = p->goidcache + GoidCacheBatch;
}
newg->goid = p->goidcache++;