1 /* Copyright (c) 2007-2014. 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. */
8 * Debug information for the MC.
11 #ifndef SIMGRID_MC_OBJECT_INFO_H
12 #define SIMGRID_MC_OBJECT_INFO_H
18 #include <unordered_map>
20 #include <simgrid_config.h>
22 #include <xbt/dynar.h>
24 #include <elfutils/libdw.h>
26 #include "mc_forward.hpp"
27 #include "mc_location.h"
28 #include "mc_process.h"
29 #include "../smpi/private.h"
33 typedef int e_mc_type_type;
38 /** Represents a type in the program
40 * It is currently used to represent members of structs and unions as well.
45 Type(Type const& type) = default;
46 Type& operator=(Type const&) = default;
47 Type(Type&& type) = default;
48 Type& operator=(Type&&) = default;
51 Dwarf_Off id; /* Offset in the section (in hexadecimal form) */
52 std::string name; /* Name of the type */
53 int byte_size; /* Size in bytes */
54 int element_count; /* Number of elements for array type */
55 std::uint64_t type_id; /* DW_AT_type id */
56 std::vector<Type> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
59 // Location (for members) is either of:
60 simgrid::mc::DwarfExpression location_expression;
62 simgrid::mc::Type* subtype; // DW_AT_type
63 simgrid::mc::Type* full_type; // The same (but more complete) type
65 bool has_offset_location() const
67 return location_expression.size() == 1 &&
68 location_expression[0].atom == DW_OP_plus_uconst;
71 // TODO, check if this shortcut is really necessary
74 xbt_assert(this->has_offset_location());
75 return this->location_expression[0].number;
78 void offset(int new_offset)
81 op.atom = DW_OP_plus_uconst;
82 op.number = new_offset;
83 this->location_expression = { op };
92 /** Bit field of options */
93 typedef int mc_object_info_flags;
94 #define MC_OBJECT_INFO_NONE 0
95 #define MC_OBJECT_INFO_EXECUTABLE 1
104 Dwarf_Off dwarf_offset; /* Global offset of the field. */
107 std::uint64_t type_id;
108 simgrid::mc::Type* type;
111 simgrid::mc::LocationList location_list;
115 simgrid::mc::ObjectInformation* object_info;
126 simgrid::mc::LocationList frame_base;
127 std::vector<Variable> variables;
128 unsigned long int id; /* DWARF offset of the subprogram */
129 std::vector<Frame> scopes;
130 Dwarf_Off abstract_origin_id;
131 simgrid::mc::ObjectInformation* object_info;
134 /** An entry in the functions index
136 * See the code of ObjectInformation::find_function.
138 struct FunctionIndexEntry {
140 simgrid::mc::Frame* function;
143 /** Information about an (ELF) executable/sharedobject
145 * This contain sall the information we have at runtime about an
146 * executable/shared object in the target (modelchecked) process:
147 * - where it is located in the virtual address space;
148 * - where are located it's different memory mapping in the the
149 * virtual address space ;
150 * - all the debugging (DWARF) information,
151 * - location of the functions,
155 * It is not copyable because we are taking pointers to Types/Frames.
156 * We'd have to update/rebuild some data structures in order to copy
160 class ObjectInformation {
165 ObjectInformation(ObjectInformation const&) = delete;
166 ObjectInformation& operator=(ObjectInformation const&) = delete;
168 mc_object_info_flags flags;
169 std::string file_name;
173 char *end_exec; // Executable segment
175 char *end_rw; // Read-write segment
177 char *end_ro; // read-only segment
178 std::unordered_map<std::uint64_t, simgrid::mc::Frame> subprograms;
179 // TODO, remove the mutable (to remove it we'll have to add a lot of const everywhere)
180 mutable std::vector<simgrid::mc::Variable> global_variables;
181 std::unordered_map<std::uint64_t, simgrid::mc::Type> types;
182 std::unordered_map<std::string, simgrid::mc::Type*> full_types_by_name;
184 /** Index of functions by IP
186 * The entries are sorted by low_pc and a binary search can be used to look
187 * them up. Should we used a binary tree instead?
189 std::vector<FunctionIndexEntry> functions_index;
191 bool executable() const
193 return this->flags & MC_OBJECT_INFO_EXECUTABLE;
196 bool privatized() const
198 return this->executable() && smpi_privatize_global_variables;
201 void* base_address() const;
203 simgrid::mc::Frame* find_function(const void *ip) const;
204 // TODO, should be simgrid::mc::Variable*
205 simgrid::mc::Variable* find_variable(const char* name) const;
213 XBT_INTERNAL std::shared_ptr<simgrid::mc::ObjectInformation> MC_find_object_info(
214 std::vector<simgrid::mc::VmMap> const& maps, const char* name, int executable);
215 XBT_INTERNAL void MC_post_process_object_info(simgrid::mc::Process* process, simgrid::mc::ObjectInformation* info);
217 XBT_INTERNAL void MC_dwarf_get_variables(simgrid::mc::ObjectInformation* info);
218 XBT_INTERNAL void MC_dwarf_get_variables_libdw(simgrid::mc::ObjectInformation* info);
219 XBT_INTERNAL const char* MC_dwarf_attrname(int attr);
220 XBT_INTERNAL const char* MC_dwarf_tagname(int tag);
222 XBT_INTERNAL void* mc_member_resolve(
223 const void* base, simgrid::mc::Type* type, simgrid::mc::Type* member,
224 simgrid::mc::AddressSpace* snapshot, int process_index);