]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add runtime.debugPinnerV1
authorAlessandro Arzilli <alessandro.arzilli@gmail.com>
Wed, 24 Jan 2024 18:02:32 +0000 (19:02 +0100)
committerKeith Randall <khr@golang.org>
Sat, 11 May 2024 20:38:24 +0000 (20:38 +0000)
Adds runtime.debugPinnerV1 which returns a runtime.Pinner object that
pins itself. This is intended to be used by debuggers in conjunction
with runtime.debugCall to keep heap memory reachable even if it isn't
referenced from anywhere else.

Change-Id: I508ee6a7b103e68df83c96f2e04a0599200300dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/558276
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/asm_amd64.s
src/runtime/asm_arm64.s
src/runtime/asm_ppc64x.s
src/runtime/debug.go

index cb21629a84b628ebe4c7684a7a06e3f386263ad5..cdf9874a7f930e00f2b1592a2feb51b5a7ea2028 100644 (file)
@@ -371,8 +371,9 @@ bad_cpu: // show that the program requires a certain microarchitecture level.
        CALL    runtime·abort(SB)
        RET
 
-       // Prevent dead-code elimination of debugCallV2, which is
+       // Prevent dead-code elimination of debugCallV2 and debugPinnerV1, which are
        // intended to be called by debuggers.
+       MOVQ    $runtime·debugPinnerV1<ABIInternal>(SB), AX
        MOVQ    $runtime·debugCallV2<ABIInternal>(SB), AX
        RET
 
index 6d77b08a1b90d6db55b6876ff29862c67514c662..64a1880589390d20b9c0fb77ec9b0628fb68f4cd 100644 (file)
@@ -96,8 +96,9 @@ nocgo:
        // start this M
        BL      runtime·mstart(SB)
 
-       // Prevent dead-code elimination of debugCallV2, which is
+       // Prevent dead-code elimination of debugCallV2 and debugPinnerV1, which are
        // intended to be called by debuggers.
+       MOVD    $runtime·debugPinnerV1<ABIInternal>(SB), R0
        MOVD    $runtime·debugCallV2<ABIInternal>(SB), R0
 
        MOVD    $0, R0
index 97c2a370bdd8c19d511d0b0a12cb4466fb4e0537..98002bccf636baab7f288ab5fba8f21fb1688427 100644 (file)
@@ -98,9 +98,10 @@ nocgo:
 
        // start this M
        BL      runtime·mstart(SB)
-       // Prevent dead-code elimination of debugCallV2, which is
+       // Prevent dead-code elimination of debugCallV2 and debugPinnerV1, which are
        // intended to be called by debuggers.
 #ifdef GOARCH_ppc64le
+       MOVD    $runtime·debugPinnerV1<ABIInternal>(SB), R31
        MOVD    $runtime·debugCallV2<ABIInternal>(SB), R31
 #endif
        MOVD    R0, 0(R0)
index 184e4127c3b89b28a814530f967e54bd084bab3c..c477e2b9f6e4a02289b099252b818393e338dec9 100644 (file)
@@ -124,3 +124,22 @@ func mayMoreStackMove() {
                gp.stackguard0 = stackForceMove
        }
 }
+
+// debugPinnerKeepUnpin is used to make runtime.(*Pinner).Unpin reachable.
+var debugPinnerKeepUnpin bool = false
+
+// debugPinnerV1 returns a new Pinner that pins itself. This function can be
+// used by debuggers to easily obtain a Pinner that will not be garbage
+// collected (or moved in memory) even if no references to it exist in the
+// target program. This pinner in turn can be used to extend this property
+// to other objects, which debuggers can use to simplify the evaluation of
+// expressions involving multiple call injections.
+func debugPinnerV1() *Pinner {
+       p := new(Pinner)
+       p.Pin(unsafe.Pointer(p))
+       if debugPinnerKeepUnpin {
+               // Make Unpin reachable.
+               p.Unpin()
+       }
+       return p
+}