log facility: make its arguments 64-bit compatible
Log arguments were hardcoded to u32_t values. On 64-bit systems, this is rather restrictive. To make things clear, arguments now have their own type, log_arg_t, which now can be adjusted in only one location if need be. It is currently defined as unsigned long whose effective width is equivalent to u32_t on 32-bit systems, and u64_t on 64-bit systems. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
344737d759
commit
0567f161d8
5 changed files with 50 additions and 44 deletions
|
@ -179,22 +179,22 @@ extern "C" {
|
|||
log_0(_str, _src_level)
|
||||
|
||||
#define _LOG_INTERNAL_1(_src_level, _str, _arg0) \
|
||||
log_1(_str, (u32_t)(_arg0), _src_level)
|
||||
log_1(_str, (log_arg_t)(_arg0), _src_level)
|
||||
|
||||
#define _LOG_INTERNAL_2(_src_level, _str, _arg0, _arg1) \
|
||||
log_2(_str, (u32_t)(_arg0), (u32_t)(_arg1), _src_level)
|
||||
log_2(_str, (log_arg_t)(_arg0), (log_arg_t)(_arg1), _src_level)
|
||||
|
||||
#define _LOG_INTERNAL_3(_src_level, _str, _arg0, _arg1, _arg2) \
|
||||
log_3(_str, (u32_t)(_arg0), (u32_t)(_arg1), (u32_t)(_arg2), _src_level)
|
||||
log_3(_str, (log_arg_t)(_arg0), (log_arg_t)(_arg1), (log_arg_t)(_arg2), _src_level)
|
||||
|
||||
#define __LOG_ARG_CAST(_x) (u32_t)(_x),
|
||||
#define __LOG_ARG_CAST(_x) (log_arg_t)(_x),
|
||||
|
||||
#define __LOG_ARGUMENTS(...) MACRO_MAP(__LOG_ARG_CAST, __VA_ARGS__)
|
||||
|
||||
#define _LOG_INTERNAL_LONG(_src_level, _str, ...) \
|
||||
do { \
|
||||
u32_t args[] = {__LOG_ARGUMENTS(__VA_ARGS__)}; \
|
||||
log_n(_str, args, ARRAY_SIZE(args), _src_level); \
|
||||
#define _LOG_INTERNAL_LONG(_src_level, _str, ...) \
|
||||
do { \
|
||||
log_arg_t args[] = {__LOG_ARGUMENTS(__VA_ARGS__)};\
|
||||
log_n(_str, args, ARRAY_SIZE(args), _src_level); \
|
||||
} while (false)
|
||||
|
||||
#define Z_LOG_LEVEL_CHECK(_level, _check_level, _default_level) \
|
||||
|
@ -442,7 +442,7 @@ void log_0(const char *str, struct log_msg_ids src_level);
|
|||
* @param src_level Log identification.
|
||||
*/
|
||||
void log_1(const char *str,
|
||||
u32_t arg1,
|
||||
log_arg_t arg1,
|
||||
struct log_msg_ids src_level);
|
||||
|
||||
/** @brief Standard log with two arguments.
|
||||
|
@ -453,8 +453,8 @@ void log_1(const char *str,
|
|||
* @param src_level Log identification.
|
||||
*/
|
||||
void log_2(const char *str,
|
||||
u32_t arg1,
|
||||
u32_t arg2,
|
||||
log_arg_t arg1,
|
||||
log_arg_t arg2,
|
||||
struct log_msg_ids src_level);
|
||||
|
||||
/** @brief Standard log with three arguments.
|
||||
|
@ -466,9 +466,9 @@ void log_2(const char *str,
|
|||
* @param src_level Log identification.
|
||||
*/
|
||||
void log_3(const char *str,
|
||||
u32_t arg1,
|
||||
u32_t arg2,
|
||||
u32_t arg3,
|
||||
log_arg_t arg1,
|
||||
log_arg_t arg2,
|
||||
log_arg_t arg3,
|
||||
struct log_msg_ids src_level);
|
||||
|
||||
/** @brief Standard log with arguments list.
|
||||
|
@ -479,7 +479,7 @@ void log_3(const char *str,
|
|||
* @param src_level Log identification.
|
||||
*/
|
||||
void log_n(const char *str,
|
||||
u32_t *args,
|
||||
log_arg_t *args,
|
||||
u32_t narg,
|
||||
struct log_msg_ids src_level);
|
||||
|
||||
|
|
|
@ -22,6 +22,12 @@ extern "C" {
|
|||
* @{
|
||||
*/
|
||||
|
||||
/** @brief Log argument type.
|
||||
*
|
||||
* Should preferably be equivalent to a native word size.
|
||||
*/
|
||||
typedef unsigned long log_arg_t;
|
||||
|
||||
/** @brief Maximum number of arguments in the standard log entry.
|
||||
*
|
||||
* It is limited by 4 bit nargs field in the log message.
|
||||
|
@ -123,7 +129,7 @@ struct log_msg_hdr {
|
|||
|
||||
/** @brief Data part of log message. */
|
||||
union log_msg_head_data {
|
||||
u32_t args[LOG_MSG_NARGS_SINGLE_CHUNK];
|
||||
log_arg_t args[LOG_MSG_NARGS_SINGLE_CHUNK];
|
||||
u8_t bytes[LOG_MSG_HEXDUMP_BYTES_SINGLE_CHUNK];
|
||||
};
|
||||
|
||||
|
@ -131,7 +137,7 @@ union log_msg_head_data {
|
|||
struct log_msg_ext_head_data {
|
||||
struct log_msg_cont *next;
|
||||
union log_msg_ext_head_data_data {
|
||||
u32_t args[LOG_MSG_NARGS_HEAD_CHUNK];
|
||||
log_arg_t args[LOG_MSG_NARGS_HEAD_CHUNK];
|
||||
u8_t bytes[LOG_MSG_HEXDUMP_BYTES_HEAD_CHUNK];
|
||||
} data;
|
||||
};
|
||||
|
@ -155,7 +161,7 @@ BUILD_ASSERT_MSG((sizeof(union log_msg_head_data) ==
|
|||
struct log_msg_cont {
|
||||
struct log_msg_cont *next; /*!< Pointer to the next chunk. */
|
||||
union log_msg_cont_data {
|
||||
u32_t args[ARGS_CONT_MSG];
|
||||
log_arg_t args[ARGS_CONT_MSG];
|
||||
u8_t bytes[HEXDUMP_BYTES_CONT_MSG];
|
||||
} payload;
|
||||
};
|
||||
|
@ -261,7 +267,7 @@ u32_t log_msg_nargs_get(struct log_msg *msg);
|
|||
* @return Argument value or 0 if arg_idx exceeds number of arguments in the
|
||||
* message.
|
||||
*/
|
||||
u32_t log_msg_arg_get(struct log_msg *msg, u32_t arg_idx);
|
||||
log_arg_t log_msg_arg_get(struct log_msg *msg, u32_t arg_idx);
|
||||
|
||||
|
||||
/** @brief Gets pointer to the unformatted string from standard log message.
|
||||
|
@ -379,7 +385,7 @@ static inline struct log_msg *log_msg_create_0(const char *str)
|
|||
* @return Pointer to allocated head of the message or NULL.
|
||||
*/
|
||||
static inline struct log_msg *log_msg_create_1(const char *str,
|
||||
u32_t arg1)
|
||||
log_arg_t arg1)
|
||||
{
|
||||
struct log_msg *msg = z_log_msg_std_alloc();
|
||||
|
||||
|
@ -407,8 +413,8 @@ static inline struct log_msg *log_msg_create_1(const char *str,
|
|||
* @return Pointer to allocated head of the message or NULL.
|
||||
*/
|
||||
static inline struct log_msg *log_msg_create_2(const char *str,
|
||||
u32_t arg1,
|
||||
u32_t arg2)
|
||||
log_arg_t arg1,
|
||||
log_arg_t arg2)
|
||||
{
|
||||
struct log_msg *msg = z_log_msg_std_alloc();
|
||||
|
||||
|
@ -438,9 +444,9 @@ static inline struct log_msg *log_msg_create_2(const char *str,
|
|||
* @return Pointer to allocated head of the message or NULL.
|
||||
*/
|
||||
static inline struct log_msg *log_msg_create_3(const char *str,
|
||||
u32_t arg1,
|
||||
u32_t arg2,
|
||||
u32_t arg3)
|
||||
log_arg_t arg1,
|
||||
log_arg_t arg2,
|
||||
log_arg_t arg3)
|
||||
{
|
||||
struct log_msg *msg = z_log_msg_std_alloc();
|
||||
|
||||
|
@ -470,7 +476,7 @@ static inline struct log_msg *log_msg_create_3(const char *str,
|
|||
* @return Pointer to allocated head of the message or NULL.
|
||||
*/
|
||||
struct log_msg *log_msg_create_n(const char *str,
|
||||
u32_t *args,
|
||||
log_arg_t *args,
|
||||
u32_t nargs);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue