-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging: transient strings are no longer duplicated correctly #44996
Comments
Further example: (following on from the patch above) static void log_strdup_showcase(void)
{
uint8_t transient_str[] = "transient_string";
uint8_t transient_str3[] = "transient_string3";
printk("String logging showcase.\n");
LOG_INF("Logging transient string:%s/%s/test", transient_str, transient_str3);
/* Overwrite transient string to show that the logger has a copy. */
transient_str[0] = '\0';
}
static void log_strdup_showcase2(void)
{
uint8_t transient_str[] = "transient_string2";
printk("String logging showcase #2.\n");
LOG_INF("Logging transient string:%s", transient_str);
/* Overwrite transient string to show that the logger has a copy. */
transient_str[0] = '\0';
} The first
Swapping all three
|
The trick is that now logging is able to parse a string and prepare a package without looking into string literal (it will be possible to not include string literals in the binary in the future if not needed be the backend). To achieve that it relies on argument types thus it cannot interpret It is a bit tricky but i wil try to handle that. Hopefully, I will come back with something in few days. |
Intriguing - I'd love to hear more about it, not sure I'm fully following at the moment. Thanks for looking in to it either way! |
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
I'd suggest keeping this issue open, as it can cause a lot of confusion... |
It is very surprising and kills a lot of code of users, which are not aware of that fine detail, that the type "char *" must be used. What's with "const char*"? Even that may be based on a mutable string and the const may only be the constraint for the processing function. |
|
Thanks for confirming. I would appreciate, if such an "advanced" solution is documented in proper way. What I found: That explains a lot for v1. And for v2: "String arguments are handled by Cbprintf Packaging thus no special action is required." thus no special action is required is misleading, because the type of the pointer is considered. Also the link to One additional question: |
PS2 GPIO: Added initial structure PS2 GPIO: Added interrupt handler and pin reading/writing helper functions PS2 GPIO: Added reading mode PS2 GPIO: Add zephyr PS2 API support for callback and read function PS2 GPIO: Fix reading not working with real PS2 device PS2 GPIO: Added write with separate edge rising callback PS2 GPIO: Made single interrupt handler PS2 GPIO: Switch to inactive and falling handler only PS2 GPIO: Switch back to edge falling PS2 GPIO: Working without writing PS2 GPIO: Enable both edges (working) PS2 GPIO: Somewhat working write PS2 GPIO: Write with ack working, but read always wrong stop bit PS2 GPIO: Cleanup code PS2 GPIO: Fix write not working by increasing clock holding time PS2 GPIO: Adde scl clock timeout for reads PS2 GPIO: Add scl clock timeout for writes PS2 GPIO: Moved pin config into separate functions (not working) PS2 GPIO: Make read work by removing some logging PS2 GPIO: Fixed memory issue with fifo PS2 GPIO: Kind of working sometimes except for ack bit PS2 GPIO: Working without ack PS2 GPIO: Fix crash: Disable resend command in read abort PS2 GPIO: Make write work (But next read fails) PS2 GPIO: PS2 GPIO: I think the next read fails because we swallow the first 0 bit when reading the ack. PS2 GPIO: Disable logging go speed up processing PS2 GPIO: Made writing mostly work; read afterwards inconsistent PS2 GPIO: Added post write debug log PS2 GPIO: Improved post-write reading success rate PS2 GPIO: Adjust timings PS2 GPIO: Added logging of time between interrupts PS2 GPIO: Instead of sleep() for write line inhibition, do delayable work PS2 GPIO: Compensate for missing stop bit in read when it happens directly after write PS2 GPIO: Adding interrupt logging PS2 GPIO: Fix set_scl() setting sda and set_sda() setting scl PS2 GPIO: Make interrupt logging work for sends PS2 GPIO: PS2 GPIO: Add interrupt logging to read functions PS2 GPIO: Add ability to disable interrupt callback during write inhibition phase PS2 GPIO: Rename inhibit slc duration config option PS2 GPIO: PS2 GPIO: Add missing inhibit setting rename PS2 GPIO: Improve handling of spurious interrupts after writing better PS2 GPIO: PS2 GPIO: Adjust scl timeouts PS2 GPIO: Added logging helper PS2 GPIO: PS2 GPIO: Logging helper PS2 GPIO: Start fixing original write functions PS2 GPIO: Cleanup read code PS2 GPIO: Cleanup write code PS2 GPIO: Adjust read/write scl timeouts PS2 GPIO: Disable logger PS2 GPIO: Add custom interrupt logging PS2 GPIO: Enable interrupt logger PS2 GPIO: Added separate write scl timeout for the first clock PS2 GPIO: Fix running out of memory due to read queue PS2 GPIO: Allow disabling of interrupt logs PS2 GPIO: Improve logging and comments PS2 GPIO: Removed old interrupt code PS2 GPIO: PS2 GPIO: interrupt stuff PS2 GPIO: PS2 GPIO: x PS 2 Mouse: Add initial mouse driver for testing PS2 driver PS2 GPIO: Add ps2 device to callback PS2 Mouse: Added initial mouse movement cmd parsing PS2 Mouse: Added actual mouse movement PS2 Mouse: PS2 Mouse: Inverted y for zmk as that is what zmk thinks is up PS2 Mouse: PS2 Mouse: comm PS2 Mouse: Changed config options to match zmk mouse naming PS2 Mouse: Added options to invert x and y mouse movements PS2 Mouse: Rename mouse movement to mouse activity PS2 Mouse: Added mouse button support PS2 GPIO: Small cleanup PS2 GPIO: Move interrupt logging around PS2 GPIO: Added write re-try on fail PS2 GPIO: Initial attempt at write await response (not working) PS2 GPIO: Revert "Initial attempt at write await response (not working)" PS2 GPIO: PS2 GPIO: This reverts commit 6e77047ba8f8537e076f3a583d03c6222874998c. PS2 GPIO: Added reason do abort_read() PS2 GPIO: Disable resend on read failure for debugging PS2 GPIO: Initialize current write byte PS2 GPIO: Added max read retry PS2 GPIO: Disable log interrupt PS2 GPIO: Made timings based on ps2 protocol defines PS2 GPIO: PS2 GPIO: Move settings PS2 GPIO: Added write_byte_await_response() PS2 GPIO: Fix write retry incorrect retry number log PS2 Mouse: Sort defines PS2 Mouse: Improve init sequence PS2 Mouse: Removed unneeded stream mode enabling command PS2 GPIO: Make no response in write_byte_await_response an failure PS2 Mouse: During init send reset command on every 4th attempt PS2 Mouse: Add sample rate setting support PS2 Mouse: Start use mouse events for movements PS2 GPIO: Change most logging to debug PS2 Mouse: Change logs from inf to dbg PS2 Mouse: Experiment with different mouse movement methods PS2 Mouse: Report mouse activity through timer instead of as it arrives. PS2 Mouse: Use zmk log level instead of ps2 PS2 GPIO: Moved retry logic into separate function that also resends on error resp from device PS2 GPIO: PS2 GPIO: Enable retry send for ps2 interface PS2 GPIO: PS2 GPIO: Fix write failure error code PS2 GPIO: Cleanup write code slightly PS2 GPIO: Disable interrupt logging PS2 GPIO: Use just one function for parity checking PS2 GPIO: Small cleanup of read and write PS2 GPIO: PS2 GPIO: Small comment improvement PS2 GPIO: In read_interrupt, moved data bits to a more logical position PS2 GPIO: PS2 GPIO: Read interrupt fix PS2 GPIO: Call zephyr PS2 callback from a worker PS2 GPIO: Remove unneeded gpio config flags PS2 GPIO: Allow to enable and disable interrupt log through kconfig PS2 Mouse: Re-enable resend request due to packet misalignment PS2 Mouse: Parse cmd buffer using a struct instead of pointers PS2 Mouse: Cleanup and improve documentation PS2 Mouse: Silence error on read data queue timeout PS2 Mouse: Improved init sequence PS2 Mouse: Move init functions around PS2 Mouse: Added scroll mode PS2 Mouse: Make scroll mode configurable PS2 Mouse: Added functions to incr and decr sampling rate PS2 GPIO: Update blocking timeout for retry changes PS2 GPIO: Increased timeout for write_byte_await_response() PS2 GPIO: Added custom work queue PS2 Mouse: Added mouse settings behavior (with queue) PS2 Mouse: Removed queue from mouse setting behavior PS2 Mouse: PS2 Mouse: A queue was added to the ps2 gpio driver itself. So there is no need for it here anymore. PS2 GPIO: Don’t log error on timed out ps2_read() PS2 Mouse: Added reset-on-power function for trackpoints PS2 Mouse: Add command to check if device is trackpoint PS2 Mouse: Added send_cmd function that can send multibyte commands and read response PS2 Mouse: Added trackpoint press to select and sensitivity setting PS2 Mouse: Add config option for tap to select PS2 Mouse: Fixed power-on-reset PS2 Mouse: Add trackpoint swap xy command PS2 Mouse: Add swap xy setting PS2 Mouse: Added option to invert x and y directly on the trackpoint PS2 Mouse: Added negative inertia setting PS2 Mouse: Added upper plateau speed (value6) PS2 Mouse: Added press-to-select threshold PS2 Mouse: Added keybindings for TP settings PS2 GPIO: Increased log break time PS2 GPIO: Re-enable re-send request on read error PS2 GPIO: Fix outdated comment PS2 GPIO: Reduce debug logging PS2 Mouse: Reduce logging PS2 Mouse: Added config option to disable clicking PS2 Mouse: Added config option for sampling rate PS2 GPIO: Automatically adjust BT priorities when PS2 GPIO driver is enabled PS2 Mouse: Lower default priority of NRF IRQs PS2 Mouse: Add out of alignment detection PS2 Mouse: Simplify out of alignment check PS2 GPIO: Fixed deadlock on write due to wrong wokr queue priorities PS2 GPIO: Log reason for write finish PS2 GPIO: Increase SCL timeout PS2 GPIO: Add pos to abort read logging PS2 GPIO: For writes read ack bit before interrupt logging PS2 GPIO: Fix interrupt_log_add crash PS2 GPIO: Make interrupt_log. log in background PS2 GPIO: Decrease priority for inhibition wait thread PS2 GPIO: Increase timeout for first write clock PS2 GPIO: Add argument to interrupt_log PS2 GPIO: Improve write debug logging PS2 Mouse: Improve misalignment detection by checking if there was prev movement PS2 Mouse: Fix crash caused by zephyr LOG bug due to transient strings PS2 Mouse: PS2 Mouse: zephyrproject-rtos/zephyr#44996 PS2 GPIO: Use main write function for 0xfe retry cmd PS2 GPIO: Add resend callback to gpio driver PS2 GPIO: Increase inhibition delay timer PS2 GPIO: Properly fail write if semaphore times out PS2 Mouse: Added resend callback PS2 Mouse: Fix TP incr/decrease not remembering prev value PS2 Mouse: Reset cmd buffer on misalignment PS2 Mouse: Re-enable abort on sharp movement PS2 Mouse: Fix mouse scrolling unintendedly if mouse mode is disabled PS2 Mouse: Log button presses as info PS2 GPIO: Re-enable scl interrupt on write failure PS2 GPIO: Increase write max retry PS2 Mouse: Make compatible with zephyr 3.2 update PS2 GPIO: Make compatible with zephyr 3.2 PS2 GPIO: Use new zephyr gpio_*_dt apis PS2 Mouse: Use new zephyr gpio_*_dt apis PS2 GPIO: Prevent lockout on resend by using cb worker PS2 GPIO: Add missing interrupt detection PS2 GPIO: Added write error code for semaphore timeout PS2 GPIO: Added mutex to prevent multiple threads writing at once PS2 Mouse: Treat packet overflow as mistransmission PS2 Mouse: If multiple mouse buttons are changed in one packet, treat it as mistransmission PS2 Mouse: Fix value6 functions actually setting neg inertia PS2 Mouse: Remove kconfig setting for mouse PS2 Mouse: Reordered includes PS2 Mouse: Switched tp sensitivity setting from float to int PS2 Mouse: Added setting saving and restoring PS2 Mouse: Created proper, automatic Kconfig PS2 Mouse: Reorder includes PS2 GPIO: Enable PS2 GPIO driver automatically if the devicetree node is present PS2 Mouse: Rename ps2_mouse to mouse_ps2 PS2 Mouse: Fully rename ps2_mouse to mouse_ps2 PS2 Mouse: Cleanup of mouse_ps2 function naming and order PS2 Mouse: Renamed activity cmd to packet PS2 Mouse: Removed sampling rate from being set from keypresses PS2 Mouse: Remove redudant decr/incr functions PS2 Mouse: Rename array functions PS2 Mouse: Ensure all functions have common prefix zmk_mouse_ps2 PS2 Mouse: Reduce logging PS2 GPIO: Make sure all functions have the ps2_gpio prefix PS2 UART: Added initial UART PS2 driver PS2 UART: Made uart PS2 read work PS2 UART: Refactored uart read code PS2 UART: Added parity error checking PS2 UART: Initial attempt at pincntrl switching Revert "PS2 UART: Initial attempt at pincntrl switching" This reverts commit 5538731a90031b7607f05775135385bbe14464dc. PS2 UART: Initial version of GPIO write (not working) PS2 UART: Kindoff working PS2 UART: Working PS2 UART: Small cleanup PS2 UART: Adjust timings and improve comments PS2 Mouse: Increase init priority to be after UART drivers PS2 UART: Attempt to not block interrupt (not working, worker never called) Revert "PS2 UART: Attempt to not block interrupt (not working, worker never called)" This reverts commit 6c37f9a236137cc0ca873c6ee4afef3f69eb5708. PS2 Mouse: Add config option to disable additional error mitigation Auto Layer: Add automatic layer toggling on mouse movement PS2 Mouse: Log transmission error reason PS2 UART: Check read error in received_byte PS2 UART: Added blocking write Auto Layer: Fixes Scroll Mode: Initial implementation PS2 Mouse: Auto lint code PS2 Mouse: Scroll mode improvements (uncommitted changes from 3 month ago) PS2 GPIO: Apply new auto-format to ps2_gpio PS2 UART: Apply new auto-format PS2 GPIO: Make write mutex names unique PS2 UART: Make write mutex names unique PS2 GPIO: Fix zephyr 3.5 compile errors PS2 UART: Fix zephyr 3.5 compile errors Mouse Settings & Scroll Mode: Apply new auto-formatting Mouse Settings: Silence zephyr 3.5 compile warnings PS2 Mouse: Move to zephyr 3.5 input system PS2 Mouse: Add mouse ps2 work queue PS2 Mouse: Increase err_msg buffer size for zmk_mouse_ps2_send_cmd_resp to avoid truncating PS2 UART: Attempt adding pinctrl states dynamically (unsuccessful) Revert "PS2 UART: Attempt adding pinctrl states dynamically (unsuccessful)" This reverts commit 1a2c3f6f6832a95a828675a093bef7070fbe5bac. PS2 UART: Fix zephyr 3.5 pinctrl change error the issue was that I was using the sleep pinctrl state, because I couldn't figure out how to create a custom state. And in zephyr 3.2 that worked fine, but in 3.5 it disables the sleep state if CONFIG_PM_DEVICE=n. So the state was missing. Mouse Settings & Scroll Mode: Update mouse settings and scroll mode behaviors to new labelless behavior init method PS2 Mouse: Disable restore of mouse PS2 settings Mouse Auto Layer: Added toggle delay to prevent accidental activations PS2 Mouse: Added script to generate interrupt priority overrides for zmk-config PS2 Mouse: Don’t override interrupt priorities in all zmk builds by default PS2 GPIO: Potentially fix SCL not being pulled down during write PS2 UART: Potentially fix inhibition not being done correctly PS2 Mouse: Reset device if invalid self-test result is received PS2 UART: Fix PM_DEVICE not enabling PS2 GPIO: Improve PS2 GPIO kconfig documentation PS2 UART: Lower BT interrupt priorities PS2 Mouse: Delay PS2 init sequence to give mouse time to send init data PS2 UART: Fix first write not working PS2 UART: Add debug write function PS2 UART: Disable debug write function PS2 UART: Log received bytes PS2 UART: Use delayable instead of k_busy_wait Revert "PS2 UART: Use delayable instead of k_busy_wait" Realized that this is pointless, since that’s a blocking function anyways. We need to not block in the interrupt handler rather than here. This reverts commit eee0c35793ccccf40d72742d19cc85762423a103. PS2 UART: Move scl interrupt into worker PS2 UART: Add cur write pos Revert "PS2 UART: Move scl interrupt into worker" This reverts commit ea24c68b1af0f6e4a367622829d92f380d92a27f. PS2 UART: Added async interrupt writing mode PS2 UART: Ignore framing errors for 0xfa received bytes PS2 UART: Log write and received bytes only in DBG PS2 Mouse: Remove kconfig settings that are handled by input-config PS2 Mouse: Moved sampling rate and press to select from kconfig to device tree PS2 Mouse: Log when settings were set successfully PS2 Mouse: Added devicetree settings for TP settings Correct val6 default value PS2 Mouse: Enable settings restore again PS2 Mouse: Don’t restore runtime settings if device config is present Mouse Settings: Added log and reset behavior Adjust settings log PS2 Mouse: Fix wrong type for tp press to select var PS2 Mouse: Replace kconfig enable clicking with devicetree disable clicking PS2 Mouse: Disable error mitigations by default PS2 Mouse: Moved axis options from kconfig to devicetree PS2 Mouse: Removed scroll mode behavior PS2 Mouse: Move scroll mode from kconfig to devicetree PS2 Mouse: Removed movement buffer / queue Remove butter kconfigs PS2 Mouse: Moved mouse_ps2 driver to module PS2 Mouse: Convert clicking to zephyr 3.5 input system Mouse Auto Layer: Removed it in preparation for zephyr 3.5 module PS2 UART: Fix Linking error due to missing config options if logging is disabled PS2 UART: Replace data queue fifo with message queue to get rid of heap use PS2 GPIO: Replace data queue fifo with message queue to get rid of heap use Input Listener: Added logging Auto Layer Toggle: Added initial version Auto Layer Toggle: Changed how config is retrieved Auto Layer Toggle: Adjust logging Auto Layer Toggle: Remove dependency on urob’s “Zen display & battery tweaks” That commit adds an additional parameter to the `zmk_keymap_layer_activate` function. Need to find a better way to make the code compatible whether urob is used or not. urob@5796aa0 PS2 GPIO & UART: Apply zmk auto-formatting PS2 UART, GPIO, Mouse: Make resend callback optional to allow compilation without zephyr fork PS2 Mouse & Auto Layer Toggle: Add urob compatibility option PS2 Mouse: Remove unneeded file
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/logger
will 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_str
parameter toLOG_INF()
- in one or both locationswait_on_log_flushed()
between calls tolog_strdup_showcase()
andlog_strdup_showcase2()
log_msg2.h
introduced 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_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:
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):
2d97bdd
or9e04273
(from Add support for Atmel SAML21, SAMR34, SAMR35 parts #41308)The text was updated successfully, but these errors were encountered: