mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: add GODEBUG wbshadow for finding missing write barriers
This is the detection code. It works well enough that I know of a handful of missing write barriers. However, those are subtle enough that I'll address them in separate followup CLs. GODEBUG=wbshadow=1 checks for a write that bypassed the write barrier at the next write barrier of the same word. If a bug can be detected in this mode it is typically easy to understand, since the crash says quite clearly what kind of word has missed a write barrier. GODEBUG=wbshadow=2 adds a check of the write barrier shadow copy during garbage collection. Bugs detected at garbage collection can be difficult to understand, because there is no context for what the found word means. Typically you have to reproduce the problem with allocfreetrace=1 in order to understand the type of the badly updated word. Change-Id: If863837308e7c50d96b5bdc7d65af4969bf53a6e Reviewed-on: https://go-review.googlesource.com/2061 Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
3191a23515
commit
dcec123a49
11 changed files with 276 additions and 39 deletions
|
|
@ -389,7 +389,7 @@ func adjustpointers(scanp unsafe.Pointer, cbv *bitvector, adjinfo *adjustinfo, f
|
|||
case _BitsPointer:
|
||||
p := *(*unsafe.Pointer)(add(scanp, i*ptrSize))
|
||||
up := uintptr(p)
|
||||
if f != nil && 0 < up && up < _PageSize && invalidptr != 0 || up == poisonGC || up == poisonStack {
|
||||
if f != nil && 0 < up && up < _PageSize && debug.invalidptr != 0 || up == poisonGC || up == poisonStack {
|
||||
// Looks like a junk value in a pointer slot.
|
||||
// Live analysis wrong?
|
||||
getg().m.traceback = 2
|
||||
|
|
@ -611,13 +611,13 @@ func round2(x int32) int32 {
|
|||
func newstack() {
|
||||
thisg := getg()
|
||||
// TODO: double check all gp. shouldn't be getg().
|
||||
if thisg.m.morebuf.g.stackguard0 == stackFork {
|
||||
if thisg.m.morebuf.g.ptr().stackguard0 == stackFork {
|
||||
throw("stack growth after fork")
|
||||
}
|
||||
if thisg.m.morebuf.g != thisg.m.curg {
|
||||
if thisg.m.morebuf.g.ptr() != thisg.m.curg {
|
||||
print("runtime: newstack called from g=", thisg.m.morebuf.g, "\n"+"\tm=", thisg.m, " m->curg=", thisg.m.curg, " m->g0=", thisg.m.g0, " m->gsignal=", thisg.m.gsignal, "\n")
|
||||
morebuf := thisg.m.morebuf
|
||||
traceback(morebuf.pc, morebuf.sp, morebuf.lr, morebuf.g)
|
||||
traceback(morebuf.pc, morebuf.sp, morebuf.lr, morebuf.g.ptr())
|
||||
throw("runtime: wrong goroutine in newstack")
|
||||
}
|
||||
if thisg.m.curg.throwsplit {
|
||||
|
|
@ -629,6 +629,8 @@ func newstack() {
|
|||
print("runtime: newstack sp=", hex(gp.sched.sp), " stack=[", hex(gp.stack.lo), ", ", hex(gp.stack.hi), "]\n",
|
||||
"\tmorebuf={pc:", hex(morebuf.pc), " sp:", hex(morebuf.sp), " lr:", hex(morebuf.lr), "}\n",
|
||||
"\tsched={pc:", hex(gp.sched.pc), " sp:", hex(gp.sched.sp), " lr:", hex(gp.sched.lr), " ctxt:", gp.sched.ctxt, "}\n")
|
||||
|
||||
traceback(morebuf.pc, morebuf.sp, morebuf.lr, gp)
|
||||
throw("runtime: stack split at bad time")
|
||||
}
|
||||
|
||||
|
|
@ -640,7 +642,7 @@ func newstack() {
|
|||
thisg.m.morebuf.pc = 0
|
||||
thisg.m.morebuf.lr = 0
|
||||
thisg.m.morebuf.sp = 0
|
||||
thisg.m.morebuf.g = nil
|
||||
thisg.m.morebuf.g = 0
|
||||
|
||||
casgstatus(gp, _Grunning, _Gwaiting)
|
||||
gp.waitreason = "stack growth"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue