Skip to content

Commit 7f9edb4

Browse files
aarzillirandall77
authored andcommitted
runtime: add runtime.debugPinnerV1
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 74a4918 commit 7f9edb4

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/runtime/asm_amd64.s

+2-1
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,9 @@ bad_cpu: // show that the program requires a certain microarchitecture level.
371371
CALL runtime·abort(SB)
372372
RET
373373

374-
// Prevent dead-code elimination of debugCallV2, which is
374+
// Prevent dead-code elimination of debugCallV2 and debugPinnerV1, which are
375375
// intended to be called by debuggers.
376+
MOVQ $runtime·debugPinnerV1<ABIInternal>(SB), AX
376377
MOVQ $runtime·debugCallV2<ABIInternal>(SB), AX
377378
RET
378379

src/runtime/asm_arm64.s

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ nocgo:
9696
// start this M
9797
BL runtime·mstart(SB)
9898

99-
// Prevent dead-code elimination of debugCallV2, which is
99+
// Prevent dead-code elimination of debugCallV2 and debugPinnerV1, which are
100100
// intended to be called by debuggers.
101+
MOVD $runtime·debugPinnerV1<ABIInternal>(SB), R0
101102
MOVD $runtime·debugCallV2<ABIInternal>(SB), R0
102103

103104
MOVD $0, R0

src/runtime/asm_ppc64x.s

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ nocgo:
9898

9999
// start this M
100100
BL runtime·mstart(SB)
101-
// Prevent dead-code elimination of debugCallV2, which is
101+
// Prevent dead-code elimination of debugCallV2 and debugPinnerV1, which are
102102
// intended to be called by debuggers.
103103
#ifdef GOARCH_ppc64le
104+
MOVD $runtime·debugPinnerV1<ABIInternal>(SB), R31
104105
MOVD $runtime·debugCallV2<ABIInternal>(SB), R31
105106
#endif
106107
MOVD R0, 0(R0)

src/runtime/debug.go

+19
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,22 @@ func mayMoreStackMove() {
124124
gp.stackguard0 = stackForceMove
125125
}
126126
}
127+
128+
// debugPinnerKeepUnpin is used to make runtime.(*Pinner).Unpin reachable.
129+
var debugPinnerKeepUnpin bool = false
130+
131+
// debugPinnerV1 returns a new Pinner that pins itself. This function can be
132+
// used by debuggers to easily obtain a Pinner that will not be garbage
133+
// collected (or moved in memory) even if no references to it exist in the
134+
// target program. This pinner in turn can be used to extend this property
135+
// to other objects, which debuggers can use to simplify the evaluation of
136+
// expressions involving multiple call injections.
137+
func debugPinnerV1() *Pinner {
138+
p := new(Pinner)
139+
p.Pin(unsafe.Pointer(p))
140+
if debugPinnerKeepUnpin {
141+
// Make Unpin reachable.
142+
p.Unpin()
143+
}
144+
return p
145+
}

0 commit comments

Comments
 (0)