1 /* Copyright (c) 2007-2019. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef SIMGRID_MC_OBJECT_INFORMATION_HPP
8 #define SIMGRID_MC_OBJECT_INFORMATION_HPP
11 #include <unordered_map>
15 #include "src/mc/Frame.hpp"
16 #include "src/mc/Type.hpp"
17 #include "src/mc/mc_forward.hpp"
18 #include "src/xbt/memory_map.hpp"
20 #include "src/smpi/include/private.hpp"
25 /** An entry in the functions index
27 * See the code of ObjectInformation::find_function.
29 struct FunctionIndexEntry {
31 simgrid::mc::Frame* function;
34 /** Information about an ELF module (executable or shared object)
36 * This contains all the information we need about an executable or
37 * shared-object in the model-checked process:
39 * - where it is located in the virtual address space;
41 * - where are located its different memory mappings in the the
42 * virtual address space;
44 * - all the debugging (DWARF) information
46 * - location of the functions and their local variables,
51 class ObjectInformation {
53 ObjectInformation() = default;
56 ObjectInformation(ObjectInformation const&) = delete;
57 ObjectInformation& operator=(ObjectInformation const&) = delete;
60 static const int Executable = 1;
62 /** Bitfield of flags */
64 std::string file_name;
65 const void* start = nullptr;
66 const void *end = nullptr;
67 // Location of its text segment:
68 char *start_exec = nullptr;
69 char *end_exec = nullptr;
70 // Location of the read-only part of its data segment:
71 char *start_rw = nullptr;
72 char *end_rw = nullptr;
73 // Location of the read/write part of its data segment:
74 char *start_ro = nullptr;
75 char *end_ro = nullptr;
77 /** All of its subprograms indexed by their address */
78 std::unordered_map<std::uint64_t, simgrid::mc::Frame> subprograms;
80 /** Index of functions by instruction address
82 * We need to efficiently find the function from any given instruction
83 * address inside its range. This index is sorted by low_pc
85 * The entries are sorted by low_pc and a binary search can be used to look
86 * them up. In order to have a better cache locality, we only keep the
87 * information we need for the lookup in this vector. We could probably
88 * replace subprograms by an ordered vector of Frame and replace this one b
89 * a parallel `std::vector<void*>`.
91 std::vector<FunctionIndexEntry> functions_index;
93 // TODO, remove the mutable (to remove it we'll have to add a lot of const everywhere)
94 mutable std::vector<simgrid::mc::Variable> global_variables;
96 /** Types indexed by DWARF ID */
97 std::unordered_map<std::uint64_t, simgrid::mc::Type> types;
99 /** Types indexed by name
101 * Different compilation units have their separate type definitions
102 * (for the same type). When we find an opaque type in one compilation unit,
103 * we use this in order to try to find its definition in another compilation
106 std::unordered_map<std::string, simgrid::mc::Type*> full_types_by_name;
108 /** Whether this module is an executable
110 * More precisely we check if this is an ET_EXE ELF. These ELF files
111 * use fixed addresses instead of base-addres relative addresses.
112 * Position independant executables are in fact ET_DYN.
114 bool executable() const
116 return this->flags & simgrid::mc::ObjectInformation::Executable;
119 /** Base address of the module
121 * All the location information in ELF and DWARF are expressed as an offsets
122 * from this base address:
124 * - location of the functions and globale variables;
126 * - the DWARF instruction `OP_addr` pushes this on the DWARF stack.
128 void* base_address() const;
130 /** Find a function by instruction address
132 * @param ip instruction address
133 * @return corresponding function (if any) or nullptr
135 simgrid::mc::Frame* find_function(const void *ip) const;
137 /** Find a global variable by name
139 * This is used to ignore global variables and to find well-known variables
140 * (`__mmalloc_default_mdp`).
142 * @param name scopes name of the global variable (`myproject::Foo::count`)
143 * @return corresponding variable (if any) or nullptr
145 simgrid::mc::Variable* find_variable(const char* name) const;
147 /** Remove a global variable (in order to ignore it)
149 * This is used to ignore a global variable for the snapshot comparison.
151 void remove_global_variable(const char* name);
153 /** Remove a loval variables (in order to ignore it)
155 * @param name Name of the globale variable
156 * @param scope Namespaceed name of the function (or null for all functions)
158 void remove_local_variable(
159 const char* name, const char* scope);
162 XBT_PRIVATE std::shared_ptr<ObjectInformation> createObjectInformation(
163 std::vector<simgrid::xbt::VmMap> const& maps, const char* name);
165 /** Augment the current module with informations about the other ones */
166 XBT_PRIVATE void postProcessObjectInformation(simgrid::mc::RemoteClient* process, simgrid::mc::ObjectInformation* info);