Skip to content

Commit 83e35d6

Browse files
committed
feat(tests, debugger): testing the debugger triggering on errors
1 parent 7a76485 commit 83e35d6

File tree

9 files changed

+24
-8
lines changed

9 files changed

+24
-8
lines changed

include/Ark/VM/Debugger.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ namespace Ark::internal
8787
*
8888
* @param vm
8989
* @param context
90+
* @param from_breakpoint true if the debugger is being invoked from a breakpoint
9091
*/
91-
void run(VM& vm, ExecutionContext& context);
92+
void run(VM& vm, ExecutionContext& context, bool from_breakpoint);
9293

9394
[[nodiscard]] inline bool isRunning() const noexcept
9495
{

src/arkreactor/VM/Debugger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ namespace Ark::internal
5757
m_states.pop_back();
5858
}
5959

60-
void Debugger::run(VM& vm, ExecutionContext& context)
60+
void Debugger::run(VM& vm, ExecutionContext& context, const bool from_breakpoint)
6161
{
62-
showContext(vm, context);
62+
if (from_breakpoint)
63+
showContext(vm, context);
6364

6465
m_running = true;
6566
const bool is_vm_running = vm.m_running;

src/arkreactor/VM/VM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ namespace Ark
12001200
if (m_state.m_features & FeatureVMDebugger && breakpoint_active)
12011201
{
12021202
initDebugger(context);
1203-
m_debugger->run(*this, context);
1203+
m_debugger->run(*this, context, /* from_breakpoint= */ true);
12041204
m_debugger->resetContextToSavedState(context);
12051205

12061206
if (m_debugger->shouldQuitVM())
@@ -2306,7 +2306,7 @@ namespace Ark
23062306
if (m_debugger && !error_from_debugger)
23072307
{
23082308
m_debugger->resetContextToSavedState(context);
2309-
m_debugger->run(*this, context);
2309+
m_debugger->run(*this, context, /* from_breakpoint= */ false);
23102310
}
23112311

23122312
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION

tests/unittests/Suites/DebuggerSuite.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ut::suite<"Debugger"> debugger_suite = [] {
3737
{
3838
Ark::VM vm(state);
3939
vm.usePromptFileForDebugger(prompt_path.generic_string(), os);
40-
vm.run(/* fail_with_exception= */ true);
40+
vm.run(/* fail_with_exception= */ false);
4141

4242
const std::string output = sanitizeOutput(os.str());
4343
expectOrDiff(data.expected, output);

tests/unittests/resources/DebuggerSuite/modify_program_state.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ In file tests/unittests/resources/DebuggerSuite/modify_program_state.ark:3
1313
4 | (prn (format "ark: i={}" i))
1414
5 | (set i (+ 1 i)) })
1515

16-
dbg[pp:0,ip:32]:000> (print i)
16+
dbg[pp:0,ip:32]:000> (prn i)
17+
6
1718
nil
1819
dbg[pp:0,ip:32]:001> c
1920
dbg: continue
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(print i)
1+
(prn i)
22
c
33
(set i 20)
44
c
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(let a 5)
2+
(prn (@ a 0))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dbg[pp:0,ip:12]:000> (prn a)
2+
5
3+
nil
4+
dbg[pp:0,ip:12]:001> (prn (type a))
5+
Number
6+
nil
7+
dbg[pp:0,ip:12]:002> c
8+
dbg: continue
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(prn a)
2+
(prn (type a))
3+
c

0 commit comments

Comments
 (0)