Re: Logging with a string via %s
Marc Herbert
On 20 May 2019, at 00:20, pawel.dunaj@nordicsemi.no wrote: There's a violation of the "Least Astonishment" principle but it's not with the '%s'. The '%s' traditionally refers to the type of the argument only, it says nothing about memory management. I don't think LOG_ASYNC('%s', ...) or LOG(O_NONBLOCK, '%s', ... ) would surprise anyone. Confusing memory semantics with format specifiers would break not just user expectations but also tools like this: https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Common-Function-Attributes.html#index-format-function-attribute (I found an insane number of bugs with this attribute) + other static checkers trying to make C a bit more safe. BTW the current API is neither "asynchronous" nor "non-blocking" in the usual API meanings. It's not asynchronous in the usual sense because there's no callback or any other second step to know when the memory can be freed or re-used. It's not non-blocking because it always succeeds, never asks to retry with EAGAIN/EWOULDBLOCK etc. It's a "globals-only", "UFO" API like nothing else.
|
|
Re: Logging with a string via %s
pawel.dunaj@...
On Fri, May 17, 2019 at 04:24 PM, Boie, Andrew P wrote:
It has it's pros and cons. Personally I don't mind it as long as it is well understood and can be turned off. Here I totally agree. I think that formatting of strings is such a well known standard that nobody will read the fine print for a logger to see what magic may lie under its hood. I think we should either assert that %s is never used and use some other format instead (i.e. force people to check the doc at least once when they hit an error) or keep %s for in place rendering and add new format for people who want to go faster. Another thing is that assert is disabled by default so many people may never notice the problem (especially for error paths).
|
|
Re: Logging with a string via %s
Paul Sokolovsky
Hello,
On Fri, 17 May 2019 14:38:14 +0000 "lairdjm" <jamie.mccrae@lairdconnect.com> wrote: Hi,Opinions vary on that matter, some people think that the logging was actually "regressed" and not "improved". Literally, it became so advanced, smart, and sophisticated, that it goes against what most people need most of the time. Of course, we'll never know if that's true unless more people provide feedback, so thanks for posting. https://foundries.io/insights/2018/08/14/zephyr-logging-part-2/ whichI personally do conversion in that direction (printf -> LOG_x) only when I'm forced to (like, when submitting code for inclusion to Zephyr). During development, I always use printk/printf which just behave as expected. [] -- Best Regards, Paul Linaro.org | Open source software for ARM SoCs Follow Linaro: http://www.facebook.com/pages/Linaro http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog
|
|
Re: Logging with a string via %s
Paul Sokolovsky
Hello,
On Fri, 17 May 2019 14:24:41 +0000 "Boie, Andrew P" <andrew.p.boie@intel.com> wrote: For an operating system that aims to support various functionalSome people think that asynchronous logging, forced on unsuspecting users, is pretty bad idea and make bets when CONFIG_LOG_IMMEDIATE will become the default behavior again.
-- Best Regards, Paul Linaro.org | Open source software for ARM SoCs Follow Linaro: http://www.facebook.com/pages/Linaro http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog
|
|
Re: Logging with a string via %s
Marc Herbert
On 17 May 2019, at 07:24, Boie, Andrew P <andrew.p.boie@intel.com> wrote: Such a "sharp tool" should at least not look exactly like the slow but safe version used absolutely everywhere else. http://www.catb.org/~esr/writings/taouu/html/ch01s03.html#rule-surprise On the same "least astonishment" principle, I think most developers expect degraded performance when logging.
|
|
Re: Logging with a string via %s
lairdjm
Hi, I think what confused me is that I was reading about the ‘improved logging’ from this guide: https://foundries.io/insights/2018/08/14/zephyr-logging-part-2/ which doesn’t mention anything about it, I was changing old code from printf() to LOG_x() and that’s when the issue arose. Thanks, Jamie
THIS MESSAGE, ANY ATTACHMENT(S), AND THE INFORMATION CONTAINED HEREIN MAY BE PROPRIETARY TO LAIRD CONNECTIVITY, INC. AND/OR ANOTHER PARTY, AND MAY FURTHER BE INTENDED TO BE KEPT CONFIDENTIAL. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE DELETE THE EMAIL AND ANY ATTACHMENTS, AND IMMEDIATELY NOTIFY THE SENDER BY RETURN EMAIL. THIS MESSAGE AND ITS CONTENTS ARE THE PROPERTY OF LAIRD CONNECTIVITY, INC. AND MAY NOT BE REPRODUCED OR USED WITHOUT THE EXPRESS WRITTEN CONSENT OF LAIRD CONNECTIVITY, INC.
|
|
Re: Logging with a string via %s
Boie, Andrew P
For an operating system that aims to support various functional safety certifications, asynchronous rendering of %s is a terrible idea.
I think %s capability should be dropped from the logger’s format string processing and a separate API added specifically to log a C string, which makes an immediate copy.
Andrew
From: devel@... [mailto:devel@...]
On Behalf Of pawel.dunaj@...
Sent: Friday, May 17, 2019 1:16 AM To: devel@... Subject: Re: [Zephyr-devel] Logging with a string via %s
Hi,
|
|
Re: Logging with a string via %s
pawel.dunaj@...
Hi,
To optimize time of log processing message construction is deferred. For this reason you cannot use arrays that will not live long enough for logger thread to see them. In other words you can always use static arrays (like you do when calling `LOG_xyz("%s", "testme")`) but you must never pass anything from the stack (like in your example). You can enable `CONFIG_LOG_IMMEDIATE` but this will affect logging performance and does not actually tells you why the problem happened in the first place. If you need to print array declared on stack you must call ` log_strdup()` to duplicate it. Personally I am against this API and I indicated it will cause bugs as people do expect `%s` to simply output a string and they also don't read documentation for something that should just work. But at least it makes logger faster if you look from the bright side. Thanks,
|
|
Re: [NRF52840] GPIO 1 problem
pawel.dunaj@...
Hi,
NRF_GPIO_PIN_MAP will effectively change pin number from 6 to (32+6). This would be ok if you use nrfx but when you use Zephyr GPIO API you should use pin id as is. So you should write to CONFIG_GPIO_P1_DEV_NAME device using pin 6. I.e. do not use NRF_GPIO_PIN_MAP macro. Thanks,
|
|
Upcoming Event: Zephyr Project: Dev Meeting - Thu, 05/16/2019 8:00am-9:00am, Please RSVP
#cal-reminder
devel@lists.zephyrproject.org Calendar <devel@...>
Reminder: Zephyr Project: Dev Meeting When: Thursday, 16 May 2019, 8:00am to 9:00am, (GMT-07:00) America/Los Angeles Where:https://zoom.us/j/993312203 An RSVP is requested. Click here to RSVP Organizer: devel@... Description: Join Zoom Meeting
|
|
[NRF52840] GPIO 1 problem
Felipe Gabardo Gonçalves <felipe@...>
Hi, I'm trying to write a value to a GPIO port 1 on a custom board and to pca_10056 and I'm getting nothing on the output. On GPIO port 0 it works properly. My code has no secrets, I'm using blinky sample code from zephyr tag v1.13.0, and I just modified the folowing: #define LED_PORT CONFIG_GPIO_P1_DEV_NAME
#define LED NRF_GPIO_PIN_MAP(1, 6) Does anyone know where I'm doing something wrong? Thank you in advance,
|
|
Re: Logging with a string via %s
Hi,
toggle quoted messageShow quoted text
There’s also a log_strdup() API to deal with this issue. Johan
On 15 May 2019, at 14.27, Stefan Jaritz <stefan@kokoontech.com> wrote:
|
|
Re: Logging with a string via %s
lairdjm
Hi Stefan, Brilliant, didn’t think of that, all working now, thank you. Thanks, Jamie
From:
devel@... <devel@...> On Behalf Of
Stefan Jaritz via Lists.Zephyrproject.Org
Sent: 15 May 2019 12:27
To: devel@... Cc: devel@... Subject: Re: [Zephyr-devel] Logging with a string via %s
EXTERNAL EMAIL: Be careful with attachments and links. Hey Lairdjm,
Depending on you logging setup, the log of the string is done inside the " LOG_DBG" command or later. Later means, that your main function was already left and your local variables are gone = invalid. Try to add following lines at your proj.conf: This will force the logger "execute" the log function. Good luck! Stefan
On 15/05/2019 11:52, lairdjm wrote:
|
|
Re: Logging with a string via %s
Stefan Jaritz
Hey Lairdjm,
Depending on you logging setup, the log of the string is done inside the "LOG_DBG" command or later. Later means, that your main function was already left and your
local variables are gone = invalid. Try to add following lines at your proj.conf: This will force the logger "execute" the log function. Good luck! Stefan
On 15/05/2019 11:52, lairdjm wrote:
|
|
Re: Logging with a string via %s
lairdjm
> sprintf(baTmpBuf, "%s", "ffffffff"); ? Using that works fine, it just doesn’t like it when a variable is used.
THIS MESSAGE, ANY ATTACHMENT(S), AND THE INFORMATION CONTAINED HEREIN MAY BE PROPRIETARY TO LAIRD CONNECTIVITY, INC. AND/OR ANOTHER PARTY, AND MAY FURTHER BE INTENDED TO BE KEPT CONFIDENTIAL. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE DELETE THE EMAIL AND ANY ATTACHMENTS, AND IMMEDIATELY NOTIFY THE SENDER BY RETURN EMAIL. THIS MESSAGE AND ITS CONTENTS ARE THE PROPERTY OF LAIRD CONNECTIVITY, INC. AND MAY NOT BE REPRODUCED OR USED WITHOUT THE EXPRESS WRITTEN CONSENT OF LAIRD CONNECTIVITY, INC.
|
|
Re: Logging with a string via %s
"K.I.R.A.
sprintf(baTmpBuf, "%s", "ffffffff"); ? ---Original--- From: "lairdjm"<jamie.mccrae@...> Date: Wed, May 15, 2019 18:52 PM To: "devel@..."<devel@...>; Subject: [Zephyr-devel] Logging with a string via %s Hi, I’m seeing an issue whereby I am unable to log strings using LOG_DBG() and %s format, for a quick example I modified the hello world sample to enable logging and change the code to this: #define LOG_DOMAIN test_domain #include <logging/log.h> LOG_MODULE_REGISTER(LOG_DOMAIN);
void main(void) { char baTmpBuf[12]; sprintf(baTmpBuf, "ffffffff"); LOG_DBG("Test : %s", baTmpBuf);
printk("Hello World! %s\n", CONFIG_BOARD); } I expect to see “Test : ffffffff” but instead I am getting “Test : %*”, if I change the code to inefficiently log each character, e.g.: LOG_DBG("Test : %c%c%c%c%c%c%c%c", baTmpBuf[0], baTmpBuf[1], baTmpBuf[2], baTmpBuf[3], baTmpBuf[4], baTmpBuf[5], baTmpBuf[6], baTmpBuf[7]); Then I get the expected output: “Test : ffffffff”
So why is %s not outputting a string? If there a configuration option I have missed? I have tried toggling “Format strings with libc” option but it doesn’t change anything. I’m testing on an nRF52840 using the nrf52840_pca10056 board file. Thanks, THIS MESSAGE, ANY ATTACHMENT(S), AND THE INFORMATION CONTAINED HEREIN MAY BE PROPRIETARY TO LAIRD CONNECTIVITY, INC. AND/OR ANOTHER PARTY, AND MAY FURTHER BE INTENDED TO BE KEPT CONFIDENTIAL. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE DELETE THE EMAIL AND ANY ATTACHMENTS, AND IMMEDIATELY NOTIFY THE SENDER BY RETURN EMAIL. THIS MESSAGE AND ITS CONTENTS ARE THE PROPERTY OF LAIRD CONNECTIVITY, INC. AND MAY NOT BE REPRODUCED OR USED WITHOUT THE EXPRESS WRITTEN CONSENT OF LAIRD CONNECTIVITY, INC.
|
|
Logging with a string via %s
lairdjm
Hi, I’m seeing an issue whereby I am unable to log strings using LOG_DBG() and %s format, for a quick example I modified the hello world sample to enable logging and change the code to this: #define LOG_DOMAIN test_domain #include <logging/log.h> LOG_MODULE_REGISTER(LOG_DOMAIN);
void main(void) { char baTmpBuf[12]; sprintf(baTmpBuf, "ffffffff"); LOG_DBG("Test : %s", baTmpBuf);
printk("Hello World! %s\n", CONFIG_BOARD); } I expect to see “Test : ffffffff” but instead I am getting “Test : %*”, if I change the code to inefficiently log each character, e.g.: LOG_DBG("Test : %c%c%c%c%c%c%c%c", baTmpBuf[0], baTmpBuf[1], baTmpBuf[2], baTmpBuf[3], baTmpBuf[4], baTmpBuf[5], baTmpBuf[6], baTmpBuf[7]); Then I get the expected output: “Test : ffffffff”
So why is %s not outputting a string? If there a configuration option I have missed? I have tried toggling “Format strings with libc” option but it doesn’t change anything. I’m testing on an nRF52840 using the nrf52840_pca10056 board file. Thanks, THIS MESSAGE, ANY ATTACHMENT(S), AND THE INFORMATION CONTAINED HEREIN MAY BE PROPRIETARY TO LAIRD CONNECTIVITY, INC. AND/OR ANOTHER PARTY, AND MAY FURTHER BE INTENDED TO BE KEPT CONFIDENTIAL. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE DELETE THE EMAIL AND ANY ATTACHMENTS, AND IMMEDIATELY NOTIFY THE SENDER BY RETURN EMAIL. THIS MESSAGE AND ITS CONTENTS ARE THE PROPERTY OF LAIRD CONNECTIVITY, INC. AND MAY NOT BE REPRODUCED OR USED WITHOUT THE EXPRESS WRITTEN CONSENT OF LAIRD CONNECTIVITY, INC.
|
|
Re: #ble Refresh advertising data after disconnect
#ble
Hi Robert,
On 14 May 2019, at 18.18, robert.konc@controlmatik.eu wrote: In disconnect callback event I was try to update advertising data but function "bt_le_adv_update_data" return with -11 (error code).You could try using BT_LE_ADV_OPT_ONE_TIME with bt_le_adv_start(). That should ensure that the stack doesn’t automatically restart advertising after a disconnection event. Johan
|
|
Upcoming Event: Zephyr Project: APIs - Tue, 05/14/2019 9:00am-10:00am, Please RSVP
#cal-reminder
devel@lists.zephyrproject.org Calendar <devel@...>
Reminder: Zephyr Project: APIs When: Tuesday, 14 May 2019, 9:00am to 10:00am, (GMT-07:00) America/Los Angeles Where:https://zoom.us/j/177647878 An RSVP is requested. Click here to RSVP Organizer: devel@... Description: Join from PC, Mac, Linux, iOS or Android: https://zoom.us/j/177647878 Live meeting minutes: https://docs.google.com/
|
|
#ble Refresh advertising data after disconnect
#ble
robert.konc@...
In disconnect callback event I was try to update advertising data but function "bt_le_adv_update_data" return with -11 (error code).
As I understand BLE stack start to advwrise after disconnect automaticly. Is there and event or callback function that indicate this. I can not use disconnect event because this event is fired befor stack start to advertise. Any suggestion? Best regards
|
|