[apparmor] [PATCH 17/20] Add the ability to dump NodeSet to dfa state mapping

John Johansen john.johansen at canonical.com
Fri Nov 5 05:51:13 GMT 2010


Signed-off-by: John Johansen <john.johansen at canonical.com>
---
 parser/libapparmor_re/apparmor_re.h |    1 +
 parser/libapparmor_re/regexp.y      |   17 ++++++++++++++---
 parser/parser_main.c                |    2 ++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/parser/libapparmor_re/apparmor_re.h b/parser/libapparmor_re/apparmor_re.h
index a17069b..04af34b 100644
--- a/parser/libapparmor_re/apparmor_re.h
+++ b/parser/libapparmor_re/apparmor_re.h
@@ -37,6 +37,7 @@ typedef enum dfaflags {
   DFA_DUMP_MINIMIZE =		1 << 28,
   DFA_DUMP_UNREACHABLE =	1 << 29,
   DFA_DUMP_RULE_EXPR =		1 << 30,
+  DFA_DUMP_NODE_TO_DFA =	1 << 31,
 } dfaflags_t;
 
 #ifdef __cplusplus
diff --git a/parser/libapparmor_re/regexp.y b/parser/libapparmor_re/regexp.y
index b42c63c..ae6f153 100644
--- a/parser/libapparmor_re/regexp.y
+++ b/parser/libapparmor_re/regexp.y
@@ -1465,6 +1465,16 @@ do { \
 	} \
 } while (0)
 
+static void dump_node_to_dfa(NodeMap &nodemap)
+{
+	cerr << "Mapping of States to expr nodes\n"
+		"  State  <=   Nodes\n"
+		"-------------------\n";
+	for (NodeMap::iterator i = nodemap.begin(); i != nodemap.end(); i++)
+		cerr << "  " << i->second->label << " <= " << *i->first.second << "\n";
+
+}
+
 /**
  * Construct a DFA from a syntax tree.
  */
@@ -1579,6 +1589,10 @@ DFA::DFA(Node *root, dfaflags_t flags) : root(root)
 		(*i)->lastpos.clear();
 		(*i)->followpos.clear();
 	}
+
+	if (flags & DFA_DUMP_NODE_TO_DFA)
+		dump_node_to_dfa(nodemap);
+
 	for (NodeMap::iterator i = nodemap.begin(); i != nodemap.end(); i++)
 		delete i->first.second;
 	nodemap.clear();
@@ -1586,9 +1600,6 @@ DFA::DFA(Node *root, dfaflags_t flags) : root(root)
 	if (flags & (DFA_DUMP_STATS))
 	  fprintf(stderr, "\033[2KCreated dfa: states %ld,\teliminated duplicates %d,\tprotostate sets: longest %u, avg %u\n", states.size(), match_count, proto_max, (unsigned int) (proto_sum/states.size()));
 
-
-	/* TODO Dump dfa with NODE mapping - or node to dfa mapping */
-	// ??????
 }
 
 
diff --git a/parser/parser_main.c b/parser/parser_main.c
index acdb193..941b1b5 100644
--- a/parser/parser_main.c
+++ b/parser/parser_main.c
@@ -211,6 +211,8 @@ optflag_table_t dumpflag_table[] = {
 	{ 1, "dfa-minimize", "Dump dfa minimization", DFA_DUMP_MINIMIZE },
 	{ 1, "dfa-unreachable", "Dump dfa unreachable states",
 	  DFA_DUMP_UNREACHABLE },
+	{ 1, "dfa-node-map", "Dump expr node set to state mapping",
+	  DFA_DUMP_NODE_TO_DFA },
 	{ 1, "compress-progress", "Dump progress of compression",
 	  DFA_DUMP_TRANS_PROGRESS | DFA_DUMP_TRANS_STATS },
 	{ 1, "compress-stats", "Dump stats on compression",
-- 
1.7.1




More information about the AppArmor mailing list