Logo AND Algorithmique Numérique Distribuée

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