Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e7a5a1bce12a6da3564b135285df2222efcfc2b0
[simgrid.git] / src / mc / mc_object_info.h
1 /* Copyright (c) 2007-2014. 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 /** file
8  *  Debug information for the MC.
9  */
10
11 #ifndef SIMGRID_MC_OBJECT_INFO_H
12 #define SIMGRID_MC_OBJECT_INFO_H
13
14 #include <stdint.h>
15
16 #include <string>
17
18 #include <simgrid_config.h>
19 #include <xbt/dict.h>
20 #include <xbt/dynar.h>
21
22 #include <elfutils/libdw.h>
23
24 #include "mc_forward.h"
25 #include "mc_location.h"
26 #include "mc_process.h"
27 #include "../smpi/private.h"
28
29 // ***** Type
30
31 typedef int e_mc_type_type;
32
33 namespace simgrid {
34 namespace mc {
35
36 /** Represents a type in the program
37  *
38  *  It is currently used to represent members of structs and unions as well.
39  */
40 class Type {
41 public:
42   Type();
43   Type(Type const& type) = default;
44   Type& operator=(Type const&) = default;
45   Type(Type&& type) = default;
46   Type& operator=(Type&&) = default;
47
48   e_mc_type_type type;
49   Dwarf_Off id; /* Offset in the section (in hexadecimal form) */
50   std::string name; /* Name of the type */
51   int byte_size; /* Size in bytes */
52   int element_count; /* Number of elements for array type */
53   std::string type_id; /* DW_AT_type id */
54   std::vector<Type> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
55   int is_pointer_type;
56
57   // Location (for members) is either of:
58   simgrid::mc::DwarfExpression location_expression;
59
60   mc_type_t subtype; // DW_AT_type
61   mc_type_t full_type; // The same (but more complete) type
62
63   bool has_offset_location() const
64   {
65     return location_expression.size() == 1 &&
66       location_expression[0].atom == DW_OP_plus_uconst;
67   }
68
69   // TODO, check if this shortcut is really necessary
70   int offset() const
71   {
72     xbt_assert(this->has_offset_location());
73     return this->location_expression[0].number;
74   }
75
76   void offset(int new_offset)
77   {
78     Dwarf_Op op;
79     op.atom = DW_OP_plus_uconst;
80     op.number = new_offset;
81     this->location_expression = { op };
82   }
83 };
84
85 }
86 }
87
88 // ***** Object info
89
90 /** Bit field of options */
91 typedef int mc_object_info_flags;
92 #define MC_OBJECT_INFO_NONE 0
93 #define MC_OBJECT_INFO_EXECUTABLE 1
94
95 namespace simgrid {
96 namespace mc {
97
98 class ObjectInformation {
99 public:
100   ObjectInformation();
101   ~ObjectInformation();
102   ObjectInformation(ObjectInformation const&) = delete;
103   ObjectInformation& operator=(ObjectInformation const&) = delete;
104
105   mc_object_info_flags flags;
106   char* file_name;
107   const void* start;
108   const void *end;
109   char *start_exec;
110   char *end_exec; // Executable segment
111   char *start_rw;
112   char *end_rw; // Read-write segment
113   char *start_ro;
114   char *end_ro; // read-only segment
115   xbt_dict_t subprograms; // xbt_dict_t<origin as hexadecimal string, mc_frame_t>
116   xbt_dynar_t global_variables; // xbt_dynar_t<mc_variable_t>
117   xbt_dict_t types; // xbt_dict_t<origin as hexadecimal string, mc_type_t>
118   xbt_dict_t full_types_by_name; // xbt_dict_t<name, mc_type_t> (full defined type only)
119
120   // Here we sort the minimal information for an efficient (and cache-efficient)
121   // lookup of a function given an instruction pointer.
122   // The entries are sorted by low_pc and a binary search can be used to look them up.
123   xbt_dynar_t functions_index;
124
125   bool executable() const
126   {
127     return this->flags & MC_OBJECT_INFO_EXECUTABLE;
128   }
129
130   bool privatized() const
131   {
132     return this->executable() && smpi_privatize_global_variables;
133   }
134
135   void* base_address() const;
136
137   mc_frame_t find_function(const void *ip) const;
138   mc_variable_t find_variable(const char* name) const;
139
140 };
141
142 }
143 }
144
145 XBT_INTERNAL std::shared_ptr<s_mc_object_info_t> MC_find_object_info(
146   std::vector<simgrid::mc::VmMap> const& maps, const char* name, int executable);
147 XBT_INTERNAL void MC_post_process_object_info(mc_process_t process, mc_object_info_t info);
148
149 XBT_INTERNAL void MC_dwarf_get_variables(mc_object_info_t info);
150 XBT_INTERNAL void MC_dwarf_get_variables_libdw(mc_object_info_t info);
151 XBT_INTERNAL const char* MC_dwarf_attrname(int attr);
152 XBT_INTERNAL const char* MC_dwarf_tagname(int tag);
153
154 XBT_INTERNAL void* mc_member_resolve(const void* base, mc_type_t type, mc_type_t member, mc_address_space_t snapshot, int process_index);
155
156 namespace simgrid {
157 namespace mc {
158
159 class Variable {
160 public:
161   Variable();
162   Variable(Variable const&) = delete;
163   Variable& operator=(Variable const&) = delete;
164
165   Dwarf_Off dwarf_offset; /* Global offset of the field. */
166   int global;
167   std::string name;
168   std::string type_id;
169   mc_type_t type;
170
171   // Use either of:
172   simgrid::mc::LocationList location_list;
173   void* address;
174
175   size_t start_scope;
176   mc_object_info_t object_info;
177
178 };
179
180 class Frame {
181 public:
182   Frame();
183   ~Frame();
184   Frame(Frame const&) = delete;
185   Frame& operator=(Frame&) = delete;
186
187   int tag;
188   std::string name;
189   void *low_pc;
190   void *high_pc;
191   simgrid::mc::LocationList frame_base;
192   xbt_dynar_t /* <mc_variable_t> */ variables; /* Cannot use dict, there may be several variables with the same name (in different lexical blocks)*/
193   unsigned long int id; /* DWARF offset of the subprogram */
194   xbt_dynar_t /* <mc_frame_t> */ scopes;
195   Dwarf_Off abstract_origin_id;
196   mc_object_info_t object_info;
197 };
198
199 }
200 }
201
202
203
204 struct s_mc_function_index_item {
205   void* low_pc, *high_pc;
206   mc_frame_t function;
207 };
208
209 #endif