Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further reduce the amount of call sites for RemoteProcess::actors()
[simgrid.git] / src / mc / sosp / Snapshot.hpp
1 /* Copyright (c) 2007-2022. 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
19  *  values is stored here.
20  * */
21 struct s_mc_snapshot_ignored_data_t {
22   void* start;
23   std::vector<char> data;
24 };
25
26 /** Information about a given stack frame */
27 struct s_mc_stack_frame_t {
28   /** Instruction pointer */
29   unw_word_t ip;
30   /** Stack pointer */
31   unw_word_t sp;
32   unw_word_t frame_base;
33   simgrid::mc::Frame* frame;
34   std::string frame_name;
35   unw_cursor_t unw_cursor;
36 };
37 using mc_stack_frame_t = s_mc_stack_frame_t*;
38
39 struct s_local_variable_t {
40   simgrid::mc::Frame* subprogram;
41   unsigned long ip;
42   std::string name;
43   simgrid::mc::Type* type;
44   void* address;
45 };
46 using local_variable_t       = s_local_variable_t*;
47 using const_local_variable_t = const s_local_variable_t*;
48
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;
53 };
54 using mc_snapshot_stack_t       = s_mc_snapshot_stack_t*;
55 using const_mc_snapshot_stack_t = const s_mc_snapshot_stack_t*;
56
57 namespace simgrid::mc {
58
59 class XBT_PRIVATE Snapshot final : public AddressSpace {
60 public:
61   /* Initialization */
62   Snapshot(long num_state, RemoteProcess* process = &mc_model_checker->get_remote_process());
63
64   /* Regular use */
65   bool on_heap(const void* address) const
66   {
67     const s_xbt_mheap_t* heap = get_remote_process()->get_heap();
68     return address >= heap->heapbase && address < heap->breakval;
69   }
70
71   void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address,
72                    ReadOptions options = ReadOptions::none()) const override;
73   Region* get_region(const void* addr) const;
74   Region* get_region(const void* addr, Region* hinted_region) const;
75   void restore(RemoteProcess* process) const;
76
77   // To be private
78   long num_state_;
79   std::size_t heap_bytes_used_ = 0;
80   std::vector<std::unique_ptr<Region>> snapshot_regions_;
81   std::vector<std::size_t> stack_sizes_;
82   std::vector<s_mc_snapshot_stack_t> stacks_;
83   std::vector<simgrid::mc::IgnoredHeapRegion> to_ignore_;
84   std::uint64_t hash_ = 0;
85   std::vector<s_mc_snapshot_ignored_data_t> ignored_data_;
86
87 private:
88   void add_region(RegionType type, ObjectInformation* object_info, void* start_addr, std::size_t size);
89   void snapshot_regions(RemoteProcess* process);
90   void snapshot_stacks(RemoteProcess* process);
91 };
92 } // namespace simgrid::mc
93
94 #endif