Add correct debugging to .mjs files

Add breakpoint on the start of the first source code line so that module file imports can be debugged.
Also extend debugger test script since Escargot uses realpaths with modules.

Signed-off-by: Ádám László Kulcsár <kuladam@inf.u-szeged.hu>
This commit is contained in:
Ádám László Kulcsár 2026-04-07 15:28:49 +02:00 committed by Patrick Kim
commit 0ac274d1fc
6 changed files with 46 additions and 0 deletions

View file

@ -1124,6 +1124,10 @@ Script::ModuleExecutionResult Script::moduleExecute(ExecutionState& state, Optio
if (LIKELY(!m_topCodeBlock->isAsync())) {
try {
#ifdef ESCARGOT_DEBUGGER
// set the next(first) breakpoint to be stopped in a newer script execution
context()->setAsAlwaysStopState();
#endif
Interpreter::interpret(newState, byteCodeBlock, reinterpret_cast<size_t>(byteCodeBlock->m_code.data()), registerFile);
} catch (const Value& e) {
resultValue = e;

View file

@ -8,6 +8,8 @@ RESULT_TEMP=`mktemp ${TEST_CASE}.out.XXXXXXXXXX`
if [[ $IS_CLIENT_SOURCE == 0 ]] && [[ $TEST_CASE != *"tools/debugger/tests/client_source_multiple"* ]]; then
if [[ $TEST_CASE == *"tools/debugger/tests/do_wait_exit2"* ]]; then
${ESCARGOT} --start-debug-server --wait-before-exit ${TEST_CASE}.js &
elif [[ $TEST_CASE == *"tools/debugger/tests/module_debug"* ]]; then
${ESCARGOT} --module --start-debug-server ${TEST_CASE}_1.mjs &
else
${ESCARGOT} --start-debug-server ${TEST_CASE}.js &
fi
@ -19,7 +21,16 @@ if [[ $IS_CLIENT_SOURCE == 0 ]] && [[ $TEST_CASE != *"tools/debugger/tests/clie
else
(cat "${TEST_CASE}.cmd" | ${DEBUGGER_CLIENT} --non-interactive) >${RESULT_TEMP} 2>&1
fi
if [[ $TEST_CASE == *"tools/debugger/tests/module_debug"* ]]; then
EXPECTED_PATH=$(realpath ./tools/debugger/tests/)
sed -i '3i\Stopped at '$EXPECTED_PATH"/module_debug_2.mjs:1" $EXPECTED_PATH"/module_debug.expected"
fi
diff -u ${TEST_CASE}.expected ${RESULT_TEMP}
if [[ $TEST_CASE == *"tools/debugger/tests/module_debug"* ]]; then
sed -i '3d' $EXPECTED_PATH"/module_debug.expected"
fi
elif [[ $IS_CLIENT_SOURCE == 1 ]]; then
if [[ $TEST_CASE == *"tools/debugger/tests/do_wait_exit2"* ]]; then
${ESCARGOT} --start-debug-server --debugger-wait-source --wait-before-exit &
@ -33,10 +44,21 @@ elif [[ $IS_CLIENT_SOURCE == 1 ]]; then
(cat "${TEST_CASE}.cmd" | ${DEBUGGER_CLIENT} --client-source ${TEST_CASE}.js --non-interactive --command "b do_command.js:2;c;e i;c") >${RESULT_TEMP} 2>&1
elif [[ $TEST_CASE == *"tools/debugger/tests/do_wait_exit1"* ]]; then
(cat "${TEST_CASE}.cmd" | ${DEBUGGER_CLIENT} --client-source ${TEST_CASE}.js --non-interactive --wait-before-exit 1) >${RESULT_TEMP} 2>&1
elif [[ $TEST_CASE == *"tools/debugger/tests/module_debug"* ]]; then
(cat "${TEST_CASE}.cmd" | ${DEBUGGER_CLIENT} --client-source ${TEST_CASE}_1.mjs --non-interactive) >${RESULT_TEMP} 2>&1
else
(cat "${TEST_CASE}.cmd" | ${DEBUGGER_CLIENT} --client-source ${TEST_CASE}.js --non-interactive) >${RESULT_TEMP} 2>&1
fi
if [[ $TEST_CASE == *"tools/debugger/tests/module_debug"* ]]; then
EXPECTED_PATH=$(realpath ./tools/debugger/tests/)
sed -i '3i\Stopped at '$EXPECTED_PATH"/module_debug_2.mjs:1" $EXPECTED_PATH"/module_debug.expected"
fi
diff -u ${TEST_CASE}.expected ${RESULT_TEMP}
if [[ $TEST_CASE == *"tools/debugger/tests/module_debug"* ]]; then
sed -i '3d' $EXPECTED_PATH"/module_debug.expected"
fi
fi

View file

@ -0,0 +1,3 @@
n
n
n

View file

@ -0,0 +1,10 @@
Connecting to: localhost:6501
Connection created!!!
(escargot-debugger) n
Stopped at tools/debugger/tests/module_debug_1.mjs:3
(escargot-debugger) n
Print: hello from module_debug_1.mjs!
Stopped at tools/debugger/tests/module_debug_1.mjs:4
(escargot-debugger) n
Print: hello from module_debug_2!
Connection closed.

View file

@ -0,0 +1,4 @@
import { hello_module2 } from "./module_debug_2.mjs";
print("hello from module_debug_1.mjs!");
hello_module2();

View file

@ -0,0 +1,3 @@
export function hello_module2() {
print("hello from module_debug_2!")
}