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. --- elaborate.h | 3 ++- main.cxx | 53 +++++++++++++++++++++++++++++++++++++++++------------ tapset-mark.cxx | 10 +++++----- tapsets.cxx | 18 +++++++++--------- 4 files changed, 57 insertions(+), 27 deletions(-) diff --git a/elaborate.h b/elaborate.h index 30a02c5b..0a1549fb 100644 --- a/elaborate.h +++ b/elaborate.h @@ -17,6 +17,7 @@ #include #include #include +#include extern "C" { #include @@ -129,7 +130,7 @@ struct derived_probe: public probe virtual probe_point* sole_location () const; virtual void printsig (std::ostream &o) const; // return arguments of probe if there - virtual void getargs (std::set &arg_set) const {} + virtual void getargs (std::list &arg_set) const {} void printsig_nested (std::ostream &o) const; virtual void collect_derivation_chain (std::vector &probes_list); 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; } diff --git a/tapset-mark.cxx b/tapset-mark.cxx index 1ce3c919..6dbc55dc 100644 --- a/tapset-mark.cxx +++ b/tapset-mark.cxx @@ -59,7 +59,7 @@ struct mark_derived_probe: public derived_probe void print_dupe_stamp (ostream& o); void emit_probe_context_vars (translator_output* o); void initialize_probe_context_vars (translator_output* o); - void getargs (std::set &arg_set) const; + void getargs (std::list &arg_set) const; void parse_probe_format (); }; @@ -465,7 +465,7 @@ mark_derived_probe::initialize_probe_context_vars (translator_output* o) } void -mark_derived_probe::getargs(std::set &arg_set) const +mark_derived_probe::getargs(std::list &arg_set) const { for (unsigned i = 0; i < mark_args.size(); i++) { @@ -473,13 +473,13 @@ mark_derived_probe::getargs(std::set &arg_set) const switch (mark_args[i]->stp_type) { case pe_long: - arg_set.insert(localname+":long"); + arg_set.push_back(localname+":long"); break; case pe_string: - arg_set.insert(localname+":string"); + arg_set.push_back(localname+":string"); break; default: - arg_set.insert(localname+":unknown"); + arg_set.push_back(localname+":unknown"); break; } } diff --git a/tapsets.cxx b/tapsets.cxx index 0711411e..916e4ddf 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -364,7 +364,7 @@ struct dwarf_derived_probe: public derived_probe void printsig (std::ostream &o) const; virtual void join_group (systemtap_session& s); void emit_probe_local_init(translator_output * o); - void getargs(std::set &arg_set) const; + void getargs(std::list &arg_set) const; void emit_unprivileged_assertion (translator_output*); void print_dupe_stamp(ostream& o); @@ -389,7 +389,7 @@ protected: {} private: - set args; + list args; void saveargs(dwarf_query& q, Dwarf_Die* scope_die, dwarf_var_expanding_visitor& v); }; @@ -3046,7 +3046,7 @@ dwarf_derived_probe::saveargs(dwarf_query& q, Dwarf_Die* scope_die, dwarf_var_ex if (has_return && dwarf_attr_die (scope_die, DW_AT_type, &type_die) && dwarf_type_name(&type_die, type_name)) - args.insert("$return:"+type_name); + args.push_back("$return:"+type_name); /* Pretend that we aren't in a .return for a moment, just so we can * check whether variables are accessible. We don't want any of the @@ -3092,7 +3092,7 @@ dwarf_derived_probe::saveargs(dwarf_query& q, Dwarf_Die* scope_die, dwarf_var_ex tsym->saved_conversion_error = 0; v.require (tsym); if (!tsym->saved_conversion_error) - args.insert("$"+string(arg_name)+":"+type_name); + args.push_back("$"+string(arg_name)+":"+type_name); } while (dwarf_siblingof (&arg, &arg) == 0); @@ -3102,9 +3102,9 @@ dwarf_derived_probe::saveargs(dwarf_query& q, Dwarf_Die* scope_die, dwarf_var_ex void -dwarf_derived_probe::getargs(std::set &arg_set) const +dwarf_derived_probe::getargs(std::list &arg_set) const { - arg_set.insert(args.begin(), args.end()); + arg_set.insert(arg_set.end(), args.begin(), args.end()); } @@ -5678,7 +5678,7 @@ struct tracepoint_derived_probe: public derived_probe vector args; void build_args(dwflpp& dw, Dwarf_Die& func_die); - void getargs (std::set &arg_set) const; + void getargs (std::list &arg_set) const; void join_group (systemtap_session& s); void print_dupe_stamp(ostream& o); void emit_probe_context_vars (translator_output* o); @@ -6066,11 +6066,11 @@ tracepoint_derived_probe::build_args(dwflpp& dw, Dwarf_Die& func_die) } void -tracepoint_derived_probe::getargs(std::set &arg_set) const +tracepoint_derived_probe::getargs(std::list &arg_set) const { for (unsigned i = 0; i < args.size(); ++i) if (args[i].usable) - arg_set.insert("$"+args[i].name+":"+args[i].c_type); + arg_set.push_back("$"+args[i].name+":"+args[i].c_type); } void -- cgit