Skip to content

Refactor to protobuf - #406

Draft
tolauwae wants to merge 26 commits into
mainfrom
nanopb
Draft

Refactor to protobuf#406
tolauwae wants to merge 26 commits into
mainfrom
nanopb

Conversation

@tolauwae

@tolauwae tolauwae commented Aug 18, 2026

Copy link
Copy Markdown
Member

Refactors the existing debugger API using a protobuf scheme. The new scheme his optimized for low message size.

protobuf scheme

Protobuf defines two message type enums:

  • Command: Frontend -> WARDuino
  • Notification: WARDuino -> frontend

For instance:

enum Command {
  COMMAND_RUN = 0;                 // no payload
  COMMAND_HALT = 1;                // no payload
  //...
}

Payloads are defined in protobuf as messages. For instance:

message CodeLocation {
    uint32 module_index = 1;
    uint32 program_counter = 2;
}

message Breakpoint {
    CodeLocation location = 1;
}

Debug messages are not fully encoded by protobuf, only these payload.
This means that debug messages are of this form:

[type: uint8][payload length: varint][protobuf payload]

This allows for minimal message size. Sending message looks like this:

write_byte(COMMAND_CONTINUE_FOR);
write_length(payload_size);
pb_encode(&stream, ContinueFor_fields, &message);

Which results in this message on the wire:

┌────────────┬────────────┬───────────────────────────────┐
│ type       │ length     │ encoded ContinueFor (payload) │
│ 22         │ 2          │ 08 05                         │
└────────────┴────────────┴───────────────────────────────┘

ABI improvements

@tolauwae
tolauwae force-pushed the nanopb branch 2 times, most recently from 0f826c5 to b6258dd Compare August 30, 2026 07:37
@MaartenS11

Copy link
Copy Markdown
Member

Oh wow the Zephyr binary size is actually slightly smaller than the current size on main.

Comment thread src/Debug/debugger.cpp
}

this->dumpHeapInfo(m);
void Debugger::dump(Module *m, bool) const { snapshot(m); }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes me wonder, should we still even have dump since it's the same as snapshot? Command dump and command snapshot are just the same at this point, might be good to just remove one now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, will remove

Comment thread src/Debug/debugger.cpp Outdated
}

void Debugger::checkpoint(Module *m, const bool force, const bool full) {
void Debugger::checkpoint(Module *, const bool force, const bool) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support for full seems to have gone missing here (just putting that here so we don't forget).

Comment thread src/Debug/debugger.cpp Outdated
endIdx++;
namespace {

bool decodeFrameLength(const std::vector<uint8_t> &bytes, size_t *headerSize,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have some comments/documentation of how this works.

Comment thread src/Debug/debugger.cpp Outdated
Comment on lines +544 to +550
functionBodies[update.function_index] = std::move(instructions);
Block &function = m->functions[update.function_index];
function.start_ptr = functionBodies[update.function_index].data();
function.end_ptr = function.start_ptr +
functionBodies[update.function_index].size() - 1;
function.br_ptr = function.end_ptr;
sendOperationResult(message->type, true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit strange to have functionBodies as a field in the Debugger but maybe it's used somewhere else that I'm not aware of.

@tolauwae
tolauwae force-pushed the nanopb branch 3 times, most recently from 49e9d78 to e8a4b03 Compare September 2, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants