Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move initial state into Session
[simgrid.git] / src / mc / ObjectInformation.hpp
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_OBJECT_INFORMATION_HPP
8 #define SIMGRID_MC_OBJECT_INFORMATION_HPP
9
10 #include <string>
11 #include <unordered_map>
12 #include <memory>
13 #include <vector>
14
15 #include <xbt/base.h>
16
17 #include "src/xbt/memory_map.hpp"
18 #include "src/mc/mc_forward.hpp"
19 #include "src/mc/Type.hpp"
20 #include "src/mc/Frame.hpp"
21
22 #include "src/smpi/private.h"
23
24 namespace simgrid {
25 namespace mc {
26
27 /** An entry in the functions index
28  *
29  *  See the code of ObjectInformation::find_function.
30  */
31 struct FunctionIndexEntry {
32   void* low_pc;
33   simgrid::mc::Frame* function;
34 };
35
36 /** Information about an (ELF) executable/sharedobject
37  *
38  *  This contain sall the information we have at runtime about an
39  *  executable/shared object in the target (modelchecked) process:
40  *  - where it is located in the virtual address space;
41  *  - where are located it's different memory mapping in the the
42  *    virtual address space ;
43  *  - all the debugging (DWARF) information,
44  *    - location of the functions,
45  *    - types
46  *  - etc.
47  *
48  *  It is not copyable because we are taking pointers to Types/Frames.
49  *  We'd have to update/rebuild some data structures in order to copy
50  *  successfully.
51  */
52
53 class ObjectInformation {
54 public:
55   ObjectInformation();
56
57   // Not copyable:
58   ObjectInformation(ObjectInformation const&) = delete;
59   ObjectInformation& operator=(ObjectInformation const&) = delete;
60
61   // Flag:
62   static const int Executable = 1;
63
64   /** Bitfield of flags */
65   int flags;
66   std::string file_name;
67   const void* start;
68   const void *end;
69   char *start_exec;
70   char *end_exec; // Executable segment
71   char *start_rw;
72   char *end_rw; // Read-write segment
73   char *start_ro;
74   char *end_ro; // read-only segment
75   std::unordered_map<std::uint64_t, simgrid::mc::Frame> subprograms;
76   // TODO, remove the mutable (to remove it we'll have to add a lot of const everywhere)
77   mutable std::vector<simgrid::mc::Variable> global_variables;
78   std::unordered_map<std::uint64_t, simgrid::mc::Type> types;
79   std::unordered_map<std::string, simgrid::mc::Type*> full_types_by_name;
80
81   /** Index of functions by IP
82    *
83    * The entries are sorted by low_pc and a binary search can be used to look
84    * them up. Should we used a binary tree instead?
85    */
86   std::vector<FunctionIndexEntry> functions_index;
87
88   bool executable() const
89   {
90     return this->flags & simgrid::mc::ObjectInformation::Executable;
91   }
92
93   void* base_address() const;
94
95   simgrid::mc::Frame* find_function(const void *ip) const;
96   simgrid::mc::Variable* find_variable(const char* name) const;
97   void remove_global_variable(const char* name);
98   void remove_local_variable(
99     const char* name, const char* scope);
100 };
101
102 XBT_PRIVATE std::shared_ptr<ObjectInformation> createObjectInformation(
103   std::vector<simgrid::xbt::VmMap> const& maps, const char* name);
104 XBT_PRIVATE void postProcessObjectInformation(
105   simgrid::mc::Process* process, simgrid::mc::ObjectInformation* info);
106
107 }
108 }
109
110 #endif