1 /* Copyright (c) 2016-2023. 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. */
6 #include "src/mc/explo/Exploration.hpp"
7 #include "src/mc/mc_config.hpp"
8 #include "src/mc/mc_exit.hpp"
9 #include "src/mc/mc_private.hpp"
11 #if SIMGRID_HAVE_STATEFUL_MC
12 #include "src/mc/sosp/RemoteProcessMemory.hpp"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_explo, mc, "Generic exploration algorithm of the model-checker");
19 namespace simgrid::mc {
21 static simgrid::config::Flag<std::string> cfg_dot_output_file{
22 "model-check/dot-output", "Name of dot output file corresponding to graph state", ""};
24 Exploration* Exploration::instance_ = nullptr; // singleton instance
26 Exploration::Exploration(const std::vector<char*>& args, bool need_memory_introspection)
27 : remote_app_(std::make_unique<RemoteApp>(args, need_memory_introspection))
29 xbt_assert(instance_ == nullptr, "Cannot have more than one exploration instance");
32 if (not cfg_dot_output_file.get().empty()) {
33 dot_output_ = fopen(cfg_dot_output_file.get().c_str(), "w");
34 xbt_assert(dot_output_ != nullptr, "Error open dot output file: %s", strerror(errno));
36 fprintf(dot_output_, "digraph graphname{\n fixedsize=true; rankdir=TB; ranksep=.25; edge [fontsize=12]; node "
37 "[fontsize=10, shape=circle,width=.5 ]; graph [resolution=20, fontsize=10];\n");
41 Exploration::~Exploration()
43 if (dot_output_ != nullptr)
48 void Exploration::dot_output(const char* fmt, ...)
50 if (dot_output_ != nullptr) {
53 vfprintf(dot_output_, fmt, ap);
59 void Exploration::log_state()
61 if (not cfg_dot_output_file.get().empty()) {
65 if (getenv("SIMGRID_MC_SYSTEM_STATISTICS")) {
66 int ret = system("free");
68 XBT_WARN("Call to system(free) did not return 0, but %d", ret);
71 // Make our tests fully reproducible despite the subtle differences of strsignal() across archs
72 static const char* signal_name(int status)
74 switch (WTERMSIG(status)) {
75 case SIGABRT: // FreeBSD uses "Abort trap" as a strsignal for SIGABRT
77 case SIGSEGV: // MacOSX uses "Segmentation fault: 11" for SIGKILL
78 return "Segmentation fault";
80 return strsignal(WTERMSIG(status));
83 XBT_ATTRIB_NORETURN void Exploration::report_crash(int status)
85 XBT_INFO("**************************");
86 XBT_INFO("** CRASH IN THE PROGRAM **");
87 XBT_INFO("**************************");
88 if (WIFSIGNALED(status))
89 XBT_INFO("From signal: %s", signal_name(status));
90 else if (WIFEXITED(status))
91 XBT_INFO("From exit: %i", WEXITSTATUS(status));
92 if (not xbt_log_no_loc)
93 XBT_INFO("%s core dump was generated by the system.", WCOREDUMP(status) ? "A" : "No");
95 XBT_INFO("Counter-example execution trace:");
96 for (auto const& s : get_textual_trace())
97 XBT_INFO(" %s", s.c_str());
98 XBT_INFO("You can debug the problem (and see the whole details) by rerunning out of simgrid-mc with "
99 "--cfg=model-check/replay:'%s'",
100 get_record_trace().to_string().c_str());
102 if (xbt_log_no_loc) {
103 XBT_INFO("Stack trace not displayed because you passed --log=no_loc");
105 #if SIMGRID_HAVE_STATEFUL_MC
106 const auto* memory = get_remote_app().get_remote_process_memory();
108 XBT_INFO("Stack trace:");
109 memory->dump_stack();
112 XBT_INFO("Stack trace not shown because there is no memory introspection.");
115 system_exit(SIMGRID_MC_EXIT_PROGRAM_CRASH);
117 XBT_ATTRIB_NORETURN void Exploration::report_assertion_failure()
119 XBT_INFO("**************************");
120 XBT_INFO("*** PROPERTY NOT VALID ***");
121 XBT_INFO("**************************");
122 XBT_INFO("Counter-example execution trace:");
123 for (auto const& s : get_textual_trace())
124 XBT_INFO(" %s", s.c_str());
125 XBT_INFO("You can debug the problem (and see the whole details) by rerunning out of simgrid-mc with "
126 "--cfg=model-check/replay:'%s'",
127 get_record_trace().to_string().c_str());
129 system_exit(SIMGRID_MC_EXIT_SAFETY);
132 void Exploration::system_exit(int status) const
137 }; // namespace simgrid::mc