Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of github.com:mquinson/simgrid
[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 <vector>
13
14 #include "mc/mc_forward.h"
15 #include "mc/Type.hpp"
16 #include "mc/Frame.hpp"
17
18 #include "smpi/private.h"
19
20 namespace simgrid {
21 namespace mc {
22
23 /** An entry in the functions index
24  *
25  *  See the code of ObjectInformation::find_function.
26  */
27 struct FunctionIndexEntry {
28   void* low_pc;
29   simgrid::mc::Frame* function;
30 };
31
32 /** Information about an (ELF) executable/sharedobject
33  *
34  *  This contain sall the information we have at runtime about an
35  *  executable/shared object in the target (modelchecked) process:
36  *  - where it is located in the virtual address space;
37  *  - where are located it's different memory mapping in the the
38  *    virtual address space ;
39  *  - all the debugging (DWARF) information,
40  *    - location of the functions,
41  *    - types
42  *  - etc.
43  *
44  *  It is not copyable because we are taking pointers to Types/Frames.
45  *  We'd have to update/rebuild some data structures in order to copy
46  *  successfully.
47  */
48
49 class ObjectInformation {
50 public:
51   ObjectInformation();
52
53   // Not copyable:
54   ObjectInformation(ObjectInformation const&) = delete;
55   ObjectInformation& operator=(ObjectInformation const&) = delete;
56
57   // Flag:
58   static const int Executable = 1;
59
60   /** Bitfield of flags */
61   int flags;
62   std::string file_name;
63   const void* start;
64   const void *end;
65   char *start_exec;
66   char *end_exec; // Executable segment
67   char *start_rw;
68   char *end_rw; // Read-write segment
69   char *start_ro;
70   char *end_ro; // read-only segment
71   std::unordered_map<std::uint64_t, simgrid::mc::Frame> subprograms;
72   // TODO, remove the mutable (to remove it we'll have to add a lot of const everywhere)
73   mutable std::vector<simgrid::mc::Variable> global_variables;
74   std::unordered_map<std::uint64_t, simgrid::mc::Type> types;
75   std::unordered_map<std::string, simgrid::mc::Type*> full_types_by_name;
76
77   /** Index of functions by IP
78    *
79    * The entries are sorted by low_pc and a binary search can be used to look
80    * them up. Should we used a binary tree instead?
81    */
82   std::vector<FunctionIndexEntry> functions_index;
83
84   bool executable() const
85   {
86     return this->flags & simgrid::mc::ObjectInformation::Executable;
87   }
88
89   bool privatized() const
90   {
91 #ifdef HAVE_SMPI
92     return this->executable() && smpi_privatize_global_variables;
93 #else
94     return false;
95 #endif
96   }
97
98   void* base_address() const;
99
100   simgrid::mc::Frame* find_function(const void *ip) const;
101   simgrid::mc::Variable* find_variable(const char* name) const;
102
103 };
104
105 }
106 }
107
108 #endif