Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3b1f60a8c00f1d7d7e484423e77c9bb1686adc81
[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 MC_OBJECT_INFO_H
12 #define MC_OBJECT_INFO_H
13
14 #include <stdint.h>
15 #include <stdbool.h>
16
17 #include <simgrid_config.h>
18 #include <xbt/dict.h>
19 #include <xbt/dynar.h>
20
21 #include "mc_forward.h"
22 #include "mc_location.h"
23 #include "mc_process.h"
24 #include "../smpi/private.h"
25
26 SG_BEGIN_DECL();
27
28 // ***** Type
29
30 typedef int e_dw_type_type;
31
32 struct s_dw_type {
33   s_dw_type();
34   ~s_dw_type();
35
36   e_dw_type_type type = 0;
37   Dwarf_Off id = 0; /* Offset in the section (in hexadecimal form) */
38   char *name = nullptr; /* Name of the type */
39   int byte_size = 0; /* Size in bytes */
40   int element_count = 0; /* Number of elements for array type */
41   char *dw_type_id = nullptr; /* DW_AT_type id */
42   xbt_dynar_t members = nullptr; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
43   int is_pointer_type = 0;
44
45   // Location (for members) is either of:
46   struct s_mc_expression location = { 0, 0, 0, 0 };
47   int offset = 0;
48
49   dw_type_t subtype = nullptr; // DW_AT_type
50   dw_type_t full_type = nullptr; // The same (but more complete) type
51 };
52
53 XBT_INTERNAL void dw_variable_free(dw_variable_t v);
54 XBT_INTERNAL void dw_variable_free_voidp(void *t);
55
56 // ***** Object info
57
58 /** Bit field of options */
59 typedef int mc_object_info_flags;
60 #define MC_OBJECT_INFO_NONE 0
61 #define MC_OBJECT_INFO_EXECUTABLE 1
62
63 struct s_mc_object_info {
64   s_mc_object_info();
65   ~s_mc_object_info();
66   s_mc_object_info(s_mc_object_info const&) = delete;
67   s_mc_object_info& operator=(s_mc_object_info const&) = delete;
68
69   mc_object_info_flags flags = 0;
70   char* file_name = nullptr;
71   const void* start = nullptr;
72   const void *end = nullptr;
73   char *start_exec = nullptr;
74   char *end_exec = nullptr; // Executable segment
75   char *start_rw = nullptr;
76   char *end_rw = nullptr; // Read-write segment
77   char *start_ro = nullptr;
78   char *end_ro = nullptr; // read-only segment
79   xbt_dict_t subprograms = nullptr; // xbt_dict_t<origin as hexadecimal string, dw_frame_t>
80   xbt_dynar_t global_variables = nullptr; // xbt_dynar_t<dw_variable_t>
81   xbt_dict_t types = nullptr; // xbt_dict_t<origin as hexadecimal string, dw_type_t>
82   xbt_dict_t full_types_by_name = nullptr; // xbt_dict_t<name, dw_type_t> (full defined type only)
83
84   // Here we sort the minimal information for an efficient (and cache-efficient)
85   // lookup of a function given an instruction pointer.
86   // The entries are sorted by low_pc and a binary search can be used to look them up.
87   xbt_dynar_t functions_index = nullptr;
88 };
89
90 static inline __attribute__ ((always_inline))
91 bool MC_object_info_executable(mc_object_info_t info)
92 {
93   return info->flags & MC_OBJECT_INFO_EXECUTABLE;
94 }
95
96 static inline __attribute__ ((always_inline))
97 bool MC_object_info_is_privatized(mc_object_info_t info)
98 {
99   return info && MC_object_info_executable(info) && smpi_privatize_global_variables;
100 }
101
102 /** Find the DWARF offset for this ELF object
103  *
104  *  An offset is applied to address found in DWARF:
105  *
106  *  <ul>
107  *    <li>for an executable obejct, addresses are virtual address
108  *        (there is no offset) i.e. \f$\text{virtual address} = \{dwarf address}\f$;</li>
109  *    <li>for a shared object, the addreses are offset from the begining
110  *        of the shared object (the base address of the mapped shared
111  *        object must be used as offset
112  *        i.e. \f$\text{virtual address} = \text{shared object base address}
113  *             + \text{dwarf address}\f$.</li>
114  *
115  */
116 XBT_INTERNAL void* MC_object_base_address(mc_object_info_t info);
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_free_object_info(mc_object_info_t* p);
121
122 XBT_INTERNAL dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, const void *ip);
123 MC_SHOULD_BE_INTERNAL dw_variable_t MC_file_object_info_find_variable_by_name(mc_object_info_t info, const char* name);
124
125 XBT_INTERNAL void MC_post_process_object_info(mc_process_t process, mc_object_info_t info);
126
127 XBT_INTERNAL void MC_dwarf_get_variables(mc_object_info_t info);
128 XBT_INTERNAL void MC_dwarf_get_variables_libdw(mc_object_info_t info);
129 XBT_INTERNAL const char* MC_dwarf_attrname(int attr);
130 XBT_INTERNAL const char* MC_dwarf_tagname(int tag);
131
132 // Not used:
133 XBT_INTERNAL char* get_type_description(mc_object_info_t info, char *type_name);
134
135 XBT_INTERNAL void* mc_member_resolve(const void* base, dw_type_t type, dw_type_t member, mc_address_space_t snapshot, int process_index);
136
137 struct s_dw_variable{
138   Dwarf_Off dwarf_offset; /* Global offset of the field. */
139   int global;
140   char *name;
141   char *type_origin;
142   dw_type_t type;
143
144   // Use either of:
145   s_mc_location_list_t locations;
146   void* address;
147
148   size_t start_scope;
149   mc_object_info_t object_info;
150
151 };
152
153 struct s_dw_frame{
154   int tag;
155   char *name;
156   void *low_pc;
157   void *high_pc;
158   s_mc_location_list_t frame_base;
159   xbt_dynar_t /* <dw_variable_t> */ variables; /* Cannot use dict, there may be several variables with the same name (in different lexical blocks)*/
160   unsigned long int id; /* DWARF offset of the subprogram */
161   xbt_dynar_t /* <dw_frame_t> */ scopes;
162   Dwarf_Off abstract_origin_id;
163   mc_object_info_t object_info;
164 };
165
166 struct s_mc_function_index_item {
167   void* low_pc, *high_pc;
168   dw_frame_t function;
169 };
170
171 XBT_INTERNAL void mc_frame_free(dw_frame_t freme);
172
173 SG_END_DECL()
174
175 #endif