Logo AND Algorithmique Numérique Distribuée

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