Skip to content

Commit 1685fbd

Browse files
committed
[release-branch.go1.2] runtime: fix crash in runtime.GoroutineProfile
This CL is not exactly a copy of the original quoted below. This CL omits the changes made to mgc0.c in the original. Those changes do not apply cleanly to the Go 1.2 tree, and they were cosmetic, simplifying code that was already doing the right thing. To double-check that omitting the mgc0.c change has not invalidated the fix, I have verified by hand that the test program in issue 6946 fails without this CL and passes with this CL. ««« CL 41640043 / e4c381446b48 runtime: fix crash in runtime.GoroutineProfile This is a possible Go 1.2.1 candidate. Fixes #6946. R=iant, r CC=golang-dev https://golang.org/cl/41640043 »»» LGTM=adg R=adg CC=golang-codereviews, golang-dev, iant, r https://golang.org/cl/68820045
1 parent 0d2f5c0 commit 1685fbd

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/pkg/runtime/mprof.goc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ saveg(uintptr pc, uintptr sp, G *gp, TRecord *r)
477477
{
478478
int32 n;
479479

480-
n = runtime·gentraceback((uintptr)pc, (uintptr)sp, 0, gp, 0, r->stk, nelem(r->stk), nil, nil, false);
480+
n = runtime·gentraceback(pc, sp, 0, gp, 0, r->stk, nelem(r->stk), nil, nil, false);
481481
if(n < nelem(r->stk))
482482
r->stk[n] = 0;
483483
}
@@ -505,7 +505,7 @@ func GoroutineProfile(b Slice) (n int, ok bool) {
505505
for(gp = runtime·allg; gp != nil; gp = gp->alllink) {
506506
if(gp == g || gp->status == Gdead)
507507
continue;
508-
saveg(gp->sched.pc, gp->sched.sp, gp, r++);
508+
saveg(~(uintptr)0, ~(uintptr)0, gp, r++);
509509
}
510510
}
511511

src/pkg/runtime/proc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ runtime·tracebackothers(G *me)
276276
if((gp = m->curg) != nil && gp != me) {
277277
runtime·printf("\n");
278278
runtime·goroutineheader(gp);
279-
runtime·traceback(gp->sched.pc, gp->sched.sp, gp->sched.lr, gp);
279+
runtime·traceback(~(uintptr)0, ~(uintptr)0, 0, gp);
280280
}
281281

282282
for(gp = runtime·allg; gp != nil; gp = gp->alllink) {
@@ -290,7 +290,7 @@ runtime·tracebackothers(G *me)
290290
runtime·printf("\tgoroutine running on other thread; stack unavailable\n");
291291
runtime·printcreatedby(gp);
292292
} else
293-
runtime·traceback(gp->sched.pc, gp->sched.sp, gp->sched.lr, gp);
293+
runtime·traceback(~(uintptr)0, ~(uintptr)0, 0, gp);
294294
}
295295
}
296296

src/pkg/runtime/traceback_arm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip,
2020
Stktop *stk;
2121
String file;
2222

23+
if(pc0 == ~(uintptr)0 && sp0 == ~(uintptr)0) { // Signal to fetch saved values from gp.
24+
if(gp->syscallstack != (uintptr)nil) {
25+
pc0 = gp->syscallpc;
26+
sp0 = gp->syscallsp;
27+
lr0 = 0;
28+
} else {
29+
pc0 = gp->sched.pc;
30+
sp0 = gp->sched.sp;
31+
lr0 = gp->sched.lr;
32+
}
33+
}
34+
2335
nprint = 0;
2436
runtime·memclr((byte*)&frame, sizeof frame);
2537
frame.pc = pc0;

src/pkg/runtime/traceback_x86.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip,
3030
String file;
3131

3232
USED(lr0);
33+
34+
if(pc0 == ~(uintptr)0 && sp0 == ~(uintptr)0) { // Signal to fetch saved values from gp.
35+
if(gp->syscallstack != (uintptr)nil) {
36+
pc0 = gp->syscallpc;
37+
sp0 = gp->syscallsp;
38+
} else {
39+
pc0 = gp->sched.pc;
40+
sp0 = gp->sched.sp;
41+
}
42+
}
3343

3444
nprint = 0;
3545
runtime·memclr((byte*)&frame, sizeof frame);

0 commit comments

Comments
 (0)