/************************************* Take Snapshot ************************************/
/****************************************************************************************/
-static void get_memory_regions(simgrid::mc::RemoteClient* process, simgrid::mc::Snapshot* snapshot)
+void simgrid::mc::Snapshot::snapshot_regions(simgrid::mc::RemoteClient* process)
{
- snapshot->snapshot_regions_.clear();
+ snapshot_regions_.clear();
for (auto const& object_info : process->object_infos)
- snapshot->add_region(simgrid::mc::RegionType::Data, object_info.get(), object_info->start_rw, object_info->start_rw,
- object_info->end_rw - object_info->start_rw);
+ add_region(simgrid::mc::RegionType::Data, object_info.get(), object_info->start_rw, object_info->start_rw,
+ object_info->end_rw - object_info->start_rw);
xbt_mheap_t heap = process->get_heap();
void* start_heap = heap->base;
void* end_heap = heap->breakval;
- snapshot->add_region(simgrid::mc::RegionType::Heap, nullptr, start_heap, start_heap,
- (char*)end_heap - (char*)start_heap);
- snapshot->heap_bytes_used_ = mmalloc_get_bytes_used_remote(heap->heaplimit, process->get_malloc_info());
- snapshot->privatization_index_ = simgrid::mc::ProcessIndexMissing;
+ add_region(simgrid::mc::RegionType::Heap, nullptr, start_heap, start_heap, (char*)end_heap - (char*)start_heap);
+ heap_bytes_used_ = mmalloc_get_bytes_used_remote(heap->heaplimit, process->get_malloc_info());
+ privatization_index_ = simgrid::mc::ProcessIndexMissing;
#if HAVE_SMPI
if (mc_model_checker->process().privatized() && MC_smpi_process_count())
// snapshot->privatization_index = smpi_loaded_page
- mc_model_checker->process().read_variable("smpi_loaded_page", &snapshot->privatization_index_,
- sizeof(snapshot->privatization_index_));
+ mc_model_checker->process().read_variable("smpi_loaded_page", &privatization_index_, sizeof(privatization_index_));
#endif
}
+
/** @brief Checks whether the variable is in scope for a given IP.
*
* A variable may be defined only from a given value of IP.
return result;
}
-static void take_snapshot_stacks(simgrid::mc::Snapshot* snapshot)
+void simgrid::mc::Snapshot::snapshot_stacks(simgrid::mc::RemoteClient* process)
{
- for (auto const& stack : mc_model_checker->process().stack_areas()) {
+ for (auto const& stack : process->stack_areas()) {
s_mc_snapshot_stack_t st;
// Read the context from remote process:
unw_word_t sp = st.stack_frames[0].sp;
- snapshot->stacks_.push_back(std::move(st));
+ stacks_.push_back(std::move(st));
size_t stack_size = (char*)stack.address + stack.size - (char*)sp;
- snapshot->stack_sizes_.push_back(stack_size);
+ stack_sizes_.push_back(stack_size);
}
}
, privatization_index_(0)
, hash_(0)
{
- for (auto const& p : mc_model_checker->process().actors())
+ for (auto const& p : process->actors())
enabled_processes_.insert(p.copy.getBuffer()->get_pid());
snapshot_handle_ignore(this);
/* Save the std heap and the writable mapped pages of libsimgrid and binary */
- get_memory_regions(process, this);
+ snapshot_regions(process);
- to_ignore_ = mc_model_checker->process().ignored_heap();
+ to_ignore_ = process->ignored_heap();
if (_sg_mc_max_visited_states > 0 || not _sg_mc_property_file.get().empty()) {
- take_snapshot_stacks(this);
+ snapshot_stacks(process);
if (_sg_mc_hash)
hash_ = simgrid::mc::hash(*this);
}
return get_region(addr, process_index);
}
-static inline void restore_snapshot_regions(simgrid::mc::Snapshot* snapshot)
+void Snapshot::restore(RemoteClient* process)
{
- for (std::unique_ptr<simgrid::mc::RegionSnapshot> const& region : snapshot->snapshot_regions_) {
- // For privatized, variables we decided it was not necessary to take the snapshot:
- if (region)
+ XBT_DEBUG("Restore snapshot %i", num_state_);
+
+ // Restore regions
+ for (std::unique_ptr<simgrid::mc::RegionSnapshot> const& region : snapshot_regions_) {
+ if (region) // privatized variables are not snapshoted
region.get()->restore();
}
-#if HAVE_SMPI
- if (snapshot->privatization_index_ >= 0) {
- // Fix the privatization mmap:
- s_mc_message_restore_t message{MC_MESSAGE_RESTORE, snapshot->privatization_index_};
- mc_model_checker->process().getChannel().send(message);
+ // Fix the privatization mmap if needed
+ if (privatization_index_ >= 0) {
+ s_mc_message_restore_t message{MC_MESSAGE_RESTORE, privatization_index_};
+ process->getChannel().send(message);
}
-#endif
-}
-void restore_snapshot(std::shared_ptr<simgrid::mc::Snapshot> snapshot)
-{
- XBT_DEBUG("Restore snapshot %i", snapshot->num_state_);
- restore_snapshot_regions(snapshot.get());
- snapshot_ignore_restore(snapshot.get());
- mc_model_checker->process().clear_cache();
+ snapshot_ignore_restore(this);
+ process->clear_cache();
}
} // namespace mc
~Snapshot() = default;
/* Initialization */
- void add_region(RegionType type, ObjectInformation* object_info, void* start_addr, void* permanent_addr,
- std::size_t size);
/* Regular use */
const void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address, int process_index = ProcessIndexAny,
ReadOptions options = ReadOptions::none()) const override;
RegionSnapshot* get_region(const void* addr, int process_index) const;
RegionSnapshot* get_region(const void* addr, int process_index, RegionSnapshot* hinted_region) const;
+ void restore(RemoteClient* process);
// To be private
int num_state_;
std::size_t heap_bytes_used_;
std::vector<std::unique_ptr<RegionSnapshot>> snapshot_regions_;
std::set<pid_t> enabled_processes_;
- int privatization_index_;
+ int privatization_index_ = 0;
std::vector<std::size_t> stack_sizes_;
std::vector<s_mc_snapshot_stack_t> stacks_;
std::vector<simgrid::mc::IgnoredHeapRegion> to_ignore_;
std::uint64_t hash_ = 0;
std::vector<s_mc_snapshot_ignored_data_t> ignored_data_;
+
+private:
+ void add_region(RegionType type, ObjectInformation* object_info, void* start_addr, void* permanent_addr,
+ std::size_t size);
+ void snapshot_regions(simgrid::mc::RemoteClient* process);
+ void snapshot_stacks(simgrid::mc::RemoteClient* process);
};
} // namespace mc
} // namespace simgrid
namespace mc {
XBT_PRIVATE std::shared_ptr<Snapshot> take_snapshot(int num_state);
-XBT_PRIVATE void restore_snapshot(std::shared_ptr<Snapshot> snapshot);
} // namespace mc
} // namespace simgrid