]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: factor out debug.invalidptr case in findObject
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 23 Oct 2019 07:28:55 +0000 (14:28 +0700)
committerAustin Clements <austin@google.com>
Sat, 26 Oct 2019 00:05:43 +0000 (00:05 +0000)
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>
src/runtime/mbitmap.go

index 7f9f71842d7bcd1475b2edb48479d935ea06b116..68a22690d25f83d401e52f9e8f53684d80f0183a 100644 (file)
@@ -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
        }