Logo AND Algorithmique Numérique Distribuée

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