Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Register symbols as pointers in the examples
[simgrid.git] / src / mc / mc_global.c
index fabab0a..4b9cf04 100644 (file)
@@ -4,6 +4,8 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include <string.h>
+
 #include "mc_base.h"
 
 #ifndef _XBT_WIN32
@@ -20,8 +22,8 @@
 #include "xbt/dict.h"
 
 #ifdef HAVE_MC
-#define UNW_LOCAL_ONLY
 #include <libunwind.h>
+#include <xbt/mmalloc.h>
 
 #include "../xbt/mmalloc/mmprivate.h"
 #include "mc_object_info.h"
 #include "mc_snapshot.h"
 #include "mc_liveness.h"
 #include "mc_private.h"
+#include "mc_unw.h"
 #endif
 #include "mc_record.h"
+#include "mc_protocol.h"
+#include "mc_client.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc,
                                 "Logging specific to MC (global)");
 
+e_mc_mode_t mc_mode;
+
 double *mc_time = NULL;
 
 #ifdef HAVE_MC
@@ -93,37 +100,29 @@ static void MC_init_dot_output()
 
 }
 
-mc_model_checker_t mc_model_checker = NULL;
-
-mc_model_checker_t MC_model_checker_new()
+void MC_init()
 {
-  mc_model_checker_t mc = xbt_new0(s_mc_model_checker_t, 1);
-  mc->pages = mc_pages_store_new();
-  mc->fd_clear_refs = -1;
-  mc->fd_pagemap = -1;
-  MC_process_init(&mc->process, getpid());
-  return mc;
-}
-
-void MC_model_checker_delete(mc_model_checker_t mc) {
-  mc_pages_store_delete(mc->pages);
-  if(mc->record)
-    xbt_dynar_free(&mc->record);
-  MC_process_clear(&mc->process);
+  MC_init_pid(getpid(), -1);
 }
 
-void MC_init()
+void MC_init_pid(pid_t pid, int socket)
 {
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
+  if (mc_mode == MC_MODE_NONE) {
+    if (getenv(MC_ENV_SOCKET_FD)) {
+      mc_mode = MC_MODE_CLIENT;
+    } else {
+      mc_mode = MC_MODE_STANDALONE;
+    }
+  }
 
   mc_time = xbt_new0(double, simix_process_maxpid);
 
   /* Initialize the data structures that must be persistent across every
      iteration of the model-checker (in RAW memory) */
 
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
-  mc_model_checker = MC_model_checker_new();
+  mc_model_checker = MC_model_checker_new(pid, socket);
 
   mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
 
@@ -178,18 +177,22 @@ void MC_init()
     /* SIMIX */
     MC_ignore_global_variable("smx_total_comms");
 
-    MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
-
-    smx_process_t process;
-    // FIXME, cross-process support (simix_global->process_list)
-    xbt_swag_foreach(process, simix_global->process_list) {
-      MC_ignore_heap(&(process->process_hookup),
-                     sizeof(process->process_hookup));
-                     }
+    if (mc_mode == MC_MODE_STANDALONE || mc_mode == MC_MODE_CLIENT) {
+      MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
+      smx_process_t process;
+      xbt_swag_foreach(process, simix_global->process_list) {
+        MC_ignore_heap(&(process->process_hookup),
+                       sizeof(process->process_hookup));
+                       }
+    }
   }
 
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
+  mmalloc_set_current_heap(heap);
+
+  if (mc_mode == MC_MODE_CLIENT) {
+    // This will move somehwere else:
+    MC_client_handle_messages();
+  }
 
 }
 
@@ -198,13 +201,9 @@ void MC_init()
 
 static void MC_modelcheck_comm_determinism_init(void)
 {
-
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
   MC_init();
 
-  if (!mc_mem_set)
-    MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   /* Create exploration stack */
   mc_stack = xbt_fifo_new();
@@ -223,21 +222,16 @@ static void MC_modelcheck_comm_determinism_init(void)
 
   MC_modelcheck_comm_determinism();
 
-  if(mc_mem_set)
-    MC_SET_MC_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 static void MC_modelcheck_safety_init(void)
 {
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
   _sg_mc_safety = 1;
 
   MC_init();
 
-  if (!mc_mem_set)
-    MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   /* Create exploration stack */
   mc_stack = xbt_fifo_new();
@@ -254,8 +248,7 @@ static void MC_modelcheck_safety_init(void)
 
   MC_modelcheck_safety();
 
-  if (mc_mem_set)
-    MC_SET_MC_HEAP;
+  mmalloc_set_current_heap(heap);
 
   xbt_abort();
   //MC_exit();
@@ -263,15 +256,11 @@ static void MC_modelcheck_safety_init(void)
 
 static void MC_modelcheck_liveness_init()
 {
-
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
   _sg_mc_liveness = 1;
 
   MC_init();
 
-  if (!mc_mem_set)
-    MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   /* Create exploration stack */
   mc_stack = xbt_fifo_new();
@@ -287,8 +276,7 @@ static void MC_modelcheck_liveness_init()
   MC_print_statistics(mc_stats);
   xbt_free(mc_time);
 
-  if (mc_mem_set)
-    MC_SET_MC_HEAP;
+  mmalloc_set_current_heap(heap);
 
 }
 
@@ -377,7 +365,7 @@ void mc_update_comm_pattern(mc_call_type call_type, smx_simcall_t req, int value
  */
 void MC_replay(xbt_fifo_t stack, int start)
 {
-  int raw_mem = (mmalloc_get_current_heap() == mc_heap);
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   int value, i = 1, count = 1, j;
   char *req_str;
@@ -500,13 +488,7 @@ void MC_replay(xbt_fifo_t stack, int start)
   }
 
   XBT_DEBUG("**** End Replay ****");
-
-  if (raw_mem)
-    MC_SET_MC_HEAP;
-  else
-    MC_SET_STD_HEAP;
-
-
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
@@ -587,8 +569,7 @@ void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
  */
 void MC_dump_stack_safety(xbt_fifo_t stack)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   MC_show_stack_safety(stack);
 
@@ -603,20 +584,13 @@ void MC_dump_stack_safety(xbt_fifo_t stack)
 
   }
 
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
-  else
-    MC_SET_STD_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 
 void MC_show_stack_safety(xbt_fifo_t stack)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   int value;
   mc_state_t state;
@@ -635,8 +609,7 @@ void MC_show_stack_safety(xbt_fifo_t stack)
     }
   }
 
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_show_deadlock(smx_simcall_t req)
@@ -681,26 +654,16 @@ void MC_show_stack_liveness(xbt_fifo_t stack)
 
 void MC_dump_stack_liveness(xbt_fifo_t stack)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
   mc_pair_t pair;
-
-  MC_SET_MC_HEAP;
   while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
     MC_pair_delete(pair);
-  MC_SET_STD_HEAP;
-
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 
 void MC_print_statistics(mc_stats_t stats)
 {
-  xbt_mheap_t previous_heap = mmalloc_get_current_heap();
-
   if (stats->expanded_pairs == 0) {
     XBT_INFO("Expanded states = %lu", stats->expanded_states);
     XBT_INFO("Visited states = %lu", stats->visited_states);
@@ -709,7 +672,7 @@ void MC_print_statistics(mc_stats_t stats)
     XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
   }
   XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
   if ((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0] != '\0')) {
     fprintf(dot_output, "}\n");
     fclose(dot_output);
@@ -722,70 +685,43 @@ void MC_print_statistics(mc_stats_t stats)
       XBT_INFO("Send-deterministic : %s",
                !initial_global_state->send_deterministic ? "No" : "Yes");
   }
-  mmalloc_set_current_heap(previous_heap);
-}
-
-void MC_assert(int prop)
-{
-  if (MC_is_active() && !prop) {
-    XBT_INFO("**************************");
-    XBT_INFO("*** PROPERTY NOT VALID ***");
-    XBT_INFO("**************************");
-    XBT_INFO("Counter-example execution trace:");
-    MC_record_dump_path(mc_stack);
-    MC_dump_stack_safety(mc_stack);
-    MC_print_statistics(mc_stats);
-    xbt_abort();
-  }
-}
-
-void MC_cut(void)
-{
-  user_max_depth_reached = 1;
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_automaton_load(const char *file)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   if (_mc_property_automaton == NULL)
     _mc_property_automaton = xbt_automaton_new();
 
   xbt_automaton_load(_mc_property_automaton, file);
-
-  MC_SET_STD_HEAP;
-
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
-void MC_automaton_new_propositional_symbol(const char *id, void *fct)
+void MC_automaton_new_propositional_symbol(const char *id, int(*fct)(void))
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   if (_mc_property_automaton == NULL)
     _mc_property_automaton = xbt_automaton_new();
 
   xbt_automaton_propositional_symbol_new(_mc_property_automaton, id, fct);
+  mmalloc_set_current_heap(heap);
+}
 
-  MC_SET_STD_HEAP;
-
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
-
+void MC_automaton_new_propositional_symbol_pointer(const char *id, int* value)
+{
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
+  if (_mc_property_automaton == NULL)
+    _mc_property_automaton = xbt_automaton_new();
+  xbt_automaton_propositional_symbol_new_pointer(_mc_property_automaton, id, value);
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_dump_stacks(FILE* file)
 {
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   int nstack = 0;
   stack_region_t current_stack;
@@ -807,9 +743,7 @@ void MC_dump_stacks(FILE* file)
 
     ++nstack;
   }
-
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
+  mmalloc_set_current_heap(heap);
 }
 #endif