1 /* Copyright (c) 2007-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. */
6 #ifndef SIMGRID_MC_SNAPSHOT_HPP
7 #define SIMGRID_MC_SNAPSHOT_HPP
9 #include "src/mc/ModelChecker.hpp"
10 #include "src/mc/inspect/mc_unw.hpp"
11 #include "src/mc/remote/RemoteClient.hpp"
12 #include "src/mc/sosp/Region.hpp"
18 * Some parts of the snapshot are ignored by zeroing them out: the real
19 * values is stored here.
21 struct s_mc_snapshot_ignored_data_t {
23 std::vector<char> data;
26 /** Information about a given stack frame */
27 struct s_mc_stack_frame_t {
28 /** Instruction pointer */
32 unw_word_t frame_base;
33 simgrid::mc::Frame* frame;
34 std::string frame_name;
35 unw_cursor_t unw_cursor;
37 typedef s_mc_stack_frame_t* mc_stack_frame_t;
39 struct s_local_variable_t {
40 simgrid::mc::Frame* subprogram;
43 simgrid::mc::Type* type;
46 typedef s_local_variable_t* local_variable_t;
47 typedef const s_local_variable_t* const_local_variable_t;
49 struct XBT_PRIVATE s_mc_snapshot_stack_t {
50 std::vector<s_local_variable_t> local_variables;
51 simgrid::mc::UnwindContext context;
52 std::vector<s_mc_stack_frame_t> stack_frames;
54 typedef s_mc_snapshot_stack_t* mc_snapshot_stack_t;
55 typedef const s_mc_snapshot_stack_t* const_mc_snapshot_stack_t;
60 class XBT_PRIVATE Snapshot final : public AddressSpace {
63 Snapshot(int num_state, RemoteClient* process = &mc_model_checker->process());
64 ~Snapshot() = default;
67 bool on_heap(const void* address) const
69 const xbt_mheap_t heap = process()->get_heap();
70 return address >= heap->heapbase && address < heap->breakval;
73 void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address,
74 ReadOptions options = ReadOptions::none()) const override;
75 Region* get_region(const void* addr) const;
76 Region* get_region(const void* addr, Region* hinted_region) const;
77 void restore(RemoteClient* process);
81 std::size_t heap_bytes_used_;
82 std::vector<std::unique_ptr<Region>> snapshot_regions_;
83 std::set<pid_t> enabled_processes_;
84 std::vector<std::size_t> stack_sizes_;
85 std::vector<s_mc_snapshot_stack_t> stacks_;
86 std::vector<simgrid::mc::IgnoredHeapRegion> to_ignore_;
87 std::uint64_t hash_ = 0;
88 std::vector<s_mc_snapshot_ignored_data_t> ignored_data_;
91 void add_region(RegionType type, ObjectInformation* object_info, void* start_addr, std::size_t size);
92 void snapshot_regions(simgrid::mc::RemoteClient* process);
93 void snapshot_stacks(simgrid::mc::RemoteClient* process);
96 } // namespace simgrid