Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finally kill the now empty ModelChecker class
[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/inspect/mc_unw.hpp"
10 #include "src/mc/sosp/Region.hpp"
11 #include "src/mc/sosp/RemoteProcessMemory.hpp"
12
13 // ***** MC Snapshot
14
15 /** Ignored data
16  *
17  *  Some parts of the snapshot are ignored by zeroing them out: the real values is stored here.
18  */
19 struct s_mc_snapshot_ignored_data_t {
20   void* start;
21   std::vector<char> data;
22 };
23
24 /** Information about a given stack frame */
25 struct s_mc_stack_frame_t {
26   /** Instruction pointer */
27   unw_word_t ip;
28   /** Stack pointer */
29   unw_word_t sp;
30   unw_word_t frame_base;
31   simgrid::mc::Frame* frame;
32   std::string frame_name;
33   unw_cursor_t unw_cursor;
34 };
35 using mc_stack_frame_t = s_mc_stack_frame_t*;
36
37 struct s_local_variable_t {
38   simgrid::mc::Frame* subprogram;
39   unsigned long ip;
40   std::string name;
41   simgrid::mc::Type* type;
42   void* address;
43 };
44 using local_variable_t       = s_local_variable_t*;
45 using const_local_variable_t = const s_local_variable_t*;
46
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;
51 };
52 using mc_snapshot_stack_t       = s_mc_snapshot_stack_t*;
53 using const_mc_snapshot_stack_t = const s_mc_snapshot_stack_t*;
54
55 namespace simgrid::mc {
56
57 using hash_type = std::uint64_t;
58
59 class XBT_PRIVATE Snapshot final : public AddressSpace {
60   PageStore& page_store_;
61
62 public:
63   /* Initialization */
64   Snapshot(long num_state, PageStore& store, RemoteProcessMemory& memory);
65
66   /* Regular use */
67   bool on_heap(const void* address) const
68   {
69     const s_xbt_mheap_t* heap = get_remote_process_memory()->get_heap();
70     return address >= heap->heapbase && address < heap->breakval;
71   }
72
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;
78
79   bool equals_to(const Snapshot& other, RemoteProcessMemory& memory);
80
81   // To be private
82   long num_state_;
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_;
90
91 private:
92   void add_region(RegionType type, RemoteProcessMemory& memory, ObjectInformation* object_info, void* start_addr,
93                   std::size_t size);
94   void snapshot_regions(RemoteProcessMemory& memory);
95   void snapshot_stacks(RemoteProcessMemory& memory);
96   void handle_ignore();
97   void ignore_restore() const;
98   hash_type do_hash() const;
99 };
100 } // namespace simgrid::mc
101
102 #endif