1 /* Copyright (c) 2008-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "internal_config.h"
8 #include "mc_object_info.h"
9 #include "mc/mc_private.h"
10 #include "smpi/private.h"
11 #include "mc/mc_snapshot.h"
12 #include "mc/mc_ignore.h"
13 #include "mc/mc_protocol.h"
14 #include "mc/mc_client.h"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mcer_ignore, mc,
19 "Logging specific to MC ignore mechanism");
21 // ***** Ignore heap chunks
23 extern xbt_dynar_t mc_heap_comparison_ignore;
25 void heap_ignore_region_free(mc_heap_ignore_region_t r)
30 void heap_ignore_region_free_voidp(void *r)
32 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
36 void MC_heap_region_ignore_insert(mc_heap_ignore_region_t region)
38 if (mc_heap_comparison_ignore == NULL) {
39 mc_heap_comparison_ignore =
40 xbt_dynar_new(sizeof(mc_heap_ignore_region_t),
41 heap_ignore_region_free_voidp);
42 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
46 unsigned int cursor = 0;
47 mc_heap_ignore_region_t current_region = NULL;
49 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
51 // Find the position where we want to insert the mc_heap_ignore_region_t:
52 while (start <= end) {
53 cursor = (start + end) / 2;
55 (mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore,
57 mc_heap_ignore_region_t);
58 if (current_region->address == region->address) {
59 heap_ignore_region_free(region);
61 } else if (current_region->address < region->address) {
68 // Insert it mc_heap_ignore_region_t:
69 if (current_region->address < region->address)
70 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
72 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
75 void MC_heap_region_ignore_remove(void *address, size_t size)
77 unsigned int cursor = 0;
79 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
80 mc_heap_ignore_region_t region;
83 while (start <= end) {
84 cursor = (start + end) / 2;
86 (mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore,
88 mc_heap_ignore_region_t);
89 if (region->address == address) {
92 } else if (region->address < address) {
95 if ((char *) region->address <= ((char *) address + size)) {
104 if (ignore_found == 1) {
105 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
106 MC_remove_ignore_heap(address, size);
110 // ***** Ignore global variables
112 void MCer_ignore_global_variable(const char *name)
114 simgrid::mc::Process* process = &mc_model_checker->process();
115 xbt_assert(!process->object_infos.empty(), "MC subsystem not initialized");
117 for (std::shared_ptr<simgrid::mc::ObjectInformation> const& info : process->object_infos) {
121 int end = info->global_variables.size() - 1;
122 while (start <= end) {
123 unsigned int cursor = (start + end) / 2;
124 simgrid::mc::Variable* current_var = &info->global_variables[cursor];
125 int cmp = strcmp(current_var->name.c_str(), name);
127 info->global_variables.erase(
128 info->global_variables.begin() + cursor);
130 end = info->global_variables.size() - 1;
131 } else if (cmp < 0) {
140 // ***** Ignore local variables
142 static void mc_ignore_local_variable_in_scope(const char *var_name,
143 const char *subprogram_name,
144 simgrid::mc::Frame* subprogram,
145 simgrid::mc::Frame* scope);
146 static void MC_ignore_local_variable_in_object(const char *var_name,
147 const char *subprogram_name,
148 simgrid::mc::ObjectInformation* info);
150 void MC_ignore_local_variable(const char *var_name, const char *frame_name)
152 simgrid::mc::Process* process = &mc_model_checker->process();
153 if (strcmp(frame_name, "*") == 0)
156 for (std::shared_ptr<simgrid::mc::ObjectInformation> const& info : process->object_infos)
157 MC_ignore_local_variable_in_object(var_name, frame_name, info.get());
160 static void MC_ignore_local_variable_in_object(const char *var_name,
161 const char *subprogram_name,
162 simgrid::mc::ObjectInformation* info)
164 for (auto& entry : info->subprograms)
165 mc_ignore_local_variable_in_scope(
166 var_name, subprogram_name, &entry.second, &entry.second);
169 /** \brief Ignore a local variable in a scope
171 * Ignore all instances of variables with a given name in
172 * any (possibly inlined) subprogram with a given namespaced
175 * \param var_name Name of the local variable (or parameter to ignore)
176 * \param subprogram_name Name of the subprogram fo ignore (NULL for any)
177 * \param subprogram (possibly inlined) Subprogram of the scope
178 * \param scope Current scope
180 static void mc_ignore_local_variable_in_scope(const char *var_name,
181 const char *subprogram_name,
182 simgrid::mc::Frame* subprogram,
183 simgrid::mc::Frame* scope)
185 // Processing of direct variables:
187 // If the current subprogram matches the given name:
188 if (subprogram_name == nullptr ||
189 (!subprogram->name.empty()
190 && subprogram->name == subprogram_name)) {
192 // Try to find the variable and remove it:
194 int end = scope->variables.size() - 1;
196 // Dichotomic search:
197 while (start <= end) {
198 int cursor = (start + end) / 2;
199 simgrid::mc::Variable* current_var = &scope->variables[cursor];
201 int compare = strcmp(current_var->name.c_str(), var_name);
203 // Variable found, remove it:
204 scope->variables.erase(scope->variables.begin() + cursor);
208 end = scope->variables.size() - 1;
209 } else if (compare < 0) {
217 // And recursive processing in nested scopes:
218 for (simgrid::mc::Frame& nested_scope : scope->scopes) {
219 // The new scope may be an inlined subroutine, in this case we want to use its
220 // namespaced name in recursive calls:
221 simgrid::mc::Frame* nested_subprogram =
223 DW_TAG_inlined_subroutine ? &nested_scope : subprogram;
225 mc_ignore_local_variable_in_scope(var_name, subprogram_name,
226 nested_subprogram, &nested_scope);
230 extern xbt_dynar_t stacks_areas;
232 void MC_stack_area_add(stack_region_t stack_area)
234 if (stacks_areas == NULL)
235 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
236 xbt_dynar_push(stacks_areas, &stack_area);