1 /* Copyright (c) 2007-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 #ifndef SIMGRID_MC_SNAPSHOT_HPP
7 #define SIMGRID_MC_SNAPSHOT_HPP
9 #include "src/mc/inspect/mc_unw.hpp"
10 #include "src/mc/sosp/Region.hpp"
11 #include "src/mc/sosp/RemoteProcessMemory.hpp"
17 * Some parts of the snapshot are ignored by zeroing them out: the real values is stored here.
19 struct s_mc_snapshot_ignored_data_t {
21 std::vector<char> data;
24 /** Information about a given stack frame */
25 struct s_mc_stack_frame_t {
26 /** Instruction pointer */
30 unw_word_t frame_base;
31 simgrid::mc::Frame* frame;
32 std::string frame_name;
33 unw_cursor_t unw_cursor;
35 using mc_stack_frame_t = s_mc_stack_frame_t*;
37 struct s_local_variable_t {
38 simgrid::mc::Frame* subprogram;
41 simgrid::mc::Type* type;
44 using local_variable_t = s_local_variable_t*;
45 using const_local_variable_t = const s_local_variable_t*;
47 struct XBT_PRIVATE s_mc_snapshot_stack_t {
48 std::vector<s_local_variable_t> local_variables;
49 simgrid::mc::UnwindContext context;
50 std::vector<s_mc_stack_frame_t> stack_frames;
52 using mc_snapshot_stack_t = s_mc_snapshot_stack_t*;
53 using const_mc_snapshot_stack_t = const s_mc_snapshot_stack_t*;
55 namespace simgrid::mc {
57 using hash_type = std::uint64_t;
59 class XBT_PRIVATE Snapshot final : public AddressSpace {
60 PageStore& page_store_;
64 Snapshot(long num_state, PageStore& store, RemoteProcessMemory& memory);
67 bool on_heap(const void* address) const
69 const s_xbt_mheap_t* heap = get_remote_process_memory()->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(RemoteProcessMemory& memory) const;
79 bool equals_to(const Snapshot& other, RemoteProcessMemory& memory);
83 std::size_t heap_bytes_used_ = 0;
84 std::vector<std::unique_ptr<Region>> snapshot_regions_;
85 std::vector<std::size_t> stack_sizes_;
86 std::vector<s_mc_snapshot_stack_t> stacks_;
87 std::vector<simgrid::mc::IgnoredHeapRegion> to_ignore_;
88 std::uint64_t hash_ = 0;
89 std::vector<s_mc_snapshot_ignored_data_t> ignored_data_;
92 void add_region(RegionType type, RemoteProcessMemory& memory, ObjectInformation* object_info, void* start_addr,
94 void snapshot_regions(RemoteProcessMemory& memory);
95 void snapshot_stacks(RemoteProcessMemory& memory);
97 void ignore_restore() const;
98 hash_type do_hash() const;
100 } // namespace simgrid::mc