Skip to content

Commit 82a8afd

Browse files
authored
Send checkpoints when stepping or pausing in trace mode (#352)
* Also send checkpoints when stepping or pausing in trace mode This works better for debuggers such as MIO which expect information about the current program counter/program state while stepping. * Reset instruction counter upon reset This ensures the debugger never reports executing more instructions than it actually did when resetting.
1 parent 289a289 commit 82a8afd

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

src/Debug/debugger.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,16 @@ void Debugger::handleSnapshotPolicy(Module *m) {
10241024
this->channel->write("\n");
10251025
} else if (snapshotPolicy == SnapshotPolicy::checkpointing) {
10261026
if (instructions_executed >= checkpointInterval || fidx_called) {
1027-
checkpoint(m);
1027+
if (min_return_values == 0) {
1028+
checkpoint(m);
1029+
} else {
1030+
if (fidx_called) {
1031+
const Type *type = m->functions[*fidx_called].type;
1032+
if (type->result_count >= min_return_values) {
1033+
checkpoint(m);
1034+
}
1035+
}
1036+
}
10281037
}
10291038
instructions_executed++;
10301039

@@ -1046,19 +1055,6 @@ void Debugger::checkpoint(Module *m, const bool force) {
10461055
return;
10471056
}
10481057

1049-
if (min_return_values != 0) {
1050-
if (!fidx_called) {
1051-
// Tracing mode is on, but no primitive was called.
1052-
return;
1053-
}
1054-
1055-
const Type *type = m->functions[*fidx_called].type;
1056-
if (type->result_count < min_return_values) {
1057-
// Primitive was called but did not have the required return values.
1058-
return;
1059-
}
1060-
}
1061-
10621058
this->channel->write(R"(CHECKPOINT {"instructions_executed": %d, )",
10631059
instructions_executed);
10641060
if (fidx_called) {
@@ -1614,10 +1610,11 @@ bool Debugger::handleUpdateStackValue(const Module *m, uint8_t *bytes) const {
16141610
return true;
16151611
}
16161612

1617-
bool Debugger::reset(Module *m) const {
1613+
bool Debugger::reset(Module *m) {
16181614
auto *wasm =
16191615
static_cast<uint8_t *>(malloc(sizeof(uint8_t) * m->byte_count));
16201616
memcpy(wasm, m->bytes, m->byte_count);
1617+
instructions_executed = 0;
16211618
m->warduino->update_module(m, wasm, m->byte_count);
16221619
this->channel->write("Reset WARDuino.\n");
16231620
return true;

src/Debug/debugger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class Debugger {
201201

202202
bool handleUpdateStackValue(const Module *m, uint8_t *bytes) const;
203203

204-
bool reset(Module *m) const;
204+
bool reset(Module *m);
205205

206206
//// Handle out-of-place debugging
207207

0 commit comments

Comments
 (0)