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"
36 /** Represents a type in the program
38 * It is currently used to represent members of structs and unions as well.
43 Type(Type const& type) = default;
44 Type& operator=(Type const&) = default;
45 Type(Type&& type) = default;
46 Type& operator=(Type&&) = default;
48 /** The DWARF TAG of the type (e.g. DW_TAG_array_type) */
50 Dwarf_Off id; /* Offset in the section (in hexadecimal form) */
51 std::string name; /* Name of the type */
52 int byte_size; /* Size in bytes */
53 int element_count; /* Number of elements for array type */
54 std::uint64_t type_id; /* DW_AT_type id */
55 std::vector<Type> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
58 // Location (for members) is either of:
59 simgrid::mc::DwarfExpression location_expression;
61 simgrid::mc::Type* subtype; // DW_AT_type
62 simgrid::mc::Type* full_type; // The same (but more complete) type
64 bool has_offset_location() const
66 return location_expression.size() == 1 &&
67 location_expression[0].atom == DW_OP_plus_uconst;
70 // TODO, check if this shortcut is really necessary
73 xbt_assert(this->has_offset_location());
74 return this->location_expression[0].number;
77 void offset(int new_offset)
80 op.atom = DW_OP_plus_uconst;
81 op.number = new_offset;
82 this->location_expression = { op };
98 Dwarf_Off dwarf_offset; /* Global offset of the field. */
101 std::uint64_t type_id;
102 simgrid::mc::Type* type;
105 simgrid::mc::LocationList location_list;
109 simgrid::mc::ObjectInformation* object_info;
120 simgrid::mc::LocationList frame_base;
121 std::vector<Variable> variables;
122 unsigned long int id; /* DWARF offset of the subprogram */
123 std::vector<Frame> scopes;
124 Dwarf_Off abstract_origin_id;
125 simgrid::mc::ObjectInformation* object_info;
128 /** An entry in the functions index
130 * See the code of ObjectInformation::find_function.
132 struct FunctionIndexEntry {
134 simgrid::mc::Frame* function;
137 /** Information about an (ELF) executable/sharedobject
139 * This contain sall the information we have at runtime about an
140 * executable/shared object in the target (modelchecked) process:
141 * - where it is located in the virtual address space;
142 * - where are located it's different memory mapping in the the
143 * virtual address space ;
144 * - all the debugging (DWARF) information,
145 * - location of the functions,
149 * It is not copyable because we are taking pointers to Types/Frames.
150 * We'd have to update/rebuild some data structures in order to copy
154 class ObjectInformation {
159 ObjectInformation(ObjectInformation const&) = delete;
160 ObjectInformation& operator=(ObjectInformation const&) = delete;
163 static const int Executable = 1;
165 /** Bitfield of flags */
167 std::string file_name;
171 char *end_exec; // Executable segment
173 char *end_rw; // Read-write segment
175 char *end_ro; // read-only segment
176 std::unordered_map<std::uint64_t, simgrid::mc::Frame> subprograms;
177 // TODO, remove the mutable (to remove it we'll have to add a lot of const everywhere)
178 mutable std::vector<simgrid::mc::Variable> global_variables;
179 std::unordered_map<std::uint64_t, simgrid::mc::Type> types;
180 std::unordered_map<std::string, simgrid::mc::Type*> full_types_by_name;
182 /** Index of functions by IP
184 * The entries are sorted by low_pc and a binary search can be used to look
185 * them up. Should we used a binary tree instead?
187 std::vector<FunctionIndexEntry> functions_index;
189 bool executable() const
191 return this->flags & simgrid::mc::ObjectInformation::Executable;
194 bool privatized() const
196 return this->executable() && smpi_privatize_global_variables;
199 void* base_address() const;
201 simgrid::mc::Frame* find_function(const void *ip) const;
202 simgrid::mc::Variable* find_variable(const char* name) const;
210 XBT_INTERNAL std::shared_ptr<simgrid::mc::ObjectInformation> MC_find_object_info(
211 std::vector<simgrid::mc::VmMap> const& maps, const char* name, int executable);
212 XBT_INTERNAL void MC_post_process_object_info(simgrid::mc::Process* process, simgrid::mc::ObjectInformation* info);
214 XBT_INTERNAL void MC_dwarf_get_variables(simgrid::mc::ObjectInformation* info);
215 XBT_INTERNAL void MC_dwarf_get_variables_libdw(simgrid::mc::ObjectInformation* info);
216 XBT_INTERNAL const char* MC_dwarf_attrname(int attr);
217 XBT_INTERNAL const char* MC_dwarf_tagname(int tag);
219 XBT_INTERNAL void* mc_member_resolve(
220 const void* base, simgrid::mc::Type* type, simgrid::mc::Type* member,
221 simgrid::mc::AddressSpace* snapshot, int process_index);