summaryrefslogtreecommitdiffstats
path: root/lib/command_match.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-10-06 01:56:17 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-10-06 01:56:17 +0200
commitb4f56274fa6aa7240e06a67da0e85bfd0e4b2052 (patch)
tree9eb397882126a65e52145439b879d57309520c2d /lib/command_match.c
parentlib: Invalid commands are errors, fix msg formatting (diff)
downloadfrr-b4f56274fa6aa7240e06a67da0e85bfd0e4b2052.tar.xz
frr-b4f56274fa6aa7240e06a67da0e85bfd0e4b2052.zip
lib: Add tracing capabilities to command matcher
Compile with -DTRACE_MATCHER to enable matcher debugging to stdout. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command_match.c')
-rw-r--r--lib/command_match.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/command_match.c b/lib/command_match.c
index dcad94361..36efa3e76 100644
--- a/lib/command_match.c
+++ b/lib/command_match.c
@@ -116,6 +116,13 @@ command_match (struct graph *cmdgraph,
assert (*el);
}
+#ifdef TRACE_MATCHER
+ if (!*el)
+ fprintf (stdout, "No match\n");
+ else
+ fprintf (stdout, "Matched command\n->string %s\n->desc %s\n", (*el)->string, (*el)->doc);
+#endif
+
// free the leader token we alloc'd
XFREE (MTYPE_TMP, vector_slot (vvline, 0));
// free vector
@@ -184,6 +191,26 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n)
// get the current operating input token
char *input_token = vector_slot (vline, n);
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "\"%s\" matches \"%s\" (%d) ? ", input_token, token->text, token->type);
+ switch (match_token (token, input_token))
+ {
+ case trivial_match:
+ fprintf (stdout, "trivial_match ");
+ break;
+ case no_match:
+ fprintf (stdout, "no_match ");
+ break;
+ case partly_match:
+ fprintf (stdout, "partly_match ");
+ break;
+ case exact_match:
+ fprintf (stdout, "exact_match ");
+ break;
+ }
+ fprintf (stdout, "(minimum: %d)\n", minmatch);
+#endif
+
// if we don't match this node, die
if (match_token (token, input_token) < minmatch)
return NULL;
@@ -301,19 +328,35 @@ command_complete (struct graph *graph,
for (ALL_LIST_ELEMENTS_RO (current,node,gn))
{
struct cmd_token *token = gn->data;
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "\"%s\" matches \"%s\" (%d) ? ", input_token, token->text, token->type);
+#endif
+
switch (match_token (token, input_token))
{
case trivial_match:
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "trivial_match\n");
+#endif
case partly_match:
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "partly_match\n");
+#endif
if (idx == vector_active (vline) - 1)
{
listnode_add (next, gn);
break;
}
case exact_match:
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "exact_match\n");
+#endif
add_nexthops (next, gn);
break;
default:
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "no_match\n");
+#endif
break;
}
}