Logo AND Algorithmique Numérique Distribuée

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