Skip to content

Commit 4cc12a0

Browse files
committed
Small fixes
Fix clone command in README.md Use debug() rather than printf() Add const and static keywords Comment out fflush(stdout)
1 parent f82f2ab commit 4cc12a0

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Supported platforms: Linux (Ubuntu), macOS, ESP-IDF, Arduino
2222
The project uses CMake. Quick install looks like this:
2323

2424
```bash
25-
git clone [email protected]:TOPLLab/WARDuino.git
25+
git clone --recursive [email protected]:TOPLLab/WARDuino.git
2626
cd WARDuino
2727
mkdir build-emu
2828
cd build-emu

src/Debug/debugger.cpp

+13-25
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
216216
}
217217

218218
// Private methods
219-
void Debugger::printValue(StackValue *v, int idx, bool end = false) {
219+
void Debugger::printValue(StackValue *v, int idx, bool end = false) const {
220220
char buff[256];
221221

222222
switch (v->value_type) {
@@ -266,7 +266,7 @@ void Debugger::handleInterruptRUN(Module *m, RunningState *program_state) {
266266
*program_state = WARDUINOrun;
267267
}
268268

269-
void Debugger::handleInterruptBP(uint8_t *interruptData) {
269+
void Debugger::handleInterruptBP(const uint8_t *interruptData) {
270270
// TODO: segfault may happen here!
271271
uint8_t len = interruptData[1];
272272
uintptr_t bp = 0x0;
@@ -305,7 +305,7 @@ void Debugger::dump(Module *m, bool full) const {
305305
}
306306

307307
dprintf(this->socket, "}\n\n");
308-
fflush(stdout);
308+
// fflush(stdout);
309309
}
310310

311311
void Debugger::dumpBreakpoints(Module *m) const {
@@ -350,7 +350,7 @@ void Debugger::dumpCallstack(Module *m) const {
350350
}
351351

352352
void Debugger::dumpLocals(Module *m) const {
353-
fflush(stdout);
353+
// fflush(stdout);
354354
int firstFunFramePtr = m->csp;
355355
while (m->callstack[firstFunFramePtr].block->block_type != 0) {
356356
firstFunFramePtr--;
@@ -360,7 +360,7 @@ void Debugger::dumpLocals(Module *m) const {
360360
}
361361
Frame *f = &m->callstack[firstFunFramePtr];
362362
dprintf(this->socket, R"({"count":%u,"locals":[)", 0);
363-
fflush(stdout); // FIXME: this is needed for ESP to propery print
363+
// fflush(stdout); // FIXME: this is needed for ESP to propery print
364364
char _value_str[256];
365365
for (size_t i = 0; i < f->block->local_count; i++) {
366366
auto v = &m->stack[m->fp + i];
@@ -387,12 +387,12 @@ void Debugger::dumpLocals(Module *m) const {
387387
v->value_type, v->value.uint64);
388388
}
389389

390-
dprintf(this->socket, "{%s, \"index\":%i}%s", _value_str,
390+
dprintf(this->socket, "{%s, \"index\":%lu}%s", _value_str,
391391
i + f->block->type->param_count,
392392
(i + 1 < f->block->local_count) ? "," : "");
393393
}
394394
dprintf(this->socket, "]}");
395-
fflush(stdout);
395+
// fflush(stdout);
396396
}
397397

398398
/**
@@ -580,7 +580,6 @@ enum ReceiveState {
580580

581581
void Debugger::freeState(Module *m, uint8_t *interruptData) {
582582
debug("freeing the program state\n");
583-
printf("freeing the program state\n");
584583
uint8_t *first_msg = nullptr;
585584
uint8_t *endfm = nullptr;
586585
first_msg = interruptData + 1; // skip interruptRecvState
@@ -596,7 +595,6 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
596595
switch (*first_msg++) {
597596
case globalsState: {
598597
debug("receiving globals info\n");
599-
printf("receiving globals info\n");
600598
uint32_t amount = read_B32(&first_msg);
601599
debug("total globals %d\n", amount);
602600
// TODO if global_count != amount Otherwise set all to zero
@@ -620,7 +618,6 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
620618
}
621619
case tblState: {
622620
debug("receiving table info\n");
623-
printf("receiving table info\n");
624621
m->table.initial = read_B32(&first_msg);
625622
m->table.maximum = read_B32(&first_msg);
626623
uint32_t size = read_B32(&first_msg);
@@ -637,15 +634,12 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
637634
}
638635
case memState: {
639636
debug("receiving memory info\n");
640-
printf("receiving memory info\n");
641637
// FIXME: init & max not needed
642638
m->memory.maximum = read_B32(&first_msg);
643639
m->memory.initial = read_B32(&first_msg);
644640
uint32_t pages = read_B32(&first_msg);
645641
debug("max %d init %d current page %d\n", m->memory.maximum,
646642
m->memory.initial, pages);
647-
printf("max %d init %d current page %d\n", m->memory.maximum,
648-
m->memory.initial, pages);
649643
// if(pages !=m->memory.pages){
650644
// if(m->memory.pages !=0)
651645
if (m->memory.bytes != nullptr) {
@@ -669,7 +663,6 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
669663
}
670664
}
671665
debug("done with first msg\n");
672-
/* printf("done with first msg\n"); */
673666
}
674667

675668
bool Debugger::saveState(Module *m, uint8_t *interruptData) {
@@ -678,7 +671,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
678671
program_state = interruptData + 1; // skip interruptRecvState
679672
endstate = program_state + read_B32(&program_state);
680673

681-
printf("saving program_state\n");
674+
debug("saving program_state\n");
682675
while (program_state < endstate) {
683676
switch (*program_state++) {
684677
case pcState: { // PC
@@ -688,7 +681,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
688681
}
689682
case breakpointsState: { // breakpoints
690683
uint8_t quantity_bps = *program_state++;
691-
printf("receiving breakpoints %" PRIu8 "\n", quantity_bps);
684+
debug("receiving breakpoints %" PRIu8 "\n", quantity_bps);
692685
for (size_t i = 0; i < quantity_bps; i++) {
693686
auto bp = (uint8_t *)readPointer(&program_state);
694687
this->addBreakpoint(bp);
@@ -697,7 +690,6 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
697690
}
698691
case callstackState: {
699692
debug("receiving callstack\n");
700-
printf("receiving callstack\n");
701693
uint16_t quantity = read_B16(&program_state);
702694
debug("quantity frames %" PRIu16 "\n", quantity);
703695
/* printf("quantity frames %" PRIu16 "\n", quantity); */
@@ -712,7 +704,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
712704
if (block_type == 0) { // a function
713705
debug("function block\n");
714706
uint32_t fidx = read_B32(&program_state);
715-
/* printf("function block idx=%" PRIu32 "\n", fidx); */
707+
/* debug("function block idx=%" PRIu32 "\n", fidx); */
716708
f->block = m->functions + fidx;
717709

718710
if (f->block->fidx != fidx) {
@@ -722,10 +714,10 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
722714
}
723715
m->fp = f->sp + 1;
724716
} else {
725-
printf("non function block\n");
717+
debug("non function block\n");
726718
uint8_t *block_key =
727719
(uint8_t *)readPointer(&program_state);
728-
/* printf("block_key=%p\n", static_cast<void
720+
/* debug("block_key=%p\n", static_cast<void
729721
* *>(block_key)); */
730722
f->block = m->block_lookup[block_key];
731723
if (f->block == nullptr) {
@@ -738,7 +730,6 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
738730
case globalsState: { // TODO merge globalsState stackvalsState into
739731
// one case
740732
debug("receiving global state\n");
741-
printf("receiving globals\n");
742733
uint32_t quantity_globals = read_B32(&program_state);
743734
uint8_t valtypes[] = {I32, I64, F32, F64};
744735

@@ -760,7 +751,6 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
760751
break;
761752
}
762753
case tblState: {
763-
printf("receiving table\n");
764754
uint8_t tbl_type =
765755
(uint8_t)*program_state++; // for now only funcref
766756
uint32_t quantity = read_B32(&program_state);
@@ -772,7 +762,6 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
772762
}
773763
case memState: {
774764
debug("receiving memory\n");
775-
printf("receiving memory\n");
776765
uint32_t begin = read_B32(&program_state);
777766
uint32_t end = read_B32(&program_state);
778767
debug("memory offsets begin=%" PRIu32 " , end=%" PRIu32 "\n",
@@ -798,7 +787,6 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
798787
}
799788
case brtblState: {
800789
debug("receiving br_table\n");
801-
printf("receiving br_table\n");
802790
uint16_t beginidx = read_B16(&program_state);
803791
uint16_t endidx = read_B16(&program_state);
804792
debug("br_table offsets begin=%" PRIu16 " , end=%" PRIu16 "\n",
@@ -819,7 +807,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
819807
case stackvalsState: {
820808
// FIXME the float does add numbers at the end. The extra
821809
// numbers are present in the send information when dump occurs
822-
printf("receiving stack\n");
810+
debug("receiving stack\n");
823811
uint16_t quantity_sv = read_B16(&program_state);
824812
uint8_t valtypes[] = {I32, I64, F32, F64};
825813
for (size_t i = 0; i < quantity_sv; i++) {

src/Debug/debugger.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Debugger {
4242

4343
// Private methods
4444

45-
void printValue(StackValue *v, int idx, bool end);
45+
void printValue(StackValue *v, int idx, bool end) const;
4646

4747
// TODO Move parsing to WARDuino class?
4848
uint8_t *parseDebugBuffer(size_t len, const uint8_t *buff);
@@ -51,7 +51,7 @@ class Debugger {
5151

5252
void handleInterruptRUN(Module *m, RunningState *program_state);
5353

54-
void handleInterruptBP(uint8_t *interruptData);
54+
void handleInterruptBP(const uint8_t *interruptData);
5555

5656
//// Information dumps
5757

@@ -67,16 +67,16 @@ class Debugger {
6767

6868
//// Handle live code update
6969

70-
bool handleChangedFunction(Module *m, uint8_t *bytes);
70+
static bool handleChangedFunction(Module *m, uint8_t *bytes);
7171

7272
bool handleChangedLocal(Module *m, uint8_t *bytes) const;
7373

7474
// WOOD
7575
bool receivingData = false;
7676
void freeState(Module *m, uint8_t *interruptData);
77-
uint8_t *findOpcode(Module *m, Block *block);
77+
static uint8_t *findOpcode(Module *m, Block *block);
7878
bool saveState(Module *m, uint8_t *interruptData);
79-
uintptr_t readPointer(uint8_t **data);
79+
static uintptr_t readPointer(uint8_t **data);
8080

8181
public:
8282
int socket;

0 commit comments

Comments
 (0)