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_dwarf.hpp"
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"
16 #include "mc/Frame.hpp"
17 #include "mc/Variable.hpp"
18 #include "mc/ObjectInformation.hpp"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mcer_ignore, mc,
23 "Logging specific to MC ignore mechanism");
25 // ***** Ignore heap chunks
27 extern xbt_dynar_t mc_heap_comparison_ignore;
29 void heap_ignore_region_free(mc_heap_ignore_region_t r)
34 void heap_ignore_region_free_voidp(void *r)
36 heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
40 void MC_heap_region_ignore_insert(mc_heap_ignore_region_t region)
42 if (mc_heap_comparison_ignore == NULL) {
43 mc_heap_comparison_ignore =
44 xbt_dynar_new(sizeof(mc_heap_ignore_region_t),
45 heap_ignore_region_free_voidp);
46 xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
50 unsigned int cursor = 0;
51 mc_heap_ignore_region_t current_region = NULL;
53 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
55 // Find the position where we want to insert the mc_heap_ignore_region_t:
56 while (start <= end) {
57 cursor = (start + end) / 2;
59 (mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore,
61 mc_heap_ignore_region_t);
62 if (current_region->address == region->address) {
63 heap_ignore_region_free(region);
65 } else if (current_region->address < region->address) {
72 // Insert it mc_heap_ignore_region_t:
73 if (current_region->address < region->address)
74 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
76 xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
79 void MC_heap_region_ignore_remove(void *address, size_t size)
81 unsigned int cursor = 0;
83 int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
84 mc_heap_ignore_region_t region;
87 while (start <= end) {
88 cursor = (start + end) / 2;
90 (mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore,
92 mc_heap_ignore_region_t);
93 if (region->address == address) {
96 } else if (region->address < address) {
99 if ((char *) region->address <= ((char *) address + size)) {
108 if (ignore_found == 1) {
109 xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
110 MC_remove_ignore_heap(address, size);
114 // ***** Ignore global variables
116 void MCer_ignore_global_variable(const char *name)
118 simgrid::mc::Process* process = &mc_model_checker->process();
119 xbt_assert(!process->object_infos.empty(), "MC subsystem not initialized");
121 for (std::shared_ptr<simgrid::mc::ObjectInformation> const& info : process->object_infos) {
125 int end = info->global_variables.size() - 1;
126 while (start <= end) {
127 unsigned int cursor = (start + end) / 2;
128 simgrid::mc::Variable* current_var = &info->global_variables[cursor];
129 int cmp = current_var->name.compare(name);
131 info->global_variables.erase(
132 info->global_variables.begin() + cursor);
134 end = info->global_variables.size() - 1;
135 } else if (cmp < 0) {
144 // ***** Ignore local variables
146 static void mc_ignore_local_variable_in_scope(const char *var_name,
147 const char *subprogram_name,
148 simgrid::mc::Frame* subprogram,
149 simgrid::mc::Frame* scope);
150 static void MC_ignore_local_variable_in_object(const char *var_name,
151 const char *subprogram_name,
152 simgrid::mc::ObjectInformation* info);
154 void MC_ignore_local_variable(const char *var_name, const char *frame_name)
156 simgrid::mc::Process* process = &mc_model_checker->process();
157 if (strcmp(frame_name, "*") == 0)
160 for (std::shared_ptr<simgrid::mc::ObjectInformation> const& info : process->object_infos)
161 MC_ignore_local_variable_in_object(var_name, frame_name, info.get());
164 static void MC_ignore_local_variable_in_object(const char *var_name,
165 const char *subprogram_name,
166 simgrid::mc::ObjectInformation* info)
168 for (auto& entry : info->subprograms)
169 mc_ignore_local_variable_in_scope(
170 var_name, subprogram_name, &entry.second, &entry.second);
173 /** \brief Ignore a local variable in a scope
175 * Ignore all instances of variables with a given name in
176 * any (possibly inlined) subprogram with a given namespaced
179 * \param var_name Name of the local variable (or parameter to ignore)
180 * \param subprogram_name Name of the subprogram fo ignore (NULL for any)
181 * \param subprogram (possibly inlined) Subprogram of the scope
182 * \param scope Current scope
184 static void mc_ignore_local_variable_in_scope(const char *var_name,
185 const char *subprogram_name,
186 simgrid::mc::Frame* subprogram,
187 simgrid::mc::Frame* scope)
189 // Processing of direct variables:
191 // If the current subprogram matches the given name:
192 if (subprogram_name == nullptr ||
193 (!subprogram->name.empty()
194 && subprogram->name == subprogram_name)) {
196 // Try to find the variable and remove it:
198 int end = scope->variables.size() - 1;
200 // Dichotomic search:
201 while (start <= end) {
202 int cursor = (start + end) / 2;
203 simgrid::mc::Variable* current_var = &scope->variables[cursor];
205 int compare = current_var->name.compare(var_name);
207 // Variable found, remove it:
208 scope->variables.erase(scope->variables.begin() + cursor);
212 end = scope->variables.size() - 1;
213 } else if (compare < 0) {
221 // And recursive processing in nested scopes:
222 for (simgrid::mc::Frame& nested_scope : scope->scopes) {
223 // The new scope may be an inlined subroutine, in this case we want to use its
224 // namespaced name in recursive calls:
225 simgrid::mc::Frame* nested_subprogram =
227 DW_TAG_inlined_subroutine ? &nested_scope : subprogram;
229 mc_ignore_local_variable_in_scope(var_name, subprogram_name,
230 nested_subprogram, &nested_scope);
234 extern xbt_dynar_t stacks_areas;
236 void MC_stack_area_add(stack_region_t stack_area)
238 if (stacks_areas == NULL)
239 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
240 xbt_dynar_push(stacks_areas, &stack_area);