1 /* Copyright (c) 2008-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
15 #include "xbt/automaton.h"
16 #include "xbt/backtrace.hpp"
17 #include "xbt/dynar.h"
29 #include "src/kernel/actor/ActorImpl.hpp"
32 #include "src/mc/checker/Checker.hpp"
33 #include "src/mc/mc_comm_pattern.hpp"
34 #include "src/mc/mc_private.hpp"
35 #include "src/mc/mc_request.hpp"
36 #include "src/mc/mc_safety.hpp"
37 #include "src/mc/mc_smx.hpp"
38 #include "src/mc/mc_unw.hpp"
39 #include "src/mc/sosp/mc_snapshot.hpp"
40 #include <libunwind.h>
43 #include "src/mc/Transition.hpp"
44 #include "src/mc/mc_record.hpp"
45 #include "src/mc/remote/Client.hpp"
46 #include "src/mc/remote/mc_protocol.h"
48 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc, "Logging specific to MC (global)");
53 std::vector<double> processes_time;
65 xbt_automaton_t property_automaton = nullptr;
71 FILE *dot_output = nullptr;
74 /******************************* Initialization of MC *******************************/
75 /*********************************************************************************/
77 void MC_init_dot_output()
79 dot_output = fopen(_sg_mc_dot_output_file.get().c_str(), "w");
81 if (dot_output == nullptr) {
82 perror("Error open dot output file");
87 "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");
91 /******************************* Core of MC *******************************/
92 /**************************************************************************/
96 simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
97 MC_ignore_heap(simgrid::mc::processes_time.data(),
98 simgrid::mc::processes_time.size() * sizeof(simgrid::mc::processes_time[0]));
99 simgrid::mc::Client::get()->mainLoop();
100 simgrid::mc::processes_time.clear();
103 void MC_show_deadlock()
105 XBT_INFO("**************************");
106 XBT_INFO("*** DEAD-LOCK DETECTED ***");
107 XBT_INFO("**************************");
108 XBT_INFO("Counter-example execution trace:");
109 for (auto const& s : mc_model_checker->getChecker()->getTextualTrace())
110 XBT_INFO("%s", s.c_str());
111 simgrid::mc::session->logState();
114 void MC_automaton_load(const char *file)
116 if (simgrid::mc::property_automaton == nullptr)
117 simgrid::mc::property_automaton = xbt_automaton_new();
119 xbt_automaton_load(simgrid::mc::property_automaton, file);
125 void dumpStack(FILE* file, unw_cursor_t&& cursor)
132 const char* name = not unw_get_proc_name(&cursor, buffer, 100, &off) ? buffer : "?";
133 // Unmangle C++ names:
134 auto realname = simgrid::xbt::demangle(name);
136 #if defined(__x86_64__)
139 unw_get_reg(&cursor, UNW_X86_64_RIP, &rip);
140 unw_get_reg(&cursor, UNW_X86_64_RSP, &rsp);
141 fprintf(file, " %i: %s (RIP=0x%" PRIx64 " RSP=0x%" PRIx64 ")\n", nframe, realname.get(), (std::uint64_t)rip,
144 fprintf(file, " %i: %s\n", nframe, realname.get());
148 } while(unw_step(&cursor));
154 static void MC_dump_stacks(FILE* file)
157 for (auto const& stack : mc_model_checker->process().stack_areas()) {
158 fprintf(file, "Stack %i:\n", nstack);
161 simgrid::mc::UnwindContext context;
162 unw_context_t raw_context =
163 (unw_context_t) mc_model_checker->process().read<unw_context_t>(
164 simgrid::mc::remote((unw_context_t *)stack.context));
165 context.initialize(&mc_model_checker->process(), &raw_context);
167 unw_cursor_t cursor = context.cursor();
168 simgrid::mc::dumpStack(file, std::move(cursor));
173 double MC_process_clock_get(smx_actor_t process)
175 if (simgrid::mc::processes_time.empty())
177 if (process != nullptr)
178 return simgrid::mc::processes_time[process->get_pid()];
182 void MC_process_clock_add(smx_actor_t process, double amount)
184 simgrid::mc::processes_time[process->get_pid()] += amount;