script-plan.md
There are two related problems in the current scripting/debugger interaction:
Lifecycle detection is too coarse
DbgIsDebugging() is currently not a fully truthful primitive during debugger startup/teardown.Script interruption is too coarse
bScriptAbort is currently used for multiple meanings:
The resulting symptom is that some scripts fail with script_failed even though the same commands work when run manually.
DbgIsDebugging() truthfulDbgIsDebugging() should become a reliable primitive meaning:
It should not return true merely because the debug loop thread has started.
Do not infer script ownership from command text such as init, attach, stop, detach, etc.
Instead, for each script command:
DbgIsDebugging() before executionDbgIsDebugging() after executionThen infer lifecycle transitions from reality:
false -> true: command started a sessiontrue -> false: command ended a sessionThis automatically supports:
bScriptAbort with an interrupt reason modelCurrent bScriptAbort conflates multiple situations.
Replace it with something like:
enum class SCRIPTINTERRUPTREASON
{
None = 0,
YieldDebugEvent,
AbortUser,
AbortAssertion,
AbortShutdown,
};
Suggested name:
gScriptInterruptReasonThis allows the script engine to distinguish:
When a script command causes DbgIsDebugging() to change:
false -> true, mark the session as script-createdtrue -> false, continuation may be allowed if the session was script-createdImportant: this should be based on observed transitions, not hardcoded command lists.
When a debug event interrupts a running script (for example during run):
Only true abort reasons should make ScriptRunAwait() / ScriptExecAwait() fail.
membp/range-executeCurrent flow:
runScriptAbortAwait()bScriptAbort = trueScriptRunAwait() returns failure before the script reaches the next line / final retScriptRunAsync()script_failedRoot cause:
DbgIsDebugging()Files to inspect:
src/dbg/_exports.cppsrc/dbg/debugger.cppDbgIsDebugging() implies valid fdProcessInfo->hProcessGoal:
DbgIsDebugging() should only be true when the debugger session is actually usableNotes:
_dbg_isdebugging() returning bIsDebugging && fdProcessInfo != nullptrFiles to inspect:
src/dbg/simplescript.cppsrc/dbg/simplescript.hsrc/dbg/debugger.cppsrc/dbg/testing.cppReplace:
bScriptAbortWith:
gScriptInterruptReasonBehavior:
AbortUser, AbortAssertion, AbortShutdown => true abort/failure behaviorYieldDebugEvent => non-failing temporary interruptionA reason enum alone is not enough.
Need a handshake so the debugger thread can:
Possible implementation pieces:
Goal:
ScriptRunAwait() remains logically in progress across debug-event yieldsWithin script command execution:
DbgIsDebugging() before commandDbgIsDebugging() after commandfalse -> true / true -> falseThis should replace command-name based ownership logic.
script_run_exitPurpose:
init + run when the debuggee exits normallyMinimal script shape:
settingset Events, EntryBreakpoint, 0
init tests/script_run_exit.exe
testassert 1, "before run executed"
run
testassert 1, "after run executed"
Expected:
membp/range-executePurpose:
run does not falsely become script_failedExpected after fix:
A dedicated script/breakpoint-yield test would be useful:
runThe intended architecture is:
DbgIsDebugging() becomes a truthful lifecycle primitiveThis should solve both:
script_failed behavior seen in scripted runs that hit breakpoints