Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move the PageStore from ModelChecker to RemoteApp
[simgrid.git] / src / mc / sosp / Snapshot.hpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_MC_SNAPSHOT_HPP
7 #define SIMGRID_MC_SNAPSHOT_HPP
8
9 #include "src/mc/ModelChecker.hpp"
10 #include "src/mc/inspect/mc_unw.hpp"
11 #include "src/mc/remote/RemoteProcess.hpp"
12 #include "src/mc/sosp/Region.hpp"
13
14 // ***** MC Snapshot
15
16 /** Ignored data
17  *
18  *  Some parts of the snapshot are ignored by zeroing them out: the real values is stored here.
19  */
20 struct s_mc_snapshot_ignored_data_t {
21   void* start;
22   std::vector<char> data;
23 };
24
25 /** Information about a given stack frame */
26 struct s_mc_stack_frame_t {
27   /** Instruction pointer */
28   unw_word_t ip;
29   /** Stack pointer */
30   unw_word_t sp;
31   unw_word_t frame_base;
32   simgrid::mc::Frame* frame;
33   std::string frame_name;
34   unw_cursor_t unw_cursor;
35 };
36 using mc_stack_frame_t = s_mc_stack_frame_t*;
37
38 struct s_local_variable_t {
39   simgrid::mc::Frame* subprogram;
40   unsigned long ip;
41   std::string name;
42   simgrid::mc::Type* type;
43   void* address;
44 };
45 using local_variable_t       = s_local_variable_t*;
46 using const_local_variable_t = const s_local_variable_t*;
47
48 struct XBT_PRIVATE s_mc_snapshot_stack_t {
49   std::vector<s_local_variable_t> local_variables;
50   simgrid::mc::UnwindContext context;
51   std::vector<s_mc_stack_frame_t> stack_frames;
52 };
53 using mc_snapshot_stack_t       = s_mc_snapshot_stack_t*;
54 using const_mc_snapshot_stack_t = const s_mc_snapshot_stack_t*;
55
56 namespace simgrid::mc {
57
58 using hash_type = std::uint64_t;
59
60 class XBT_PRIVATE Snapshot final : public AddressSpace {
61   PageStore& page_store_;
62
63 public:
64   /* Initialization */
65   Snapshot(long num_state, PageStore& store, RemoteProcess* process = &mc_model_checker->get_remote_process());
66
67   /* Regular use */
68   bool on_heap(const void* address) const
69   {
70     const s_xbt_mheap_t* heap = get_remote_process()->get_heap();
71     return address >= heap->heapbase && address < heap->breakval;
72   }
73
74   void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address,
75                    ReadOptions options = ReadOptions::none()) const override;
76   Region* get_region(const void* addr) const;
77   Region* get_region(const void* addr, Region* hinted_region) const;
78   void restore(RemoteProcess* process) const;
79
80   bool operator==(const Snapshot& other);
81   bool operator!=(const Snapshot& other) { return not(*this == other); }
82
83   // To be private
84   long num_state_;
85   std::size_t heap_bytes_used_ = 0;
86   std::vector<std::unique_ptr<Region>> snapshot_regions_;
87   std::vector<std::size_t> stack_sizes_;
88   std::vector<s_mc_snapshot_stack_t> stacks_;
89   std::vector<simgrid::mc::IgnoredHeapRegion> to_ignore_;
90   std::uint64_t hash_ = 0;
91   std::vector<s_mc_snapshot_ignored_data_t> ignored_data_;
92
93 private:
94   void add_region(RegionType type, ObjectInformation* object_info, void* start_addr, std::size_t size);
95   void snapshot_regions(RemoteProcess* process);
96   void snapshot_stacks(RemoteProcess* process);
97   void handle_ignore();
98   void ignore_restore() const;
99   hash_type do_hash() const;
100 };
101 } // namespace simgrid::mc
102
103 #endif