News for hackers. Stuff that matters.
Re:std::source_location Is Broken by tomasGiden on Thursday November 16, 2023 @03:11PM (#38294804)
Regarding the problem of strings in embedded, I once did a pretty nifty thing in a logging framework I built for an embedded system in an elevator (Cortex M0 I think it was) with very little flash for the binary and for logging. I had a logging macro which took in a string to log together with some arguments (like printf). The macro expanded to add an attribute to the string constant to put it in a special section I created with a linker script. Then in the macro what it actually logged was the memory offset in the section together with the arguments. So that way the log was extremely slim. As an extra bonus, I then stripped the special section with the strings from the binary and had an offline script translate the logged memory offsets and attributes to strings.
Re:std::source_location Is Broken by thrtythreeforty on Thursday November 16, 2023 @03:57PM (#38295398)
Google's embedded library Pigweed [1] industrializes exactly this approach and has some unholy macro nonsense to make the string hashing work in pure C as well.

[1]: https://pigweed.dev/pw_log_tokenized/

Re:std::source_location Is Broken by dale_glass on Thursday November 16, 2023 @05:53PM (#38296813)
Out of curiosity, why would you have to be so efficient in an elevator?

An elevator I imagine costs big $$$, has no lack of power, and plenty room for electronics.

Re:std::source_location Is Broken by ska on Thursday November 16, 2023 @07:20PM (#38297588)
Ask the hardware team to do a board rev just so it is easier for you to log, and see how much traction you get...

This seems like a pretty niche problem to have though.

Re:std::source_location Is Broken by sapling-ginger on Friday November 17, 2023 @02:54AM (#38300743)
Same reason a top of the line PC tower still has crappy stamped metal frame and crappy injection molded plastic trims.

The main contractor of the elevator unit is a mechanical engineering company, they contract out the control unit to the lowest bidder.

Re:std::source_location Is Broken by tomasGiden on Friday November 17, 2023 @05:15PM (#38311219)
Nope. This was all in house. But we are talking at home lifts for the rich and lazy (and sometimes elderly). And there was quite a bit of electronics in it with processors at each floor, on the control panel and for the motor controller and so on. So the cost added up. But yeah, I agree, some more flash would have been worth it.
Re:std::source_location Is Broken by stockhorn on Friday November 17, 2023 @02:08AM (#38300469)
Defmt is a rust library that does exactly this. This has become almost a standard in embedded rust.

There is even a c++ client-side implementation: https://github.com/Javier-varez/Postform/

...which uses macros for logging ;)