#
# Syntax: dd <variable name>
#
-# where the variable named either has one of the types
-# shown in the _howTo list or whose address has one of the
-# types shown in the _howTo list.
+# where <variable name> has a type foo * or foo for which
+# there is a function foo_debug(FILE *, foo_t *) that presumably
+# displays values of type foo_t in a useful, legible format.
#
# When the command is run, it calls the appropriate FreeRADIUS
# function to display the value the variable points at (or
# we're running under gdb or lldb, we can have a single Python
# source that can do the right thing for the debugger it's running
# under.
+#
+# NOTE: this function cheerfully assumes such functions exist, but
+# will report if the call fails (modulo an issue with lldb and
+# fr_value_box_t being defined twice--see below). The idea is that
+# these reports will point out where an appropriate foo_debug()
+# function needs to exist or to be modified to fit the signature.
import sys
-_howTo = {
- 'fr_value_box_t *' : ('fr_value_box_debug', True),
- 'fr_value_box_list_t *' : ('fr_value_box_list_debug', True),
- 'tmpl_t *' : ('tmpl_debug', True),
- 'CONF_ITEM *' : ('_cf_debug', True),
- 'dl_loader_t *' : ('dl_loader_debug', False),
- 'fr_dict_gctx_t * ' : ('fr_dict_global_ctx_debug', True),
- 'fr_pair_t *' : ('fr_pair_debug', True),
- 'fr_pair_list_t *' : ('fr_pair_list_debug', True),
- 'fr_sbuff_term_t *' : ('fr_sbuff_terminal_debug', True),
- 'fr_sbuff_parse_rules_t *' : ('fr_sbuff_parse_rules_debug', True),
- 'fr_sbuff_unescape_rules_t *': ('fr_sbuff_unescape_debug', True),
- 'tmpl_attr_list_head_t *' : ('tmpl_attr_ref_list_debug', True),
- 'tmpl_attr_rules_t *' : ('tmpl_attr_rules_debug', True),
- 'fr_dlist_head_t *' : ('tmpl_extents_debug', False),
- 'tmpl_request_list_head_t *' : ('tmpl_request_ref_list_debug', True),
- 'tmpl_rules_t *' : ('tmpl_rules_debug', True),
- 'lua_State *' : ('_util_log_debug', False),
- 'xlat_exp_t *' : ('xlat_debug', True)
-}
+def debug_function(ptr_foo_name):
+ # ditch trailng ' *' (will always be there)
+ ptr_foo_name = ptr_foo_name[:-2]
+ # ditch trailing ' const'
+ if ptr_foo_name.endswith(' const'):
+ ptr_foo_name = ptr_foo_name[:-6]
+ # ditch trailing '_t' (again should always be there)
+ if ptr_foo_name.endswith('_t'):
+ ptr_foo_name = ptr_foo_name[:-2]
+ return f'{ptr_foo_name}_debug'
try:
import gdb # Attempt to import GDB module
if not sb_var.IsValid():
sb_var = target.FindFirstGlobalVariable(command)
if not sb_var.IsValid():
- result.SetError('{} is not a variable'.format(command))
+ result.SetError(f'{command} is not a variable')
return
arg = sb_var if sb_var.type.is_pointer else sb_var.address_of
type = arg.GetDisplayTypeName()
- if not (type in _howTo):
- result.SetError('unsupported type "{}"'.format(type))
- return
- function, const = _howTo[type]
- cast = '({} const *)'.format(type[0:-2]) if const else ''
- argName = arg.GetName()
- cmd = 'expr {0}({1}({2}))'.format(function, cast, argName)
+ function = debug_function(type)
+ cast = f'({type[:-2]} const *)'
+ cmd = f'expr {function}(stderr, {cast}({arg.GetName()}))'
interpreter = debugger.GetCommandInterpreter()
if not interpreter.IsValid():
result.SetError("can't set up SBCommandInterpreter")
for i in range(2):
if (cmdStatus := interpreter.HandleCommand(cmd, result)) == lldb.eReturnStatusSuccessFinishResult:
return
- result.SetError("command {} failed, status {}".format(cmd, cmdStatus))
+ result.SetError(f'command "{cmd}" failed, status {cmdStatus}')
# And then some boilerplate to set up the command and announce its availability.
# I'm guessing that the -f option is <file name without extension>.<name of function>,
argMod = '&'
var = var.address
varType = str(var.type)
- if not (varType in _howTo):
- print('unsupported type "{}"'.format(varType))
- return
- function, const = _howTo[varType]
- cast = '({} const *)'.format(varType[0:-2]) if const else ''
- command = 'call {0}({1}{2}({3}))'.format(function, cast, argMod, arg)
+ function = debug_function(varType)
+ cast = f'({varType[0:-2]} const *)'
+ command = f'call {function}(stderr, {cast}{argMod}({arg}))'
try:
gdb.execute(command)
except:
}
tp->func(ctx, &vps, buf, len, decode_ctx);
- if (fr_debug_lvl > 3) fr_pair_list_debug(&vps);
+ if (fr_debug_lvl > 3) fr_pair_list_debug(stderr, &vps);
talloc_free(decode_ctx);
talloc_free(ctx);
*/
if (fr_debug_lvl > 5) fr_dict_debug(fr_log_fp, cc->tmpl_rules.attr.dict_def);
+
RETURN_OK(0);
}
void *walk_ctx = NULL;
printf("Command hierarchy --------");
- fr_command_debug(stdout, command_head);
+ fr_cmd_debug(stdout, command_head);
printf("Command list --------");
while (fr_command_walk(command_head, &walk_ctx, NULL, command_walk) == 1) {
*/
if (diff < 0) {
#if 0
- fr_atomic_queue_debug(aq, stderr);
+ fr_atomic_queue_debug(stderr, aq);
#endif
return false;
}
* @param[in] aq The atomic queue to debug.
* @param[in] fp where the debugging information will be printed.
*/
-void fr_atomic_queue_debug(fr_atomic_queue_t *aq, FILE *fp)
+void fr_atomic_queue_debug(FILE * fp, fr_atomic_queue_t *aq)
{
size_t i;
int64_t head, tail;
#endif
#ifndef NDEBUG
-void fr_atomic_queue_debug(fr_atomic_queue_t *aq, FILE *fp);
+void fr_atomic_queue_debug(FILE *fp, fr_atomic_queue_t *aq);
#endif
* @param[in] ms the message set
* @param[in] fp the FILE where the messages are printed.
*/
-void fr_message_set_debug(fr_message_set_t *ms, FILE *fp)
+void fr_message_set_debug(FILE *fp, fr_message_set_t *ms)
{
int i;
int fr_message_set_messages_used(fr_message_set_t *ms) CC_HINT(nonnull);
void fr_message_set_gc(fr_message_set_t *ms) CC_HINT(nonnull);
-void fr_message_set_debug(fr_message_set_t *ms, FILE *fp) CC_HINT(nonnull);
+void fr_message_set_debug(FILE *fp, fr_message_set_t *ms) CC_HINT(nonnull);
#ifdef __cplusplus
}
#ifndef NDEBUG
/** Dump a queue.
*
- * @param[in] fq the queue
* @param[in] fp where the debugging information will be printed.
+ * @param[in] fq the queue
*/
-void fr_queue_debug(fr_queue_t *fq, FILE *fp)
+void fr_queue_debug(FILE *fp, fr_queue_t *fq)
{
int i;
int fr_queue_localize_atomic(fr_queue_t *fq, fr_atomic_queue_t *aq) CC_HINT(nonnull);
#ifndef NDEBUG
-void fr_queue_debug(fr_queue_t *fq, FILE *fp) CC_HINT(nonnull);
+void fr_queue_debug(FILE *fp, fr_queue_t *fq) CC_HINT(nonnull);
#endif
* @param[in] rb the ring buffer
* @param[in] fp the FILE where the messages are printed.
*/
-void fr_ring_buffer_debug(fr_ring_buffer_t *rb, FILE *fp)
+void fr_ring_buffer_debug(FILE *fp, fr_ring_buffer_t *rb)
{
fprintf(fp, "Buffer %p, write_offset %zu, data_start %zu, data_end %zu\n",
rb->buffer, rb->write_offset, rb->data_start, rb->data_end);
size_t fr_ring_buffer_used(fr_ring_buffer_t *rb) CC_HINT(nonnull);
-void fr_ring_buffer_debug(fr_ring_buffer_t *rb, FILE *fp) CC_HINT(nonnull);
+void fr_ring_buffer_debug(FILE *fp, fr_ring_buffer_t *rb) CC_HINT(nonnull);
#ifdef __cplusplus
}
}
}
-void fr_command_debug(FILE *fp, fr_cmd_t *head)
+void fr_cmd_debug(FILE *fp, fr_cmd_t *head)
{
fr_command_debug_internal(fp, head, 0);
}
int fr_command_tab_expand(TALLOC_CTX *ctx, fr_cmd_t *head, fr_cmd_info_t *info, int max_expansions, char const **expansions);
char const *fr_command_help(fr_cmd_t *head, int argc, char *argv[]);
int fr_command_run(FILE *fp, FILE *fp_err, fr_cmd_info_t *info, bool read_only);
-void fr_command_debug(FILE *fp, fr_cmd_t *head);
+void fr_cmd_debug(FILE *fp, fr_cmd_t *head);
int fr_command_str_to_argv(fr_cmd_t *head, fr_cmd_info_t *info, char const *str);
int fr_command_clear(int new_argc, fr_cmd_info_t *info) CC_HINT(nonnull);
#define tmpl_aexpand_type(_ctx, _out, _type, _request, _vpt) \
_tmpl_to_atype(_ctx, (void *)(_out), _request, _vpt, NULL, NULL, _type)
-void tmpl_debug(tmpl_t const *vpt) CC_HINT(nonnull);
+void tmpl_debug(FILE *fp, tmpl_t const *vpt) CC_HINT(nonnull);
fr_pair_list_t *tmpl_list_head(request_t *request, fr_dict_attr_t const *list);
int tmpl_afrom_value_box(TALLOC_CTX *ctx, tmpl_t **out, fr_value_box_t *data, bool steal) CC_HINT(nonnull);
-void tmpl_attr_ref_debug(const tmpl_attr_t *ar, int idx) CC_HINT(nonnull);
+void tmpl_attr_ref_debug(FILE *fp, const tmpl_attr_t *ar, int idx) CC_HINT(nonnull);
-void tmpl_attr_ref_list_debug(FR_DLIST_HEAD(tmpl_attr_list) const *ar_head) CC_HINT(nonnull);
+void tmpl_attr_ref_list_debug(FILE *fp, FR_DLIST_HEAD(tmpl_attr_list) const *ar_head) CC_HINT(nonnull);
-void tmpl_attr_debug(tmpl_t const *vpt) CC_HINT(nonnull);
+void tmpl_attr_debug(FILE *fp, tmpl_t const *vpt) CC_HINT(nonnull);
int tmpl_attr_copy(tmpl_t *dst, tmpl_t const *src) CC_HINT(nonnull);
int tmpl_extents_build_to_leaf_parent(fr_dlist_head_t *leaf, fr_dlist_head_t *interior,
tmpl_t const *vpt) CC_HINT(nonnull);
-void tmpl_extents_debug(fr_dlist_head_t *head) CC_HINT(nonnull);
+void tmpl_extents_debug(FILE *fp, fr_dlist_head_t *head) CC_HINT(nonnull);
int tmpl_eval_pair(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt);
return 0;
}
-void tmpl_extents_debug(fr_dlist_head_t *head)
+void tmpl_extents_debug(FILE *fp, fr_dlist_head_t *head)
{
tmpl_attr_extent_t const *extent = NULL;
fr_pair_t *vp = NULL;
char const *ctx_name;
if (ar) {
- FR_FAULT_LOG("extent-interior-attr");
- tmpl_attr_ref_debug(extent->ar, 0);
+ fprintf(fp, "extent-interior-attr\n");
+ tmpl_attr_ref_debug(fp, extent->ar, 0);
} else {
- FR_FAULT_LOG("extent-leaf");
+ fprintf(fp, "extent-leaf\n");
}
ctx_name = talloc_get_name(extent->list_ctx);
if (strcmp(ctx_name, "fr_pair_t") == 0) {
- FR_FAULT_LOG("list_ctx : %p (%s, %s)", extent->list_ctx, ctx_name,
+ fprintf(fp, "list_ctx : %p (%s, %s)\n", extent->list_ctx, ctx_name,
((fr_pair_t *)extent->list_ctx)->da->name);
} else {
- FR_FAULT_LOG("list_ctx : %p (%s)", extent->list_ctx, ctx_name);
+ fprintf(fp, "list_ctx : %p (%s)\n", extent->list_ctx, ctx_name);
}
- FR_FAULT_LOG("list : %p", extent->list);
+ fprintf(fp, "list : %p", extent->list);
if (fr_pair_list_empty(extent->list)) {
- FR_FAULT_LOG("list (first) : none (%p)", extent->list);
+ fprintf(fp, "list (first) : none (%p)\n", extent->list);
} else {
vp = fr_pair_list_head(extent->list);
- FR_FAULT_LOG("list (first) : %s (%p)", vp->da->name, extent->list);
+ fprintf(fp, "list (first) : %s (%p)\n", vp->da->name, extent->list);
}
}
return ret;
}
-void tmpl_attr_ref_debug(const tmpl_attr_t *ar, int i)
+void tmpl_attr_ref_debug(FILE *fp, const tmpl_attr_t *ar, int i)
{
char buffer[sizeof(STRINGIFY(INT16_MAX)) + 1];
case TMPL_ATTR_TYPE_UNSPEC:
case TMPL_ATTR_TYPE_UNKNOWN:
if (!ar->da) {
- FR_FAULT_LOG("\t[%u] %s null%s%s%s",
- i,
- fr_table_str_by_value(attr_table, ar->type, "<INVALID>"),
- ar->ar_num != NUM_UNSPEC ? "[" : "",
- ar->ar_num != NUM_UNSPEC ? fr_table_str_by_value(attr_num_table, ar->ar_num, buffer) : "",
- ar->ar_num != NUM_UNSPEC ? "]" : "");
+ fprintf(fp, "\t[%u] %s null%s%s%s\n",
+ i,
+ fr_table_str_by_value(attr_table, ar->type, "<INVALID>"),
+ ar->ar_num != NUM_UNSPEC ? "[" : "",
+ ar->ar_num != NUM_UNSPEC ? fr_table_str_by_value(attr_num_table, ar->ar_num, buffer) : "",
+ ar->ar_num != NUM_UNSPEC ? "]" : "");
return;
}
- FR_FAULT_LOG("\t[%u] %s %s %s%s%s%s (%p) attr %u",
- i,
- fr_table_str_by_value(attr_table, ar->type, "<INVALID>"),
- fr_type_to_str(ar->da->type),
- ar->da->name,
- ar->ar_num != NUM_UNSPEC ? "[" : "",
- ar->ar_num != NUM_UNSPEC ? fr_table_str_by_value(attr_num_table, ar->ar_num, buffer) : "",
- ar->ar_num != NUM_UNSPEC ? "]" : "",
- ar->da,
- ar->da->attr
+ fprintf(fp, "\t[%u] %s %s %s%s%s%s (%p) attr %u\n ",
+ i,
+ fr_table_str_by_value(attr_table, ar->type, "<INVALID>"),
+ fr_type_to_str(ar->da->type),
+ ar->da->name,
+ ar->ar_num != NUM_UNSPEC ? "[" : "",
+ ar->ar_num != NUM_UNSPEC ? fr_table_str_by_value(attr_num_table, ar->ar_num, buffer) : "",
+ ar->ar_num != NUM_UNSPEC ? "]" : "",
+ ar->da,
+ ar->da->attr
);
- FR_FAULT_LOG("\t is_raw : %s", ar_is_raw(ar) ? "yes" : "no");
- FR_FAULT_LOG("\t is_unknown : %s", ar_is_unknown(ar) ? "yes" : "no");
- if (ar->ar_parent) FR_FAULT_LOG("\t parent : %s (%p)", ar->ar_parent->name, ar->ar_parent);
+ fprintf(fp, "\t is_raw : %s\n", ar_is_raw(ar) ? "yes" : "no");
+ fprintf(fp, "\t is_unknown : %s", ar_is_unknown(ar) ? "yes" : "no");
+ if (ar->ar_parent) fprintf(fp, "\t parent : %s (%p)", ar->ar_parent->name, ar->ar_parent);
break;
* Type reveals unresolved status
* so we don't need to add it explicitly
*/
- FR_FAULT_LOG("\t[%u] %s %s%s%s%s",
- i,
- fr_table_str_by_value(attr_table, ar->type, "<INVALID>"),
- ar->ar_unresolved,
- ar->ar_num != NUM_UNSPEC ? "[" : "",
- ar->ar_num != NUM_UNSPEC ? fr_table_str_by_value(attr_num_table, ar->ar_num, buffer) : "",
- ar->ar_num != NUM_UNSPEC ? "]" : "");
- if (ar->ar_parent) FR_FAULT_LOG("\t parent : %s", ar->ar_parent->name);
- if (ar->ar_unresolved_namespace) FR_FAULT_LOG("\t namespace : %s", ar->ar_unresolved_namespace->name);
+ fprintf(fp, "\t[%u] %s %s%s%s%s\n",
+ i,
+ fr_table_str_by_value(attr_table, ar->type, "<INVALID>"),
+ ar->ar_unresolved,
+ ar->ar_num != NUM_UNSPEC ? "[" : "",
+ ar->ar_num != NUM_UNSPEC ? fr_table_str_by_value(attr_num_table, ar->ar_num, buffer) : "",
+ ar->ar_num != NUM_UNSPEC ? "]" : "");
+ if (ar->ar_parent) fprintf(fp, "\t parent : %s", ar->ar_parent->name);
+ if (ar->ar_unresolved_namespace) fprintf(fp, "\t namespace : %s", ar->ar_unresolved_namespace->name);
break;
default:
- FR_FAULT_LOG("\t[%u] Bad type %s(%u)",
+ fprintf(fp, "\t[%u] Bad type %s(%u)",
i, fr_table_str_by_value(attr_table, ar->type, "<INVALID>"), ar->type);
break;
}
}
-void tmpl_attr_ref_list_debug(FR_DLIST_HEAD(tmpl_attr_list) const *ar_head)
+void tmpl_attr_ref_list_debug(FILE *fp, FR_DLIST_HEAD(tmpl_attr_list) const *ar_head)
{
tmpl_attr_t *ar = NULL;
unsigned int i = 0;
- FR_FAULT_LOG("attribute references:");
+ fprintf(fp, "attribute references:\n");
/*
* Print all the attribute references
*/
while ((ar = tmpl_attr_list_next(ar_head, ar))) {
- tmpl_attr_ref_debug(ar, i);
+ tmpl_attr_ref_debug(fp, ar, i);
i++;
}
}
-void tmpl_attr_debug(tmpl_t const *vpt)
+void tmpl_attr_debug(FILE *fp, tmpl_t const *vpt)
{
tmpl_request_t *rr = NULL;
unsigned int i = 0;
break;
default:
- FR_FAULT_LOG("%s can't print tmpls of type %s", __FUNCTION__,
- tmpl_type_to_str(vpt->type));
+ fprintf(fp, "%s can't print tmpls of type %s\n", __FUNCTION__,
+ tmpl_type_to_str(vpt->type));
return;
}
- FR_FAULT_LOG("tmpl_t %s (%.8x) \"%pV\" (%p)",
- tmpl_type_to_str(vpt->type),
- vpt->type,
- fr_box_strvalue_len(vpt->name, vpt->len), vpt);
+ fprintf(fp, "tmpl_t %s (%.8x) \"%pV\" (%p)\n",
+ tmpl_type_to_str(vpt->type),
+ vpt->type,
+ fr_box_strvalue_len(vpt->name, vpt->len), vpt);
- FR_FAULT_LOG("\tcast : %s", fr_type_to_str(tmpl_rules_cast(vpt)));
- FR_FAULT_LOG("\tquote : %s", fr_table_str_by_value(fr_token_quotes_table, vpt->quote, "<INVALID>"));
+ fprintf(fp, "\tcast : %s\n", fr_type_to_str(tmpl_rules_cast(vpt)));
+ fprintf(fp, "\tquote : %s\n", fr_table_str_by_value(fr_token_quotes_table, vpt->quote, "<INVALID>"));
- FR_FAULT_LOG("request references:");
+ fprintf(fp, "request references:");
/*
* Print all the request references
*/
while ((rr = tmpl_request_list_next(&vpt->data.attribute.rr, rr))) {
- FR_FAULT_LOG("\t[%u] %s (%u)", i,
+ fprintf(fp, "\t[%u] %s (%u)\n", i,
fr_table_str_by_value(tmpl_request_ref_table, rr->request, "<INVALID>"), rr->request);
i++;
}
- FR_FAULT_LOG("list: %s", tmpl_list_name(tmpl_list(vpt), "<INVALID>"));
- tmpl_attr_ref_list_debug(tmpl_attr(vpt));
+ fprintf(fp, "list: %s\n", tmpl_list_name(tmpl_list(vpt), "<INVALID>"));
+ tmpl_attr_ref_list_debug(fp, tmpl_attr(vpt));
}
-void tmpl_debug(tmpl_t const *vpt)
+void tmpl_debug(FILE *fp, tmpl_t const *vpt)
{
switch (vpt->type) {
case TMPL_TYPE_ATTR:
case TMPL_TYPE_ATTR_UNRESOLVED:
- tmpl_attr_debug(vpt);
+ tmpl_attr_debug(fp, vpt);
return;
default:
break;
}
- FR_FAULT_LOG("tmpl_t %s (%.8x) \"%s\" (%p)",
- tmpl_type_to_str(vpt->type),
- vpt->type,
- vpt->name, vpt);
+ fprintf(fp, "tmpl_t %s (%.8x) \"%pR\" (%p)\n",
+ tmpl_type_to_str(vpt->type),
+ vpt->type,
+ vpt->name, vpt);
- FR_FAULT_LOG("\tcast : %s", fr_type_to_str(tmpl_rules_cast(vpt)));
- FR_FAULT_LOG("\tquote : %s", fr_table_str_by_value(fr_token_quotes_table, vpt->quote, "<INVALID>"));
+ fprintf(fp, "\tcast : %s\n", fr_type_to_str(tmpl_rules_cast(vpt)));
+ fprintf(fp, "\tquote : %s\n", fr_table_str_by_value(fr_token_quotes_table, vpt->quote, "<INVALID>"));
switch (vpt->type) {
case TMPL_TYPE_DATA:
- FR_FAULT_LOG("\ttype : %s", fr_type_to_str(tmpl_value_type(vpt)));
- FR_FAULT_LOG("\tlen : %zu", tmpl_value_length(vpt));
- FR_FAULT_LOG("\tvalue : %pV", tmpl_value(vpt));
+ fprintf(fp, "\ttype : %s\n", fr_type_to_str(tmpl_value_type(vpt)));
+ fprintf(fp, "\tlen : %zu\n", tmpl_value_length(vpt));
+ fprintf(fp, "\tvalue : %pV\n", tmpl_value(vpt));
- if (tmpl_value_enumv(vpt)) FR_FAULT_LOG("\tenumv : %s (%p)",
- tmpl_value_enumv(vpt)->name, tmpl_value_enumv(vpt));
+ if (tmpl_value_enumv(vpt)) fprintf(fp, "\tenumv : %s (%p)",
+ tmpl_value_enumv(vpt)->name, tmpl_value_enumv(vpt));
return;
case TMPL_TYPE_XLAT:
xlat_aprint(NULL, &str, tmpl_xlat(vpt), NULL);
- FR_FAULT_LOG("\texpansion : %s", str);
+ fprintf(fp, "\texpansion : %s\n", str);
talloc_free(str);
}
case TMPL_TYPE_REGEX:
{
- FR_FAULT_LOG("\tpattern : %s", vpt->name);
+ fprintf(fp, "\tpattern : %s\n", vpt->name);
}
break;
default:
if (tmpl_needs_resolving(vpt)) {
if (tmpl_is_data_unresolved(vpt)) {
- FR_FAULT_LOG("\tunescaped : %s", vpt->data.unescaped);
- FR_FAULT_LOG("\tlen : %zu", talloc_array_length(vpt->data.unescaped) - 1);
+ fprintf(fp, "\tunescaped : %s\n", vpt->data.unescaped);
+ fprintf(fp, "\tlen : %zu\n", talloc_array_length(vpt->data.unescaped) - 1);
} else {
- FR_FAULT_LOG("\tunresolved : %s", vpt->name);
- FR_FAULT_LOG("\tlen : %zu", vpt->len);
+ fprintf(fp, "\tunresolved : %s\n", vpt->name);
+ fprintf(fp, "\tlen : %zu\n", vpt->len);
}
} else {
- FR_FAULT_LOG("debug nyi");
+ fprintf(fp, "debug nyi\n");
}
break;
}
switch (ar->type) {
case TMPL_ATTR_TYPE_NORMAL:
if (seen_unknown) {
- tmpl_attr_debug(vpt);
+ tmpl_attr_debug(stderr, vpt);
fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: "
"TMPL_TYPE_ATTR known attribute \"%s\" "
"occurred after unknown attribute %s "
ar->unknown.da->name);
}
if (seen_unresolved) {
- tmpl_attr_debug(vpt);
+ tmpl_attr_debug(stderr, vpt);
fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: "
"TMPL_TYPE_ATTR known attribute \"%s\" "
"occurred after unresolved attribute \"%s\""
case TMPL_ATTR_TYPE_UNSPEC:
if (seen_unknown) {
- tmpl_attr_debug(vpt);
+ tmpl_attr_debug(stderr, vpt);
fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: "
"TMPL_TYPE_ATTR unspecified attribute "
"occurred after unknown attribute %s "
ar->unknown.da->name);
}
if (seen_unresolved) {
- tmpl_attr_debug(vpt);
+ tmpl_attr_debug(stderr, vpt);
fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: "
"TMPL_TYPE_ATTR unspecified attribute "
"occurred after unresolved attribute \"%s\""
case TMPL_ATTR_TYPE_UNKNOWN:
seen_unknown = ar;
if (seen_unresolved) {
- tmpl_attr_debug(vpt);
+ tmpl_attr_debug(stderr, vpt);
fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: "
"TMPL_TYPE_ATTR unknown attribute \"%s\" "
"occurred after unresolved attribute %s "
if ((tmpl_attr_list_num_elements(tmpl_attr(vpt)) > 0) &&
((tmpl_attr_t *)tmpl_attr_list_tail(tmpl_attr(vpt)))->da) {
#ifndef NDEBUG
- tmpl_attr_debug(vpt);
+ tmpl_attr_debug(stderr, vpt);
#endif
fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_ATTR_UNRESOLVED contains %u "
"references", file, line, tmpl_attr_list_num_elements(tmpl_attr(vpt)));
* The other tmpl types MUST have already been
* converted to the "realized" types.
*/
- tmpl_debug(vpt);
+ tmpl_debug(stderr, vpt);
fr_assert(0);
break;
}
} else {
start = 0;
- fr_value_box_debug(start_vb);
+ fr_value_box_debug(fr_log_fp, start_vb);
end = fr_value_box_list_head(&start_vb->vb_group)->vb_uint64;
step = 1;
}
}
if (!fr_value_box_is_safe_for(vb, FR_VALUE_BOX_SAFE_FOR_ANY)) {
- fr_value_box_debug(vb);
+ fr_value_box_debug(fr_log_fp, vb);
REDEBUG("Refusing to reference attribute from unsafe data");
return XLAT_ACTION_FAIL;
}
/*
* Regex? Or something else weird?
*/
- tmpl_debug(vpt);
+ tmpl_debug(stderr, vpt);
fr_assert(0);
}
}
void fr_dict_global_ctx_read_only(void);
-void fr_dict_global_ctx_debug(fr_dict_gctx_t const *gctx);
+void fr_dict_gctx_debug(FILE *fp, fr_dict_gctx_t const *gctx);
char const *fr_dict_global_ctx_dir(void);
da->attr,
fr_type_to_str(da->type),
ctx->flags);
-
+
dict_attr_ext_debug(ctx->prefix, da); /* Print all the extension debug info */
ext = fr_dict_attr_ext(da, FR_DICT_ATTR_EXT_ENUMV);
enumv;
enumv = fr_hash_table_iter_next(ext->name_by_value, &iter)) {
char *value = fr_asprintf(NULL, "%pV", enumv->value);
-
+
fprintf(ctx->fp, "%s %s -> %s\n",
ctx->prefix,
enumv->name,
fprintf(fp, "%-40s\t%s\n", da->name, buffer);
}
}
-
if (still_loaded) {
#ifndef NDEBUG
- fr_dict_global_ctx_debug(gctx);
+ fr_dict_gctx_debug(stderr, gctx);
#endif
return -1;
}
*
* Intended to be called from a debugger
*/
-void fr_dict_global_ctx_debug(fr_dict_gctx_t const *gctx)
+void fr_dict_gctx_debug(FILE *fp, fr_dict_gctx_t const *gctx)
{
fr_hash_iter_t dict_iter;
fr_dict_t *dict;
if (gctx == NULL) gctx = dict_gctx;
if (!gctx) {
- FR_FAULT_LOG("gctx not initialised");
+ fprintf(fp, "gctx not initialised\n");
return;
}
- FR_FAULT_LOG("gctx %p report", dict_gctx);
+ fprintf(fp, "gctx %p report\n", dict_gctx);
for (dict = fr_hash_table_iter_init(gctx->protocol_by_num, &dict_iter);
dict;
dict = fr_hash_table_iter_next(gctx->protocol_by_num, &dict_iter)) {
for (dep = fr_rb_iter_init_inorder(&dep_iter, dict->dependents);
dep;
dep = fr_rb_iter_next_inorder(&dep_iter)) {
- FR_FAULT_LOG("\t%s is referenced from %s count (%d)", dict->root->name, dep->dependent, dep->count);
+ fprintf(fp, "\t%s is referenced from %s count (%d)\n",
+ dict->root->name, dep->dependent, dep->count);
}
}
for (dep = fr_rb_iter_init_inorder(&dep_iter, gctx->internal->dependents);
dep;
dep = fr_rb_iter_next_inorder(&dep_iter)) {
- FR_FAULT_LOG("\t%s is referenced from %s count (%d)", gctx->internal->root->name, dep->dependent, dep->count);
+ fprintf(fp, "\t%s is referenced from %s count (%d)\n",
+ gctx->internal->root->name, dep->dependent, dep->count);
}
}
}
/** Called from a debugger to print information about a dl_loader
*
*/
-void dl_loader_debug(dl_loader_t *dl)
+void dl_loader_debug(FILE *fp, dl_loader_t *dl)
{
- FR_FAULT_LOG("dl_loader %p", dl);
- FR_FAULT_LOG("lib_dir : %s", dl->lib_dir);
- FR_FAULT_LOG("do_dlclose : %s", dl->do_dlclose ? "yes" : "no");
- FR_FAULT_LOG("uctx : %p", dl->uctx);
- FR_FAULT_LOG("uctx_free : %s", dl->do_dlclose ? "yes" : "no");
- FR_FAULT_LOG("defer_symbol_init : %s", dl->defer_symbol_init ? "yes" : "no");
+ fprintf(fp, "dl_loader %p", dl);
+ fprintf(fp, "lib_dir : %s\n", dl->lib_dir);
+ fprintf(fp, "do_dlclose : %s\n", dl->do_dlclose ? "yes" : "no");
+ fprintf(fp, "uctx : %p\n", dl->uctx);
+ fprintf(fp, "uctx_free : %s\n", dl->do_dlclose ? "yes" : "no");
+ fprintf(fp, "defer_symbol_init : %s\n", dl->defer_symbol_init ? "yes" : "no");
fr_dlist_foreach(&dl->sym_init, dl_symbol_init_t, sym) {
- FR_FAULT_LOG("symbol_init %s", sym->symbol ? sym->symbol : "<base>");
- FR_FAULT_LOG("\tpriority : %u", sym->priority);
- FR_FAULT_LOG("\tfunc : %p", sym->func);
- FR_FAULT_LOG("\tuctx : %p", sym->uctx);
+ fprintf(fp, "symbol_init %s\n", sym->symbol ? sym->symbol : "<base>");
+ fprintf(fp, "\tpriority : %u\n", sym->priority);
+ fprintf(fp, "\tfunc : %p\n", sym->func);
+ fprintf(fp, "\tuctx : %p\n", sym->uctx);
}
fr_dlist_foreach(&dl->sym_free, dl_symbol_free_t, sym) {
- FR_FAULT_LOG("symbol_free %s", sym->symbol ? sym->symbol : "<base>");
- FR_FAULT_LOG("\tpriority : %u", sym->priority);
- FR_FAULT_LOG("\tfunc : %p", sym->func);
- FR_FAULT_LOG("\tuctx : %p", sym->uctx);
+ fprintf(fp, "symbol_free %s\n", sym->symbol ? sym->symbol : "<base>");
+ fprintf(fp, "\tpriority : %u\n", sym->priority);
+ fprintf(fp, "\tfunc : %p\n", sym->func);
+ fprintf(fp, "\tuctx : %p\n", sym->uctx);
}
}
bool dl_loader_set_static(dl_loader_t *dl_loader, bool do_static) CC_HINT(nonnull);
-void dl_loader_debug(dl_loader_t *dl);
+void dl_loader_debug(FILE *fp, dl_loader_t *dl) CC_HINT(nonnull);
#ifdef __cplusplus
}
#endif
void _fr_pair_list_log(fr_log_t const *log, int lvl, fr_pair_t *parent,
fr_pair_list_t const *list, char const *file, int line) CC_HINT(nonnull(1,4));
-void fr_pair_list_debug(fr_pair_list_t const *list) CC_HINT(nonnull);
-void fr_pair_debug(fr_pair_t const *pair) CC_HINT(nonnull);
+void fr_pair_list_debug(FILE *fp, fr_pair_list_t const *list) CC_HINT(nonnull);
+void _fr_pair_list_debug(FILE *fp, int lvl, fr_pair_t *parent, fr_pair_list_t const *list)
+ CC_HINT(nonnull(1, 4));
+void fr_pair_debug(FILE *fp, fr_pair_t const *pair) CC_HINT(nonnull);
/** @} */
fr_pair_list_log_sbuff(log, lvl, parent, list, file, line, &sbuff);
}
+static void fr_pair_list_debug_sbuff(FILE *fp, int lvl, fr_pair_t *parent, fr_pair_list_t const *list, fr_sbuff_t *sbuff)
+{
+ fr_dict_attr_t const *parent_da = NULL;
+
+ fr_pair_list_foreach(list, vp) {
+ PAIR_VERIFY_WITH_LIST(list, vp);
+
+ fr_sbuff_set_to_start(sbuff);
+
+ if (vp->vp_raw) (void) fr_sbuff_in_strcpy(sbuff, "raw.");
+
+ if (parent && (parent->vp_type != FR_TYPE_GROUP)) parent_da = parent->da;
+ if (fr_dict_attr_oid_print(sbuff, parent_da, vp->da, false) <= 0) return;
+
+ /*
+ * Recursively print grouped attributes.
+ */
+ switch (vp->vp_type) {
+ case FR_TYPE_STRUCTURAL:
+ fprintf(fp, "%*s%*s {\n", lvl * 2, "", (int) fr_sbuff_used(sbuff), fr_sbuff_start(sbuff));
+ _fr_pair_list_debug(fp, lvl + 1, vp, &vp->vp_group);
+ fprintf(fp, "%*s}\n", lvl * 2, "");
+ break;
+
+ default:
+ (void) fr_sbuff_in_strcpy(sbuff, " = ");
+ if (fr_value_box_print_quoted(sbuff, &vp->data, T_DOUBLE_QUOTED_STRING)< 0) break;
+
+ fprintf(fp, "%*s%*s\n", lvl * 2, "", (int) fr_sbuff_used(sbuff), fr_sbuff_start(sbuff));
+ }
+ }
+}
+
+/** Print a list of attributes and enumv
+ *
+ * @param[in] fp to output to.
+ * @param[in] lvl depth in structural attribute.
+ * @param[in] parent parent attribute
+ * @param[in] list to print.
+ */
+void _fr_pair_list_debug(FILE *fp, int lvl, fr_pair_t *parent, fr_pair_list_t const *list)
+{
+ fr_sbuff_t sbuff;
+ char buffer[1024];
+
+ fr_sbuff_init_out(&sbuff, buffer, sizeof(buffer));
+
+ fr_pair_list_debug_sbuff(fp, lvl, parent, list, &sbuff);
+}
+
/** Dumps a list to the default logging destination - Useful for calling from debuggers
*
*/
-void fr_pair_list_debug(fr_pair_list_t const *list)
+void fr_pair_list_debug(FILE *fp, fr_pair_list_t const *list)
{
- _fr_pair_list_log(&default_log, 0, NULL, list, "<internal>", 0);
+ _fr_pair_list_debug(fp, 0, NULL, list);
}
/** Dumps a pair to the default logging destination - Useful for calling from debuggers
*
*/
-void fr_pair_debug(fr_pair_t const *pair)
+void fr_pair_debug(FILE *fp, fr_pair_t const *pair)
{
fr_sbuff_t sbuff;
char buffer[1024];
(void) fr_pair_print(&sbuff, NULL, pair);
- fr_log(&default_log, L_DBG, __FILE__, __LINE__, "%pV",
- fr_box_strvalue_len(fr_sbuff_start(&sbuff), fr_sbuff_used(&sbuff)));
+ fprintf(fp, "%pV\n", fr_box_strvalue_len(fr_sbuff_start(&sbuff), fr_sbuff_used(&sbuff)));
}
}
}
-void fr_sbuff_unescape_debug(fr_sbuff_unescape_rules_t const *escapes)
+void fr_sbuff_unescape_debug(FILE *fp, fr_sbuff_unescape_rules_t const *escapes)
{
uint8_t i;
- FR_FAULT_LOG("Escape rules %s (%p)", escapes->name, escapes);
- FR_FAULT_LOG("chr : %c", escapes->chr ? escapes->chr : ' ');
- FR_FAULT_LOG("do_hex : %s", escapes->do_hex ? "yes" : "no");
- FR_FAULT_LOG("do_oct : %s", escapes->do_oct ? "yes" : "no");
+ fprintf(fp, "Escape rules %s (%p)\n", escapes->name, escapes);
+ fprintf(fp, "chr : %c\n", escapes->chr ? escapes->chr : ' ');
+ fprintf(fp, "do_hex : %s\n", escapes->do_hex ? "yes" : "no");
+ fprintf(fp, "do_oct : %s\n", escapes->do_oct ? "yes" : "no");
- FR_FAULT_LOG("substitutions:");
+ fprintf(fp, "substitutions:\n");
for (i = 0; i < UINT8_MAX; i++) {
- if (escapes->subs[i]) FR_FAULT_LOG("\t%s -> %s",
+ if (escapes->subs[i]) FR_FAULT_LOG("\t%s -> %s\n",
sbuff_print_char((char)i),
sbuff_print_char((char)escapes->subs[i]));
}
- FR_FAULT_LOG("skipes:");
+ fprintf(fp, "skipes:\n");
for (i = 0; i < UINT8_MAX; i++) {
- if (escapes->skip[i]) FR_FAULT_LOG("\t%s", sbuff_print_char((char)i));
+ if (escapes->skip[i]) fprintf(fp, "\t%s\n", sbuff_print_char((char)i));
}
}
-void fr_sbuff_terminal_debug(fr_sbuff_term_t const *tt)
+void fr_sbuff_terminal_debug(FILE *fp, fr_sbuff_term_t const *tt)
{
size_t i;
- FR_FAULT_LOG("Terminal count %zu", tt->len);
+ fprintf(fp, "Terminal count %zu\n", tt->len);
- for (i = 0; i < tt->len; i++) FR_FAULT_LOG("\t\"%s\" (%zu)", tt->elem[i].str, tt->elem[i].len);
+ for (i = 0; i < tt->len; i++) fprintf(fp, "\t\"%s\" (%zu)\n", tt->elem[i].str, tt->elem[i].len);
}
-void fr_sbuff_parse_rules_debug(fr_sbuff_parse_rules_t const *p_rules)
+void fr_sbuff_parse_rules_debug(FILE *fp, fr_sbuff_parse_rules_t const *p_rules)
{
- FR_FAULT_LOG("Parse rules %p", p_rules);
+ fprintf(fp, "Parse rules %p\n", p_rules);
FR_FAULT_LOG("Escapes - ");
if (p_rules->escapes) {
- fr_sbuff_unescape_debug(p_rules->escapes);
+ fr_sbuff_unescape_debug(fp, p_rules->escapes);
} else {
- FR_FAULT_LOG("<none>");
+ fprintf(fp, "<none>\n");
}
FR_FAULT_LOG("Terminals - ");
if (p_rules->terminals) {
- fr_sbuff_terminal_debug(p_rules->terminals);
+ fr_sbuff_terminal_debug(fp, p_rules->terminals);
} else {
- FR_FAULT_LOG("<none>");
+ fprintf(fp, "<none>\n");
}
}
/** @} */
-void fr_sbuff_unescape_debug(fr_sbuff_unescape_rules_t const *escapes);
+void fr_sbuff_unescape_debug(FILE *fp, fr_sbuff_unescape_rules_t const *escapes);
-void fr_sbuff_terminal_debug(fr_sbuff_term_t const *tt);
+void fr_sbuff_terminal_debug(FILE *fp, fr_sbuff_term_t const *tt);
-void fr_sbuff_parse_rules_debug(fr_sbuff_parse_rules_t const *p_rules);
+void fr_sbuff_parse_rules_debug(FILE *fp, fr_sbuff_parse_rules_t const *p_rules);
/*
* ...printf("foo %.*s", fr_sbuff_as_percent_s(&sbuff));
}
}
-#define INFO_INDENT(_fmt, ...) FR_FAULT_LOG("%*s"_fmt, depth * 2, " ", ## __VA_ARGS__)
+#define INFO_INDENT(_fmt, ...) fprintf(fp, "%*s" _fmt "\n", 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_value_box_list_t const *head, int depth)
+static void _fr_value_box_debug(FILE *fp, fr_value_box_t const *vb, int depth, int idx);
+static void _fr_value_box_list_debug(FILE *fp, fr_value_box_list_t const *head, int depth)
{
int i = 0;
INFO_INDENT("{");
- fr_value_box_list_foreach(head, vb) _fr_value_box_debug(vb, depth + 1, i++);
+ fr_value_box_list_foreach(head, vb) _fr_value_box_debug(fp, vb, depth + 1, i++);
INFO_INDENT("}");
}
*
* @note Call directly from the debugger
*/
-void fr_value_box_list_debug(fr_value_box_list_t const *head)
+void fr_value_box_list_debug(FILE *fp, fr_value_box_list_t const *head)
{
- _fr_value_box_list_debug(head, 0);
+ _fr_value_box_list_debug(fp, head, 0);
}
-static void _fr_value_box_debug(fr_value_box_t const *vb, int depth, int idx)
+static void _fr_value_box_debug(FILE *fp, fr_value_box_t const *vb, int depth, int idx)
{
char *value;
char buffer[64];
if (fr_type_is_structural(vb->type)) {
- _fr_value_box_list_debug(&vb->vb_group, depth + 1);
+ _fr_value_box_list_debug(fp, &vb->vb_group, depth + 1);
return;
}
*
* @note Call directly from the debugger
*/
-void fr_value_box_debug(fr_value_box_t const *vb)
+void fr_value_box_debug(FILE *fp, fr_value_box_t const *vb)
{
- _fr_value_box_debug(vb, 0, -1);
+ _fr_value_box_debug(fp, vb, 0, -1);
}
*
* @{
*/
-void fr_value_box_list_debug(fr_value_box_list_t const *head);
-void fr_value_box_debug(fr_value_box_t const *vb);
+void fr_value_box_list_debug(FILE *fp, fr_value_box_list_t const *head);
+void fr_value_box_debug(FILE *fp, fr_value_box_t const *vb);
/** @} */
#undef _CONST
*/
vp = fr_pair_dcursor_by_da_init(&cursor, vps, attr_dns_packet);
if (!vp) {
- fr_pair_list_debug(vps);
+ fr_pair_list_log(&default_log, 0, vps);
fr_strerror_const("attribute list does not include DNS packet header");
return -1;
#ifndef NDEBUG
if (debug_lvl) {
printf("Start\n");
- fr_atomic_queue_debug(aq, stdout);
+ fr_atomic_queue_debug(stdout, aq);
if (debug_lvl > 1) printf("Filling with %d\n", size);
}
#ifndef NDEBUG
if (debug_lvl > 1) {
printf("iteration %d\n", i);
- fr_atomic_queue_debug(aq, stdout);
+ fr_atomic_queue_debug(stdout, aq);
}
#endif
}
#ifndef NDEBUG
if (debug_lvl) {
printf("Full\n");
- fr_atomic_queue_debug(aq, stdout);
+ fr_atomic_queue_debug(stdout, aq);
if (debug_lvl > 1) printf("Emptying\n");
}
#ifndef NDEBUG
if (debug_lvl > 1) {
printf("iteration %d\n", i);
- fr_atomic_queue_debug(aq, stdout);
+ fr_atomic_queue_debug(stdout, aq);
}
#endif
}
#ifndef NDEBUG
if (debug_lvl) {
printf("Empty\n");
- fr_atomic_queue_debug(aq, stdout);
+ fr_atomic_queue_debug(stdout, aq);
}
#endif
MPRINT2("GC\n");
fr_message_set_gc(ms);
- if (debug_lvl > 1) fr_message_set_debug(ms, stdout);
+ if (debug_lvl > 1) fr_message_set_debug(stdout, ms);
/*
* After the garbage collection, all messages marked "done" MUST also be marked "free".
MPRINT2("Worker GC\n");
fr_message_set_gc(ms);
- if (debug_lvl > 1) fr_message_set_debug(ms, stdout);
+ if (debug_lvl > 1) fr_message_set_debug(stdout, ms);
/*
* After the garbage collection, all messages marked "done" MUST also be marked "free".
MPRINT1("TEST 1 used %d (%zu)\n", fr_message_set_messages_used(ms), used);
- if (debug_lvl) fr_message_set_debug(ms, stdout);
+ if (debug_lvl) fr_message_set_debug(stdout, ms);
/*
* Double the size of the allocations
MPRINT1("TEST 2 used %d\n", fr_message_set_messages_used(ms));
- if (debug_lvl) fr_message_set_debug(ms, stdout);
+ if (debug_lvl) fr_message_set_debug(stdout, ms);
/*
* Double the size of the allocations
*/
MPRINT1("TEST 3 used %d\n", fr_message_set_messages_used(ms));
- if (debug_lvl) fr_message_set_debug(ms, stdout);
+ if (debug_lvl) fr_message_set_debug(stdout, ms);
/*
* Do another 1000 rounds of alloc / free.
MPRINT1("TEST 4 used %d\n", fr_message_set_messages_used(ms));
- if (debug_lvl) fr_message_set_debug(ms, stdout);
+ if (debug_lvl) fr_message_set_debug(stdout, ms);
#if 0
MPRINT1("TEST 5 used %d\n", fr_message_set_messages_used(ms));
- if (debug_lvl) fr_message_set_debug(ms, stdout);
+ if (debug_lvl) fr_message_set_debug(stdout, ms);
/*
* Double the number of the allocations again,
MPRINT1("TEST 6 used %d\n", fr_message_set_messages_used(ms));
- if (debug_lvl) fr_message_set_debug(ms, stdout);
+ if (debug_lvl) fr_message_set_debug(stdout, ms);
#endif
my_alloc_size = end - start;
MPRINT1("GC\n");
fr_message_set_gc(ms);
- if (debug_lvl) fr_message_set_debug(ms, stdout);
+ if (debug_lvl) fr_message_set_debug(stdout, ms);
/*
* After the garbage collection, all messages marked "done" MUST also be marked "free".
MPRINT2("GC\n");
fr_message_set_gc(ms);
- if (debug_lvl > 1) fr_message_set_debug(ms, stdout);
+ if (debug_lvl > 1) fr_message_set_debug(stdout, ms);
/*
* After the garbage collection, all messages marked "done" MUST also be marked "free".
MPRINT2("GC\n");
fr_message_set_gc(ms);
- if (debug_lvl > 1) fr_message_set_debug(ms, stdout);
+ if (debug_lvl > 1) fr_message_set_debug(stdout, ms);
/*
* After the garbage collection, all messages marked "done" MUST also be marked "free".