Skip to content

Commit

Permalink
proto: Add hex marker macro
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Apr 1, 2020
1 parent dd02185 commit 21b87d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/lib/util/proto.c
Expand Up @@ -53,6 +53,21 @@ void fr_proto_print_hex_data(char const *file, int line, uint8_t const *data, si
}
fr_log_hex(&default_log, L_DBG, file, line, data, data_len, "hex: ");
}

void fr_proto_print_hex_marker(char const *file, int line, uint8_t const *data, size_t data_len, ssize_t slen, char const *fmt, ...)
{
va_list ap;
char *msg;

if (fmt) {
va_start(ap, fmt);
msg = talloc_vasprintf(NULL, fmt, ap);
va_end(ap);
fr_log(&default_log, L_DBG, file, line, "hex: -- %s --", msg);
talloc_free(msg);
}
fr_log_hex_marker(&default_log, L_DBG, file, line, data, data_len, slen, "current position", "hex: ");
}
DIAG_ON(format-nonliteral)

void fr_proto_da_stack_print(char const *file, int line, char const *func, fr_da_stack_t *da_stack, unsigned int depth)
Expand Down
10 changes: 7 additions & 3 deletions src/lib/util/proto.h
Expand Up @@ -37,12 +37,14 @@ do { \
} while (0);

#ifndef NDEBUG
# define FR_PROTO_TRACE(_fmt, ...) if (fr_debug_lvl > L_DBG_LVL_3) fr_proto_print(__FILE__, __LINE__, _fmt, ## __VA_ARGS__)
# define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt, ...) if (fr_debug_lvl > L_DBG_LVL_3) fr_proto_print_hex_data(__FILE__, __LINE__, _data, _data_len, _fmt, ## __VA_ARGS__)
# define FR_PROTO_STACK_PRINT(_x, _y) if (fr_debug_lvl > L_DBG_LVL_3) fr_proto_da_stack_print( __FILE__, __LINE__, __FUNCTION__, _x, _y)
# define FR_PROTO_TRACE(_fmt, ...) if (fr_debug_lvl >= L_DBG_LVL_4) fr_proto_print(__FILE__, __LINE__, _fmt, ## __VA_ARGS__)
# define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt, ...) if (fr_debug_lvl >= L_DBG_LVL_4) fr_proto_print_hex_data(__FILE__, __LINE__, _data, _data_len, _fmt, ## __VA_ARGS__)
# define FR_PROTO_HEX_MARKER(_data, _data_len, _slen, _fmt, ...) if (fr_debug_lvl >= L_DBG_LVL_4) fr_proto_print_hex_marker(__FILE__, __LINE__, _data, _data_len, _slen, _fmt, ## __VA_ARGS__)
# define FR_PROTO_STACK_PRINT(_stack, _depth) if (fr_debug_lvl >= L_DBG_LVL_4) fr_proto_da_stack_print(__FILE__, __LINE__, __FUNCTION__, _stack, _depth)
#else
# define FR_PROTO_TRACE(_fmt, ...)
# define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt, ...)
# define FR_PROTO_HEX_MARKER(_data, _data_len, _slen, _fmt, ...)
# define FR_PROTO_STACK_PRINT(_x, _y)
#endif

Expand All @@ -57,6 +59,8 @@ void fr_proto_print(char const *file, int line, char const *fmt, ...) CC_HINT(fo

void fr_proto_print_hex_data(char const *file, int line, uint8_t const *data, size_t data_len, char const *fmt, ...);

void fr_proto_print_hex_marker(char const *file, int line, uint8_t const *data, size_t data_len, ssize_t slen, char const *fmt, ...);

void *fr_proto_next_encodable(void **prev, void *to_eval, void *uctx);

void fr_proto_da_stack_print(char const *file, int line, char const *func, fr_da_stack_t *da_stack, unsigned int depth);
Expand Down

0 comments on commit 21b87d9

Please sign in to comment.