howto strip trailing newline from a format string at compile-time ?

jim.cromie at gmail.com jim.cromie at gmail.com
Wed Oct 12 15:05:07 EDT 2022


hi all

So Im (always) hacking on dynamic-debug..

Ive added a 'T' flag, which causes dyndbg to send its message
to /sys/kernel/tracing/trace instead of syslog (p does that).

trouble is, pr_debug() calls almost always have a trailing newline,
and ftrace adds its own, so the tracefile has empty lines after each
pr_debug's message.


I would like to fix this in the format-string, with a macro,
and add the newline explicitly, when given originally, for the 'p'/syslog case.
While still needing an add-newline? decision,
it avoids scanning format or sprint-d bufs for the trailing newline.


ie
#define strip_trailing_newline(str) .....
#define has_trailing_newline(str) ...

theyd get used in:
#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
...
.format = strip_trailing_newline(fmt), \
.add_nl = has_trailing_newline(fmt), \

that new .add_nl bit-field might be difficult - the other flags in _ddebug
are not individual bit-fields, but I think this would have to be separate
to be initializable in the macro.  maybe no big deal.

and how to fix the 'fmt expanded 2x' problem ?



More information about the Kernelnewbies mailing list