Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9dbbf53a96b24790e4893c8d4f4195cd78f61b5a
[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();
44   Type(Type const& type) = delete;
45   Type& operator=(Type const&) = delete;
46
47   e_mc_type_type type;
48   Dwarf_Off id; /* Offset in the section (in hexadecimal form) */
49   std::string name; /* Name of the type */
50   int byte_size; /* Size in bytes */
51   int element_count; /* Number of elements for array type */
52   std::string dw_type_id; /* DW_AT_type id */
53   xbt_dynar_t members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
54   int is_pointer_type;
55
56   // Location (for members) is either of:
57   simgrid::mc::DwarfExpression location_expression;
58
59   mc_type_t subtype; // DW_AT_type
60   mc_type_t full_type; // The same (but more complete) type
61
62   bool has_offset_location() const
63   {
64     return location_expression.size() == 1 &&
65       location_expression[0].atom == DW_OP_plus_uconst;
66   }
67
68   // TODO, check if this shortcut is really necessary
69   int offset() const
70   {
71     xbt_assert(this->has_offset_location());
72     return this->location_expression[0].number;
73   }
74
75   void offset(int new_offset)
76   {
77     Dwarf_Op op;
78     op.atom = DW_OP_plus_uconst;
79     op.number = new_offset;
80     this->location_expression = { op };
81   }
82 };
83
84 }
85 }
86
87 // ***** Object info
88
89 /** Bit field of options */
90 typedef int mc_object_info_flags;
91 #define MC_OBJECT_INFO_NONE 0
92 #define MC_OBJECT_INFO_EXECUTABLE 1
93
94 namespace simgrid {
95 namespace mc {
96
97 class ObjectInformation {
98 public:
99   ObjectInformation();
100   ~ObjectInformation();
101   ObjectInformation(ObjectInformation const&) = delete;
102   ObjectInformation& operator=(ObjectInformation const&) = delete;
103
104   mc_object_info_flags flags;
105   char* file_name;
106   const void* start;
107   const void *end;
108   char *start_exec;
109   char *end_exec; // Executable segment
110   char *start_rw;
111   char *end_rw; // Read-write segment
112   char *start_ro;
113   char *end_ro; // read-only segment
114   xbt_dict_t subprograms; // xbt_dict_t<origin as hexadecimal string, dw_frame_t>
115   xbt_dynar_t global_variables; // xbt_dynar_t<dw_variable_t>
116   xbt_dict_t types; // xbt_dict_t<origin as hexadecimal string, mc_type_t>
117   xbt_dict_t full_types_by_name; // xbt_dict_t<name, mc_type_t> (full defined type only)
118
119   // Here we sort the minimal information for an efficient (and cache-efficient)
120   // lookup of a function given an instruction pointer.
121   // The entries are sorted by low_pc and a binary search can be used to look them up.
122   xbt_dynar_t functions_index;
123
124   bool executable() const
125   {
126     return this->flags & MC_OBJECT_INFO_EXECUTABLE;
127   }
128
129   bool privatized() const
130   {
131     return this->executable() && smpi_privatize_global_variables;
132   }
133
134   void* base_address() const;
135
136   dw_frame_t find_function(const void *ip) const;
137   dw_variable_t find_variable(const char* name) const;
138
139 };
140
141 }
142 }
143
144 XBT_INTERNAL std::shared_ptr<s_mc_object_info_t> MC_find_object_info(
145   std::vector<simgrid::mc::VmMap> const& maps, const char* name, int executable);
146 XBT_INTERNAL void MC_post_process_object_info(mc_process_t process, mc_object_info_t info);
147
148 XBT_INTERNAL void MC_dwarf_get_variables(mc_object_info_t info);
149 XBT_INTERNAL void MC_dwarf_get_variables_libdw(mc_object_info_t info);
150 XBT_INTERNAL const char* MC_dwarf_attrname(int attr);
151 XBT_INTERNAL const char* MC_dwarf_tagname(int tag);
152
153 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);
154
155 struct s_dw_variable{
156   Dwarf_Off dwarf_offset; /* Global offset of the field. */
157   int global;
158   char *name;
159   char *type_origin;
160   mc_type_t type;
161
162   // Use either of:
163   s_mc_location_list_t locations;
164   void* address;
165
166   size_t start_scope;
167   mc_object_info_t object_info;
168
169 };
170
171 struct s_dw_frame{
172   int tag;
173   char *name;
174   void *low_pc;
175   void *high_pc;
176   s_mc_location_list_t frame_base;
177   xbt_dynar_t /* <dw_variable_t> */ variables; /* Cannot use dict, there may be several variables with the same name (in different lexical blocks)*/
178   unsigned long int id; /* DWARF offset of the subprogram */
179   xbt_dynar_t /* <dw_frame_t> */ scopes;
180   Dwarf_Off abstract_origin_id;
181   mc_object_info_t object_info;
182 };
183
184 struct s_mc_function_index_item {
185   void* low_pc, *high_pc;
186   dw_frame_t function;
187 };
188
189 XBT_INTERNAL void mc_frame_free(dw_frame_t freme);
190
191 #endif