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 mc_process_t process = &mc_model_checker->process();
115 xbt_assert(process->object_infos, "MC subsystem not initialized");
117 size_t n = process->object_infos_size;
118 for (size_t i=0; i!=n; ++i) {
119 mc_object_info_t info = process->object_infos[i];
123 int end = xbt_dynar_length(info->global_variables) - 1;
124 while (start <= end) {
125 unsigned int cursor = (start + end) / 2;
126 dw_variable_t current_var =
127 (dw_variable_t) xbt_dynar_get_as(info->global_variables,
128 cursor, dw_variable_t);
129 if (strcmp(current_var->name, name) == 0) {
130 xbt_dynar_remove_at(info->global_variables, cursor, NULL);
132 end = xbt_dynar_length(info->global_variables) - 1;
133 } else if (strcmp(current_var->name, name) < 0) {
142 // ***** Ignore local variables
144 static void mc_ignore_local_variable_in_scope(const char *var_name,
145 const char *subprogram_name,
146 dw_frame_t subprogram,
148 static void MC_ignore_local_variable_in_object(const char *var_name,
149 const char *subprogram_name,
150 mc_object_info_t info);
152 void MC_ignore_local_variable(const char *var_name, const char *frame_name)
154 mc_process_t process = &mc_model_checker->process();
155 if (strcmp(frame_name, "*") == 0)
158 size_t n = process->object_infos_size;
160 for (i=0; i!=n; ++i) {
161 MC_ignore_local_variable_in_object(var_name, frame_name, process->object_infos[i]);
165 static void MC_ignore_local_variable_in_object(const char *var_name,
166 const char *subprogram_name,
167 mc_object_info_t info)
169 xbt_dict_cursor_t cursor2;
172 xbt_dict_foreach(info->subprograms, cursor2, key, frame) {
173 mc_ignore_local_variable_in_scope(var_name, subprogram_name, frame, frame);
177 /** \brief Ignore a local variable in a scope
179 * Ignore all instances of variables with a given name in
180 * any (possibly inlined) subprogram with a given namespaced
183 * \param var_name Name of the local variable (or parameter to ignore)
184 * \param subprogram_name Name of the subprogram fo ignore (NULL for any)
185 * \param subprogram (possibly inlined) Subprogram of the scope
186 * \param scope Current scope
188 static void mc_ignore_local_variable_in_scope(const char *var_name,
189 const char *subprogram_name,
190 dw_frame_t subprogram,
193 // Processing of direct variables:
195 // If the current subprogram matches the given name:
196 if (!subprogram_name ||
197 (subprogram->name && strcmp(subprogram_name, subprogram->name) == 0)) {
199 // Try to find the variable and remove it:
201 int end = xbt_dynar_length(scope->variables) - 1;
203 // Dichotomic search:
204 while (start <= end) {
205 int cursor = (start + end) / 2;
206 dw_variable_t current_var =
207 (dw_variable_t) xbt_dynar_get_as(scope->variables, cursor,
210 int compare = strcmp(current_var->name, var_name);
212 // Variable found, remove it:
213 xbt_dynar_remove_at(scope->variables, cursor, NULL);
217 end = xbt_dynar_length(scope->variables) - 1;
218 } else if (compare < 0) {
226 // And recursive processing in nested scopes:
228 dw_frame_t nested_scope = NULL;
229 xbt_dynar_foreach(scope->scopes, cursor, nested_scope) {
230 // The new scope may be an inlined subroutine, in this case we want to use its
231 // namespaced name in recursive calls:
232 dw_frame_t nested_subprogram =
234 DW_TAG_inlined_subroutine ? nested_scope : subprogram;
236 mc_ignore_local_variable_in_scope(var_name, subprogram_name,
237 nested_subprogram, nested_scope);
241 // ****** Checkpoint ignore:
243 static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r)
248 static void checkpoint_ignore_region_free_voidp(void *r)
250 checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
253 xbt_dynar_t MC_checkpoint_ignore_new(void)
255 return xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t),
256 checkpoint_ignore_region_free_voidp);
259 // ***** Generic memory ignore mechanism
261 void MC_process_ignore_memory(mc_process_t process, void *addr, size_t size)
263 xbt_dynar_t checkpoint_ignore = process->checkpoint_ignore;
264 mc_checkpoint_ignore_region_t region =
265 xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
269 if (xbt_dynar_is_empty(checkpoint_ignore)) {
270 xbt_dynar_push(checkpoint_ignore, ®ion);
273 unsigned int cursor = 0;
275 int end = xbt_dynar_length(checkpoint_ignore) - 1;
276 mc_checkpoint_ignore_region_t current_region = NULL;
278 while (start <= end) {
279 cursor = (start + end) / 2;
281 (mc_checkpoint_ignore_region_t) xbt_dynar_get_as(checkpoint_ignore,
283 mc_checkpoint_ignore_region_t);
284 if (current_region->addr == addr) {
285 if (current_region->size == size) {
286 checkpoint_ignore_region_free(region);
288 } else if (current_region->size < size) {
293 } else if (current_region->addr < addr) {
300 if (current_region->addr == addr) {
301 if (current_region->size < size) {
302 xbt_dynar_insert_at(checkpoint_ignore, cursor + 1, ®ion);
304 xbt_dynar_insert_at(checkpoint_ignore, cursor, ®ion);
306 } else if (current_region->addr < addr) {
307 xbt_dynar_insert_at(checkpoint_ignore, cursor + 1, ®ion);
309 xbt_dynar_insert_at(checkpoint_ignore, cursor, ®ion);
314 extern xbt_dynar_t stacks_areas;
316 void MC_stack_area_add(stack_region_t stack_area)
318 if (stacks_areas == NULL)
319 stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
320 xbt_dynar_push(stacks_areas, &stack_area);