Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move ignore_local_variable() into Process
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 20 Nov 2015 15:09:25 +0000 (16:09 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 23 Nov 2015 15:40:08 +0000 (16:40 +0100)
src/mc/Frame.hpp
src/mc/ModelChecker.cpp
src/mc/ObjectInformation.cpp
src/mc/ObjectInformation.hpp
src/mc/Process.cpp
src/mc/Process.hpp
src/mc/mcer_ignore.cpp

index 9e2c692..77fcc05 100644 (file)
@@ -35,6 +35,7 @@ public:
   simgrid::mc::ObjectInformation* object_info;
 
   void* frame_base(unw_cursor_t& unw_cursor) const;
   simgrid::mc::ObjectInformation* object_info;
 
   void* frame_base(unw_cursor_t& unw_cursor) const;
+  void remove_variable(char* name);
 };
 
 inline
 };
 
 inline
index 92be558..4d2b523 100644 (file)
@@ -130,31 +130,36 @@ void ModelChecker::start()
   ptrace(PTRACE_CONT, pid_, 0, 0);
 }
 
   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<const char*, const char*> ignored_local_variables[] = {
+  std::pair<const char*, const char*>{  "e", "*" },
+  std::pair<const char*, const char*>{ "__ex_cleanup", "*" },
+  std::pair<const char*, const char*>{ "__ex_mctx_en", "*" },
+  std::pair<const char*, const char*>{ "__ex_mctx_me", "*" },
+  std::pair<const char*, const char*>{ "__xbt_ex_ctx_ptr", "*" },
+  std::pair<const char*, const char*>{ "_log_ev", "*" },
+  std::pair<const char*, const char*>{ "_throw_ctx", "*" },
+  std::pair<const char*, const char*>{ "ctx", "*" },
+
+  std::pair<const char*, const char*>{ "self", "simcall_BODY_mc_snapshot" },
+  std::pair<const char*, const char*>{ "next_context", "smx_ctx_sysv_suspend_serial" },
+  std::pair<const char*, const char*>{ "i", "smx_ctx_sysv_suspend_serial" },
 
   /* Ignore local variable about time used for tracing */
 
   /* Ignore local variable about time used for tracing */
-  MC_ignore_local_variable("start_time", "*");
+  std::pair<const char*, const char*>{ "start_time", "*" },
+};
+
+void ModelChecker::setup_ignore()
+{
+  Process& process = this->process();
+  for (std::pair<const char*, const char*> const& var :
+      ignored_local_variables)
+    process.ignore_local_variable(var.first, var.second);
 
   /* Static variable used for tracing */
 
   /* Static variable used for tracing */
-  this->process().ignore_global_variable("counter");
+  process.ignore_global_variable("counter");
 
   /* SIMIX */
 
   /* SIMIX */
-  this->process().ignore_global_variable("smx_total_comms");
+  process.ignore_global_variable("smx_total_comms");
 }
 
 void ModelChecker::shutdown()
 }
 
 void ModelChecker::shutdown()
index 9889f08..942cbad 100644 (file)
@@ -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<Variable>::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
 }
 }
\ No newline at end of file
index 1a59340..ac1fd1b 100644 (file)
@@ -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);
   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);
 };
 
 };
 
+
+
 }
 }
 
 }
 }
 
index 665e29e..f90af18 100644 (file)
@@ -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<simgrid::mc::ObjectInformation> const& info :
+      this->object_infos)
+    info->remove_local_variable(var_name, frame_name);
+}
+
 }
 }
 }
 }
index 2999813..0b47eac 100644 (file)
@@ -191,6 +191,8 @@ public:
   void ignore_heap(IgnoredHeapRegion const& region);
   void unignore_heap(void *address, size_t size);
 
   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();
 private:
   void init_memory_map_info();
   void refresh_heap();
index 1ef7852..e78f482 100644 (file)
@@ -25,94 +25,3 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mcer_ignore, mc,
                                 "Logging specific to MC ignore mechanism");
 
 }
                                 "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<simgrid::mc::ObjectInformation> 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