Logo AND Algorithmique Numérique Distribuée

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