Skip to content

Commit d01accd

Browse files
committed
Clean up pause/restart logic
1 parent f5d2b99 commit d01accd

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

Common/src/main/kotlin/gay/object/hexdebug/adapter/DebugAdapter.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
134134
val result = debugger.startExecuting(env, iotas)
135135
?: throw IllegalDebugSessionException("Debug session is already executing something")
136136
lastDebugger = debugger
137-
handleDebuggerStep(debugger.threadId, result)
137+
handleDebuggerStep(debugger.threadId, result, wasPaused = false)
138138
}
139139

140140
fun disconnectClient() {
@@ -207,7 +207,11 @@ class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
207207
?: ResponseError(ResponseErrorCode.InternalError, e.toString(), e.stackTraceToString())
208208
}
209209

210-
private fun handleDebuggerStep(threadId: Int, result: DebugStepResult): ExecutionClientView? {
210+
private fun handleDebuggerStep(
211+
threadId: Int,
212+
result: DebugStepResult,
213+
wasPaused: Boolean = true,
214+
): ExecutionClientView? {
211215
val view = result.clientInfo?.also {
212216
MsgEvaluatorClientInfoS2C(threadId, it).sendToPlayer(player)
213217
}
@@ -234,7 +238,7 @@ class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
234238
debugger(threadId)?.getNextIotaToEvaluate()?.also { (iota, index) ->
235239
printDebuggerStatus(iota, index)
236240
}
237-
} else {
241+
} else if (wasPaused) {
238242
// running
239243
remoteProxy.continued(ContinuedEventArguments().also {
240244
it.threadId = threadId

Common/src/main/kotlin/gay/object/hexdebug/debugger/HexDebugger.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ class HexDebugger(
411411
return result
412412
}
413413

414+
fun pause() {
415+
lastStepType = RequestStepType.IN
416+
debugEnv.pause()
417+
}
418+
414419
fun executeUntilStopped(stepType: RequestStepType? = null): DebugStepResult {
415420
val vm = getVM() ?: return DebugStepResult(null)
416421

Core/src/main/java/gay/object/hexdebug/core/api/debugging/DebugEnvironment.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ protected DebugEnvironment(@NotNull ServerPlayer caster) {
3333

3434
/**
3535
* Attempts to pause the debuggee. This is called by the debugger when requested by the user.
36-
* @return whether the debuggee was successfully paused
3736
*/
38-
public abstract boolean pause();
37+
public abstract void pause();
3938

4039
/**
4140
* Attempts to resume execution of the debuggee. This is called by the debugger after the
@@ -54,9 +53,8 @@ public abstract boolean resume(
5453
* <br>
5554
* The previous debug thread is removed before this method is called, so the implementation may
5655
* use {@link HexDebugCoreAPI#createDebugThread} and {@link HexDebugCoreAPI#startExecuting}.
57-
* @return whether the debuggee was successfully restarted
5856
*/
59-
public abstract boolean restart(int threadId);
57+
public abstract void restart(int threadId);
6058

6159
/**
6260
* For in-world debugees, returns whether the caster is close enough to the debuggee to allow

Core/src/main/java/gay/object/hexdebug/core/api/debugging/SimplePlayerBasedDebugEnv.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public SimplePlayerBasedDebugEnv(
3131
}
3232

3333
@Override
34-
public boolean pause() {
35-
return false;
36-
}
34+
public void pause() {}
3735

3836
@Override
3937
public boolean resume(
@@ -45,13 +43,10 @@ public boolean resume(
4543
}
4644

4745
@Override
48-
public boolean restart(int threadId) {
46+
public void restart(int threadId) {
4947
try {
5048
start(threadId);
51-
return true;
52-
} catch (DebugException ignored) {
53-
return false;
54-
}
49+
} catch (DebugException ignored) {}
5550
}
5651

5752
@Override

0 commit comments

Comments
 (0)