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. */
16 #include <xbt/dynar.h>
17 #include <xbt/automaton.h>
30 #include "src/simix/ActorImpl.hpp"
33 #include <libunwind.h>
34 #include "src/mc/mc_comm_pattern.h"
35 #include "src/mc/mc_request.h"
36 #include "src/mc/mc_safety.h"
37 #include "src/mc/mc_snapshot.h"
38 #include "src/mc/mc_private.h"
39 #include "src/mc/mc_unw.h"
40 #include "src/mc/mc_smx.h"
41 #include "src/mc/Checker.hpp"
44 #include "src/mc/mc_record.h"
45 #include "src/mc/mc_protocol.h"
46 #include "src/mc/Client.hpp"
47 #include "src/mc/Transition.hpp"
49 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc, "Logging specific to MC (global)");
54 std::vector<double> processes_time;
66 xbt_automaton_t property_automaton = nullptr;
72 FILE *dot_output = nullptr;
75 /******************************* Initialization of MC *******************************/
76 /*********************************************************************************/
78 void MC_init_dot_output()
80 dot_output = fopen(_sg_mc_dot_output_file, "w");
82 if (dot_output == nullptr) {
83 perror("Error open dot output file");
88 "digraph graphname{\n fixedsize=true; rankdir=TB; ranksep=.25; edge [fontsize=12]; node [fontsize=10, shape=circle,width=.5 ]; graph [resolution=20, fontsize=10];\n");
92 /******************************* Core of MC *******************************/
93 /**************************************************************************/
97 simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
98 MC_ignore_heap(simgrid::mc::processes_time.data(),
99 simgrid::mc::processes_time.size() * sizeof(simgrid::mc::processes_time[0]));
101 xbt_swag_foreach(process, simix_global->process_list)
102 MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
103 simgrid::mc::Client::get()->mainLoop();
104 simgrid::mc::processes_time.clear();
107 void MC_show_deadlock(void)
109 XBT_INFO("**************************");
110 XBT_INFO("*** DEAD-LOCK DETECTED ***");
111 XBT_INFO("**************************");
112 XBT_INFO("Counter-example execution trace:");
113 for (auto& s : mc_model_checker->getChecker()->getTextualTrace())
114 XBT_INFO("%s", s.c_str());
115 simgrid::mc::session->logState();
118 void MC_automaton_load(const char *file)
120 if (simgrid::mc::property_automaton == nullptr)
121 simgrid::mc::property_automaton = xbt_automaton_new();
123 xbt_automaton_load(simgrid::mc::property_automaton, file);
129 void dumpStack(FILE* file, unw_cursor_t cursor)
136 const char * name = !unw_get_proc_name(&cursor, buffer, 100, &off) ? buffer : "?";
140 // Unmangle C++ names:
141 char* realname = abi::__cxa_demangle(name, 0, 0, &status);
143 #if defined(__x86_64__)
146 unw_get_reg(&cursor, UNW_X86_64_RIP, &rip);
147 unw_get_reg(&cursor, UNW_X86_64_RSP, &rsp);
148 fprintf(file, " %i: %s (RIP=0x%" PRIx64 " RSP=0x%" PRIx64 ")\n",
149 nframe, realname ? realname : name, (std::uint64_t) rip, (std::uint64_t) rsp);
151 fprintf(file, " %i: %s\n", nframe, realname ? realname : name);
156 } while(unw_step(&cursor));
162 static void MC_dump_stacks(FILE* file)
165 for (auto const& stack : mc_model_checker->process().stack_areas()) {
166 fprintf(file, "Stack %i:\n", nstack++);
168 simgrid::mc::UnwindContext context;
169 unw_context_t raw_context =
170 (unw_context_t) mc_model_checker->process().read<unw_context_t>(
171 simgrid::mc::remote((unw_context_t *)stack.context));
172 context.initialize(&mc_model_checker->process(), &raw_context);
174 unw_cursor_t cursor = context.cursor();
175 simgrid::mc::dumpStack(file, cursor);
180 double MC_process_clock_get(smx_actor_t process)
182 if (simgrid::mc::processes_time.empty())
184 if (process != nullptr)
185 return simgrid::mc::processes_time[process->pid];
189 void MC_process_clock_add(smx_actor_t process, double amount)
191 simgrid::mc::processes_time[process->pid] += amount;