From: Gabriel Corona Date: Fri, 20 Nov 2015 15:09:25 +0000 (+0100) Subject: [mc] Move ignore_local_variable() into Process X-Git-Tag: v3_13~1565 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/dc0b6bff49507332f7978675d174aa4fa9916fc2 [mc] Move ignore_local_variable() into Process --- diff --git a/src/mc/Frame.hpp b/src/mc/Frame.hpp index 9e2c69294f..77fcc050b4 100644 --- a/src/mc/Frame.hpp +++ b/src/mc/Frame.hpp @@ -35,6 +35,7 @@ public: simgrid::mc::ObjectInformation* object_info; void* frame_base(unw_cursor_t& unw_cursor) const; + void remove_variable(char* name); }; inline diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index 92be55851a..4d2b523a76 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -130,31 +130,36 @@ void ModelChecker::start() ptrace(PTRACE_CONT, pid_, 0, 0); } -void ModelChecker::setup_ignore() -{ - /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */ - MC_ignore_local_variable("e", "*"); - MC_ignore_local_variable("__ex_cleanup", "*"); - MC_ignore_local_variable("__ex_mctx_en", "*"); - MC_ignore_local_variable("__ex_mctx_me", "*"); - MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*"); - MC_ignore_local_variable("_log_ev", "*"); - MC_ignore_local_variable("_throw_ctx", "*"); - MC_ignore_local_variable("ctx", "*"); - - MC_ignore_local_variable("self", "simcall_BODY_mc_snapshot"); - MC_ignore_local_variable("next_cont" - "ext", "smx_ctx_sysv_suspend_serial"); - MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial"); +static const std::pair ignored_local_variables[] = { + std::pair{ "e", "*" }, + std::pair{ "__ex_cleanup", "*" }, + std::pair{ "__ex_mctx_en", "*" }, + std::pair{ "__ex_mctx_me", "*" }, + std::pair{ "__xbt_ex_ctx_ptr", "*" }, + std::pair{ "_log_ev", "*" }, + std::pair{ "_throw_ctx", "*" }, + std::pair{ "ctx", "*" }, + + std::pair{ "self", "simcall_BODY_mc_snapshot" }, + std::pair{ "next_context", "smx_ctx_sysv_suspend_serial" }, + std::pair{ "i", "smx_ctx_sysv_suspend_serial" }, /* Ignore local variable about time used for tracing */ - MC_ignore_local_variable("start_time", "*"); + std::pair{ "start_time", "*" }, +}; + +void ModelChecker::setup_ignore() +{ + Process& process = this->process(); + for (std::pair const& var : + ignored_local_variables) + process.ignore_local_variable(var.first, var.second); /* Static variable used for tracing */ - this->process().ignore_global_variable("counter"); + process.ignore_global_variable("counter"); /* SIMIX */ - this->process().ignore_global_variable("smx_total_comms"); + process.ignore_global_variable("smx_total_comms"); } void ModelChecker::shutdown() diff --git a/src/mc/ObjectInformation.cpp b/src/mc/ObjectInformation.cpp index 9889f08665..942cbadce2 100644 --- a/src/mc/ObjectInformation.cpp +++ b/src/mc/ObjectInformation.cpp @@ -133,5 +133,71 @@ void ObjectInformation::remove_global_variable(const char* name) } } +/** \brief Ignore a local variable in a scope + * + * Ignore all instances of variables with a given name in + * any (possibly inlined) subprogram with a given namespaced + * name. + * + * \param var_name Name of the local variable (or parameter to ignore) + * \param subprogram_name Name of the subprogram fo ignore (NULL for any) + * \param subprogram (possibly inlined) Subprogram of the scope + * \param scope Current scope + */ +static void remove_local_variable(simgrid::mc::Frame& scope, + const char *var_name, + const char *subprogram_name, + simgrid::mc::Frame const& subprogram) +{ + typedef std::vector::size_type size_type; + + // If the current subprogram matches the given name: + if ((subprogram_name == nullptr || + (!subprogram.name.empty() + && subprogram.name == subprogram_name)) + && !scope.variables.empty()) { + + // Try to find the variable and remove it: + size_type start = 0; + size_type end = scope.variables.size() - 1; + + // Binary search: + while (start <= end) { + size_type cursor = start + (end - start) / 2; + simgrid::mc::Variable& current_var = scope.variables[cursor]; + int compare = current_var.name.compare(var_name); + if (compare == 0) { + // Variable found, remove it: + scope.variables.erase(scope.variables.begin() + cursor); + break; + } else if (compare < 0) + start = cursor + 1; + else if (cursor != 0) + end = cursor - 1; + else + break; + } + } + + // And recursive processing in nested scopes: + for (simgrid::mc::Frame& nested_scope : scope.scopes) { + // The new scope may be an inlined subroutine, in this case we want to use its + // namespaced name in recursive calls: + simgrid::mc::Frame const& nested_subprogram = + nested_scope.tag == + DW_TAG_inlined_subroutine ? nested_scope : subprogram; + remove_local_variable(nested_scope, var_name, subprogram_name, + nested_subprogram); + } +} + +void ObjectInformation::remove_local_variable( + const char* var_name, const char* subprogram_name) +{ + for (auto& entry : this->subprograms) + simgrid::mc::remove_local_variable(entry.second, + var_name, subprogram_name, entry.second); +} + } } \ No newline at end of file diff --git a/src/mc/ObjectInformation.hpp b/src/mc/ObjectInformation.hpp index 1a59340afe..ac1fd1b2df 100644 --- a/src/mc/ObjectInformation.hpp +++ b/src/mc/ObjectInformation.hpp @@ -93,9 +93,12 @@ public: simgrid::mc::Frame* find_function(const void *ip) const; simgrid::mc::Variable* find_variable(const char* name) const; void remove_global_variable(const char* name); - + void remove_local_variable( + const char* name, const char* scope); }; + + } } diff --git a/src/mc/Process.cpp b/src/mc/Process.cpp index 665e29e71e..f90af18891 100644 --- a/src/mc/Process.cpp +++ b/src/mc/Process.cpp @@ -698,5 +698,14 @@ void Process::unignore_heap(void *address, size_t size) } } +void Process::ignore_local_variable(const char *var_name, const char *frame_name) +{ + if (frame_name != nullptr && strcmp(frame_name, "*") == 0) + frame_name = nullptr; + for (std::shared_ptr const& info : + this->object_infos) + info->remove_local_variable(var_name, frame_name); +} + } } diff --git a/src/mc/Process.hpp b/src/mc/Process.hpp index 2999813f9d..0b47eac56a 100644 --- a/src/mc/Process.hpp +++ b/src/mc/Process.hpp @@ -191,6 +191,8 @@ public: void ignore_heap(IgnoredHeapRegion const& region); void unignore_heap(void *address, size_t size); + void ignore_local_variable(const char *var_name, const char *frame_name); + private: void init_memory_map_info(); void refresh_heap(); diff --git a/src/mc/mcer_ignore.cpp b/src/mc/mcer_ignore.cpp index 1ef7852a84..e78f482000 100644 --- a/src/mc/mcer_ignore.cpp +++ b/src/mc/mcer_ignore.cpp @@ -25,94 +25,3 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mcer_ignore, mc, "Logging specific to MC ignore mechanism"); } - -// ***** Ignore local variables - -static void mc_ignore_local_variable_in_scope(const char *var_name, - const char *subprogram_name, - simgrid::mc::Frame* subprogram, - simgrid::mc::Frame* scope); -static void MC_ignore_local_variable_in_object(const char *var_name, - const char *subprogram_name, - simgrid::mc::ObjectInformation* info); - -extern "C" -void MC_ignore_local_variable(const char *var_name, const char *frame_name) -{ - simgrid::mc::Process* process = &mc_model_checker->process(); - if (strcmp(frame_name, "*") == 0) - frame_name = NULL; - - for (std::shared_ptr const& info : process->object_infos) - MC_ignore_local_variable_in_object(var_name, frame_name, info.get()); -} - -static void MC_ignore_local_variable_in_object(const char *var_name, - const char *subprogram_name, - simgrid::mc::ObjectInformation* info) -{ - for (auto& entry : info->subprograms) - mc_ignore_local_variable_in_scope( - var_name, subprogram_name, &entry.second, &entry.second); -} - -/** \brief Ignore a local variable in a scope - * - * Ignore all instances of variables with a given name in - * any (possibly inlined) subprogram with a given namespaced - * name. - * - * \param var_name Name of the local variable (or parameter to ignore) - * \param subprogram_name Name of the subprogram fo ignore (NULL for any) - * \param subprogram (possibly inlined) Subprogram of the scope - * \param scope Current scope - */ -static void mc_ignore_local_variable_in_scope(const char *var_name, - const char *subprogram_name, - simgrid::mc::Frame* subprogram, - simgrid::mc::Frame* scope) -{ - // Processing of direct variables: - - // If the current subprogram matches the given name: - if (subprogram_name == nullptr || - (!subprogram->name.empty() - && subprogram->name == subprogram_name)) { - - // Try to find the variable and remove it: - int start = 0; - int end = scope->variables.size() - 1; - - // Dichotomic search: - while (start <= end) { - int cursor = (start + end) / 2; - simgrid::mc::Variable* current_var = &scope->variables[cursor]; - - int compare = current_var->name.compare(var_name); - if (compare == 0) { - // Variable found, remove it: - scope->variables.erase(scope->variables.begin() + cursor); - - // and start again: - start = 0; - end = scope->variables.size() - 1; - } else if (compare < 0) { - start = cursor + 1; - } else { - end = cursor - 1; - } - } - - } - // And recursive processing in nested scopes: - for (simgrid::mc::Frame& nested_scope : scope->scopes) { - // The new scope may be an inlined subroutine, in this case we want to use its - // namespaced name in recursive calls: - simgrid::mc::Frame* nested_subprogram = - nested_scope.tag == - DW_TAG_inlined_subroutine ? &nested_scope : subprogram; - - mc_ignore_local_variable_in_scope(var_name, subprogram_name, - nested_subprogram, &nested_scope); - } -} \ No newline at end of file