I don’t quite know how to convey this idea without an example, so you’re getting one
DEBUG_LOG("Assert message {d}, {d}", a, b);
On embedded platforms that are memory constrained, you wouldn’t want to:
- Store the template strings in device memory
- Spend device time processing the string (might remove race conditions for example)
So you come up with the following Idea:
- Store the actual template string in some metadata section that is not going to be loaded on the device, saving on memory
- In the actual implementation , instead of spending time formatting the string, just push the pointer to the string in the metadata section to a buffer, and then push the arguments to the buffer too, saving on performance
- After the execution is done dump the buffer over JTAG or some similar protocol and reconstruct the whole log on the host using the metadata from the ELF file
When it comes to implementing something like this in C like languages, it becomes a lot of hacking using the preprocessor, static variables, gnu attributes, linker scripts and maybe something else I missed.
Over the last week I was wondering what an actually good design for something like this would look like in Zig: My mental conclusion is a compile builtin providing a API like the following:
const format_pointer = @push_meta(".log_meta", .{ format: "Assert message {d} {d}" });
I am looking to hear other peoples opinions on how this type of thing could be implemented