]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fixup verification functions, add value box debug functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 20 Feb 2023 23:59:02 +0000 (17:59 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 22 Feb 2023 02:35:26 +0000 (20:35 -0600)
src/lib/unlang/map.c
src/lib/util/value.c
src/lib/util/value.h

index f771c084a15badb5b0757d90bc4035076fd8f6f3..3d841aaa115eec9366be299a7d8d010d3b95dbc7 100644 (file)
@@ -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;
 }
index 5b3cae4ef7efbf69b005db50d50c1e118ad5d7e6..a24fd2f46eefb71bbc46d1d4dd585149ae1e549a 100644 (file)
@@ -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);
+}
+
+
index 5f2884c29a8fd74673b0e62ddf06b2672a604a83..6f6c568287fdc437456f1e73f4620e4aae76b15c 100644 (file)
@@ -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