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 std::vector<simgrid::mc::Variable> global_variables;
95 /** Types indexed by DWARF ID */
96 std::unordered_map<std::uint64_t, simgrid::mc::Type> types;
98 /** Types indexed by name
100 * Different compilation units have their separate type definitions
101 * (for the same type). When we find an opaque type in one compilation unit,
102 * we use this in order to try to find its definition in another compilation
105 std::unordered_map<std::string, simgrid::mc::Type*> full_types_by_name;
107 /** Whether this module is an executable
109 * More precisely we check if this is an ET_EXE ELF. These ELF files
110 * use fixed addresses instead of base-addres relative addresses.
111 * Position independant executables are in fact ET_DYN.
113 bool executable() const
115 return this->flags & simgrid::mc::ObjectInformation::Executable;
118 /** Base address of the module
120 * All the location information in ELF and DWARF are expressed as an offsets
121 * from this base address:
123 * - location of the functions and globale variables;
125 * - the DWARF instruction `OP_addr` pushes this on the DWARF stack.
127 void* base_address() const;
129 /** Find a function by instruction address
131 * @param ip instruction address
132 * @return corresponding function (if any) or nullptr
134 simgrid::mc::Frame* find_function(const void *ip) const;
136 /** Find a global variable by name
138 * This is used to ignore global variables and to find well-known variables
139 * (`__mmalloc_default_mdp`).
141 * @param name scopes name of the global variable (`myproject::Foo::count`)
142 * @return corresponding variable (if any) or nullptr
144 const simgrid::mc::Variable* find_variable(const char* name) const;
146 /** Remove a global variable (in order to ignore it)
148 * This is used to ignore a global variable for the snapshot comparison.
150 void remove_global_variable(const char* name);
152 /** Remove a loval variables (in order to ignore it)
154 * @param name Name of the globale variable
155 * @param scope Namespaceed name of the function (or null for all functions)
157 void remove_local_variable(
158 const char* name, const char* scope);
161 XBT_PRIVATE std::shared_ptr<ObjectInformation> createObjectInformation(
162 std::vector<simgrid::xbt::VmMap> const& maps, const char* name);
164 /** Augment the current module with informations about the other ones */
165 XBT_PRIVATE void postProcessObjectInformation(simgrid::mc::RemoteClient* process, simgrid::mc::ObjectInformation* info);