1 unstable release

new 0.1.0 Apr 13, 2024

#248 in Debugging

MIT license

35KB
727 lines

cdefmt

cdefmt ("c de format", short for "c deferred formatting") is a highly efficient logging framework that targets resource-constrained devices, like microcontrollers.

Inspired by https://github.com/knurling-rs/defmt/

Setup

c

  1. Add cdefmt modifications to the linkerscript:
    1. Update/add .note.gnu.build-id section to define the necessary memory locations:
      .note.gnu.build-id : {
          PROVIDE(__cdefmt_build_id = .);
          *(.note.gnu.build-id)
      }
      
    2. Add the cdefmt metadata section to the end of the linker script (or right before /DISCARD/ if it exists):
      /* CDEFMT: log metadata section */
      .cdefmt 0 (INFO) : {
          KEEP(*(.cdefmt.init .cdefmt.init.*))
          . = . + 8;
          KEEP(*(.cdefmt .cdefmt.*))
      }
      
  2. Make sure that you compile with the following flags:
    • -g - need debugging information in order to parse log arguments.
    • -Wl,--build-id - link build-id into the binary to verify elf compatibility on init.
  3. Add the header cdefmt.h to your project.
  4. Include the header wherever you want to use it.
  5. Implement cdefmt_log in your project.
  6. Call CDEFMT_GENERATE_INIT() somewhere in your main file.
  7. Call cdefmt_init() after your logging backend is initialized and cdefmt_log can be safely called.
  8. Enjoy.

Rust

TBD

Usage

Basically cdefmt_log should store/write log into the log sink, then these bytes should be provided to the parser as-is, accompanied with the elf binary.

See:

  • stdout for generating logs.
  • stdin for parsing the logs.

License

Dependencies

~5–7.5MB
~144K SLoC