Describe the bug
Since #43520 was merged (specifically the changes to include/zephyr/logging/log_msg2.h, ping @nordic-krch), logged strings that are not in read-only memory are no longer correctly duplicated and preserved for deferred output... in some cases... (🤯)
If the following conditions are met, you will expose the issue: (there may be others)
- The string variable is declared
uint8_t * or uint8_t []
- One or more calls to
LOG_*(), where it needs to duplicate more than one string between log flushes
This patch to samples/subsys/logging/logger will demonstrate the issue: 0001-demo-string-handling-bug.zip
I have removed the call to log_strdup() as A) it should be unnecessary, B) it's return type is char *, so you'll need to introduce a cast to see the issue, which isn't as clear.
To prevent the issue from occurring, you can take one of the following actions:
This is demonstrable on a SAMR34 XPro that I've recently added support for (see #41308), and the qemu_cortex_m0 target... though I expect others would exhibit the issue too - possibly restricted to ARM / Cortex-M0, but I doubt it.
Expected behavior
Log output should appear as follows:
String logging showcase.
demo_tag [00:00:01.356,077] <inf> main: Logging transient string:transient_string
String logging showcase #2.
demo_tag [00:00:01.356,178] <inf> main: Logging transient string:transient_string2
Log output actually shows:
String logging showcase.
demo_tag [00:00:01.356,078] <inf> main: Logging transient string:transient_string2
String logging showcase #2.
demo_tag [00:00:01.356,162] <inf> main: Logging transient string:transient_string2
Swapping the log_strdup_showcase2() call for a second log_strdup_showcase() results in the following (no text shown here, can be garbage).
String logging showcase.
demo_tag [00:00:01.356,078] <inf> main: Logging transient string:
String logging showcase.
demo_tag [00:00:01.356,160] <inf> main: Logging transient string:
Impact
I've spent quite a bit of time tracking this down... I going forwards I can make sure to use char *, but I suspect others will bump into this before long.
Environment (please complete the following information):
Describe the bug
Since #43520 was merged (specifically the changes to
include/zephyr/logging/log_msg2.h, ping @nordic-krch), logged strings that are not in read-only memory are no longer correctly duplicated and preserved for deferred output... in some cases... (🤯)If the following conditions are met, you will expose the issue: (there may be others)
uint8_t *oruint8_t []LOG_*(), where it needs to duplicate more than one string between log flushesThis patch to
samples/subsys/logging/loggerwill demonstrate the issue: 0001-demo-string-handling-bug.zipI have removed the call to
log_strdup()as A) it should be unnecessary, B) it's return type ischar *, so you'll need to introduce a cast to see the issue, which isn't as clear.To prevent the issue from occurring, you can take one of the following actions:
char [], or cast thetransient_strparameter toLOG_INF()- in one or both locationswait_on_log_flushed()between calls tolog_strdup_showcase()andlog_strdup_showcase2()log_msg2.hintroduced by Logging: Add support to new cbprintf packaging features #43520 (patch: 0001-revert-changes-from-b98f8e3.zip)This is demonstrable on a SAMR34 XPro that I've recently added support for (see #41308), and the
qemu_cortex_m0target... though I expect others would exhibit the issue too - possibly restricted to ARM / Cortex-M0, but I doubt it.Expected behavior
Log output should appear as follows:
Log output actually shows:
Swapping the
log_strdup_showcase2()call for a secondlog_strdup_showcase()results in the following (no text shown here, can be garbage).Impact
I've spent quite a bit of time tracking this down... I going forwards I can make sure to use
char *, but I suspect others will bump into this before long.Environment (please complete the following information):
2d97bddor9e04273(from Add support for Atmel SAML21, SAMR34, SAMR35 parts #41308)