log: Allow LOG_DEBUG to always enable log output
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
At present if CONFIG_LOG enabled, putting LOG_DEBUG at the top of a file (before log.h inclusion) causes _log() to be executed for every log() call, regardless of the build- or run-time logging level.
However there is no guarantee that the log record will actually be displayed. If the current log level is lower than LOGL_DEBUG then it will not be.
Add a way to signal that the log record should always be displayed and update log_passes_filters() to handle this.
---
common/log.c | 11 ++++++++--- doc/README.log | 10 ++++------ include/log.h | 16 ++++++++++++---- test/log/syslog_test.c | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-)
common/log.c +8 -3
@@ -156,16 +156,20 @@ static bool log_has_file(const char *file_list, const char *file)static bool log_passes_filters (struct log_device *ldev,struct log_rec *rec) {struct log_filter *filt; +int level = rec->level &LOGL_LEVEL_MASK ; + +if (rec->force_debug && level <=LOGL_DEBUG ) +return true;/* If there are no filters, filter on the default log level */ if (list_empty (&ldev->filter_head)) { -if (rec->level > gd->default_log_level) +if (level > gd->default_log_level)return false;return true; }list_for_each_entry (filt, &ldev->filter_head, sibling_node) { -if (rec->level > filt->max_level) +if (level > filt->max_level)continue ;if ((filt->flags &LOGFF_HAS_CAT ) && !log_has_cat (filt->cat_list, rec->cat))
@@ -208,7 +212,8 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,va_list args; rec.cat = cat; - rec.level = level; + rec.level = level &LOGL_LEVEL_MASK ; + rec.force_debug = level &LOGL_FORCE_DEBUG ; rec.file = file; rec.line = line; rec.func = func;
doc/README.log +4 -6
@@ -77,12 +77,10 @@ Sometimes it is useful to turn on logging just in one file. You can use this: #define LOG_DEBUG -to enable building in of all logging statements in a single file. Put it at -the top of the file, before any #includes. - -To actually get U-Boot to output this you need to also set the default logging -level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 (LOGL_DEBUG) or more. Otherwise -debug output is suppressed and will not be generated. +to enable building in of all debug logging statements in a single file. Put it +at the top of the file, before any #includes. This overrides any log-level +setting in U-Boot, including CONFIG_LOG_DEFAULT_LEVEL, but just for that file. +All logging statements, up to and including LOGL_DEBUG, will be displayed. Convenience functions
include/log.h +12 -4
@@ -33,6 +33,9 @@ enum log_level_t {LOGL_COUNT ,LOGL_NONE , +LOGL_LEVEL_MASK =0xf ,/* Mask for valid log levels */ +LOGL_FORCE_DEBUG =0x10 ,/* Mask to force output due to LOG_DEBUG */ +LOGL_FIRST =LOGL_EMERG , LOGL_MAX = LOGL_DEBUG_IO, };
@@ -133,7 +136,7 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,#if CONFIG_IS_ENABLED (LOG )#ifdef LOG_DEBUG -#define _LOG_DEBUG 1 +#define _LOG_DEBUG LOGL_FORCE_DEBUG#else #define _LOG_DEBUG 0#endif
@@ -141,9 +144,9 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,/* Emit a log record if the level is less that the maximum */ #define log(_cat, _level, _fmt, _args...) ({ \ int _l = _level; \ - if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \ - _log((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \ - __func__, \ + if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ + _log((enum log_category_t)(_cat), _l | _LOG_DEBUG, __FILE__, \ + __LINE__, __func__, \ pr_fmt(_fmt), ##_args); \ })#else
@@ -279,8 +282,12 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,* Memebers marked as 'allocated' are allocated (e.g. via strdup()) by the log * system. * +* TODO([email protected]): Compress this struct down a bit to reduce space, e.g. +* a single u32 for cat, level, line and force_debug +* * @cat: Category, representing a uclass or part of U-Boot * @level: Severity level, less severe is higher +* @force_debug: Force output of debug * @file: Name of file where the log record was generated (not allocated) * @line: Line number where the log record was generated * @func: Function where the log record was generated (not allocated)
@@ -289,6 +296,7 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,struct log_rec {enum log_category_t cat;enum log_level_t level; +bool force_debug;const char *file;int line;const char *func;
test/log/syslog_test.c +1 -1
@@ -276,7 +276,7 @@ static int log_test_syslog_nodebug(struct unit_test_state *uts)sandbox_eth_set_tx_handler (0 , sb_log_tx_handler);/* Used by ut_assert macros in the tx_handler */ sandbox_eth_set_priv (0 , &env); -log_debug ("testing %s\n" ,"log_debug" ); +log_content ("testing %s\n" ,"log_debug" );sandbox_eth_set_tx_handler (0 ,NULL );/* Check that the callback function was not called */ ut_assertnonnull (env.expected);
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Quoted 4 lines · Simon Glass
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat the top of a file (beforelog.hinclusion) causes_log()to be executed for everylog()call, regardless of the build- or run-time logging level.
Quoted 8 lines
However there is no guarantee that the log record will actually be displayed. If the current log level is lower than
LOGL_DEBUGthen it will not be.Add a way to signal that the log record should always be displayed and update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>
Hello Simon,
we have different debug levels:
LOGL_DEBUGLOGL_DEBUG_CONTENTLOGL_DEBUG_IO
If I understand you right, with your patch putting #define LOG_DEBUG at the top of the file enables all of these. This may be more than I want.
Wouldn't it be more flexible if we could put something like:
#define LOG_DEBUG LOGL_DEBUG
at the top of the file if we want logging up to level 7 in this file.
Best regards
Heinrich
Best regards
Quoted 137 lines
---
common/log.c | 11 ++++++++--- doc/README.log | 10 ++++------ include/log.h | 16 ++++++++++++---- test/log/syslog_test.c | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-)common/log.c +8
-3@@ -156,16 +156,20 @@ static bool log_has_file(const char *file_list, const char *file)static bool log_passes_filters (struct log_device *ldev,struct log_rec *rec) {struct log_filter *filt; +int level = rec->level &LOGL_LEVEL_MASK ; + +if (rec->force_debug && level <=LOGL_DEBUG ) +return true;/* If there are no filters, filter on the default log level */ if (list_empty (&ldev->filter_head)) { -if (rec->level > gd->default_log_level) +if (level > gd->default_log_level)return false;return true; }list_for_each_entry (filt, &ldev->filter_head, sibling_node) { -if (rec->level > filt->max_level) +if (level > filt->max_level)continue ;if ((filt->flags &LOGFF_HAS_CAT ) && !log_has_cat (filt->cat_list, rec->cat))@@ -208,7 +212,8 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,va_list args; rec.cat = cat; - rec.level = level; + rec.level = level &LOGL_LEVEL_MASK ; + rec.force_debug = level &LOGL_FORCE_DEBUG ; rec.file = file; rec.line = line; rec.func = func;doc/README.log +4
-6@@ -77,12 +77,10 @@ Sometimes it is useful to turn on logging just in one file. You can use this: #define LOG_DEBUG -to enable building in of all logging statements in a single file. Put it at -the top of the file, before any #includes. - -To actually get U-Boot to output this you need to also set the default logging -level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 (LOGL_DEBUG) or more. Otherwise -debug output is suppressed and will not be generated. +to enable building in of all debug logging statements in a single file. Put it +at the top of the file, before any #includes. This overrides any log-level +setting in U-Boot, including CONFIG_LOG_DEFAULT_LEVEL, but just for that file. +All logging statements, up to and including LOGL_DEBUG, will be displayed. Convenience functionsinclude/log.h +12
-4@@ -33,6 +33,9 @@ enum log_level_t {LOGL_COUNT ,LOGL_NONE , +LOGL_LEVEL_MASK =0xf ,/* Mask for valid log levels */ +LOGL_FORCE_DEBUG =0x10 ,/* Mask to force output due to LOG_DEBUG */ +LOGL_FIRST =LOGL_EMERG , LOGL_MAX = LOGL_DEBUG_IO, };@@ -133,7 +136,7 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,#if CONFIG_IS_ENABLED (LOG )#ifdef LOG_DEBUG -#define _LOG_DEBUG 1 +#define _LOG_DEBUG LOGL_FORCE_DEBUG#else #define _LOG_DEBUG 0#endif @@ -141,9 +144,9 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,/* Emit a log record if the level is less that the maximum */ #define log(_cat, _level, _fmt, _args...) ({ \ int _l = _level; \ - if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \ - _log((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \ - __func__, \ + if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ + _log((enum log_category_t)(_cat), _l | _LOG_DEBUG, __FILE__, \ + __LINE__, __func__, \ pr_fmt(_fmt), ##_args); \ })#else @@ -279,8 +282,12 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,* Memebers marked as 'allocated' are allocated (e.g. via strdup()) by the log * system. * +* TODO(sjg at chromium.org): Compress this struct down a bit to reduce space, e.g. +* a single u32 for cat, level, line and force_debug +* * @cat: Category, representing a uclass or part of U-Boot * @level: Severity level, less severe is higher +* @force_debug: Force output of debug * @file: Name of file where the log record was generated (not allocated) * @line: Line number where the log record was generated * @func: Function where the log record was generated (not allocated) @@ -289,6 +296,7 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,struct log_rec {enum log_category_t cat;enum log_level_t level; +bool force_debug;const char *file;int line;const char *func;test/log/syslog_test.c +1
-1@@ -276,7 +276,7 @@ static int log_test_syslog_nodebug(struct unit_test_state *uts)sandbox_eth_set_tx_handler (0 , sb_log_tx_handler);/* Used by ut_assert macros in the tx_handler */ sandbox_eth_set_priv (0 , &env); -log_debug ("testing %s\n" ,"log_debug" ); +log_content ("testing %s\n" ,"log_debug" );sandbox_eth_set_tx_handler (0 ,NULL );/* Check that the callback function was not called */ ut_assertnonnull (env.expected);
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Hi Heinrich,
Quoted 23 lines · Heinrich Schuchardt
Quoted 4 lines · Simon Glass
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat the top of a file (beforelog.hinclusion) causes_log()to be executed for everylog()call, regardless of the build- or run-time logging level.Quoted 8 lines
However there is no guarantee that the log record will actually be displayed. If the current log level is lower than
LOGL_DEBUGthen it will not be.Add a way to signal that the log record should always be displayed and update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>Hello Simon,
we have different debug levels:
LOGL_DEBUGLOGL_DEBUG_CONTENTLOGL_DEBUG_IO
Quoted 8 lines
If I understand you right, with your patch putting #define
LOG_DEBUGat the top of the file enables all of these. This may be more than I want.Wouldn't it be more flexible if we could put something like:
#define
LOG_DEBUGLOGL_DEBUGat the top of the file if we want logging up to level 7 in this file.
Actually the way I implemented it, it only enables update LOGL_DEBUG.
Certainly your idea is more flexible. I wonder if we could make the level optional, so:
#define LOG_DEBUG
means
#define LOG_DEBUG LOGL_DEBUG
Regards,
Simon
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
In reply to Simon GlassQuoted 4 lines · Simon Glass
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat the top of a file (beforelog.hinclusion) causes_log()to be executed for everylog()call, regardless of the build- or run-time logging level.
Quoted 8 lines
However there is no guarantee that the log record will actually be displayed. If the current log level is lower than
LOGL_DEBUGthen it will not be.Add a way to signal that the log record should always be displayed and update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>
This exposes an underlying problem with LOG and clang I believe:
https://gitlab.denx.de/u-boot/u-boot/-/jobs/135789
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200805/6eaf247d/attachment.sig>
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat the top of a file (beforelog.hinclusion) causes_log()to be executed for everylog()call, regardless of the build- or run-time logging level.However there is no guarantee that the log record will actually be displayed. If the current log level is lower than
LOGL_DEBUGthen it will not be.
Quoted 8 lines
Quoted 4 lines
Add a way to signal that the log record should always be displayed and update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>This exposes an underlying problem with LOG and clang I believe:
https://gitlab.denx.de/u-boot/u-boot/-/jobs/135789
include/log.h:147:44: note: expanded from macro 'log'
if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <=
_LOG_MAX_LEVEL)) \
^drivers/misc/p2sb_emul.c:197:10: error: converting the enum constant to a boolean [-Werror,-Wint-in-bool-context]
This seems to be a Clang bug. _LOG_DEBUG is not an enum:
#if CONFIG_IS_ENABLED(LOG)
#ifdef LOG_DEBUG
#define _LOG_DEBUG??????1
#else
#define _LOG_DEBUG??????0
#endif
So there seems to be a bug in the Clang you used.
Compiling with clang on Debian Bullseye does not show the problem:
make HOSTCC=clang sandbox_defconfig
make HOSTCC=clang CC=clang -j8
clang version 9.0.1-13
LLVM version 9.0.1
Which Clang version did you use?
This is the change that added the test:
https://reviews.llvm.org/D63082
-Wint-in-bool-context seems to be new in Clang 10.
All over the U-Boot code we assume that a non-zero integer is true. Do we really want to enable -Wint-in-bool-context?
Best regards
Heinrich
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Quoted 48 lines · Heinrich Schuchardt
Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat the top of a file (beforelog.hinclusion) causes_log()to be executed for everylog()call, regardless of the build- or run-time logging level.However there is no guarantee that the log record will actually be displayed. If the current log level is lower than
LOGL_DEBUGthen it will not be.Quoted 8 lines
Quoted 4 lines
Add a way to signal that the log record should always be displayed and update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>This exposes an underlying problem with LOG and clang I believe:
https://gitlab.denx.de/u-boot/u-boot/-/jobs/135789
include/log.h:147:44: note: expanded from macro 'log'if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ ^
drivers/misc/p2sb_emul.c:197:10: error: converting the enum constant to a boolean [-Werror,-Wint-in-bool-context]This seems to be a Clang bug.
_LOG_DEBUGis not an enum:#if
CONFIG_IS_ENABLED(LOG)
#ifdefLOG_DEBUG
#define _LOG_DEBUG??????1
#else
#define _LOG_DEBUG??????0
#endifSo there seems to be a bug in the Clang you used.
Compiling with clang on Debian Bullseye does not show the problem:
make HOSTCC=clang
sandbox_defconfig
make HOSTCC=clang CC=clang -j8clang version 9.0.1-13
LLVM version 9.0.1Which Clang version did you use?
Quoted 7 lines
This is the change that added the test:
https://reviews.llvm.org/D63082-Wint-in-bool-context seems to be new in Clang 10.
All over the U-Boot code we assume that a non-zero integer is true. Do we really want to enable -Wint-in-bool-context?
I'm using the official Clang 10 stable builds.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200805/dcdd3217/attachment.sig>
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Quoted 52 lines · Tom Rini
Quoted 51 lines · Heinrich Schuchardt
Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat the top of a file (beforelog.hinclusion) causes_log()to be executed for everylog()call, regardless of the build- or run-time logging level.However there is no guarantee that the log record will actually be displayed. If the current log level is lower than
LOGL_DEBUGthen it will not be.Quoted 8 lines
Quoted 4 lines
Add a way to signal that the log record should always be displayed and update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>This exposes an underlying problem with LOG and clang I believe:
https://gitlab.denx.de/u-boot/u-boot/-/jobs/135789
include/log.h:147:44: note: expanded from macro 'log'if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ ^
drivers/misc/p2sb_emul.c:197:10: error: converting the enum constant to a boolean [-Werror,-Wint-in-bool-context]This seems to be a Clang bug.
_LOG_DEBUGis not an enum:#if
CONFIG_IS_ENABLED(LOG)
#ifdefLOG_DEBUG
#define _LOG_DEBUG??????1
#else
#define _LOG_DEBUG??????0
#endifSo there seems to be a bug in the Clang you used.
Compiling with clang on Debian Bullseye does not show the problem:
make HOSTCC=clang
sandbox_defconfig
make HOSTCC=clang CC=clang -j8clang version 9.0.1-13
LLVM version 9.0.1Which Clang version did you use?
This is the change that added the test:
https://reviews.llvm.org/D63082
Quoted 7 lines
Quoted 4 lines
-Wint-in-bool-context seems to be new in Clang 10.
All over the U-Boot code we assume that a non-zero integer is true. Do we really want to enable -Wint-in-bool-context?
I'm using the official Clang 10 stable builds.
Do you really want to forbid using integers as booleans (-Wint-in-bool-context)?
Best regards
Heinrich
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Quoted 55 lines · Heinrich Schuchardt
Quoted 54 lines · Tom Rini
Quoted 53 lines · Heinrich Schuchardt
Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat the top of a file (beforelog.hinclusion) causes_log()to be executed for everylog()call, regardless of the build- or run-time logging level.However there is no guarantee that the log record will actually be displayed. If the current log level is lower than
LOGL_DEBUGthen it will not be.Quoted 8 lines
Quoted 4 lines
Add a way to signal that the log record should always be displayed and update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>This exposes an underlying problem with LOG and clang I believe:
https://gitlab.denx.de/u-boot/u-boot/-/jobs/135789
include/log.h:147:44: note: expanded from macro 'log'if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ ^
drivers/misc/p2sb_emul.c:197:10: error: converting the enum constant to a boolean [-Werror,-Wint-in-bool-context]This seems to be a Clang bug.
_LOG_DEBUGis not an enum:#if
CONFIG_IS_ENABLED(LOG)
#ifdefLOG_DEBUG
#define _LOG_DEBUG??????1
#else
#define _LOG_DEBUG??????0
#endifSo there seems to be a bug in the Clang you used.
Compiling with clang on Debian Bullseye does not show the problem:
make HOSTCC=clang
sandbox_defconfig
make HOSTCC=clang CC=clang -j8clang version 9.0.1-13
LLVM version 9.0.1Which Clang version did you use?
This is the change that added the test:
https://reviews.llvm.org/D63082-Wint-in-bool-context seems to be new in Clang 10.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
All over the U-Boot code we assume that a non-zero integer is true. Do we really want to enable -Wint-in-bool-context?
I'm using the official Clang 10 stable builds.
Do you really want to forbid using integers as booleans (-Wint-in-bool-context)?
So, interesting. The Linux kernel isn't disabling this warning. It's mentioned in two commits, one of which is "clang found a bug here", of which this is not the case. The other is more like ours:
commit 968e5170939662341242812b9c82ef51cf140a33
Author: Nathan Chancellor <[email protected]> Date: Thu Sep 26 09:22:59 2019 -0700
tracing: Fix clang -Wint-in-bool-context warnings in IF_ASSIGN macro
After r372664 in clang, the IF_ASSIGN macro causes a couple hundred warnings along the lines of:
kernel/trace/trace_output.c:1331:2: warning: converting the enum constant to a boolean [-Wint-in-bool-context] kernel/trace/trace.h:409:3: note: expanded from macro 'trace_assign_type'
IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, ^
kernel/trace/trace.h:371:14: note: expanded from macro 'IF_ASSIGN'
WARN_ON(id && (entry)->type != id); \
^
264 warnings generated.
This warning can catch issues with constructs like:
if (state == A || B)
where the developer really meant:
if (state == A || state == B)
This is currently the only occurrence of the warning in the kernel tree across defconfig, allyesconfig, allmodconfig for arm32, arm64, and x86_64. Add the implicit '!= 0' to the WARN_ON statement to fix the warnings and find potential issues in the future.
Which is like our case, and reworking the test to be explicit. I lean towards that.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200805/0edf6d54/attachment.sig>
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Hi Tom,
Quoted 106 lines · Tom Rini
Quoted 55 lines · Heinrich Schuchardt
Quoted 54 lines · Tom Rini
Quoted 53 lines · Heinrich Schuchardt
Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat the top of a file (beforelog.hinclusion) causes_log()to be executed for everylog()call, regardless of the build- or run-time logging level.However there is no guarantee that the log record will actually be displayed. If the current log level is lower than
LOGL_DEBUGthen it will not be.Quoted 8 lines
Quoted 4 lines
Add a way to signal that the log record should always be displayed and update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>This exposes an underlying problem with LOG and clang I believe:
https://gitlab.denx.de/u-boot/u-boot/-/jobs/135789
include/log.h:147:44: note: expanded from macro 'log'if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ ^
drivers/misc/p2sb_emul.c:197:10: error: converting the enum constant to a boolean [-Werror,-Wint-in-bool-context]This seems to be a Clang bug.
_LOG_DEBUGis not an enum:#if
CONFIG_IS_ENABLED(LOG)
#ifdefLOG_DEBUG
#define_LOG_DEBUG1
#else
#define_LOG_DEBUG0
#endifSo there seems to be a bug in the Clang you used.
Compiling with clang on Debian Bullseye does not show the problem:
make HOSTCC=clang
sandbox_defconfig
make HOSTCC=clang CC=clang -j8clang version 9.0.1-13
LLVM version 9.0.1Which Clang version did you use?
This is the change that added the test:
https://reviews.llvm.org/D63082-Wint-in-bool-context seems to be new in Clang 10.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
All over the U-Boot code we assume that a non-zero integer is true. Do we really want to enable -Wint-in-bool-context?
I'm using the official Clang 10 stable builds.
Do you really want to forbid using integers as booleans (-Wint-in-bool-context)?
So, interesting. The Linux kernel isn't disabling this warning. It's mentioned in two commits, one of which is "clang found a bug here", of which this is not the case. The other is more like ours:
commit968e5170939662341242812b9c82ef51cf140a33Author: Nathan Chancellor <[email protected]> Date: Thu Sep 26 09:22:59 2019 -0700tracing: Fix clang -Wint-in-bool-context warnings in
IF_ASSIGNmacroAfter r372664 in clang, the
IF_ASSIGNmacro causes a couple hundred warnings along the lines of:
kernel/trace/trace_output.c:1331:2: warning: converting the enum constant to a boolean [-Wint-in-bool-context]kernel/trace/trace.h:409:3: note: expanded from macro 'trace_assign_type'
IF_ASSIGN(var, ent, structftrace_graph_ret_entry, ^
kernel/trace/trace.h:371:14: note: expanded from macro 'IF_ASSIGN'
WARN_ON(id && (entry)->type != id); \
^
264 warnings generated.This warning can catch issues with constructs like:
if (state == A || B)
where the developer really meant:
if (state == A || state == B)
This is currently the only occurrence of the warning in the kernel tree across defconfig, allyesconfig, allmodconfig for arm32, arm64, and
x86_64. Add the implicit '!= 0' to theWARN_ONstatement to fix the warnings and find potential issues in the future.
Quoted 6 lines
Reviewed-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>Signed-off-by Steven Rostedt (VMware) <[email protected]>Which is like our case, and reworking the test to be explicit. I lean towards that.
Oh dear I really want to vote against that.
if (x)
should allow C to consider x to be a boolean. I am hitting this in Zephyr and feels like it is undoing a long-standing C feature, with major disruption, for no benefit I can detect.
Hopefully I am misunderstanding what -Wint-in-bool-context means, and it just applies to enums?
Regards,
Simon
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Quoted 118 lines · Simon Glass
Hi Tom,
Quoted 106 lines · Tom Rini
Quoted 55 lines · Heinrich Schuchardt
Quoted 54 lines · Tom Rini
Quoted 53 lines · Heinrich Schuchardt
Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat the top of a file (beforelog.hinclusion) causes_log()to be executed for everylog()call, regardless of the build- or run-time logging level.However there is no guarantee that the log record will actually be displayed. If the current log level is lower than
LOGL_DEBUGthen it will not be.Quoted 8 lines
Quoted 4 lines
Add a way to signal that the log record should always be displayed and update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>This exposes an underlying problem with LOG and clang I believe:
https://gitlab.denx.de/u-boot/u-boot/-/jobs/135789
include/log.h:147:44: note: expanded from macro 'log'if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ ^
drivers/misc/p2sb_emul.c:197:10: error: converting the enum constant to a boolean [-Werror,-Wint-in-bool-context]This seems to be a Clang bug.
_LOG_DEBUGis not an enum:#if
CONFIG_IS_ENABLED(LOG)
#ifdefLOG_DEBUG
#define_LOG_DEBUG1
#else
#define_LOG_DEBUG0
#endifSo there seems to be a bug in the Clang you used.
Compiling with clang on Debian Bullseye does not show the problem:
make HOSTCC=clang
sandbox_defconfig
make HOSTCC=clang CC=clang -j8clang version 9.0.1-13
LLVM version 9.0.1Which Clang version did you use?
This is the change that added the test:
https://reviews.llvm.org/D63082-Wint-in-bool-context seems to be new in Clang 10.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
All over the U-Boot code we assume that a non-zero integer is true. Do we really want to enable -Wint-in-bool-context?
I'm using the official Clang 10 stable builds.
Do you really want to forbid using integers as booleans (-Wint-in-bool-context)?
So, interesting. The Linux kernel isn't disabling this warning. It's mentioned in two commits, one of which is "clang found a bug here", of which this is not the case. The other is more like ours:
commit968e5170939662341242812b9c82ef51cf140a33Author: Nathan Chancellor <[email protected]> Date: Thu Sep 26 09:22:59 2019 -0700tracing: Fix clang -Wint-in-bool-context warnings in
IF_ASSIGNmacroAfter r372664 in clang, the
IF_ASSIGNmacro causes a couple hundred warnings along the lines of:
kernel/trace/trace_output.c:1331:2: warning: converting the enum constant to a boolean [-Wint-in-bool-context]kernel/trace/trace.h:409:3: note: expanded from macro 'trace_assign_type'
IF_ASSIGN(var, ent, structftrace_graph_ret_entry, ^
kernel/trace/trace.h:371:14: note: expanded from macro 'IF_ASSIGN'
WARN_ON(id && (entry)->type != id); \
^
264 warnings generated.This warning can catch issues with constructs like:
if (state == A || B)
where the developer really meant:
if (state == A || state == B)
This is currently the only occurrence of the warning in the kernel tree across defconfig, allyesconfig, allmodconfig for arm32, arm64, and
x86_64. Add the implicit '!= 0' to theWARN_ONstatement to fix the warnings and find potential issues in the future.Quoted 6 lines
Reviewed-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>Signed-off-by Steven Rostedt (VMware) <[email protected]>Which is like our case, and reworking the test to be explicit. I lean towards that.
Oh dear I really want to vote against that.
Quoted 8 lines
if (x)
should allow C to consider x to be a boolean. I am hitting this in Zephyr and feels like it is undoing a long-standing C feature, with major disruption, for no benefit I can detect.
Hopefully I am misunderstanding what -Wint-in-bool-context means, and it just applies to enums?
Yes, it's not the simple case, it's the complex case as noted in the kernel commit message. Our change I believe would be:
include/log.h +1 -1
@@ -141,7 +141,7 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,/* Emit a log record if the level is less that the maximum */ #define log(_cat, _level, _fmt, _args...) ({ \ int _l = _level; \ - if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \ + if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG == 1)) \ _log((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \ __func__, \ pr_fmt(_fmt), ##_args); \
It's not a new warning from clang (We've been on LLVM-10 since February), it's only that the logging code is now being run through it via CI.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200805/6ae0559f/attachment.sig>
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Am 5. August 2020 21:03:28 MESZ schrieb Tom Rini <[email protected]>:
Quoted 160 lines · Simon Glass
Quoted 5 lines
Hi Tom,
Quoted 2 lines · Tom Rini
On Wed, Aug 05, 2020 at 08:31:55PM +0200, Heinrich Schuchardt
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines · Tom Rini
Quoted 1 line
On Wed, Aug 05, 2020 at 02:54:05PM +0200, Heinrich Schuchardt
Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Tom Rini
Quoted 3 lines · Simon Glass
Quoted 2 lines
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat thetop of a file
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
(before
log.hinclusion) causes_log()to be executed forevery
log()Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
call, regardless of the build- or run-time logging level.
However there is no guarantee that the log record will
actually be
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
displayed. If the current log level is lower than
LOGL_DEBUGthen it will
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
not be.
Add a way to signal that the log record should always be
displayed and
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>This exposes an underlying problem with LOG and clang I
believe:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
include/log.h:147:44: note: expanded from macro 'log'if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ ^
drivers/misc/p2sb_emul.c:197:10: error: converting the enumconstant to
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
a boolean [-Werror,-Wint-in-bool-context]
This seems to be a Clang bug.
_LOG_DEBUGis not an enum:#if
CONFIG_IS_ENABLED(LOG)
#ifdefLOG_DEBUG
#define_LOG_DEBUG1
#else
#define_LOG_DEBUG0
#endifQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
So there seems to be a bug in the Clang you used.
Compiling with clang on Debian Bullseye does not show the
problem:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
make HOSTCC=clang
sandbox_defconfig
make HOSTCC=clang CC=clang -j8clang version 9.0.1-13
LLVM version 9.0.1Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Which Clang version did you use?
This is the change that added the test:
https://reviews.llvm.org/D63082-Wint-in-bool-context seems to be new in Clang 10.
All over the U-Boot code we assume that a non-zero integer is
true. Do
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
we really want to enable -Wint-in-bool-context?
I'm using the official Clang 10 stable builds.
Do you really want to forbid using integers as booleans (-Wint-in-bool-context)?
So, interesting. The Linux kernel isn't disabling this warning.
It's
Quoted 1 line
Quoted 1 line
mentioned in two commits, one of which is "clang found a bug here",
of
Quoted 6 lines
Quoted 6 lines
which this is not the case. The other is more like ours:
commit968e5170939662341242812b9c82ef51cf140a33Author: Nathan Chancellor <[email protected]> Date: Thu Sep 26 09:22:59 2019 -0700tracing: Fix clang -Wint-in-bool-context warnings in
IF_ASSIGNmacro
Quoted 2 lines
Quoted 2 lines
After r372664 in clang, the
IF_ASSIGNmacro causes a couplehundred
Quoted 3 lines
Quoted 3 lines
warnings along the lines of:
kernel/trace/trace_output.c:1331:2: warning: converting theenum
Quoted 4 lines
Quoted 4 lines
constant to a boolean [-Wint-in-bool-context]
kernel/trace/trace.h:409:3: note: expanded from macro 'trace_assign_type'
IF_ASSIGN(var, ent, struct
ftrace_graph_ret_entry,Quoted 2 lines
Quoted 2 lines
^
kernel/trace/trace.h:371:14: note: expanded from macro'
IF_ASSIGN'Quoted 6 lines
Quoted 6 lines
WARN_ON(id && (entry)->type != id); \
^
264 warnings generated.This warning can catch issues with constructs like:
Quoted 7 lines
Quoted 7 lines
if (state == A || B)
where the developer really meant:
if (state == A || state == B)
This is currently the only occurrence of the warning in the
kernel
Quoted 1 line
Quoted 1 line
tree across defconfig, allyesconfig, allmodconfig for arm32,
arm64,
Quoted 1 line
Quoted 1 line
and x86_64. Add the implicit '!= 0' to the WARN_ON statement tofix
Quoted 3 lines
Quoted 3 lines
the warnings and find potential issues in the future.
Link:
https://github.com/llvm/llvm-project/commit/28b38c277a2941e9e891b2db30652cfd962f070b
Quoted 2 lines
Quoted 2 lines
Link:
http://lkml.kernel.org/r/20190926162258.466321-1-natechancellor at gmail.com
Quoted 6 lines
Quoted 6 lines
Reviewed-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>Signed-off-by Steven Rostedt (VMware) <[email protected]>Which is like our case, and reworking the test to be explicit. I
lean
Quoted 4 lines
Quoted 1 line
towards that.
Oh dear I really want to vote against that.
Quoted 8 lines
if (x)
should allow C to consider x to be a boolean. I am hitting this in Zephyr and feels like it is undoing a long-standing C feature, with major disruption, for no benefit I can detect.
Hopefully I am misunderstanding what -Wint-in-bool-context means, and it just applies to enums?
Yes, it's not the simple case, it's the complex case as noted in the kernel commit message. Our change I believe would be:
include/log.h +0
-0
include/log.h static inline int _log_nop(enum log_category_t cat, · line 146
Quoted 7 lines
include/log.h +1
-1@@ -141,7 +141,7 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level, /* Emit a log record if the level is less that the maximum */ #define log(_cat, _level, _fmt, _args...) ({ \ int _l = _level; \ - if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \ + if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG == 1)) \
Why wouldn't we define _LOG_DEBUG as true or false? Shouldn't clang know that true is boolean?
Quoted 7 lines
include/log.h +0
-0_log((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \__func__, \ pr_fmt(_fmt), ##_args); \It's not a new warning from clang (We've been on LLVM-10 since February), it's only that the logging code is now being run through it via CI.
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Quoted 156 lines · Heinrich Schuchardt
Am 5. August 2020 21:03:28 MESZ schrieb Tom Rini <[email protected]>:
Quoted 155 lines · Simon Glass
Quoted 5 lines
Hi Tom,
Quoted 2 lines · Tom Rini
On Wed, Aug 05, 2020 at 08:31:55PM +0200, Heinrich Schuchardt
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines · Tom Rini
Quoted 1 line
On Wed, Aug 05, 2020 at 02:54:05PM +0200, Heinrich Schuchardt
Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Tom Rini
Quoted 3 lines · Simon Glass
Quoted 2 lines
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat thetop of a file
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
(before
log.hinclusion) causes_log()to be executed forevery
log()Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
call, regardless of the build- or run-time logging level.
However there is no guarantee that the log record will
actually be
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
displayed. If the current log level is lower than
LOGL_DEBUGthen it will
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
not be.
Add a way to signal that the log record should always be
displayed and
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>This exposes an underlying problem with LOG and clang I
believe:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
include/log.h:147:44: note: expanded from macro 'log'if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ ^
drivers/misc/p2sb_emul.c:197:10: error: converting the enumconstant to
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
a boolean [-Werror,-Wint-in-bool-context]
This seems to be a Clang bug.
_LOG_DEBUGis not an enum:#if
CONFIG_IS_ENABLED(LOG)
#ifdefLOG_DEBUG
#define_LOG_DEBUG1
#else
#define_LOG_DEBUG0
#endifQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
So there seems to be a bug in the Clang you used.
Compiling with clang on Debian Bullseye does not show the
problem:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
make HOSTCC=clang
sandbox_defconfig
make HOSTCC=clang CC=clang -j8clang version 9.0.1-13
LLVM version 9.0.1Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Which Clang version did you use?
This is the change that added the test:
https://reviews.llvm.org/D63082-Wint-in-bool-context seems to be new in Clang 10.
All over the U-Boot code we assume that a non-zero integer is
true. Do
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
we really want to enable -Wint-in-bool-context?
I'm using the official Clang 10 stable builds.
Do you really want to forbid using integers as booleans (-Wint-in-bool-context)?
So, interesting. The Linux kernel isn't disabling this warning.
It's
Quoted 1 line
Quoted 1 line
mentioned in two commits, one of which is "clang found a bug here",
of
Quoted 6 lines
Quoted 6 lines
which this is not the case. The other is more like ours:
commit968e5170939662341242812b9c82ef51cf140a33Author: Nathan Chancellor <[email protected]> Date: Thu Sep 26 09:22:59 2019 -0700tracing: Fix clang -Wint-in-bool-context warnings in
IF_ASSIGNmacro
Quoted 2 lines
Quoted 2 lines
After r372664 in clang, the
IF_ASSIGNmacro causes a couplehundred
Quoted 3 lines
Quoted 3 lines
warnings along the lines of:
kernel/trace/trace_output.c:1331:2: warning: converting theenum
Quoted 4 lines
Quoted 4 lines
constant to a boolean [-Wint-in-bool-context]
kernel/trace/trace.h:409:3: note: expanded from macro 'trace_assign_type'
IF_ASSIGN(var, ent, struct
ftrace_graph_ret_entry,Quoted 2 lines
Quoted 2 lines
^
kernel/trace/trace.h:371:14: note: expanded from macro'
IF_ASSIGN'Quoted 6 lines
Quoted 6 lines
WARN_ON(id && (entry)->type != id); \
^
264 warnings generated.This warning can catch issues with constructs like:
Quoted 7 lines
Quoted 7 lines
if (state == A || B)
where the developer really meant:
if (state == A || state == B)
This is currently the only occurrence of the warning in the
kernel
Quoted 1 line
Quoted 1 line
tree across defconfig, allyesconfig, allmodconfig for arm32,
arm64,
Quoted 1 line
Quoted 1 line
and x86_64. Add the implicit '!= 0' to the WARN_ON statement tofix
Quoted 3 lines
Quoted 3 lines
the warnings and find potential issues in the future.
Link:
https://github.com/llvm/llvm-project/commit/28b38c277a2941e9e891b2db30652cfd962f070b
Quoted 2 lines
Quoted 2 lines
Link:
http://lkml.kernel.org/r/20190926162258.466321-1-natechancellor at gmail.com
Quoted 6 lines
Quoted 6 lines
Reviewed-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>Signed-off-by Steven Rostedt (VMware) <[email protected]>Which is like our case, and reworking the test to be explicit. I
lean
Quoted 4 lines
Quoted 1 line
towards that.
Oh dear I really want to vote against that.
Quoted 8 lines
if (x)
should allow C to consider x to be a boolean. I am hitting this in Zephyr and feels like it is undoing a long-standing C feature, with major disruption, for no benefit I can detect.
Hopefully I am misunderstanding what -Wint-in-bool-context means, and it just applies to enums?
Yes, it's not the simple case, it's the complex case as noted in the kernel commit message. Our change I believe would be:
Quoted 14 lines
include/log.h static inline int _log_nop(enum log_category_t cat, · line 146
Quoted 12 lines
include/log.h +1
-1@@ -141,7 +141,7 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level, /* Emit a log record if the level is less that the maximum */ #define log(_cat, _level, _fmt, _args...) ({ \ int _l = _level; \ - if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \ + if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG == 1)) \Why wouldn't we define
_LOG_DEBUGas true or false? Shouldn't clang know that true is boolean?
Because I didn't think of that instead, mainly.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200805/87489458/attachment.sig>
PATCH 1/1 log: Allow LOG_DEBUG to always enable log output
Hi,
Quoted 173 lines · Tom Rini
Quoted 156 lines · Heinrich Schuchardt
Am 5. August 2020 21:03:28 MESZ schrieb Tom Rini <[email protected]>:
Quoted 155 lines · Simon Glass
Quoted 5 lines
Hi Tom,
Quoted 2 lines · Tom Rini
On Wed, Aug 05, 2020 at 08:31:55PM +0200, Heinrich Schuchardt
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines · Tom Rini
Quoted 1 line
On Wed, Aug 05, 2020 at 02:54:05PM +0200, Heinrich Schuchardt
Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Tom Rini
Quoted 3 lines · Simon Glass
Quoted 2 lines
At present if
CONFIG_LOGenabled, puttingLOG_DEBUGat thetop of a file
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
(before
log.hinclusion) causes_log()to be executed forevery
log()Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
call, regardless of the build- or run-time logging level.
However there is no guarantee that the log record will
actually be
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
displayed. If the current log level is lower than
LOGL_DEBUGthen it will
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
not be.
Add a way to signal that the log record should always be
displayed and
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
update
log_passes_filters()to handle this.Signed-off-by Simon Glass <[email protected]>This exposes an underlying problem with LOG and clang I
believe:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
include/log.h:147:44: note: expanded from macro 'log'if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \ ^
drivers/misc/p2sb_emul.c:197:10: error: converting the enumconstant to
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
a boolean [-Werror,-Wint-in-bool-context]
This seems to be a Clang bug.
_LOG_DEBUGis not an enum:#if
CONFIG_IS_ENABLED(LOG)
#ifdefLOG_DEBUG
#define_LOG_DEBUG1
#else
#define_LOG_DEBUG0
#endifQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
So there seems to be a bug in the Clang you used.
Compiling with clang on Debian Bullseye does not show the
problem:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
make HOSTCC=clang
sandbox_defconfig
make HOSTCC=clang CC=clang -j8clang version 9.0.1-13
LLVM version 9.0.1Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Which Clang version did you use?
This is the change that added the test:
https://reviews.llvm.org/D63082-Wint-in-bool-context seems to be new in Clang 10.
All over the U-Boot code we assume that a non-zero integer is
true. Do
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
we really want to enable -Wint-in-bool-context?
I'm using the official Clang 10 stable builds.
Do you really want to forbid using integers as booleans (-Wint-in-bool-context)?
So, interesting. The Linux kernel isn't disabling this warning.
It's
Quoted 1 line
Quoted 1 line
mentioned in two commits, one of which is "clang found a bug here",
of
Quoted 6 lines
Quoted 6 lines
which this is not the case. The other is more like ours:
commit968e5170939662341242812b9c82ef51cf140a33Author: Nathan Chancellor <[email protected]> Date: Thu Sep 26 09:22:59 2019 -0700tracing: Fix clang -Wint-in-bool-context warnings in
IF_ASSIGNmacro
Quoted 2 lines
Quoted 2 lines
After r372664 in clang, the
IF_ASSIGNmacro causes a couplehundred
Quoted 3 lines
Quoted 3 lines
warnings along the lines of:
kernel/trace/trace_output.c:1331:2: warning: converting theenum
Quoted 4 lines
Quoted 4 lines
constant to a boolean [-Wint-in-bool-context]
kernel/trace/trace.h:409:3: note: expanded from macro 'trace_assign_type'
IF_ASSIGN(var, ent, struct
ftrace_graph_ret_entry,Quoted 2 lines
Quoted 2 lines
^
kernel/trace/trace.h:371:14: note: expanded from macro'
IF_ASSIGN'Quoted 6 lines
Quoted 6 lines
WARN_ON(id && (entry)->type != id); \
^
264 warnings generated.This warning can catch issues with constructs like:
Quoted 7 lines
Quoted 7 lines
if (state == A || B)
where the developer really meant:
if (state == A || state == B)
This is currently the only occurrence of the warning in the
kernel
Quoted 1 line
Quoted 1 line
tree across defconfig, allyesconfig, allmodconfig for arm32,
arm64,
Quoted 1 line
Quoted 1 line
and x86_64. Add the implicit '!= 0' to the WARN_ON statement tofix
Quoted 3 lines
Quoted 3 lines
the warnings and find potential issues in the future.
Link:
https://github.com/llvm/llvm-project/commit/28b38c277a2941e9e891b2db30652cfd962f070b
Quoted 2 lines
Quoted 2 lines
Link:
http://lkml.kernel.org/r/20190926162258.466321-1-natechancellor at gmail.com
Quoted 6 lines
Quoted 6 lines
Reviewed-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>Signed-off-by Steven Rostedt (VMware) <[email protected]>Which is like our case, and reworking the test to be explicit. I
lean
Quoted 4 lines
Quoted 1 line
towards that.
Oh dear I really want to vote against that.
Quoted 8 lines
if (x)
should allow C to consider x to be a boolean. I am hitting this in Zephyr and feels like it is undoing a long-standing C feature, with major disruption, for no benefit I can detect.
Hopefully I am misunderstanding what -Wint-in-bool-context means, and it just applies to enums?
Yes, it's not the simple case, it's the complex case as noted in the kernel commit message. Our change I believe would be:
Quoted 14 lines
include/log.h static inline int _log_nop(enum log_category_t cat, · line 146
Quoted 12 lines
include/log.h +1
-1@@ -141,7 +141,7 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level, /* Emit a log record if the level is less that the maximum */ #define log(_cat, _level, _fmt, _args...) ({ \ int _l = _level; \ - if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \ + if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG == 1)) \Why wouldn't we define
_LOG_DEBUGas true or false? Shouldn't clang know that true is boolean?
Quoted 2 lines
Because I didn't think of that instead, mainly.
I've resent this patch with just this change to fix clang-10.
Regards,
Simon