r/rust • • 5d ago

🛠️ project Runtime debugger for embedded

Hello
I have been developing/maintaining an open source runtime debugger for embedded C/C++ for several years now. It's called Scrutiny
I've recently ported the instrumentation hook so it works with Rust and I wanted to let you guys know.

It essentially add an instrumentation hook in a firmware and let a server inspect the memory and do event catching through any peripheral (like CAN bus, Serial, TCP, etc) rather than a debug port. It works like XCP based software, FreeMaster or UcProbe (for the old timers). No need for an RTOS, baremetal interrupts is fine.

It's the kind of tool you need to do real time control to monitor the control loops without affecting them. If you're new to the concept, I've written a small introduction article here: https://embeddedrelated.com/showarticle/1781.php

Feedbacks are welcome
Cheers

17 Upvotes

10 comments sorted by

2

u/fersegv 5d ago

nice, being able to watch control loops over can without a debug probe attached is super handy. does the rust hook work with embassy or is it bare metal only for now?

1

u/pylessard 5d ago

Yes it works with embassy. You have to make the glue code between the lib and the peripheral.
I made it work locally with it, but I don't have an official demo though.

3

u/fersegv 5d ago

nice, an official embassy example would probably bring a lot of people in, that's what most new embedded rust projects use now

0

u/VantaPetal 4d ago

i've been messing with embassy lately too, hope they get it working soon

0

u/sparklingLipzz 4d ago

that embassy question tho, now i'm invested too

1

u/fersegv 4d ago

lol it's Embassy the Rust async framework for microcontrollers, not an actual embassy. reddit's translation is wild XDDD

1

u/mellissa_Taroute 4d ago

nice, debugging over CAN without halting the core is huge for motor control stuff. What's the typical flash and RAM overhead for the instrumentation hook on a baremetal target?

1

u/pylessard 4d ago

Yes. I'm an ex motor control engineer. The C++ version takes between 5k an 11k of ROM depending on the features. RAM greatly depends on the size pf the buffers allocated, but it's about 150 bytes of stack and maybe 500 bytes of storage. Detailed numbers here: https://scrutinydebugger.com/guide-optimization.html

1

u/Rhytera 5d ago

nice, live inspection over can or serial without halting the core is exactly what you want once the control loop is closed. how does the rust side find the variables, from the elf debug info or do you register them in code?

1

u/pylessard 5d ago edited 5d ago

both! Most of them comes from the debug symbols.

There is also fallback mechanism to register extra ones at runtime. They are identified with a 16bits ID and reading/writing invoke a user defined callback

the way I manage the debug info: I extract the variables in a postbuild step. It create a separate file that identify the firmware. You "install" it (a copy is made in a storage) and then as soon as you connect your device in, the server identifies the firmware and auto load the debug file.

Runtime variable works even without that debug file being installed.