Skip to content

Commit

Permalink
[nrf fromlist] logging: Macro cleanup to fix cpp warnings
Browse files Browse the repository at this point in the history
Cleanup to fix warnings coming from c++ compilation.

Upstream PR: zephyrproject-rtos/zephyr#34516

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
(cherry picked from commit d8076c3527331bb8887edda3f1386b1227867027)
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
  • Loading branch information
nordic-krch authored and trond-snekvik committed Apr 27, 2021
1 parent 2e6cafe commit 97cb292
Showing 1 changed file with 38 additions and 40 deletions.
78 changes: 38 additions & 40 deletions include/logging/log_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,7 @@ extern "C" {
* @param _addr Address of the element.
*/
#define LOG_CONST_ID_GET(_addr) \
Z_LOG_EVAL(\
CONFIG_LOG,\
(__log_level ? \
log_const_source_id((const struct log_source_const_data *)_addr) : \
0),\
(0)\
)
COND_CODE_1(CONFIG_LOG, ((__log_level ? log_const_source_id(_addr) : 0)), (0))

/**
* @def LOG_CURRENT_MODULE_ID
Expand All @@ -134,12 +128,7 @@ extern "C" {
* @param _addr Address of the element.
*/
#define LOG_DYNAMIC_ID_GET(_addr) \
Z_LOG_EVAL(\
CONFIG_LOG,\
(__log_level ? \
log_dynamic_source_id((struct log_source_dynamic_data *)_addr) : 0),\
(0)\
)
COND_CODE_1(CONFIG_LOG, ((__log_level ? log_dynamic_source_id(_addr) : 0)), (0))

/* Set of defines that are set to 1 if function name prefix is enabled for given level. */
#define Z_LOG_FUNC_PREFIX_1U COND_CODE_1(CONFIG_LOG_FUNC_NAME_PREFIX_ERR, (1), (0))
Expand Down Expand Up @@ -214,10 +203,10 @@ extern "C" {
} \
} while (false)

#define Z_LOG_INTERNAL(is_user_context, _level, _source, ...) do { \
#define Z_LOG_INTERNAL(is_user_context, _level, _source, _dsource, ...) do { \
uint16_t src_id = \
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
LOG_DYNAMIC_ID_GET(_source) : LOG_CONST_ID_GET(_source);\
LOG_DYNAMIC_ID_GET(_dsource) : LOG_CONST_ID_GET(_source); \
struct log_msg_ids src_level = { \
.level = _level, \
.domain_id = CONFIG_LOG_DOMAIN_ID, \
Expand Down Expand Up @@ -302,7 +291,7 @@ static inline char z_log_minimal_level_to_char(int level)
/*****************************************************************************/
/****************** Macros for standard logging ******************************/
/*****************************************************************************/
#define Z_LOG2(_level, _source, ...) do { \
#define Z_LOG2(_level, _source, _dsource, ...) do { \
if (!Z_LOG_CONST_LEVEL_CHECK(_level)) { \
break; \
} \
Expand All @@ -313,17 +302,20 @@ static inline char z_log_minimal_level_to_char(int level)
\
bool is_user_context = k_is_user_context(); \
uint32_t filters = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
((struct log_source_dynamic_data *)(void *)(_source))->filters : 0;\
(_dsource)->filters : 0;\
if (!LOG_CHECK_CTX_LVL_FILTER(is_user_context, _level, filters)) { \
break; \
} \
if (IS_ENABLED(CONFIG_LOG2)) { \
int _mode; \
void *_src = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
(void *)_dsource : (void *)_source; \
Z_LOG_MSG2_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), _mode, \
CONFIG_LOG_DOMAIN_ID, _source, _level, NULL,\
CONFIG_LOG_DOMAIN_ID, _src, _level, NULL,\
0, __VA_ARGS__); \
} else { \
Z_LOG_INTERNAL(is_user_context, _level, _source, __VA_ARGS__);\
Z_LOG_INTERNAL(is_user_context, _level, \
_source, _dsource, __VA_ARGS__);\
} \
if (false) { \
/* Arguments checker present but never evaluated.*/ \
Expand All @@ -334,27 +326,27 @@ static inline char z_log_minimal_level_to_char(int level)
} while (false)

#define Z_LOG(_level, ...) \
Z_LOG2(_level, \
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
(void *)__log_current_dynamic_data : \
(void *)__log_current_const_data, \
__VA_ARGS__)
Z_LOG2(_level, __log_current_const_data, __log_current_dynamic_data, __VA_ARGS__)

#define Z_LOG_INSTANCE(_level, _inst, ...) \
Z_LOG2(_level, Z_LOG_INST(_inst), __VA_ARGS__)

Z_LOG2(_level, \
COND_CODE_1(CONFIG_LOG_RUNTIME_FILTERING, (NULL), (Z_LOG_INST(_inst))), \
(struct log_source_dynamic_data *)COND_CODE_1( \
CONFIG_LOG_RUNTIME_FILTERING, \
(Z_LOG_INST(_inst)), (NULL)), \
__VA_ARGS__)

/*****************************************************************************/
/****************** Macros for hexdump logging *******************************/
/*****************************************************************************/
#define Z_LOG_HEXDUMP2(_level, _source, _data, _len, ...) do { \
#define Z_LOG_HEXDUMP2(_level, _source, _dsource, _data, _len, ...) do { \
const char *_str = GET_ARG_N(1, __VA_ARGS__); \
if (!Z_LOG_CONST_LEVEL_CHECK(_level)) { \
break; \
} \
bool is_user_context = k_is_user_context(); \
uint32_t filters = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
((struct log_source_dynamic_data *)(void *)(_source))->filters : 0;\
(_dsource)->filters : 0;\
\
if (IS_ENABLED(CONFIG_LOG_MINIMAL)) { \
Z_LOG_TO_PRINTK(_level, "%s", _str); \
Expand All @@ -367,8 +359,10 @@ static inline char z_log_minimal_level_to_char(int level)
} \
if (IS_ENABLED(CONFIG_LOG2)) { \
int mode; \
void *_src = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
(void *)_dsource : (void *)_source; \
Z_LOG_MSG2_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), mode, \
CONFIG_LOG_DOMAIN_ID, _source, _level, \
CONFIG_LOG_DOMAIN_ID, _src, _level, \
_data, _len, \
COND_CODE_0(NUM_VA_ARGS_LESS_1(_, ##__VA_ARGS__), \
(), \
Expand All @@ -378,7 +372,7 @@ static inline char z_log_minimal_level_to_char(int level)
} \
uint16_t src_id = \
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
LOG_DYNAMIC_ID_GET(_source) : LOG_CONST_ID_GET(_source);\
LOG_DYNAMIC_ID_GET(_dsource) : LOG_CONST_ID_GET(_source);\
struct log_msg_ids src_level = { \
.level = _level, \
.domain_id = CONFIG_LOG_DOMAIN_ID, \
Expand All @@ -395,13 +389,18 @@ static inline char z_log_minimal_level_to_char(int level)
} while (false)

#define Z_LOG_HEXDUMP(_level, _data, _length, ...) \
Z_LOG_HEXDUMP2(_level, IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
(void *)__log_current_dynamic_data : \
(void *)__log_current_const_data, \
Z_LOG_HEXDUMP2(_level, \
__log_current_const_data, \
__log_current_dynamic_data, \
_data, _length, __VA_ARGS__)

#define Z_LOG_HEXDUMP_INSTANCE(_level, _inst, _data, _length, _str) \
Z_LOG_HEXDUMP2(_level, Z_LOG_INST(_inst), _data, _length, _str)
Z_LOG_HEXDUMP2(_level, \
COND_CODE_1(CONFIG_LOG_RUNTIME_FILTERING, (NULL), (Z_LOG_INST(_inst))), \
(struct log_source_dynamic_data *)COND_CODE_1( \
CONFIG_LOG_RUNTIME_FILTERING, \
(Z_LOG_INST(_inst)), (NULL)), \
_data, _length, _str)

/*****************************************************************************/
/****************** Filtering macros *****************************************/
Expand Down Expand Up @@ -797,12 +796,11 @@ __syscall void z_log_hexdump_from_user(uint32_t src_level_val,
/******************************************************************************/
#define Z_LOG_VA(_level, _str, _valist, _argnum, _strdup_action)\
__LOG_VA(_level, \
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
(void *)__log_current_dynamic_data : \
(void *)__log_current_const_data, \
__log_current_const_data, \
__log_current_dynamic_data, \
_str, _valist, _argnum, _strdup_action)

#define __LOG_VA(_level, _source, _str, _valist, _argnum, _strdup_action) do { \
#define __LOG_VA(_level, _source, _dsource, _str, _valist, _argnum, _strdup_action) do { \
if (!Z_LOG_CONST_LEVEL_CHECK(_level)) { \
break; \
} \
Expand All @@ -813,7 +811,7 @@ __syscall void z_log_hexdump_from_user(uint32_t src_level_val,
\
bool is_user_context = k_is_user_context(); \
uint32_t filters = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
((struct log_source_dynamic_data *)(void *)(_source))->filters : 0;\
_dsource->filters : 0;\
if (!LOG_CHECK_CTX_LVL_FILTER(is_user_context, _level, filters)) { \
break; \
} \
Expand All @@ -824,7 +822,7 @@ __syscall void z_log_hexdump_from_user(uint32_t src_level_val,
} \
uint16_t _id = \
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
LOG_DYNAMIC_ID_GET(_source) : LOG_CONST_ID_GET(_source);\
LOG_DYNAMIC_ID_GET(_dsource) : LOG_CONST_ID_GET(_source);\
struct log_msg_ids src_level = { \
.level = _level, \
.domain_id = CONFIG_LOG_DOMAIN_ID, \
Expand Down

0 comments on commit 97cb292

Please sign in to comment.