Skip to content

Commit 8efd92b

Browse files
committed
Add DebugEnvironment.postStep
1 parent 4afd406 commit 8efd92b

File tree

9 files changed

+69
-16
lines changed

9 files changed

+69
-16
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import at.petrak.hexcasting.api.casting.math.HexPattern
1111
import gay.`object`.hexdebug.HexDebug
1212
import gay.`object`.hexdebug.adapter.proxy.DebugProxyServerLauncher
1313
import gay.`object`.hexdebug.config.HexDebugServerConfig
14+
import gay.`object`.hexdebug.core.api.debugging.StopReason
1415
import gay.`object`.hexdebug.core.api.debugging.env.DebugEnvironment
1516
import gay.`object`.hexdebug.core.api.exceptions.IllegalDebugSessionException
1617
import gay.`object`.hexdebug.core.api.exceptions.IllegalDebugThreadException
@@ -244,8 +245,12 @@ class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
244245
// stopped
245246
sendStoppedEvent(threadId, result.reason)
246247

247-
debugger(threadId)?.getNextIotaToEvaluate()?.also { (iota, index) ->
248-
printDebuggerStatus(iota, index)
248+
debugger(threadId)?.let { debugger ->
249+
debugger.getNextIotaToEvaluate()?.also { (iota, index) ->
250+
printDebuggerStatus(iota, index)
251+
}
252+
253+
debugger.postStep(result.reason)
249254
}
250255
} else if (wasPaused) {
251256
// running
@@ -260,10 +265,18 @@ class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
260265
private fun sendStoppedEvent(threadId: Int?, reason: StopReason) {
261266
if (threadId == null) {
262267
debuggers.keys.forEach { sendStoppedEvent(it, reason) }
263-
} else if (reason.value != null) {
268+
} else {
269+
val reasonStr = when (reason) {
270+
StopReason.STEP -> StoppedEventArgumentsReason.STEP
271+
StopReason.PAUSE -> StoppedEventArgumentsReason.PAUSE
272+
StopReason.BREAKPOINT -> StoppedEventArgumentsReason.BREAKPOINT
273+
StopReason.EXCEPTION -> StoppedEventArgumentsReason.EXCEPTION
274+
StopReason.STARTED -> StoppedEventArgumentsReason.ENTRY
275+
StopReason.TERMINATED -> return
276+
}
264277
remoteProxy.stopped(StoppedEventArguments().also {
265278
it.threadId = threadId
266-
it.reason = reason.value
279+
it.reason = reasonStr
267280
})
268281
}
269282
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gay.`object`.hexdebug.debugger
22

33
import at.petrak.hexcasting.api.casting.eval.ExecutionClientView
44
import gay.`object`.hexdebug.core.api.debugging.DebugStepType
5+
import gay.`object`.hexdebug.core.api.debugging.StopReason
56
import org.eclipse.lsp4j.debug.Source
67
import org.eclipse.lsp4j.debug.LoadedSourceEventArgumentsReason as LoadedSourceReason
78

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package gay.`object`.hexdebug.debugger
22

3-
import org.eclipse.lsp4j.debug.StoppedEventArgumentsReason
4-
53
enum class DebuggerState(val canPause: Boolean = false, val canResume: Boolean = false) {
64
RUNNING(canPause = true),
75
PAUSING(canPause = true),
@@ -10,15 +8,6 @@ enum class DebuggerState(val canPause: Boolean = false, val canResume: Boolean =
108
TERMINATED,
119
}
1210

13-
enum class StopReason(val value: String?, val stopImmediately: Boolean) {
14-
STEP(StoppedEventArgumentsReason.STEP, false),
15-
PAUSE(StoppedEventArgumentsReason.PAUSE, true),
16-
BREAKPOINT(StoppedEventArgumentsReason.BREAKPOINT, true),
17-
EXCEPTION(StoppedEventArgumentsReason.EXCEPTION, true),
18-
STARTED(StoppedEventArgumentsReason.ENTRY, true),
19-
TERMINATED(null, true),
20-
}
21-
2211
enum class SourceBreakpointMode(val label: String, val description: String) {
2312
EVALUATED("Evaluated", "Stop if this iota would be evaluated. (default)"),
2413
ESCAPED("Escaped", "Stop if this iota would be escaped."),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import at.petrak.hexcasting.common.casting.actions.eval.OpEval
1515
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
1616
import gay.`object`.hexdebug.casting.eval.FrameBreakpoint
1717
import gay.`object`.hexdebug.casting.iotas.CognitohazardIota
18-
import gay.`object`.hexdebug.core.api.debugging.env.DebugEnvironment
1918
import gay.`object`.hexdebug.core.api.debugging.DebugStepType
19+
import gay.`object`.hexdebug.core.api.debugging.StopReason
20+
import gay.`object`.hexdebug.core.api.debugging.env.DebugEnvironment
2021
import gay.`object`.hexdebug.debugger.allocators.VariablesAllocator
2122
import gay.`object`.hexdebug.impl.IDebugEnvAccessor
2223
import gay.`object`.hexdebug.utils.ceilToPow
@@ -138,6 +139,10 @@ class HexDebugger(
138139
return iotaToString(iota, isSource = false) to (meta?.lineIndex ?: -1)
139140
}
140141

142+
fun postStep(reason: StopReason) {
143+
currentEnv?.let { debugEnv.postStep(it, image, reason) }
144+
}
145+
141146
fun getStackFrames(): Sequence<StackFrame> {
142147
var frameId = 1
143148
var virtualFrameId = (callStack.size + 1).ceilToPow(10)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package gay.object.hexdebug.core.api.debugging;
2+
3+
public enum StopReason {
4+
STEP(false),
5+
PAUSE(true),
6+
BREAKPOINT(true),
7+
EXCEPTION(true),
8+
STARTED(true),
9+
TERMINATED(true);
10+
11+
public final boolean stopImmediately;
12+
13+
StopReason(boolean stopImmediately) {
14+
this.stopImmediately = stopImmediately;
15+
}
16+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import gay.object.hexdebug.core.api.HexDebugCoreAPI;
99
import gay.object.hexdebug.core.api.debugging.DebugOutputCategory;
1010
import gay.object.hexdebug.core.api.debugging.DebugStepType;
11+
import gay.object.hexdebug.core.api.debugging.StopReason;
1112
import net.minecraft.network.chat.Component;
1213
import net.minecraft.server.level.ServerPlayer;
1314
import org.jetbrains.annotations.ApiStatus;
@@ -80,6 +81,18 @@ public abstract boolean resume(
8081
@NotNull
8182
public abstract Component getName();
8283

84+
/**
85+
* Do whatever you like after each debugger step.
86+
* <br>
87+
* Called by the debugger after an execution step is finished, unless the debug session was
88+
* resumed or terminated as a result of the step.
89+
*/
90+
public void postStep(
91+
@NotNull CastingEnvironment env,
92+
@NotNull CastingImage image,
93+
@NotNull StopReason reason
94+
) {}
95+
8396
public void printDebugMessage(@NotNull Component message) {
8497
printDebugMessage(message, DebugOutputCategory.STDOUT, true);
8598
}

plantuml/debug_api/initialization.puml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ activate Debuggee
4040
return stopped on entry
4141

4242
Adapter ->> User: event: stopped on entry
43+
44+
Adapter -> DebugEnv ++: ""postStep(env, image, reason)""
45+
return
4346
return
4447
return
4548
deactivate Debuggee

plantuml/debug_api/nested.puml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ User ->> Adapter ++: request: step
3838
return stopped on step
3939

4040
Adapter ->> User: event: stopped on step
41+
42+
Adapter -> DebugEnv ++: ""postStep(env, image, reason)""
43+
return
4144
deactivate Adapter
4245

4346
...
@@ -49,6 +52,9 @@ Debuggee2 -> Debuggee2 ++: pause
4952
return stopped on entry
5053

5154
Adapter ->> User: event: stopped on entry
55+
56+
Adapter -> DebugEnv ++: ""postStep(env, image, reason)""
57+
return
5258
return
5359
return
5460
deactivate Debuggee2

plantuml/debug_api/stepping.puml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ User ->> Adapter ++: request: step forward
2222
end
2323
return
2424
return stopped on step
25+
2526
Adapter ->> User: event: stopped on step
27+
28+
Adapter -> DebugEnv ++: ""postStep(env, image, reason)""
29+
return
2630
else caster out of range
2731
Adapter ->> User: error: out of range
2832
end
@@ -55,6 +59,9 @@ Debuggee -> API ++: ""startDebuggingIotas(...)""
5559
return stopped on step
5660

5761
Adapter ->> User: event: stopped on step
62+
63+
Adapter -> DebugEnv ++: ""postStep(env, image, reason)""
64+
return
5865
return
5966
return
6067
deactivate Debuggee

0 commit comments

Comments
 (0)