Skip to content

Commit 1b953bc

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 2f07901 commit 1b953bc

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
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

+21-24
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,7 @@ 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");
583+
debug("freeing the program state\n");
584584
uint8_t *first_msg = nullptr;
585585
uint8_t *endfm = nullptr;
586586
first_msg = interruptData + 1; // skip interruptRecvState
@@ -596,7 +596,7 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
596596
switch (*first_msg++) {
597597
case globalsState: {
598598
debug("receiving globals info\n");
599-
printf("receiving globals info\n");
599+
debug("receiving globals info\n");
600600
uint32_t amount = read_B32(&first_msg);
601601
debug("total globals %d\n", amount);
602602
// TODO if global_count != amount Otherwise set all to zero
@@ -620,7 +620,7 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
620620
}
621621
case tblState: {
622622
debug("receiving table info\n");
623-
printf("receiving table info\n");
623+
debug("receiving table info\n");
624624
m->table.initial = read_B32(&first_msg);
625625
m->table.maximum = read_B32(&first_msg);
626626
uint32_t size = read_B32(&first_msg);
@@ -637,15 +637,13 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
637637
}
638638
case memState: {
639639
debug("receiving memory info\n");
640-
printf("receiving memory info\n");
640+
debug("receiving memory info\n");
641641
// FIXME: init & max not needed
642642
m->memory.maximum = read_B32(&first_msg);
643643
m->memory.initial = read_B32(&first_msg);
644644
uint32_t pages = read_B32(&first_msg);
645645
debug("max %d init %d current page %d\n", m->memory.maximum,
646646
m->memory.initial, pages);
647-
printf("max %d init %d current page %d\n", m->memory.maximum,
648-
m->memory.initial, pages);
649647
// if(pages !=m->memory.pages){
650648
// if(m->memory.pages !=0)
651649
if (m->memory.bytes != nullptr) {
@@ -669,7 +667,6 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
669667
}
670668
}
671669
debug("done with first msg\n");
672-
/* printf("done with first msg\n"); */
673670
}
674671

675672
bool Debugger::saveState(Module *m, uint8_t *interruptData) {
@@ -681,13 +678,13 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
681678
while (program_state < endstate) {
682679
switch (*program_state++) {
683680
case pcState: { // PC
684-
printf("reciving pc\n");
681+
debug("receiving pc\n");
685682
m->pc_ptr = (uint8_t *)readPointer(&program_state);
686683
break;
687684
}
688685
case breakpointsState: { // breakpoints
689686
uint8_t quantity_bps = *program_state++;
690-
printf("receiving breakpoints %" PRIu8 "\n", quantity_bps);
687+
debug("receiving breakpoints %" PRIu8 "\n", quantity_bps);
691688
for (size_t i = 0; i < quantity_bps; i++) {
692689
auto bp = (uint8_t *)readPointer(&program_state);
693690
this->addBreakpoint(bp);
@@ -696,7 +693,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
696693
}
697694
case callstackState: {
698695
debug("receiving callstack\n");
699-
printf("receiving callstack\n");
696+
debug("receiving callstack\n");
700697
uint16_t quantity = read_B16(&program_state);
701698
debug("quantity frames %" PRIu16 "\n", quantity);
702699
for (size_t i = 0; i < quantity; i++) {
@@ -719,10 +716,10 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
719716
}
720717
m->fp = f->sp + 1;
721718
} else {
722-
printf("non function block\n");
719+
debug("non function block\n");
723720
uint8_t *block_key =
724721
(uint8_t *)readPointer(&program_state);
725-
/* printf("block_key=%p\n", static_cast<void
722+
/* debug("block_key=%p\n", static_cast<void
726723
* *>(block_key)); */
727724
f->block = m->block_lookup[block_key];
728725
if (f->block == nullptr) {
@@ -735,7 +732,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
735732
case globalsState: { // TODO merge globalsState stackvalsState into
736733
// one case
737734
debug("receiving global state\n");
738-
printf("receiving globals\n");
735+
debug("receiving globals\n");
739736
uint32_t quantity_globals = read_B32(&program_state);
740737
uint8_t valtypes[] = {I32, I64, F32, F64};
741738

@@ -757,7 +754,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
757754
break;
758755
}
759756
case tblState: {
760-
printf("receiving table\n");
757+
debug("receiving table\n");
761758
uint8_t tbl_type =
762759
(uint8_t)*program_state++; // for now only funcref
763760
uint32_t quantity = read_B32(&program_state);
@@ -769,7 +766,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
769766
}
770767
case memState: {
771768
debug("receiving memory\n");
772-
printf("receiving memory\n");
769+
debug("receiving memory\n");
773770
uint32_t begin = read_B32(&program_state);
774771
uint32_t end = read_B32(&program_state);
775772
debug("memory offsets begin=%" PRIu32 " , end=%" PRIu32 "\n",
@@ -795,7 +792,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
795792
}
796793
case brtblState: {
797794
debug("receiving br_table\n");
798-
printf("receiving br_table\n");
795+
debug("receiving br_table\n");
799796
uint16_t beginidx = read_B16(&program_state);
800797
uint16_t endidx = read_B16(&program_state);
801798
debug("br_table offsets begin=%" PRIu16 " , end=%" PRIu16 "\n",
@@ -816,7 +813,7 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
816813
case stackvalsState: {
817814
// FIXME the float does add numbers at the end. The extra
818815
// numbers are present in the send information when dump occurs
819-
printf("receiving stack\n");
816+
debug("receiving stack\n");
820817
uint16_t quantity_sv = read_B16(&program_state);
821818
uint8_t valtypes[] = {I32, I64, F32, F64};
822819
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)