mirror of
https://github.com/golang/go
synced 2024-11-18 12:24:48 -07:00
runtime: factor out debug.invalidptr case in findObject
This helps keeping findObject's frame small. Updates #35068 Change-Id: I1b8c1fcc5831944c86f1a30ed2f2d867a5f2b242 Reviewed-on: https://go-review.googlesource.com/c/go/+/202797 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
80315322f3
commit
813d8e8862
@ -349,6 +349,32 @@ func heapBitsForAddr(addr uintptr) (h heapBits) {
|
||||
return
|
||||
}
|
||||
|
||||
// badPointer throws bad pointer in heap panic.
|
||||
func badPointer(s *mspan, p, refBase, refOff uintptr) {
|
||||
// Typically this indicates an incorrect use
|
||||
// of unsafe or cgo to store a bad pointer in
|
||||
// the Go heap. It may also indicate a runtime
|
||||
// bug.
|
||||
//
|
||||
// TODO(austin): We could be more aggressive
|
||||
// and detect pointers to unallocated objects
|
||||
// in allocated spans.
|
||||
printlock()
|
||||
print("runtime: pointer ", hex(p))
|
||||
if s.state != mSpanInUse {
|
||||
print(" to unallocated span")
|
||||
} else {
|
||||
print(" to unused region of span")
|
||||
}
|
||||
print(" span.base()=", hex(s.base()), " span.limit=", hex(s.limit), " span.state=", s.state, "\n")
|
||||
if refBase != 0 {
|
||||
print("runtime: found in object at *(", hex(refBase), "+", hex(refOff), ")\n")
|
||||
gcDumpObject("object", refBase, refOff)
|
||||
}
|
||||
getg().m.traceback = 2
|
||||
throw("found bad pointer in Go heap (incorrect use of unsafe or cgo?)")
|
||||
}
|
||||
|
||||
// findObject returns the base address for the heap object containing
|
||||
// the address p, the object's span, and the index of the object in s.
|
||||
// If p does not point into a heap object, it returns base == 0.
|
||||
@ -372,32 +398,10 @@ func findObject(p, refBase, refOff uintptr) (base uintptr, s *mspan, objIndex ui
|
||||
if s.state == mSpanManual {
|
||||
return
|
||||
}
|
||||
|
||||
// The following ensures that we are rigorous about what data
|
||||
// structures hold valid pointers.
|
||||
if debug.invalidptr != 0 {
|
||||
// Typically this indicates an incorrect use
|
||||
// of unsafe or cgo to store a bad pointer in
|
||||
// the Go heap. It may also indicate a runtime
|
||||
// bug.
|
||||
//
|
||||
// TODO(austin): We could be more aggressive
|
||||
// and detect pointers to unallocated objects
|
||||
// in allocated spans.
|
||||
printlock()
|
||||
print("runtime: pointer ", hex(p))
|
||||
if s.state != mSpanInUse {
|
||||
print(" to unallocated span")
|
||||
} else {
|
||||
print(" to unused region of span")
|
||||
}
|
||||
print(" span.base()=", hex(s.base()), " span.limit=", hex(s.limit), " span.state=", s.state, "\n")
|
||||
if refBase != 0 {
|
||||
print("runtime: found in object at *(", hex(refBase), "+", hex(refOff), ")\n")
|
||||
gcDumpObject("object", refBase, refOff)
|
||||
}
|
||||
getg().m.traceback = 2
|
||||
throw("found bad pointer in Go heap (incorrect use of unsafe or cgo?)")
|
||||
badPointer(s, p, refBase, refOff)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user