Skip to content

Commit 177d1f8

Browse files
committed
Other misc not really important changes
1 parent bffc0cd commit 177d1f8

File tree

7 files changed

+40
-24
lines changed

7 files changed

+40
-24
lines changed

platforms/CLI-Emulator/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ int main(int argc, const char *argv[]) {
394394

395395
// Start supervising proxy device (new thread)
396396
wac->debugger->startProxySupervisor(connection);
397+
std::this_thread::sleep_for (std::chrono::seconds(1));
398+
397399
}
398400

399401
// Start debugger (new thread)

src/Debug/debugger.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
181181
fflush(stdout);
182182

183183
printf("Interrupt: %x\n", *interruptData);
184-
this->channel->write("Interrupt: %x\n", *interruptData);
184+
//this->channel->write("Interrupt: %x\n", *interruptData);
185185

186186
long start = 0, size = 0;
187187
switch (*interruptData) {
@@ -317,6 +317,8 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
317317
this->transfer(m, interruptData);
318318
free(interruptData);
319319
this->channel->write("Transferred!\n");
320+
//this->snapshot(m);
321+
//exit(0);
320322
break;
321323
case interruptProxyCall: {
322324
this->handleProxyCall(m, program_state, interruptData + 1);
@@ -785,7 +787,7 @@ void Debugger::inspect(Module *m, const uint16_t sizeStateArray,
785787
const uint8_t *state) const {
786788
debug("asked for inspect\n");
787789
uint16_t idx = 0;
788-
auto toVA = [m](uint8_t *addr) { return toVirtualAddress(addr, m); };
790+
auto toVA = [m](uint8_t *addr) { return 0; };
789791
bool addComma = false;
790792

791793
this->channel->write("{");
@@ -1130,7 +1132,7 @@ void Debugger::load(uint8_t *bytes, Module *m) {
11301132
auto start = read_B8(&bytes);
11311133
auto limit = read_B8(&bytes);
11321134
auto total_bytes = limit - start + 1;
1133-
this->channel->write("loading into %u - %u \n", start, limit);
1135+
printf("loading into %u - %u \n", start, limit);
11341136
memcpy(m->memory.bytes + start, bytes, total_bytes);
11351137
}
11361138

@@ -1493,6 +1495,9 @@ void Debugger::sendProxyCallResult(Module *m) const {
14931495
bool Debugger::isProxy() const { return this->proxy != nullptr; }
14941496

14951497
bool Debugger::isProxied(Module *m, const uint32_t fidx) const {
1498+
if (this->supervisor == nullptr) {
1499+
printf("Has no supervisor!\n");
1500+
}
14961501
return this->supervisor != nullptr && fidx < m->import_count;
14971502
}
14981503

@@ -1695,7 +1700,7 @@ void Debugger::notifyCompleteStep(Module *m) const {
16951700
m->warduino->debugger->checkpoint(m);
16961701
}
16971702
this->channel->write("STEP!\n");
1698-
printf("STEP!\n");
1703+
//printf("STEP!\n");
16991704
}
17001705

17011706
Debugger::~Debugger() {

src/Debug/debugger.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Debugger {
125125
std::queue<uint8_t *> parsedInterrupts{};
126126
long interruptSize{};
127127
bool receivingData = false;
128-
128+
public:
129129
Proxy *proxy = nullptr; // proxy module for debugger
130130

131131
bool connected_to_proxy = false;

src/Oop/proxy_supervisor.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ void ProxySupervisor::listenToSocket() {
8585
}
8686
if (readAmount > 0) {
8787
std::string msg_str = std::string(reinterpret_cast<char *>(message));
88-
printf("msg_str = \"%s\"\n", (char*) message);
88+
//printf("msg_str = \"%s\"\n", (char*) message);
8989
while (!msg_str.empty()) {
9090
auto first_msg = msg_str.substr(0, msg_str.find('\n'));
9191
msg_str = msg_str.substr(msg_str.find('\n') + 1);
92-
printf("first_msg = \"%s\"\n", first_msg.c_str());
92+
//printf("first_msg = \"%s\"\n", first_msg.c_str());
9393

9494
try {
9595
nlohmann::basic_json<> parsed = nlohmann::json::parse(first_msg);
96-
printf("parseJSON: %s\n", parsed.dump().c_str());
96+
//printf("parseJSON: %s\n", parsed.dump().c_str());
9797

9898
if (isEvent(parsed)) {
9999
CallbackHandler::push_event(new Event(

src/Primitives/emulated.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,16 @@ std::vector<IOStateElement *> get_io_state(Module *) {
688688
return ioState;
689689
}
690690

691-
std::string get_backward(Module *m, uint32_t index) {
691+
std::string get_backward(Module *m, uint32_t fidx) {
692692
std::stringstream transfer;
693693
auto *buffer = new char[6];
694694
sprintf(buffer, "%02" PRIx8 "00%02" PRIx8, interruptTransfer, 1);
695695
delete[] buffer;
696696

697-
if (index < ALL_PRIMITIVES) {
698-
auto &primitive = primitives[index];
699-
printf("transfering for %s", primitive.name);
697+
// TODO: map fidx into primitive index
698+
if (fidx < ALL_PRIMITIVES) {
699+
auto &primitive = primitives[fidx];
700+
printf("transfering for %s\n", primitive.name);
700701
if (primitive.f_backward) {
701702
m->sp += primitive.t->param_count;
702703
auto data = primitive.f_backward(m);
@@ -713,16 +714,17 @@ std::string get_backward(Module *m, uint32_t index) {
713714
// fix length at start of 52 message
714715
// send nothing if length is 0
715716

716-
bool do_forward(Module *m, uint32_t index) {
717-
if (index < ALL_PRIMITIVES) {
718-
auto &primitive = primitives[index];
719-
printf("transfering for %s", primitive.name);
717+
bool do_forward(Module *m, uint32_t fidx) {
718+
if (fidx < ALL_PRIMITIVES) {
719+
auto &primitive = primitives[fidx];
720720
if (primitive.f_forward) {
721+
printf("transfering for %s\n", primitive.name);
721722
auto data = primitive.f_forward(m);
722723
printf("transfer built\n");
723724
WARDuino::instance()->debugger->channel->write(
724725
"%02" PRIx8 "00%02" PRIx8 "%s", interruptTransfer, 1, data);
725726
free(data);
727+
//exit(0);
726728
}
727729
} else {
728730
return false;

src/Primitives/primitives.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ void invoke_primitive(Module *m, const std::string &function_name, Ts... args) {
8181
primitive(m);
8282
}
8383

84-
bool do_forward(Module *m, uint32_t index);
84+
bool do_forward(Module *m, uint32_t fidx);
8585

86-
std::string get_backward(Module *m, uint32_t index);
86+
std::string get_backward(Module *m, uint32_t fidx);
8787

8888
#endif

src/Utils/sockets.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <cstdio>
1515
#include <cstdlib>
1616
#include <cstring>
17+
#include <thread>
1718

1819
#ifndef __ZEPHYR__
1920
// Socket Debugger Interface
@@ -35,8 +36,8 @@ int createSocketFileDescriptor() {
3536
return socket_fd;
3637
}
3738

38-
void bindSocketToAddress(int socket_fd, struct sockaddr_in address) {
39-
if (bind(socket_fd, (struct sockaddr *)&address, sizeof(address)) < 0) {
39+
void bindSocketToAddress(int socket_fd, sockaddr_in address) {
40+
if (bind(socket_fd, (sockaddr*) &address, sizeof(address)) < 0) {
4041
perror("Binding socket to address failed");
4142
exit(EXIT_FAILURE);
4243
}
@@ -136,13 +137,19 @@ void WebSocket::open() {
136137
}
137138

138139
void ClientSocket::open() {
140+
//std::this_thread::sleep_for (std::chrono::seconds(1));
139141
// bind socket to address
140142
this->fileDescriptor = createSocketFileDescriptor();
141-
struct sockaddr_in address = createAddress(this->port); // server port
142-
if (connect(this->fileDescriptor, (struct sockaddr *)&address,
143+
sockaddr_in address = createAddress(this->port); // server port
144+
int i = 0;
145+
while (connect(this->fileDescriptor, (sockaddr*) &address,
143146
sizeof(address)) < 0) {
144-
perror("Failed to connect to socket");
145-
exit(EXIT_FAILURE);
147+
perror("Failed to connect to socket, retrying...\n");
148+
std::this_thread::sleep_for (std::chrono::seconds(1));
149+
i++;
150+
if (i >= 5) {
151+
exit(EXIT_FAILURE);
152+
}
146153
}
147154

148155
this->socket = this->fileDescriptor;

0 commit comments

Comments
 (0)