From: Arran Cudbard-Bell Date: Mon, 20 Feb 2023 23:59:02 +0000 (-0600) Subject: Fixup verification functions, add value box debug functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86b2fb99944fa3a6310b05385fb295da90a3058f;p=thirdparty%2Ffreeradius-server.git Fixup verification functions, add value box debug functions --- diff --git a/src/lib/unlang/map.c b/src/lib/unlang/map.c index f771c084a15..3d841aaa115 100644 --- a/src/lib/unlang/map.c +++ b/src/lib/unlang/map.c @@ -297,9 +297,9 @@ static unlang_action_t map_proc_apply(rlm_rcode_t *p_result, request_t *request, /* * FIXME - We don't yet support async LHS/RHS expansions for map procs */ - fr_value_box_list_verify(&map_proc_state->src_result); + VALUE_BOX_LIST_VERIFY(&map_proc_state->src_result); *p_result = map_proc(request, gext->proc_inst, &map_proc_state->src_result); - fr_value_box_list_verify(&map_proc_state->src_result); + VALUE_BOX_LIST_VERIFY(&map_proc_state->src_result); return UNLANG_ACTION_CALCULATE_RESULT; } diff --git a/src/lib/util/value.c b/src/lib/util/value.c index 5b3cae4ef7e..a24fd2f46ee 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -5811,7 +5811,7 @@ void fr_value_box_list_untaint(FR_DLIST_HEAD(fr_value_box_list) *head) /** Validation function to check that a fr_value_box_t is correctly initialised * */ -void value_box_verify(char const *file, int line, fr_value_box_t const *vb, bool talloced) +void fr_value_box_verify(char const *file, int line, fr_value_box_t const *vb, bool talloced) { DIAG_OFF(nonnull-compare) /* @@ -5844,7 +5844,7 @@ DIAG_ON(nonnull-compare) break; case FR_TYPE_GROUP: - value_box_list_verify(file, line, &vb->vb_group, talloced); + fr_value_box_list_verify(file, line, &vb->vb_group, talloced); break; default: @@ -5852,11 +5852,9 @@ DIAG_ON(nonnull-compare) } } -void value_box_list_verify(char const *file, int line, FR_DLIST_HEAD(fr_value_box_list) const *list, bool talloced) +void fr_value_box_list_verify(char const *file, int line, FR_DLIST_HEAD(fr_value_box_list) const *list, bool talloced) { - fr_value_box_t const *vb = NULL; - - while ((vb = fr_value_box_list_next(list, vb))) value_box_verify(file, line, vb, talloced); + fr_value_box_list_foreach(list, vb) fr_value_box_verify(file, line, vb, talloced); } @@ -5933,3 +5931,53 @@ bool fr_value_box_is_truthy(fr_value_box_t const *in) return box.vb_bool; } } + +#define INFO_INDENT(_fmt, ...) FR_FAULT_LOG("%*s"_fmt, depth * 2, " ", ## __VA_ARGS__) + +static void _fr_value_box_debug(fr_value_box_t const *vb, int depth, int idx); +static void _fr_value_box_list_debug(FR_DLIST_HEAD(fr_value_box_list) const *head, int depth) +{ + int i = 0; + + INFO_INDENT("{"); + fr_value_box_list_foreach(head, vb) _fr_value_box_debug(vb, depth + 1, i++); + INFO_INDENT("}"); +} + +/** Print a list of value boxes as info messages + * + * @note Call directly from the debugger + */ +void fr_value_box_list_debug(FR_DLIST_HEAD(fr_value_box_list) const *head) +{ + _fr_value_box_list_debug(head, 0); +} + +static void _fr_value_box_debug(fr_value_box_t const *vb, int depth, int idx) +{ + char *value; + + if (fr_type_is_structural(vb->type)) { + _fr_value_box_list_debug(&vb->vb_group, depth + 1); + return; + } + + fr_value_box_aprint(NULL, &value, vb, NULL); + if (idx >= 0) { + INFO_INDENT("[%d] %s", idx, value); + } else { + INFO_INDENT("%s", value); + } + talloc_free(value); +} + +/** Print the value of a box as info messages + * + * @note Call directly from the debugger + */ +void fr_value_box_debug(fr_value_box_t const *vb) +{ + _fr_value_box_debug(vb, 0, -1); +} + + diff --git a/src/lib/util/value.h b/src/lib/util/value.h index 5f2884c29a8..6f6c568287f 100644 --- a/src/lib/util/value.h +++ b/src/lib/util/value.h @@ -170,7 +170,6 @@ FR_DLIST_FUNCS(fr_value_box_list, fr_value_box_t, entry) #define fr_value_box_list_foreach(_list_head, _iter) fr_dlist_foreach(fr_value_box_list_dlist_head(_list_head), fr_value_box_t, _iter) #define fr_value_box_list_foreach_safe(_list_head, _iter) fr_dlist_foreach_safe(fr_value_box_list_dlist_head(_list_head), fr_value_box_t, _iter) -#define fr_value_box_list_verify(_list_head) _fr_value_box_list_verify(__FILE__, __LINE__, _list_head) FR_DCURSOR_FUNCS(fr_value_box_dcursor, fr_value_box_list, fr_value_box_t) /** @} */ @@ -1058,16 +1057,16 @@ uint32_t fr_value_box_hash(fr_value_box_t const *vb); /** @} */ -void value_box_verify(char const *file, int line, fr_value_box_t const *vb, bool talloced) +void fr_value_box_verify(char const *file, int line, fr_value_box_t const *vb, bool talloced) CC_HINT(nonnull(3)); -void value_box_list_verify(char const *file, int line, FR_DLIST_HEAD(fr_value_box_list) const *list, bool talloced) +void fr_value_box_list_verify(char const *file, int line, FR_DLIST_HEAD(fr_value_box_list) const *list, bool talloced) CC_HINT(nonnull(3)); #ifdef WITH_VERIFY_PTR -# define VALUE_BOX_VERIFY(_x) value_box_verify(__FILE__, __LINE__, _x, false) -# define VALUE_BOX_LIST_VERIFY(_x) value_box_list_verify(__FILE__, __LINE__, _x, false) -# define VALUE_BOX_TALLOC_VERIFY(_x) value_box_verify(__FILE__, __LINE__, _x, true) -# define VALUE_BOX_TALLOC_LIST_VERIFY(_x) value_box_list_verify(__FILE__, __LINE__, _x, true) +# define VALUE_BOX_VERIFY(_x) fr_value_box_verify(__FILE__, __LINE__, _x, false) +# define VALUE_BOX_LIST_VERIFY(_x) fr_value_box_list_verify(__FILE__, __LINE__, _x, false) +# define VALUE_BOX_TALLOC_VERIFY(_x) fr_value_box_verify(__FILE__, __LINE__, _x, true) +# define VALUE_BOX_TALLOC_LIST_VERIFY(_x) fr_value_box_list_verify(__FILE__, __LINE__, _x, true) #else /* * Even if were building without WITH_VERIFY_PTR @@ -1080,6 +1079,14 @@ void value_box_list_verify(char const *file, int line, FR_DLIST_HEAD(fr_value_b # define VALUE_BOX_TALLOC_LIST_VERIFY(_x) fr_assert(_x) #endif +/** @name Debug functions + * + * @{ + */ +void fr_value_box_list_debug(FR_DLIST_HEAD(fr_value_box_list) const *head); +void fr_value_box_debug(fr_value_box_t const *vb); +/** @} */ + #undef _CONST #ifdef __cplusplus