Logo AND Algorithmique Numérique Distribuée

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