Skip to content

🚀 Memory syncing in oop debugging #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0677022
Add dummy primitive
tolauwae Mar 20, 2024
322708e
✅ Add unit test for dummy primitive
tolauwae Mar 20, 2024
db61df7
Implement store proxy
tolauwae Mar 26, 2024
1a936ff
Fix proxy store prototype for emulator
tolauwae Mar 26, 2024
95eaed2
Fix compilation + store format
tolauwae Apr 3, 2024
3f840b9
Make `Supervisor` inherit from `Debugger`
tolauwae Apr 3, 2024
62cdd68
🧰 Fix compile warnings
tolauwae Nov 26, 2024
75d2e08
Check debug messages during blocking RFC call
tolauwae Apr 3, 2024
49f0696
🎨 Clang format
tolauwae Nov 26, 2024
cc7e442
Add missing virtual destructor
tolauwae Apr 3, 2024
cdb85cc
Fix ESP IDF compilation
tolauwae Apr 3, 2024
0a97f0d
Fix internal tests compilation
tolauwae Apr 3, 2024
dcd932c
Fix compilation
tolauwae Nov 26, 2024
557b9c5
✅ Add first unit test for out-of-place
tolauwae Nov 26, 2024
6c4a9a6
Fix local save in proxied store
tolauwae Dec 2, 2024
d0370e6
Fix compilation & `isProxied` implementation
tolauwae Dec 2, 2024
f03f5f2
fixup! ✅ Add first unit test for out-of-place
tolauwae Dec 2, 2024
8429745
Increase timeout
tolauwae Dec 3, 2024
4afbfd1
fixup! Increase timeout
tolauwae Dec 3, 2024
dfd05c3
Refactor Edward -> Oop
tolauwae Feb 6, 2025
b2309c3
fixup! Refactor Edward -> Oop
tolauwae Feb 7, 2025
972197e
Add transfer debug operation
tolauwae Feb 9, 2025
b42ae4b
Fix load for transfer operation
tolauwae Feb 9, 2025
7d57709
Add transfer to RFC call
tolauwae Feb 9, 2025
3f6d3a5
fixup! Add transfer to RFC call
tolauwae Mar 2, 2025
cda76db
Fix transfer
tolauwae Mar 2, 2025
729fd29
Split in forward and backward
tolauwae Mar 2, 2025
225e6e7
fixup! Split in forward and backward
tolauwae Mar 2, 2025
fe01282
Fix do forward in proxy
tolauwae Mar 3, 2025
7834583
Fix get backward
tolauwae Mar 3, 2025
89e7aa0
Clang format
tolauwae Mar 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ if (BUILD_EMULATOR)
src/Primitives/emulated.cpp
src/Interpreter/instructions.cpp
src/Interpreter/interpreter.cpp
src/Interpreter/proxied.cpp
src/Memory/mem.cpp
src/Utils/util.cpp
src/Utils/util_arduino.cpp
src/Utils/macros.cpp
src/Utils/sockets.cpp
src/Debug/debugger.cpp
src/Edward/proxy.cpp
src/Edward/proxy_supervisor.cpp
src/Edward/RFC.cpp
src/Oop/proxy.cpp
src/Oop/proxy_supervisor.cpp
src/Oop/RFC.cpp
src/Oop/stateful.cpp
)

add_definitions(-DINFO=0)
Expand Down Expand Up @@ -87,15 +89,17 @@ if (BUILD_UNITTEST)
src/Primitives/emulated.cpp
src/Interpreter/instructions.cpp
src/Interpreter/interpreter.cpp
src/Interpreter/proxied.cpp
src/Memory/mem.cpp
src/Utils/util.cpp
src/Utils/util_arduino.cpp
src/Utils/macros.cpp
src/Utils/sockets.cpp
src/Debug/debugger.cpp
src/Edward/proxy.cpp
src/Edward/proxy_supervisor.cpp
src/Edward/RFC.cpp
src/Oop/proxy.cpp
src/Oop/proxy_supervisor.cpp
src/Oop/RFC.cpp
src/Oop/stateful.cpp
)

# Set default compile flags for GCC
Expand Down
7 changes: 4 additions & 3 deletions platforms/ESP-IDF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ set(SOURCE_FILES
../../src/Debug/debugger.cpp
../../src/Interpreter/instructions.cpp
../../src/Interpreter/interpreter.cpp
../../src/Interpreter/proxied.cpp
../../src/Memory/mem.cpp
../../src/Primitives/idf.cpp
../../src/Edward/proxy.cpp
../../src/Edward/proxy_supervisor.cpp
../../src/Edward/RFC.cpp
../../src/Oop/proxy.cpp
../../src/Oop/proxy_supervisor.cpp
../../src/Oop/RFC.cpp
../../src/Utils/macros.cpp
../../src/Utils/sockets.cpp
../../src/Utils/util.cpp
Expand Down
6 changes: 3 additions & 3 deletions platforms/Zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ target_sources(app PRIVATE
../../src/Utils/macros.cpp
../../src/Utils/sockets.cpp
../../src/Debug/debugger.cpp
../../src/Edward/proxy.cpp
../../src/Edward/proxy_supervisor.cpp
../../src/Edward/RFC.cpp
../../src/Oop/proxy.cpp
../../src/Oop/proxy_supervisor.cpp
../../src/Oop/RFC.cpp
upload.h
)

Expand Down
61 changes: 56 additions & 5 deletions src/Debug/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../../lib/json/single_include/nlohmann/json.hpp"
#endif

#include "../Interpreter/proxied.h"
#include "../Memory/mem.h"
#include "../Primitives/primitives.h"
#include "../Utils//util.h"
Expand Down Expand Up @@ -179,6 +180,7 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
debug("received interrupt %x\n", *interruptData);
fflush(stdout);

printf("Interrupt: %x\n", *interruptData);
this->channel->write("Interrupt: %x\n", *interruptData);

long start = 0, size = 0;
Expand Down Expand Up @@ -311,6 +313,11 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
this->channel->write("%s!\n", receivingData ? "ack" : "done");
}
break;
case interruptTransfer:
this->transfer(m, interruptData);
free(interruptData);
this->channel->write("Transferred!\n");
break;
case interruptProxyCall: {
this->handleProxyCall(m, program_state, interruptData + 1);
free(interruptData);
Expand Down Expand Up @@ -362,6 +369,10 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
this->removeOverride(m, interruptData + 1);
free(interruptData);
break;
case interruptStore:
this->receiveStore(m, interruptData + 1);
free(interruptData);
break;
default:
// handle later
this->channel->write("COULD not parse interrupt data!\n");
Expand Down Expand Up @@ -449,12 +460,12 @@ void Debugger::handleInterruptRUN(const Module *m,
*program_state = WARDUINOrun;
}

void Debugger::handleSTEP(const Module *m, RunningState *program_state) {
void Debugger::handleSTEP(Module *m, RunningState *program_state) {
*program_state = WARDUINOstep;
this->skipBreakpoint = m->pc_ptr;
}

void Debugger::handleSTEPOver(const Module *m, RunningState *program_state) {
void Debugger::handleSTEPOver(Module *m, RunningState *program_state) {
this->skipBreakpoint = m->pc_ptr;
uint8_t const opcode = *m->pc_ptr;
if (opcode == 0x10) { // step over direct call
Expand Down Expand Up @@ -1115,6 +1126,31 @@ void Debugger::freeState(Module *m, uint8_t *interruptData) {
debug("done with first msg\n");
}

void Debugger::load(uint8_t *bytes, Module *m) {
auto start = read_B8(&bytes);
auto limit = read_B8(&bytes);
auto total_bytes = limit - start + 1;
this->channel->write("loading into %u - %u \n", start, limit);
memcpy(m->memory.bytes + start, bytes, total_bytes);
}

void Debugger::transfer(Module *m, uint8_t *interruptData) {
uint8_t *cursor = interruptData;
uint8_t *end = nullptr;
uint16_t len = read_B16(&(++cursor));
end = cursor + len;

while (cursor < end) {
switch (*cursor++) {
case memoryState:
load(cursor, m);
default: {
debug("do nothing\n");
}
}
}
}

bool Debugger::saveState(Module *m, uint8_t *interruptData) {
uint8_t *program_state = nullptr;
uint8_t *end_state = nullptr;
Expand Down Expand Up @@ -1413,7 +1449,12 @@ uintptr_t Debugger::readPointer(uint8_t **data) {

void Debugger::proxify() {
WARDuino::instance()->program_state = PROXYhalt;
delete WARDuino::instance()->interpreter;
WARDuino::instance()->interpreter = new Proxied();
this->proxy = new Proxy(); // TODO delete
if (this->channel) {
this->channel->write("PROXIED!\n");
}
}

void Debugger::handleProxyCall(Module *m, RunningState *,
Expand All @@ -1431,7 +1472,7 @@ void Debugger::handleProxyCall(Module *m, RunningState *,
StackValue *args = Proxy::readRFCArgs(func, data);
dbg_trace("Enqueuing callee %" PRIu32 "\n", func->fidx);

auto *rfc = new RFC(fidx, func->type, args);
auto *rfc = new RFC(m, fidx, func->type, args);
this->proxy->pushRFC(m, rfc);
}

Expand All @@ -1451,8 +1492,8 @@ void Debugger::sendProxyCallResult(Module *m) const {

bool Debugger::isProxy() const { return this->proxy != nullptr; }

bool Debugger::isProxied(const uint32_t fidx) const {
return this->supervisor != nullptr && this->supervisor->isProxied(fidx);
bool Debugger::isProxied(Module *m, const uint32_t fidx) const {
return this->supervisor != nullptr && fidx < m->import_count;
}

void Debugger::handleMonitorProxies(const Module *m,
Expand Down Expand Up @@ -1500,6 +1541,15 @@ void Debugger::updateCallbackmapping(Module *m, const char *interruptData) {
}
}

void Debugger::receiveStore(Module *m, uint8_t *interruptData) {
uint8_t *pos = interruptData;
uint32_t addr = read_LEB_32(&pos);
auto *sval = (StackValue *)malloc(sizeof(struct StackValue));
deserialiseStackValue(pos, true, sval);
m->warduino->interpreter->store(m, sval->value_type, addr, *sval);
free(sval);
}

// Stop the debugger
void Debugger::stop() {
if (this->channel != nullptr) {
Expand Down Expand Up @@ -1645,6 +1695,7 @@ void Debugger::notifyCompleteStep(Module *m) const {
m->warduino->debugger->checkpoint(m);
}
this->channel->write("STEP!\n");
printf("STEP!\n");
}

Debugger::~Debugger() {
Expand Down
21 changes: 14 additions & 7 deletions src/Debug/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include <unordered_map>
#include <vector>

#include "../Edward/proxy.h"
#include "../Edward/proxy_supervisor.h"
#include "../Oop/proxy.h"
#include "../Threading/warduino-thread.h"
#include "../Utils/sockets.h"

Expand Down Expand Up @@ -77,6 +76,9 @@ enum InterruptTypes {
// Remote REPL
interruptINVOKE = 0x40,

// Stateful out-of-place
interruptTransfer = 0x52,

// Pull Debugging
interruptSnapshot = 0x60,
interruptSetSnapshotPolicy = 0x61,
Expand All @@ -99,7 +101,6 @@ enum InterruptTypes {

// Operations
interruptStore = 0xa0,
interruptStored = 0xa1,
};

enum class SnapshotPolicy : int {
Expand All @@ -109,6 +110,8 @@ enum class SnapshotPolicy : int {
// points where primitives are used.
};

class ProxySupervisor;

class Debugger {
private:
std::deque<uint8_t *> debugMessages = {};
Expand Down Expand Up @@ -159,9 +162,9 @@ class Debugger {

void handleInterruptRUN(const Module *m, RunningState *program_state);

void handleSTEP(const Module *m, RunningState *program_state);
void handleSTEP(Module *m, RunningState *program_state);

void handleSTEPOver(const Module *m, RunningState *program_state);
void handleSTEPOver(Module *m, RunningState *program_state);

void handleInterruptBP(Module *m, uint8_t *interruptData);

Expand Down Expand Up @@ -208,11 +211,15 @@ class Debugger {

bool saveState(Module *m, uint8_t *interruptData);

void load(uint8_t *bytes, Module *m);

void transfer(Module *m, uint8_t *interruptData);

static uintptr_t readPointer(uint8_t **data);

static void updateCallbackmapping(Module *m, const char *interruptData);

bool operation(Module *m, operation op);
void receiveStore(Module *m, uint8_t *interruptData);

public:
// Public fields
Expand Down Expand Up @@ -283,7 +290,7 @@ class Debugger {

bool isProxy() const;

bool isProxied(uint32_t fidx) const;
bool isProxied(Module *m, uint32_t fidx) const;

void startProxySupervisor(Channel *socket);

Expand Down
4 changes: 0 additions & 4 deletions src/Edward/RFC.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions src/Edward/RFC.h

This file was deleted.

6 changes: 3 additions & 3 deletions src/Interpreter/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ bool proxy_call(Module *m, uint32_t fidx) {
if (type->param_count > 0) {
m->sp -= type->param_count;
StackValue *args = &m->stack[m->sp + 1];
rfc = new RFC(fidx, type, args);
rfc = new RFC(m, fidx, type, args);
} else {
rfc = new RFC(fidx, type);
rfc = new RFC(m, fidx, type);
}

if (!supervisor->call(rfc)) {
Expand Down Expand Up @@ -282,7 +282,7 @@ bool i_instr_return(Module *m) {
bool i_instr_call(Module *m) {
uint32_t fidx = read_LEB_32(&m->pc_ptr);

if (m->warduino->debugger->isProxied(fidx)) {
if (m->warduino->debugger->isProxied(m, fidx)) {
return proxy_call(m, fidx);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Interpreter/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ uint32_t STORE_SIZE[] = {4, 8, 4, 8, 1, 2, 1, 2, 4};

bool Interpreter::store(Module *m, uint8_t type, uint32_t addr,
StackValue &sval) {
if (m->warduino->debugger->isProxy()) {
return m->warduino->debugger;
}

uint8_t *maddr, *mem_end;
uint32_t size = STORE_SIZE[abs(type - I32)];
bool overflow = false;
Expand Down Expand Up @@ -474,3 +470,5 @@ void Interpreter::report_overflow([[maybe_unused]] Module *m,
m->memory.bytes + m->memory.pages * (uint32_t)PAGE_SIZE, maddr);
sprintf(exception, "out of bounds memory access");
}

Interpreter::~Interpreter() {}
5 changes: 4 additions & 1 deletion src/Interpreter/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class Interpreter {
public:
virtual ~Interpreter();

/**
* Push a new frame on to the call stack
* @param m module
Expand Down Expand Up @@ -48,7 +50,8 @@ class Interpreter {
/* Stateful operations
* ************************************************************************/

bool store(Module *m, uint8_t type, uint32_t addr, StackValue &sval);
virtual bool store(Module *m, uint8_t type, uint32_t addr,
StackValue &sval);

bool load(Module *m, uint8_t type, uint32_t addr, uint32_t offset);

Expand Down
23 changes: 23 additions & 0 deletions src/Interpreter/proxied.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "./proxied.h"

#include "../Debug/debugger.h"
#include "../Utils//util.h"

void send_leb(Channel *channel, uint32_t value, const char *end = "") {
uint8_t *buffer = write_LEB(value);
uint32_t size = size_leb(value);
for (uint32_t i = 0; i < size; ++i) {
channel->write("%02" PRIx8 "%s", buffer[i], end);
}
free(buffer);
}

bool Proxied::store(Module *m, [[maybe_unused]] uint8_t type, uint32_t addr,
StackValue &sval) {
Interpreter::store(m, type, addr, sval);
// m->warduino->debugger->channel->write("%02" PRIx8, interruptStore);
// send_leb(m->warduino->debugger->channel, addr);
// send_leb(m->warduino->debugger->channel, 0);
// send_leb(m->warduino->debugger->channel, sval.value.uint32, "\n");
return true;
}
Loading
Loading