From d0bfd2ac518333369a384d58882ff37d5288225f Mon Sep 17 00:00:00 2001 From: Nobuhiro Tachino Date: Tue, 2 Feb 2010 12:19:18 -0500 Subject: rhbz 560890: preserve -L/-l variable ordering Switch to list from set for collecting available $var lists. Use O(N**2) list-uniqueifier that preserves initial ordering. --- main.cxx | 53 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'main.cxx') diff --git a/main.cxx b/main.cxx index cbedd6e4..0126f323 100644 --- a/main.cxx +++ b/main.cxx @@ -156,6 +156,26 @@ usage (systemtap_session& s, int exitcode) } +static void uniq_list(list& l) +{ + list r; + set s; + + for (list::iterator i = l.begin(); i != l.end(); ++i) { + s.insert(*i); + } + + for (list::iterator i = l.begin(); i != l.end(); ++i) { + if (s.find(*i) != s.end()) { + s.erase(*i); + r.push_back(*i); + } + } + + l.clear(); + l.assign(r.begin(), r.end()); +} + static void printscript(systemtap_session& s, ostream& o) { @@ -211,8 +231,10 @@ printscript(systemtap_session& s, ostream& o) // Print the locals and arguments for -L mode only if (s.listing_mode_vars) { - map var_list; // format <"name:type",count> - map arg_list; + map var_count; // format <"name:type",count> + map arg_count; + list var_list; + list arg_list; // traverse set to collect all locals and arguments for (set::iterator ix=it->second.begin(); ix!=it->second.end(); ++ix) { @@ -223,21 +245,28 @@ printscript(systemtap_session& s, ostream& o) stringstream tmps; vardecl* v = p->locals[j]; v->printsig (tmps); - var_list[tmps.str()]++; + var_count[tmps.str()]++; + var_list.push_back(tmps.str()); } // collect arguments of the probe if there - set arg_set; + list arg_set; p->getargs(arg_set); - for (set::iterator ia=arg_set.begin(); ia!=arg_set.end(); ++ia) - arg_list[*ia]++; + for (list::iterator ia=arg_set.begin(); ia!=arg_set.end(); ++ia) { + arg_count[*ia]++; + arg_list.push_back(*ia); + } } + + uniq_list(arg_list); + uniq_list(var_list); + // print the set-intersection only - for (map::iterator ir=var_list.begin(); ir!=var_list.end(); ++ir) - if (ir->second == it->second.size()) // print locals - o << " " << ir->first; - for (map::iterator ir=arg_list.begin(); ir!=arg_list.end(); ++ir) - if (ir->second == it->second.size()) // print arguments - o << " " << ir->first; + for (list::iterator ir=var_list.begin(); ir!=var_list.end(); ++ir) + if (var_count.find(*ir)->second == it->second.size()) // print locals + o << " " << *ir; + for (list::iterator ir=arg_list.begin(); ir!=arg_list.end(); ++ir) + if (arg_count.find(*ir)->second == it->second.size()) // print arguments + o << " " << *ir; } o << endl; } -- cgit