From: Arran Cudbard-Bell Date: Thu, 19 Nov 2020 16:05:12 +0000 (-0600) Subject: Add more debug functions X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eb4e5cfc53d49d22a2dc2545ce466bacb30b751a;p=thirdparty%2Ffreeradius-server.git Add more debug functions --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index c07f86ada8a..da63072d6a4 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -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); diff --git a/src/lib/util/dict_ext_priv.h b/src/lib/util/dict_ext_priv.h index 5bca70f0d28..0af23c20a40 100644 --- a/src/lib/util/dict_ext_priv.h +++ b/src/lib/util/dict_ext_priv.h @@ -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); } /** @} */ diff --git a/src/lib/util/dict_print.c b/src/lib/util/dict_print.c index 7e8da4ead27..944ce757ba4 100644 --- a/src/lib/util/dict_print.c +++ b/src/lib/util/dict_print.c @@ -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, ""), - 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 }; diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index df737cf9acb..04fb5849562 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -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); diff --git a/src/lib/util/ext.c b/src/lib/util/ext.c index 308386c063b..de42c25da81 100644 --- a/src/lib/util/ext.c +++ b/src/lib/util/ext.c @@ -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, ""); 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); } } diff --git a/src/lib/util/hash.c b/src/lib/util/hash.c index 53663b34bfc..0722c1e6665 100644 --- a/src/lib/util/hash.c +++ b/src/lib/util/hash.c @@ -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; } diff --git a/src/lib/util/hash.h b/src/lib/util/hash.h index 0c256b81bfa..bbff2b32d5b 100644 --- a/src/lib/util/hash.h +++ b/src/lib/util/hash.h @@ -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);