Skip to content

Commit 86b69ef

Browse files
committed
runtime: replace cgoCtxt slice with index in traceback
Currently, gentraceback consumes the gp.cgoCtxt slice by copying the slice header and then sub-slicing it as it unwinds. The code for this is nice and clear, but we're about to lift this state into a structure and mutating it is going to introduce write barriers that are disallowed in gentraceback. This CL replaces the mutable slice header with an index into gp.cgoCtxt. For #54466. Change-Id: I6b701bb67d657290a784baaca34ed02d8247ede2 Reviewed-on: https://go-review.googlesource.com/c/go/+/466863 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent ec319d6 commit 86b69ef

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/runtime/traceback.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
7676
if usesLR {
7777
frame.lr = lr0
7878
}
79-
cgoCtxt := gp.cgoCtxt
79+
cgoCtxt := len(gp.cgoCtxt) - 1 // Index into gp.cgoCtxt
8080
printing := pcbuf == nil && callback == nil
8181

8282
// If the PC is zero, it's likely a nil function call.
@@ -175,7 +175,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
175175
flag = f.flag
176176
frame.lr = gp.sched.lr
177177
frame.sp = gp.sched.sp
178-
cgoCtxt = gp.cgoCtxt
178+
cgoCtxt = len(gp.cgoCtxt) - 1
179179
case funcID_systemstack:
180180
// systemstack returns normally, so just follow the
181181
// stack transition.
@@ -192,7 +192,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
192192
}
193193
gp = gp.m.curg
194194
frame.sp = gp.sched.sp
195-
cgoCtxt = gp.cgoCtxt
195+
cgoCtxt = len(gp.cgoCtxt) - 1
196196
flag &^= funcFlag_SPWRITE
197197
}
198198
}
@@ -390,9 +390,9 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
390390
}
391391
n++
392392

393-
if f.funcID == funcID_cgocallback && len(cgoCtxt) > 0 {
394-
ctxt := cgoCtxt[len(cgoCtxt)-1]
395-
cgoCtxt = cgoCtxt[:len(cgoCtxt)-1]
393+
if f.funcID == funcID_cgocallback && cgoCtxt >= 0 {
394+
ctxt := gp.cgoCtxt[cgoCtxt]
395+
cgoCtxt--
396396

397397
// skip only applies to Go frames.
398398
// callback != nil only used when we only care

0 commit comments

Comments
 (0)