[apparmor] [PATCH 2/2] Add debugging dump for DFA partition minimization

John Johansen john.johansen at canonical.com
Thu May 19 22:32:08 UTC 2011


Allow dumping out which states where dropped during partition minimization
and which state became the partitions representative state.

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

diff --git a/parser/libapparmor_re/apparmor_re.h b/parser/libapparmor_re/apparmor_re.h
index 0a3aa70..f216217 100644
--- a/parser/libapparmor_re/apparmor_re.h
+++ b/parser/libapparmor_re/apparmor_re.h
@@ -30,6 +30,7 @@ typedef enum dfaflags {
   DFA_CONTROL_REMOVE_UNREACHABLE =	1 << 7,
   DFA_CONTROL_TRANS_HIGH =	1 << 8,
 
+  DFA_DUMP_MIN_PARTS =		1 << 13,
   DFA_DUMP_UNIQ_PERMS =		1 << 14,
   DFA_DUMP_MIN_UNIQ_PERMS =	1 << 15,
   DFA_DUMP_TREE_STATS =		1 << 16,
diff --git a/parser/libapparmor_re/hfa.cc b/parser/libapparmor_re/hfa.cc
index 40bf6e1..1470214 100644
--- a/parser/libapparmor_re/hfa.cc
+++ b/parser/libapparmor_re/hfa.cc
@@ -477,10 +477,14 @@ void DFA::minimize(dfaflags_t flags)
 	 * to states within the same partitions, however this can slow
 	 * down compressed dfa compression as there are more states,
 	 */
+	if (flags & DFA_DUMP_MIN_PARTS)
+		cerr << "Partitions after minimization\n";
 	for (list<Partition *>::iterator p = partitions.begin();
 	     p != partitions.end(); p++) {
 		/* representative state for this partition */
 		State *rep = *((*p)->begin());
+		if (flags & DFA_DUMP_MIN_PARTS)
+			cerr << *rep << " : ";
 
 		/* update representative state's transitions */
 		if (rep->cases.otherwise) {
@@ -498,6 +502,8 @@ void DFA::minimize(dfaflags_t flags)
 		 * and accumulate permissions */
 		for (Partition::iterator i = ++(*p)->begin(); i != (*p)->end(); i++) {
 //cerr << " " << (*i)->label;
+			if (flags & DFA_DUMP_MIN_PARTS)
+				cerr << **i << ", ";
 			(*i)->label = -1;
 			rep->accept |= (*i)->accept;
 			rep->audit |= (*i)->audit;
@@ -506,6 +512,8 @@ void DFA::minimize(dfaflags_t flags)
 			final_accept++;
 //if ((*p)->size() > 1)
 //cerr << "\n";
+		if (flags & DFA_DUMP_MIN_PARTS)
+			cerr << "\n";
 	}
 	if (flags & DFA_DUMP_STATS)
 		cerr << "\033[2KMinimized dfa: final partitions "
diff --git a/parser/parser_main.c b/parser/parser_main.c
index 6f4cf1e..117f42e 100644
--- a/parser/parser_main.c
+++ b/parser/parser_main.c
@@ -216,6 +216,8 @@ optflag_table_t dumpflag_table[] = {
 	  DFA_DUMP_UNIQ_PERMS },
 	{ 1, "dfa-minimize-uniq-perms", "Dump unique perms post minimization",
 	  DFA_DUMP_MIN_UNIQ_PERMS },
+	{ 1, "dfa-minimize-partitions", "Dump dfa minimization partitions",
+	  DFA_DUMP_MIN_PARTS },
 	{ 1, "compress-progress", "Dump progress of compression",
 	  DFA_DUMP_TRANS_PROGRESS | DFA_DUMP_TRANS_STATS },
 	{ 1, "compress-stats", "Dump stats on compression",
-- 
1.7.4.1




More information about the AppArmor mailing list