1 /* Copyright (c) 2007-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
8 * Debug information for the MC.
11 #ifndef MC_OBJECT_INFO_H
12 #define MC_OBJECT_INFO_H
17 #include <simgrid_config.h>
19 #include <xbt/dynar.h>
21 #include "mc_forward.h"
22 #include "mc_location.h"
23 #include "mc_process.h"
24 #include "../smpi/private.h"
30 typedef int e_dw_type_type;
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;
45 // Location (for members) is either of:
46 struct s_mc_expression location = { 0, 0, 0, 0 };
49 dw_type_t subtype = nullptr; // DW_AT_type
50 dw_type_t full_type = nullptr; // The same (but more complete) type
53 XBT_INTERNAL void dw_variable_free(dw_variable_t v);
54 XBT_INTERNAL void dw_variable_free_voidp(void *t);
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
63 struct 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;
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)
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;
90 static inline __attribute__ ((always_inline))
91 bool MC_object_info_executable(mc_object_info_t info)
93 return info->flags & MC_OBJECT_INFO_EXECUTABLE;
96 static inline __attribute__ ((always_inline))
97 bool MC_object_info_is_privatized(mc_object_info_t info)
99 return info && MC_object_info_executable(info) && smpi_privatize_global_variables;
102 /** Find the DWARF offset for this ELF object
104 * An offset is applied to address found in DWARF:
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>
116 XBT_INTERNAL void* MC_object_base_address(mc_object_info_t info);
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);
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);
125 XBT_INTERNAL void MC_post_process_object_info(mc_process_t process, mc_object_info_t info);
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);
133 XBT_INTERNAL char* get_type_description(mc_object_info_t info, char *type_name);
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);
137 struct s_dw_variable{
138 Dwarf_Off dwarf_offset; /* Global offset of the field. */
145 s_mc_location_list_t locations;
149 mc_object_info_t object_info;
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;
166 struct s_mc_function_index_item {
167 void* low_pc, *high_pc;
171 XBT_INTERNAL void mc_frame_free(dw_frame_t freme);