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_environ.h"
9 #include "src/mc/mc_exit.hpp"
10 #include "src/mc/mc_private.hpp"
12 #if SIMGRID_HAVE_STATEFUL_MC
13 #include "src/mc/sosp/RemoteProcessMemory.hpp"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_explo, mc, "Generic exploration algorithm of the model-checker");
20 namespace simgrid::mc {
22 static simgrid::config::Flag<std::string> cfg_dot_output_file{
23 "model-check/dot-output", "Name of dot output file corresponding to graph state", ""};
25 Exploration* Exploration::instance_ = nullptr; // singleton instance
27 Exploration::Exploration(const std::vector<char*>& args, bool need_memory_introspection)
28 : remote_app_(std::make_unique<RemoteApp>(args, need_memory_introspection))
30 xbt_assert(instance_ == nullptr, "Cannot have more than one exploration instance");
33 if (not cfg_dot_output_file.get().empty()) {
34 dot_output_ = fopen(cfg_dot_output_file.get().c_str(), "w");
35 xbt_assert(dot_output_ != nullptr, "Error open dot output file: %s", strerror(errno));
37 fprintf(dot_output_, "digraph graphname{\n fixedsize=true; rankdir=TB; ranksep=.25; edge [fontsize=12]; node "
38 "[fontsize=10, shape=circle,width=.5 ]; graph [resolution=20, fontsize=10];\n");
42 Exploration::~Exploration()
44 if (dot_output_ != nullptr)
49 void Exploration::dot_output(const char* fmt, ...)
51 if (dot_output_ != nullptr) {
54 vfprintf(dot_output_, fmt, ap);
60 void Exploration::log_state()
62 if (not cfg_dot_output_file.get().empty()) {
66 if (getenv(MC_ENV_SYSTEM_STATISTICS)) {
67 int ret = system("free");
69 XBT_WARN("Call to system(free) did not return 0, but %d", ret);
72 // Make our tests fully reproducible despite the subtle differences of strsignal() across archs
73 static const char* signal_name(int status)
75 switch (WTERMSIG(status)) {
76 case SIGABRT: // FreeBSD uses "Abort trap" as a strsignal for SIGABRT
78 case SIGSEGV: // MacOSX uses "Segmentation fault: 11" for SIGKILL
79 return "Segmentation fault";
81 return strsignal(WTERMSIG(status));
84 XBT_ATTRIB_NORETURN void Exploration::report_crash(int status)
86 XBT_INFO("**************************");
87 XBT_INFO("** CRASH IN THE PROGRAM **");
88 XBT_INFO("**************************");
89 if (WIFSIGNALED(status))
90 XBT_INFO("From signal: %s", signal_name(status));
91 else if (WIFEXITED(status))
92 XBT_INFO("From exit: %i", WEXITSTATUS(status));
93 if (not xbt_log_no_loc)
94 XBT_INFO("%s core dump was generated by the system.", WCOREDUMP(status) ? "A" : "No");
96 XBT_INFO("Counter-example execution trace:");
97 for (auto const& s : get_textual_trace())
98 XBT_INFO(" %s", s.c_str());
99 XBT_INFO("You can debug the problem (and see the whole details) by rerunning out of simgrid-mc with "
100 "--cfg=model-check/replay:'%s'",
101 get_record_trace().to_string().c_str());
103 if (xbt_log_no_loc) {
104 XBT_INFO("Stack trace not displayed because you passed --log=no_loc");
106 #if SIMGRID_HAVE_STATEFUL_MC
107 const auto* memory = get_remote_app().get_remote_process_memory();
109 XBT_INFO("Stack trace:");
110 memory->dump_stack();
113 XBT_INFO("Stack trace not shown because there is no memory introspection.");
116 system_exit(SIMGRID_MC_EXIT_PROGRAM_CRASH);
118 XBT_ATTRIB_NORETURN void Exploration::report_assertion_failure()
120 XBT_INFO("**************************");
121 XBT_INFO("*** PROPERTY NOT VALID ***");
122 XBT_INFO("**************************");
123 XBT_INFO("Counter-example execution trace:");
124 for (auto const& s : get_textual_trace())
125 XBT_INFO(" %s", s.c_str());
126 XBT_INFO("You can debug the problem (and see the whole details) by rerunning out of simgrid-mc with "
127 "--cfg=model-check/replay:'%s'",
128 get_record_trace().to_string().c_str());
130 system_exit(SIMGRID_MC_EXIT_SAFETY);
133 void Exploration::system_exit(int status) const
138 }; // namespace simgrid::mc