mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 06:16:03 +00:00
Merge parser: Dump more partition debug information
We need to be able to dump the initial partition assignments, and then the partitions after minimization but before remapping to be able to check on what is being done by minimization. Add these as part of -D dfa-minimize-partitions Ideally we would rework the code so that the existing mininimization dump could share the dump routine but, its interwined with computation state and information is thrown away before reaching the end. Signed-off-by: John Johansen <john.johansen@canonical.com> MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1651 Approved-by: John Johansen <john@jjmx.net> Merged-by: John Johansen <john@jjmx.net>
This commit is contained in:
@@ -83,6 +83,12 @@ ostream &operator<<(ostream &os, State &state)
|
||||
return os;
|
||||
}
|
||||
|
||||
ostream &operator<<(ostream &os, perms_t &perms)
|
||||
{
|
||||
perms.dump(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
ostream &operator<<(ostream &os,
|
||||
const std::pair<State * const, Renumber_Map *> &p)
|
||||
{
|
||||
@@ -670,6 +676,39 @@ int DFA::apply_and_clear_deny(void)
|
||||
return c;
|
||||
}
|
||||
|
||||
ostream &DFA::dump_partition(ostream &os, Partition &p)
|
||||
{
|
||||
/* first entry is the representative state */
|
||||
for (Partition::iterator i = p.begin(); i != p.end(); i++) {
|
||||
os << **i;
|
||||
if (i == p.begin())
|
||||
os << " : ";
|
||||
else
|
||||
os << ", ";
|
||||
}
|
||||
os << "\n";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
ostream &DFA::dump_partitions(ostream &os, const char *description,
|
||||
list<Partition *> &partitions)
|
||||
{
|
||||
size_t j = 0;
|
||||
|
||||
os << "Dumping Minimization partition mapping: " << description << "\n";
|
||||
for (list<Partition *>::iterator p = partitions.begin();
|
||||
p != partitions.end(); p++) {
|
||||
os << " [" << j++ << "] ";
|
||||
os << (*(*p)->begin())->perms << ": ";
|
||||
(void) dump_partition(os, **p);
|
||||
os << "\n";
|
||||
}
|
||||
os << "\n";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
/* minimize the number of dfa states */
|
||||
void DFA::minimize(optflags const &opts)
|
||||
@@ -703,6 +742,9 @@ void DFA::minimize(optflags const &opts)
|
||||
<< " (accept " << accept_count << ")\r";
|
||||
}
|
||||
|
||||
if (opts.dump & DUMP_DFA_MIN_PARTS)
|
||||
(void) dump_partitions(cerr, "Initial", partitions);
|
||||
|
||||
/* perm_map is no longer needed so free the memory it is using.
|
||||
* Don't remove - doing it manually here helps reduce peak memory usage.
|
||||
*/
|
||||
@@ -768,6 +810,9 @@ void DFA::minimize(optflags const &opts)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (opts.dump & DUMP_DFA_MIN_PARTS)
|
||||
(void) dump_partitions(cerr, "Pre-remap", partitions);
|
||||
|
||||
/* Remap the dfa so it uses the representative states
|
||||
* Use the first state of a partition as the representative state
|
||||
* At this point all states with in a partition have transitions
|
||||
|
@@ -60,11 +60,12 @@ public:
|
||||
{
|
||||
os << "(allow/deny/prompt/audit/quiet)";
|
||||
}
|
||||
void dump(ostream &os)
|
||||
ostream &dump(ostream &os)
|
||||
{
|
||||
os << "(0x " << hex
|
||||
<< allow << "/" << deny << "/" << "/" << prompt << "/" << audit << "/" << quiet
|
||||
<< ')' << dec;
|
||||
return os;
|
||||
}
|
||||
|
||||
void clear(void) {
|
||||
@@ -391,7 +392,9 @@ public:
|
||||
void dump(ostream &os, Renumber_Map *renum);
|
||||
void dump_dot_graph(ostream &os);
|
||||
void dump_uniq_perms(const char *s);
|
||||
|
||||
ostream &dump_partition(ostream &os, Partition &p);
|
||||
ostream &dump_partitions(ostream &os, const char *description,
|
||||
list<Partition *> &partitions);
|
||||
map<transchar, transchar> equivalence_classes(optflags const &flags);
|
||||
void apply_equivalence_classes(map<transchar, transchar> &eq);
|
||||
|
||||
|
Reference in New Issue
Block a user