]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add more debug functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 19 Nov 2020 16:05:12 +0000 (10:05 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 26 Nov 2020 17:18:30 +0000 (10:18 -0700)
src/lib/util/dict.h
src/lib/util/dict_ext_priv.h
src/lib/util/dict_print.c
src/lib/util/dict_util.c
src/lib/util/ext.c
src/lib/util/hash.c
src/lib/util/hash.h

index c07f86ada8a9ac3167060778b4c4b0b64b1a1265..da63072d6a483d9f0b13893b52846ffc52b4462e 100644 (file)
@@ -368,6 +368,8 @@ static inline  CC_HINT(nonnull) int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a,
  *
  * @{
  */
+void                   fr_dict_namespace_debug(fr_dict_attr_t const *da);
+
 void                   fr_dict_attr_debug(fr_dict_attr_t const *da);
 
 void                   fr_dict_debug(fr_dict_t const *dict);
index 5bca70f0d28c072b5c3a31ca6206597e1094f1f1..0af23c20a409fbd590ec7695200a6f090a0293d9 100644 (file)
@@ -102,9 +102,9 @@ static inline int dict_attr_ext_copy_all(fr_dict_attr_t **da_out_p, fr_dict_attr
 /** Print extension debug information for attributes
  *
  */
-static inline void dict_attr_ext_debug(fr_dict_attr_t const *da)
+static inline void dict_attr_ext_debug(char const *name, fr_dict_attr_t const *da)
 {
-       fr_ext_debug(&fr_dict_attr_ext_def, da->name, da);
+       fr_ext_debug(&fr_dict_attr_ext_def, name, da);
 }
 /** @} */
 
index 7e8da4ead273dc075ffebd76881a7e7fbc9a7a69..944ce757ba46e4e7f2fc0a3715e18b17369e8a82 100644 (file)
@@ -119,7 +119,8 @@ ssize_t fr_dict_attr_oid_print(fr_sbuff_t *out, fr_dict_attr_t const *ancestor,
 
 typedef struct {
        fr_dict_t const         *dict;
-       char                    buff[256];
+       char                    prefix[256];
+       char                    flags[256];
        unsigned int            start_depth;
 } fr_dict_attr_debug_t;
 
@@ -130,19 +131,23 @@ static int dict_attr_debug(fr_dict_attr_t const *da, void *uctx)
        fr_dict_enum_t const            *enumv;
        fr_dict_attr_ext_enumv_t        *ext;
 
-       fr_dict_snprint_flags(&FR_SBUFF_OUT(our_uctx->buff, sizeof(our_uctx->buff)),
+       fr_dict_snprint_flags(&FR_SBUFF_OUT(our_uctx->flags, sizeof(our_uctx->flags)),
                              our_uctx->dict, da->type, &da->flags);
 
-       FR_FAULT_LOG("[%02i] 0x%016" PRIxPTR "%*s %s(%u) %s %s",
-                    da->depth,
-                    (unsigned long)da,
-                    (da->depth - our_uctx->start_depth) * 4, "",
+       snprintf(our_uctx->prefix, sizeof(our_uctx->prefix),
+                "[%02i] 0x%016" PRIxPTR "%*s",
+                da->depth,
+                (unsigned long)da,
+                (da->depth - our_uctx->start_depth) * 4, "");
+
+       FR_FAULT_LOG("%s%s(%u) %s %s",
+                    our_uctx->prefix,
                     da->name,
                     da->attr,
                     fr_table_str_by_value(fr_value_box_type_table, da->type, "<INVALID>"),
-                    our_uctx->buff);
+                    our_uctx->flags);
 
-       dict_attr_ext_debug(da);        /* Print all the extension debug info */
+       dict_attr_ext_debug(our_uctx->prefix, da);      /* Print all the extension debug info */
 
        ext = fr_dict_attr_ext(da, FR_DICT_ATTR_EXT_ENUMV);
        if (!ext || !ext->name_by_value) return 0;
@@ -150,17 +155,29 @@ static int dict_attr_debug(fr_dict_attr_t const *da, void *uctx)
        for (enumv = fr_hash_table_iter_init(ext->name_by_value, &iter);
             enumv;
             enumv = fr_hash_table_iter_next(ext->name_by_value, &iter)) {
-               FR_FAULT_LOG("[%02i] 0x%016" PRIxPTR "%*s%s -> %pV",
-                            da->depth,
-                            (unsigned long)da,
-                            ((da->depth + 1) - our_uctx->start_depth) * 4, "",
+               char *value = fr_asprintf(NULL, "%pV", enumv->value);
+
+               FR_FAULT_LOG("%s    %s -> %s",
+                            our_uctx->prefix,
                             enumv->name,
-                            enumv->value);
+                            value);
+               talloc_free(value);
        }
 
        return 0;
 }
 
+void fr_dict_namespace_debug(fr_dict_attr_t const *da)
+{
+       fr_dict_attr_debug_t    uctx = { .dict = fr_dict_by_da(da), .start_depth = da->depth };
+       fr_hash_table_t         *namespace;
+
+       namespace = dict_attr_namespace(da);
+       if (!namespace) FR_FAULT_LOG("%s does not have namespace", da->name);
+
+       fr_hash_table_walk(namespace, (fr_hash_table_walk_t)dict_attr_debug, &uctx);
+}
+
 void fr_dict_attr_debug(fr_dict_attr_t const *da)
 {
        fr_dict_attr_debug_t uctx = { .dict = fr_dict_by_da(da), .start_depth = da->depth };
index df737cf9acba9bf4e6592bed8572e86e8fc3d7bc..04fb58495623e3a68815da244d4ccf9e2cbe9ceb 100644 (file)
@@ -1994,15 +1994,15 @@ typedef struct {
 
 /** Search for an attribute name in all dictionaries
  *
- * @param[in] ctx      Attribute to search for.
  * @param[in] data     Dictionary to search in.
+ * @param[in] uctx     Attribute to search for.
  * @return
  *     - 0 if attribute not found in dictionary.
  *     - 1 if attribute found in dictionary.
  */
-static int _dict_attr_find_in_dicts(void *ctx, void *data)
+static int _dict_attr_find_in_dicts(void *data, void *uctx)
 {
-       dict_attr_search_t      *search = ctx;
+       dict_attr_search_t      *search = uctx;
        fr_dict_t               *dict;
        fr_hash_table_t         *namespace;
 
@@ -2748,7 +2748,7 @@ int dict_dlopen(fr_dict_t *dict, char const *name)
        return 0;
 }
 
-static int _dict_free_autoref(UNUSED void *ctx, void *data)
+static int _dict_free_autoref(void *data, UNUSED void *uctx)
 {
        fr_dict_t *dict = talloc_get_type_abort(data, fr_dict_t);
 
index 308386c063b174234a54e3cd7a9a85aed8127706..de42c25da8195eb3f6f54ab1b54f3d95608a699d 100644 (file)
@@ -239,7 +239,7 @@ void fr_ext_debug(fr_ext_t const *def, char const *name, void const *chunk)
 {
        int i;
 
-       FR_FAULT_LOG("ext: %s - total len = %zu", name, talloc_get_size(chunk));
+       FR_FAULT_LOG("%sext total_len=%zu", name, talloc_get_size(chunk));
        for (i = 0; i < (int)def->max; i++) {
                uint8_t *chunk_ext = CHUNK_EXT(def->info, def->offset_of_exts);
                if (chunk_ext[i]) {
@@ -251,13 +251,13 @@ void fr_ext_debug(fr_ext_t const *def, char const *name, void const *chunk)
                                                                                i, "<INVALID>");
 
                        if (ext_len > 1024) {
-                               FR_FAULT_LOG("ext: %s - possibly bad length %zu - limiting dump to 1024",
-                                            ext_name, ext_len);
+                               FR_FAULT_LOG("%sext id=%s - possibly bad length %zu - limiting dump to 1024",
+                                            name, ext_name, ext_len);
                                ext_len = 1024;
                        }
 
-                       FR_FAULT_LOG("ext: %s - start=%p end=%p len=%zu",
-                                    ext_name, ext, ((uint8_t *)ext) + ext_len, ext_len);
+                       FR_FAULT_LOG("%sext id=%s start=%p end=%p len=%zu",
+                                    name, ext_name, ext, ((uint8_t *)ext) + ext_len, ext_len);
                        FR_FAULT_LOG_HEX(ext, ext_len);
                }
        }
index 53663b34bfcabec889256b2690e404ef1fb970c6..0722c1e6665fa27937915e476be8a579c7cea2df 100644 (file)
@@ -619,7 +619,7 @@ int fr_hash_table_num_elements(fr_hash_table_t *ht)
  */
 int fr_hash_table_walk(fr_hash_table_t *ht,
                       fr_hash_table_walk_t callback,
-                      void *context)
+                      void *uctx)
 {
        int i, ret;
 
@@ -636,7 +636,7 @@ int fr_hash_table_walk(fr_hash_table_t *ht,
                for (node = ht->buckets[i]; node != &ht->null; node = next) {
                        next = node->next;
 
-                       ret = callback(context, node->data);
+                       ret = callback(node->data, uctx);
 
                        if (ret != 0) return ret;
                }
index 0c256b81bfa728ce7337685dc48037af0e06d942..bbff2b32d5bdf63e363b3a113d67100d433b5c45 100644 (file)
@@ -57,7 +57,7 @@ typedef struct fr_hash_table_s fr_hash_table_t;
 typedef void (*fr_hash_table_free_t)(void *);
 typedef uint32_t (*fr_hash_table_hash_t)(void const *);
 typedef int (*fr_hash_table_cmp_t)(void const *, void const *);
-typedef int (*fr_hash_table_walk_t)(void * /* ctx */, void * /* data */);
+typedef int (*fr_hash_table_walk_t)(void *data, void *uctx);
 
 fr_hash_table_t *fr_hash_table_create(TALLOC_CTX *ctx,
                                      fr_hash_table_hash_t hashNode,
@@ -82,7 +82,7 @@ int           fr_hash_table_num_elements(fr_hash_table_t *ht);
 
 int            fr_hash_table_walk(fr_hash_table_t *ht,
                                   fr_hash_table_walk_t callback,
-                                  void *ctx);
+                                  void *uctx);
 
 void           *fr_hash_table_iter_next(fr_hash_table_t *ht, fr_hash_iter_t *iter);