@@ -151,7 +151,8 @@ extern "C" {
151151 * used.
152152 */
153153
154- #define Z_LOG_STR (...) "%s: " GET_ARG_N(1, __VA_ARGS__), __func__\
154+ #define Z_LOG_STR (...) "%s: " GET_ARG_N(1, __VA_ARGS__), \
155+ (const char *)__func__\
155156 COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__),\
156157 (),\
157158 (, GET_ARGS_LESS_N(1, __VA_ARGS__))\
@@ -162,7 +163,7 @@ extern "C" {
162163/****************** Internal macros for log frontend **************************/
163164/******************************************************************************/
164165/**@brief Second stage for Z_LOG_NARGS_POSTFIX */
165- #define _LOG_NARGS_POSTFIX_IMPL ( \
166+ #define Z_LOG_NARGS_POSTFIX_IMPL ( \
166167 _ignored , \
167168 _0 , _1 , _2 , _3 , _4 , _5 , _6 , _7 , _8 , _9 , _10 , \
168169 _11 , _12 , _13 , _14 , N , ...) N
@@ -176,22 +177,38 @@ extern "C" {
176177 * @retval Postfix, number of arguments or _LONG when more than 3 arguments.
177178 */
178179#define Z_LOG_NARGS_POSTFIX (...) \
179- _LOG_NARGS_POSTFIX_IMPL (__VA_ARGS__, LONG, LONG, LONG, LONG, LONG, \
180+ Z_LOG_NARGS_POSTFIX_IMPL (__VA_ARGS__, LONG, LONG, LONG, LONG, LONG, \
180181 LONG, LONG, LONG, LONG, LONG, LONG, LONG, 3, 2, 1, 0, ~)
181182
182183#define Z_LOG_INTERNAL_X (N , ...) UTIL_CAT(_LOG_INTERNAL_, N)(__VA_ARGS__)
183184
184- #define __LOG_INTERNAL (is_user_context , _src_level , ...) \
185- do { \
186- if (is_user_context) { \
187- log_from_user(_src_level, __VA_ARGS__); \
188- } else if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) { \
189- log_string_sync(_src_level, __VA_ARGS__); \
190- } else { \
191- Z_LOG_INTERNAL_X(Z_LOG_NARGS_POSTFIX(__VA_ARGS__), \
192- _src_level, __VA_ARGS__);\
193- } \
194- } while (false)
185+ #define Z_LOG_INTERNAL2 (is_user_context , _src_level , ...) do { \
186+ if (is_user_context) { \
187+ log_from_user(_src_level, __VA_ARGS__); \
188+ } else if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) { \
189+ log_string_sync(_src_level, __VA_ARGS__); \
190+ } else { \
191+ Z_LOG_INTERNAL_X(Z_LOG_NARGS_POSTFIX(__VA_ARGS__), \
192+ _src_level, __VA_ARGS__); \
193+ } \
194+ } while (false)
195+
196+ #define Z_LOG_INTERNAL (is_user_context , _level , _source , ...) do { \
197+ uint16_t src_id = \
198+ IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
199+ LOG_DYNAMIC_ID_GET(_source) : LOG_CONST_ID_GET(_source);\
200+ struct log_msg_ids src_level = { \
201+ .level = _level, \
202+ .domain_id = CONFIG_LOG_DOMAIN_ID, \
203+ .source_id = src_id \
204+ }; \
205+ if (BIT(_level) & LOG_FUNCTION_PREFIX_MASK) {\
206+ Z_LOG_INTERNAL2(is_user_context, src_level, \
207+ Z_LOG_STR(__VA_ARGS__)); \
208+ } else { \
209+ Z_LOG_INTERNAL2(is_user_context, src_level, __VA_ARGS__); \
210+ } \
211+ } while (0)
195212
196213#define _LOG_INTERNAL_0 (_src_level , _str ) \
197214 log_0(_str, _src_level)
@@ -228,9 +245,9 @@ extern "C" {
228245 ) \
229246 ))
230247
231- /****************************************************************************** /
232- /****************** Defiinitions used by minimal logging ********************** /
233- /****************************************************************************** /
248+ /*****************************************************************************/
249+ /****************** Defiinitions used by minimal logging *********************/
250+ /*****************************************************************************/
234251void z_log_minimal_hexdump_print (int level , const void * data , size_t size );
235252void z_log_minimal_vprintk (const char * fmt , va_list ap );
236253void z_log_minimal_printk (const char * fmt , ...);
@@ -256,118 +273,95 @@ static inline char z_log_minimal_level_to_char(int level)
256273 return '?' ;
257274 }
258275}
259- /******************************************************************************/
260- /****************** Macros for standard logging *******************************/
261- /******************************************************************************/
262- #define __LOG (_level , _id , _filter , ...) \
263- do { \
264- if (Z_LOG_CONST_LEVEL_CHECK(_level)) { \
265- bool is_user_context = k_is_user_context(); \
266- \
267- if (IS_ENABLED(CONFIG_LOG_MINIMAL)) { \
268- Z_LOG_TO_PRINTK(_level, __VA_ARGS__); \
269- } else if (LOG_CHECK_CTX_LVL_FILTER(is_user_context, \
270- _level, _filter)) { \
271- struct log_msg_ids src_level = { \
272- .level = _level, \
273- .domain_id = CONFIG_LOG_DOMAIN_ID, \
274- .source_id = _id \
275- }; \
276- \
277- if ((BIT(_level) & \
278- LOG_FUNCTION_PREFIX_MASK) != 0U) { \
279- __LOG_INTERNAL(is_user_context, \
280- src_level, \
281- Z_LOG_STR(__VA_ARGS__));\
282- } else { \
283- __LOG_INTERNAL(is_user_context, \
284- src_level, \
285- __VA_ARGS__); \
286- } \
287- } else { \
288- } \
289- } \
290- if (false) { \
291- /* Arguments checker present but never evaluated.*/ \
292- /* Placed here to ensure that __VA_ARGS__ are*/ \
293- /* evaluated once when log is enabled.*/ \
294- log_printf_arg_checker (__VA_ARGS__ ); \
295- } \
296- } while (false)
297-
298- #define Z_LOG (_level , ...) \
299- __LOG(_level, \
300- (uint16_t)LOG_CURRENT_MODULE_ID(), \
301- LOG_CURRENT_DYNAMIC_DATA_ADDR(), \
302- __VA_ARGS__)
276+ /*****************************************************************************/
277+ /****************** Macros for standard logging ******************************/
278+ /*****************************************************************************/
279+ #define Z_LOG2 (_level , _source , ...) do { \
280+ if (!Z_LOG_CONST_LEVEL_CHECK(_level)) { \
281+ break; \
282+ } \
283+ if (IS_ENABLED(CONFIG_LOG_MINIMAL)) { \
284+ Z_LOG_TO_PRINTK(_level, __VA_ARGS__); \
285+ break; \
286+ } \
287+ \
288+ bool is_user_context = k_is_user_context(); \
289+ uint32_t filters = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
290+ ((struct log_source_dynamic_data *)(void *)(_source))->filters : 0;\
291+ if (!LOG_CHECK_CTX_LVL_FILTER(is_user_context, _level, filters)) { \
292+ break; \
293+ } \
294+ \
295+ Z_LOG_INTERNAL(is_user_context, _level, _source, __VA_ARGS__);\
296+ if (false) { \
297+ /* Arguments checker present but never evaluated.*/ \
298+ /* Placed here to ensure that __VA_ARGS__ are*/ \
299+ /* evaluated once when log is enabled.*/ \
300+ z_log_printf_arg_checker (__VA_ARGS__ ); \
301+ } \
302+ } while (false)
303303
304- #define Z_LOG_INSTANCE (_level , _inst , ...) \
305- __LOG (_level, \
304+ #define Z_LOG (_level , ...) \
305+ Z_LOG2 (_level, \
306306 IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
307- LOG_DYNAMIC_ID_GET(_inst) : \
308- LOG_CONST_ID_GET(_inst), \
309- _inst, \
307+ (void *)__log_current_dynamic_data : \
308+ (void *)__log_current_const_data, \
310309 __VA_ARGS__)
311310
311+ #define Z_LOG_INSTANCE (_level , _inst , ...) Z_LOG2(_level, _inst, __VA_ARGS__)
312+
313+
314+ /*****************************************************************************/
315+ /****************** Macros for hexdump logging *******************************/
316+ /*****************************************************************************/
317+ #define Z_LOG_HEXDUMP2 (_level , _source , _data , _len , ...) do { \
318+ const char *_str = GET_ARG_N(1, __VA_ARGS__); \
319+ if (!Z_LOG_CONST_LEVEL_CHECK(_level)) { \
320+ break; \
321+ } \
322+ bool is_user_context = k_is_user_context(); \
323+ uint32_t filters = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
324+ ((struct log_source_dynamic_data *)(void *)(_source))->filters : 0;\
325+ \
326+ if (IS_ENABLED(CONFIG_LOG_MINIMAL)) { \
327+ Z_LOG_TO_PRINTK(_level, "%s", _str); \
328+ z_log_minimal_hexdump_print(_level, \
329+ (const char *)_data, _len);\
330+ break; \
331+ } \
332+ if (!LOG_CHECK_CTX_LVL_FILTER(is_user_context, _level, filters)) { \
333+ break; \
334+ } \
335+ uint16_t src_id = \
336+ IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
337+ LOG_DYNAMIC_ID_GET(_source) : LOG_CONST_ID_GET(_source);\
338+ struct log_msg_ids src_level = { \
339+ .level = _level, \
340+ .domain_id = CONFIG_LOG_DOMAIN_ID, \
341+ .source_id = src_id, \
342+ }; \
343+ if (is_user_context) { \
344+ log_hexdump_from_user(src_level, _str, \
345+ (const char *)_data, _len); \
346+ } else if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) { \
347+ log_hexdump_sync(src_level, _str, (const char *)_data, _len); \
348+ } else { \
349+ log_hexdump(_str, (const char *)_data, _len, src_level); \
350+ } \
351+ } while (false)
312352
313- /******************************************************************************/
314- /****************** Macros for hexdump logging ********************************/
315- /******************************************************************************/
316- #define __LOG_HEXDUMP (_level , _id , _filter , _data , _length , _str ) \
317- do { \
318- if (Z_LOG_CONST_LEVEL_CHECK(_level)) { \
319- bool is_user_context = k_is_user_context(); \
320- \
321- if (IS_ENABLED(CONFIG_LOG_MINIMAL)) { \
322- Z_LOG_TO_PRINTK(_level, "%s", _str); \
323- z_log_minimal_hexdump_print(_level, \
324- (const char *)_data, \
325- _length); \
326- } else if (LOG_CHECK_CTX_LVL_FILTER(is_user_context, \
327- _level, _filter)) { \
328- struct log_msg_ids src_level = { \
329- .level = _level, \
330- .domain_id = CONFIG_LOG_DOMAIN_ID, \
331- .source_id = _id, \
332- }; \
333- \
334- if (is_user_context) { \
335- log_hexdump_from_user(src_level, _str, \
336- (const char *)_data, \
337- _length); \
338- } else if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) { \
339- log_hexdump_sync(src_level, _str, \
340- (const char *)_data, \
341- _length); \
342- } else { \
343- log_hexdump(_str, (const char *)_data, \
344- _length, \
345- src_level); \
346- } \
347- } else { \
348- } \
349- } \
350- } while (false)
351-
352- #define Z_LOG_HEXDUMP (_level , _data , _length , _str ) \
353- __LOG_HEXDUMP(_level, \
354- (uint16_t)LOG_CURRENT_MODULE_ID(), \
355- LOG_CURRENT_DYNAMIC_DATA_ADDR(), \
356- _data, _length, _str)
353+ #define Z_LOG_HEXDUMP (_level , _data , _length , ...) \
354+ Z_LOG_HEXDUMP2(_level, IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
355+ (void *)__log_current_dynamic_data : \
356+ (void *)__log_current_const_data, \
357+ _data, _length, __VA_ARGS__)
357358
358359#define Z_LOG_HEXDUMP_INSTANCE (_level , _inst , _data , _length , _str ) \
359- __LOG_HEXDUMP(_level, \
360- IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
361- LOG_DYNAMIC_ID_GET(_inst) : \
362- LOG_CONST_ID_GET(_inst), \
363- _inst, \
364- _data, \
365- _length, \
366- _str)
360+ Z_LOG_HEXDUMP2(_level, _inst, _data, _length, _str)
367361
368- /****************************************************************************** /
369- /****************** Filtering macros ****************************************** /
370- /****************************************************************************** /
362+ /*****************************************************************************/
363+ /****************** Filtering macros *****************************************/
364+ /*****************************************************************************/
371365
372366/** @brief Number of bits used to encode log level. */
373367#define LOG_LEVEL_BITS 3U
@@ -409,9 +403,9 @@ static inline char z_log_minimal_level_to_char(int level)
409403#define LOG_CHECK_CTX_LVL_FILTER (ctx , _level , _filter ) \
410404 (ctx || (_level <= LOG_RUNTIME_FILTER(_filter)))
411405#define LOG_RUNTIME_FILTER (_filter ) \
412- LOG_FILTER_SLOT_GET(&( _filter)->filters , LOG_FILTER_AGGR_SLOT_IDX)
406+ LOG_FILTER_SLOT_GET(&_filter, LOG_FILTER_AGGR_SLOT_IDX)
413407#else
414- #define LOG_CHECK_CTX_LVL_FILTER (ctx , _level , _filter ) (true)
408+ #define LOG_CHECK_CTX_LVL_FILTER (ctx , _level , _filter ) (( true) | _filter )
415409#define LOG_RUNTIME_FILTER (_filter ) LOG_LEVEL_DBG
416410#endif
417411
@@ -430,6 +424,20 @@ enum log_strdup_action {
430424 LOG_STRDUP_CHECK_EXEC /**< Duplicate RAM strings, if not dupl. before.*/
431425};
432426
427+ #define Z_LOG_PRINTK (...) do { \
428+ if (IS_ENABLED(CONFIG_LOG_MINIMAL) || !IS_ENABLED(CONFIG_LOG2)) { \
429+ z_log_minimal_printk(__VA_ARGS__); \
430+ break; \
431+ } \
432+ int _mode; \
433+ if (0) {\
434+ z_log_printf_arg_checker(__VA_ARGS__); \
435+ } \
436+ Z_LOG_MSG2_CREATE(!IS_ENABLED(CONFIG_USERSPACE), _mode, \
437+ CONFIG_LOG_DOMAIN_ID, NULL, \
438+ LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, __VA_ARGS__);\
439+ } while (0)
440+
433441/** @brief Get name of the log source.
434442 *
435443 * @param source_id Source ID.
@@ -508,7 +516,7 @@ static inline uint32_t log_dynamic_source_id(struct log_source_dynamic_data *dat
508516
509517/** @brief Dummy function to trigger log messages arguments type checking. */
510518static inline __printf_like (1 , 2 )
511- void log_printf_arg_checker (const char * fmt , ...)
519+ void z_log_printf_arg_checker (const char * fmt , ...)
512520{
513521 ARG_UNUSED (fmt );
514522}
@@ -660,7 +668,20 @@ uint32_t log_get_strdup_longest_string(void);
660668
661669/** @brief Indicate to the log core that one log message has been dropped.
662670 */
663- void log_dropped (void );
671+ void z_log_dropped (void );
672+
673+ /** @brief Read and clear current drop indications counter.
674+ *
675+ * @return Dropped count.
676+ */
677+ uint32_t z_log_dropped_read_and_clear (void );
678+
679+ /** @brief Check if there are any pending drop notifications.
680+ *
681+ * @retval true Pending unreported drop indications.
682+ * @retval false No pending unreported drop indications.
683+ */
684+ bool z_log_dropped_pending (void );
664685
665686/** @brief Log a message from user mode context.
666687 *
@@ -674,6 +695,9 @@ void log_dropped(void);
674695void __printf_like (2 , 3 ) log_from_user (struct log_msg_ids src_level ,
675696 const char * fmt , ...);
676697
698+ /* Internal function used by log_from_user(). */
699+ __syscall void z_log_string_from_user (uint32_t src_level_val , const char * str );
700+
677701/**
678702 * @brief Create mask with occurences of a string format specifiers (%s).
679703 *
@@ -687,9 +711,6 @@ void __printf_like(2, 3) log_from_user(struct log_msg_ids src_level,
687711 */
688712uint32_t z_log_get_s_mask (const char * str , uint32_t nargs );
689713
690- /* Internal function used by log_from_user(). */
691- __syscall void z_log_string_from_user (uint32_t src_level_val , const char * str );
692-
693714/** @brief Log binary data (displayed as hexdump) from user mode context.
694715 *
695716 * @note This function is intended to be used internally
@@ -760,7 +781,7 @@ static inline log_arg_t z_log_do_strdup(uint32_t msk, uint32_t idx,
760781 enum log_strdup_action action )
761782{
762783#ifndef CONFIG_LOG_MINIMAL
763- char * log_strdup (const char * str );
784+ char * z_log_strdup (const char * str );
764785
765786 if (msk & (1 << idx )) {
766787 const char * str = (const char * )param ;
@@ -770,7 +791,7 @@ static inline log_arg_t z_log_do_strdup(uint32_t msk, uint32_t idx,
770791 * if already not duplicated.
771792 */
772793 if (action == LOG_STRDUP_EXEC || !log_is_strdup (str )) {
773- param = (log_arg_t )log_strdup (str );
794+ param = (log_arg_t )z_log_strdup (str );
774795 }
775796 }
776797#else
@@ -792,7 +813,7 @@ do { \
792813 _LOG_INTERNAL_0(_src_level, _str); \
793814 } else { \
794815 uint32_t mask = (_strdup_action != LOG_STRDUP_SKIP) ? \
795- z_log_get_s_mask(_str, _argnum) \
816+ z_log_get_s_mask(_str, _argnum) \
796817 : 0; \
797818 \
798819 if (_argnum == 1) { \
0 commit comments