#include <simgrid_config.h>
+#include <string>
+#include <cstdarg>
+
#if HAVE_MC
#include <stdexcept>
#include <cstddef>
#include <cstdlib>
#include <cstring>
-#include <string>
#include <iterator>
#include <xbt/sysdep.h>
+#endif
+
namespace simgrid {
namespace xbt {
+#if HAVE_MC
+
/** POD structure representation of a string
*/
struct string_data {
return b <= a;
}
-}
-}
-
#else
-#include <string>
+typedef std::string string;
-namespace simgrid {
-namespace xbt {
+#endif
-typedef std::string string;
+std::string string_vprintf(const char *fmt, va_list ap);
+std::string string_printf(const char *fmt, ...);
}
}
#endif
-
-#endif
for (auto const& state : stack_) {
int value;
smx_simcall_t req = MC_state_get_executed_request(state.get(), &value);
- if (req) {
- char* req_str = simgrid::mc::request_to_string(
- req, value, simgrid::mc::RequestType::executed);
- trace.push_back(req_str);
- xbt_free(req_str);
- }
+ if (req)
+ trace.push_back(simgrid::mc::request_to_string(
+ req, value, simgrid::mc::RequestType::executed));
}
return trace;
}
int CommunicationDeterminismChecker::main(void)
{
-
- char *req_str = nullptr;
int value;
std::unique_ptr<simgrid::mc::VisitedState> visited_state = nullptr;
smx_simcall_t req = nullptr;
&& (req = MC_state_get_request(state, &value))
&& (visited_state == nullptr)) {
- req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix);
- XBT_DEBUG("Execute: %s", req_str);
- xbt_free(req_str);
+ XBT_DEBUG("Execute: %s",
+ simgrid::mc::request_to_string(
+ req, value, simgrid::mc::RequestType::simix).c_str());
+ char* req_str = nullptr;
if (dot_output != nullptr)
req_str = simgrid::mc::request_get_dot_output(req, value);
req = &issuer->simcall;
/* Debug information */
- if (XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)) {
- char* req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix);
- XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state.get());
- xbt_free(req_str);
- }
-
+ XBT_DEBUG("Replay (depth = %d) : %s (%p)",
+ depth,
+ simgrid::mc::request_to_string(
+ req, value, simgrid::mc::RequestType::simix).c_str(),
+ state.get());
}
simgrid::mc::handle_simcall(req, value);
for (std::shared_ptr<Pair> const& pair : explorationStack_) {
int value;
smx_simcall_t req = MC_state_get_executed_request(pair->graph_state.get(), &value);
- if (req && req->call != SIMCALL_NONE) {
- char* req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::executed);
- trace.push_back(std::string(req_str));
- xbt_free(req_str);
- }
+ if (req && req->call != SIMCALL_NONE)
+ trace.push_back(simgrid::mc::request_to_string(
+ req, value, simgrid::mc::RequestType::executed));
}
return trace;
}
fflush(dot_output);
}
- char* req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix);
- XBT_DEBUG("Execute: %s", req_str);
- xbt_free(req_str);
+ XBT_DEBUG("Execute: %s",
+ simgrid::mc::request_to_string(
+ req, value, simgrid::mc::RequestType::simix).c_str());
/* Set request as executed */
MC_state_set_executed_request(current_pair->graph_state.get(), req, value);
for (auto const& state : stack_) {
int value;
smx_simcall_t req = MC_state_get_executed_request(state.get(), &value);
- if (req) {
- char* req_str = simgrid::mc::request_to_string(
- req, value, simgrid::mc::RequestType::executed);
- trace.push_back(req_str);
- xbt_free(req_str);
- }
+ if (req)
+ trace.push_back(simgrid::mc::request_to_string(
+ req, value, simgrid::mc::RequestType::executed));
}
return trace;
}
// If there are processes to interleave and the maximum depth has not been
// reached then perform one step of the exploration algorithm.
-
- if (XBT_LOG_ISENABLED(mc_safety, xbt_log_priority_debug)) {
- char* req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix);
- XBT_DEBUG("Execute: %s", req_str);
- xbt_free(req_str);
- }
+ XBT_DEBUG("Execute: %s",
+ simgrid::mc::request_to_string(
+ req, value, simgrid::mc::RequestType::simix).c_str());
char* req_str = nullptr;
if (dot_output != nullptr)
XBT_DEBUG("Dependent Transitions:");
int value;
smx_simcall_t prev_req = MC_state_get_executed_request(prev_state, &value);
- char* req_str = simgrid::mc::request_to_string(prev_req, value, simgrid::mc::RequestType::internal);
- XBT_DEBUG("%s (state=%d)", req_str, prev_state->num);
- xbt_free(req_str);
+ XBT_DEBUG("%s (state=%d)",
+ simgrid::mc::request_to_string(
+ prev_req, value, simgrid::mc::RequestType::internal).c_str(),
+ prev_state->num);
prev_req = MC_state_get_executed_request(state.get(), &value);
- req_str = simgrid::mc::request_to_string(prev_req, value, simgrid::mc::RequestType::executed);
- XBT_DEBUG("%s (state=%d)", req_str, state->num);
- xbt_free(req_str);
+ XBT_DEBUG("%s (state=%d)",
+ simgrid::mc::request_to_string(
+ prev_req, value, simgrid::mc::RequestType::executed).c_str(),
+ state->num);
}
if (!prev_state->processStates[issuer->pid].done())
smx_simcall_t req = &issuer->simcall;
/* Debug information */
- if (XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)) {
- char* req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix);
- XBT_DEBUG("Replay: %s (%p)", req_str, state.get());
- xbt_free(req_str);
- }
+ XBT_DEBUG("Replay: %s (%p)",
+ simgrid::mc::request_to_string(
+ req, value, simgrid::mc::RequestType::simix).c_str(),
+ state.get());
/* TODO : handle test and testany simcalls */
e_mc_call_type_t call = MC_CALL_TYPE_NONE;
}
-char *simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid::mc::RequestType request_type)
+std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid::mc::RequestType request_type)
{
bool use_remote_comm = true;
switch(request_type) {
THROW_UNIMPLEMENTED;
}
- char* str;
+ std::string str;
if (args != nullptr)
- str =
- bprintf("[(%lu)%s (%s)] %s(%s)", issuer->pid,
+ str = simgrid::xbt::string_printf("[(%lu)%s (%s)] %s(%s)", issuer->pid,
MC_smx_process_get_host_name(issuer),
MC_smx_process_get_name(issuer),
type, args);
else
- str =
- bprintf("[(%lu)%s (%s)] %s ", issuer->pid,
+ str = simgrid::xbt::string_printf("[(%lu)%s (%s)] %s ", issuer->pid,
MC_smx_process_get_host_name(issuer),
MC_smx_process_get_name(issuer),
type);
#ifndef SIMGRID_MC_REQUEST_H
#define SIMGRID_MC_REQUEST_H
+#include <string>
+
#include <xbt/base.h>
#include "src/simix/smx_private.h"
XBT_PRIVATE bool request_depend(smx_simcall_t req1, smx_simcall_t req2);
-XBT_PRIVATE char* request_to_string(smx_simcall_t req, int value, simgrid::mc::RequestType type);
+XBT_PRIVATE std::string request_to_string(smx_simcall_t req, int value, simgrid::mc::RequestType type);
XBT_PRIVATE bool request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx);
/* 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 <cstdarg>
+#include <cstdio>
+
#include <simgrid_config.h>
+
#include <xbt/string.hpp>
+#include <xbt/sysdep.h>
namespace simgrid {
namespace xbt {
#endif
+std::string string_vprintf(const char *fmt, va_list ap)
+{
+ // Get the size:
+ va_list ap2;
+ va_copy(ap2, ap);
+ int size = std::vsnprintf(nullptr, 0, fmt, ap2);
+ va_end(ap2);
+ if (size < 0)
+ xbt_die("string_vprintf error");
+
+ // Allocate the string and format:
+ std::string res;
+ res.resize(size);
+ if (size != 0 && std::vsnprintf(&res[0], size + 1, fmt, ap) != size)
+ xbt_die("string_vprintf error");
+ return res;
+}
+
+std::string string_printf(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ std::string res;
+ try {
+ res = string_vprintf(fmt, ap);
+ }
+ catch(...) {
+ va_end(ap);
+ throw;
+ }
+ va_end(ap);
+ return res;
+}
+
}
}