Skip to content

Commit 2f07901

Browse files
committed
Format + Add missing #include
1 parent 573dbb9 commit 2f07901

File tree

4 files changed

+51
-56
lines changed

4 files changed

+51
-56
lines changed

src/Debug/debugger.cpp

+46-48
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include "debugger.h"
22

3-
#include <inttypes.h>
3+
#include <unistd.h>
44

5+
#include <algorithm>
6+
#include <cinttypes>
57
#include <cstring>
6-
#include <unistd.h>
78

89
#include "../Memory/mem.h"
910
#include "../Utils//util.h"
1011
#include "../Utils/macros.h"
11-
#include "../WARDuino.h"
1212

1313
// Debugger
1414

@@ -180,7 +180,8 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
180180
break;
181181
case interruptOffset: {
182182
free(interruptData);
183-
dprintf(this->socket, "\"{\"offset\":\"%p\"}\"\n", (void *)m->bytes);
183+
dprintf(this->socket, "\"{\"offset\":\"%p\"}\"\n",
184+
(void *)m->bytes);
184185
break;
185186
}
186187
case interruptRecvState: {
@@ -198,7 +199,7 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
198199
free(interruptData);
199200
debug("sending %s!\n", receivingData ? "ack" : "done");
200201
dprintf(this->socket, "%s!\n", receivingData ? "ack" : "done");
201-
if(!this->receivingData){
202+
if (!this->receivingData) {
202203
debug("receiving state done\n");
203204
}
204205
}
@@ -215,37 +216,32 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
215216
}
216217

217218
// Private methods
218-
void Debugger::printValue(StackValue *v, int idx, bool end = false){
219-
char buff[256];
220-
221-
switch (v->value_type) {
222-
case I32:
223-
snprintf(buff, 255, R"("type":"i32","value":%)" PRIi32,
224-
v->value.uint32);
225-
break;
226-
case I64:
227-
snprintf(buff, 255, R"("type":"i64","value":%)" PRIi64,
228-
v->value.uint64);
229-
break;
230-
case F32:
231-
snprintf(buff, 255, R"("type":"F32","value":%.7f)",
232-
v->value.f32);
233-
break;
234-
case F64:
235-
snprintf(buff, 255, R"("type":"F64","value":%.7f)",
236-
v->value.f64);
237-
break;
238-
default:
239-
snprintf(buff, 255,
240-
R"("type":"%02x","value":"%)" PRIx64 "\"",
241-
v->value_type, v->value.uint64);
242-
}
243-
dprintf(this->socket, R"({"idx":%d,%s}%s)", idx, buff,
244-
end ? "": ",");
219+
void Debugger::printValue(StackValue *v, int idx, bool end = false) {
220+
char buff[256];
245221

222+
switch (v->value_type) {
223+
case I32:
224+
snprintf(buff, 255, R"("type":"i32","value":%)" PRIi32,
225+
v->value.uint32);
226+
break;
227+
case I64:
228+
snprintf(buff, 255, R"("type":"i64","value":%)" PRIi64,
229+
v->value.uint64);
230+
break;
231+
case F32:
232+
snprintf(buff, 255, R"("type":"F32","value":%.7f)", v->value.f32);
233+
break;
234+
case F64:
235+
snprintf(buff, 255, R"("type":"F64","value":%.7f)", v->value.f64);
236+
break;
237+
default:
238+
snprintf(buff, 255, R"("type":"%02x","value":"%)" PRIx64 "\"",
239+
v->value_type, v->value.uint64);
240+
}
241+
dprintf(this->socket, R"({"idx":%d,%s}%s)", idx, buff, end ? "" : ",");
246242
}
247243

248-
uint8_t * Debugger::findOpcode(Module *m, Block *block){
244+
uint8_t *Debugger::findOpcode(Module *m, Block *block) {
249245
auto find =
250246
std::find_if(std::begin(m->block_lookup), std::end(m->block_lookup),
251247
[&](const std::pair<uint8_t *, Block *> &pair) {
@@ -262,7 +258,6 @@ uint8_t * Debugger::findOpcode(Module *m, Block *block){
262258
return opcode;
263259
}
264260

265-
266261
void Debugger::handleInterruptRUN(Module *m, RunningState *program_state) {
267262
dprintf(this->socket, "GO!\n");
268263
if (*program_state == WARDUINOpause && this->isBreakpoint(m->pc_ptr)) {
@@ -510,12 +505,12 @@ void Debugger::woodDump(Module *m) {
510505
size_t i = 0;
511506
for (auto bp : this->breakpoints) {
512507
dprintf(this->socket, R"("%p"%s)", bp,
513-
(++i < this->breakpoints.size()) ? "," : "");
508+
(++i < this->breakpoints.size()) ? "," : "");
514509
}
515510
dprintf(this->socket, "],");
516511

517512
// printf("asked for stack\n");
518-
//stack
513+
// stack
519514
dprintf(this->socket, "\"stack\":[");
520515
char _value_str[256];
521516
for (int i = 0; i <= m->sp; i++) {
@@ -530,7 +525,8 @@ void Debugger::woodDump(Module *m) {
530525
Frame *f = &m->callstack[i];
531526
uint8_t *block_key =
532527
f->block->block_type == 0 ? nullptr : findOpcode(m, f->block);
533-
dprintf(this->socket,
528+
dprintf(
529+
this->socket,
534530
R"({"type":%u,"fidx":"0x%x","sp":%d,"fp":%d,"block_key":"%p", "ra":"%p"}%s)",
535531
f->block->block_type, f->block->fidx, f->sp, f->fp, block_key,
536532
static_cast<void *>(f->ra_ptr), (i < m->csp) ? "," : "");
@@ -541,13 +537,13 @@ void Debugger::woodDump(Module *m) {
541537
dprintf(this->socket, "],\"globals\":[");
542538
for (uint32_t i = 0; i < m->global_count; i++) {
543539
auto v = m->globals + i;
544-
printValue(v, i, i == (m->global_count - 1));
540+
printValue(v, i, i == (m->global_count - 1));
545541
}
546542
dprintf(this->socket, "]"); // closing globals
547543

548544
// printf("asked for table\n");
549545
dprintf(this->socket, ",\"table\":{\"max\":%d, \"init\":%d, \"elements\":[",
550-
m->table.maximum, m->table.initial);
546+
m->table.maximum, m->table.initial);
551547

552548
write(this->socket, m->table.entries, sizeof(uint32_t) * m->table.size);
553549
dprintf(this->socket, "]}"); // closing table
@@ -556,15 +552,16 @@ void Debugger::woodDump(Module *m) {
556552
// memory
557553
uint32_t total_elems =
558554
m->memory.pages * (uint32_t)PAGE_SIZE; // TODO debug PAGE_SIZE
559-
dprintf(this->socket, ",\"memory\":{\"pages\":%d,\"max\":%d,\"init\":%d,\"bytes\":[",
560-
m->memory.pages, m->memory.maximum, m->memory.initial);
555+
dprintf(this->socket,
556+
",\"memory\":{\"pages\":%d,\"max\":%d,\"init\":%d,\"bytes\":[",
557+
m->memory.pages, m->memory.maximum, m->memory.initial);
561558

562559
write(this->socket, m->memory.bytes, total_elems * sizeof(uint8_t));
563560
dprintf(this->socket, "]}"); // closing memory
564561

565-
566562
// printf("asked for br_table\n");
567-
dprintf(this->socket, ",\"br_table\":{\"size\":\"0x%x\",\"labels\":[", BR_TABLE_SIZE);
563+
dprintf(this->socket, ",\"br_table\":{\"size\":\"0x%x\",\"labels\":[",
564+
BR_TABLE_SIZE);
568565
write(this->socket, m->br_table, BR_TABLE_SIZE * sizeof(uint32_t));
569566
dprintf(this->socket, "]}}\n");
570567
}
@@ -648,10 +645,10 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
648645
debug("max %d init %d current page %d\n", m->memory.maximum,
649646
m->memory.initial, pages);
650647
printf("max %d init %d current page %d\n", m->memory.maximum,
651-
m->memory.initial, pages);
648+
m->memory.initial, pages);
652649
// if(pages !=m->memory.pages){
653650
// if(m->memory.pages !=0)
654-
if(m->memory.bytes != nullptr){
651+
if (m->memory.bytes != nullptr) {
655652
free(m->memory.bytes);
656653
}
657654
m->memory.bytes =
@@ -725,10 +722,11 @@ bool Debugger::saveState(Module *m, uint8_t *interruptData) {
725722
printf("non function block\n");
726723
uint8_t *block_key =
727724
(uint8_t *)readPointer(&program_state);
728-
/* printf("block_key=%p\n", static_cast<void *>(block_key)); */
725+
/* printf("block_key=%p\n", static_cast<void
726+
* *>(block_key)); */
729727
f->block = m->block_lookup[block_key];
730-
if(f->block == nullptr){
731-
FATAL("block_lookup cannot be nullptr\n");
728+
if (f->block == nullptr) {
729+
FATAL("block_lookup cannot be nullptr\n");
732730
}
733731
}
734732
}

src/Debug/debugger.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ class Debugger {
7171

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

74-
75-
//WOOD
74+
// WOOD
7675
bool receivingData = false;
77-
void freeState(Module *m, uint8_t * interruptData);
76+
void freeState(Module *m, uint8_t *interruptData);
7877
uint8_t *findOpcode(Module *m, Block *block);
7978
bool saveState(Module *m, uint8_t *interruptData);
8079
uintptr_t readPointer(uint8_t **data);
8180

82-
8381
public:
8482
int socket;
8583

@@ -104,7 +102,7 @@ class Debugger {
104102
void deleteBreakpoint(uint8_t *loc);
105103

106104
bool isBreakpoint(uint8_t *loc);
107-
105+
108106
// WOOD
109107
void woodDump(Module *m);
110108
};

src/Utils/util.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ double wa_fmin(double a, double b) {
162162
return c;
163163
}
164164

165-
166-
//WOOD
165+
// WOOD
167166
uint32_t read_B32(uint8_t **bytes) {
168167
uint8_t *b = *bytes;
169168
uint32_t n = (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + b[3];

src/Utils/util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ double wa_fmax(double a, double b);
6767

6868
double wa_fmin(double a, double b);
6969

70-
//WOOD
70+
// WOOD
7171
uint32_t read_B32(uint8_t **bytes);
7272
uint16_t read_B16(uint8_t **bytes);
7373
int read_B32_signed(uint8_t **bytes);

0 commit comments

Comments
 (0)