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
16 #include <simgrid_config.h>
18 #include <xbt/dynar.h>
20 #include "mc_forward.h"
21 #include "mc_location.h"
22 #include "mc_process.h"
28 typedef int e_dw_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*/
40 // Location (for members) is either of:
41 struct s_mc_expression location;
44 dw_type_t subtype; // DW_AT_type
45 dw_type_t full_type; // The same (but more complete) type
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);
54 enum mc_object_info_flags {
55 MC_OBJECT_INFO_NONE = 0,
56 MC_OBJECT_INFO_EXECUTABLE = 1
59 struct s_mc_object_info {
60 enum mc_object_info_flags flags;
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)
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;
76 static inline __attribute__ ((always_inline))
77 bool MC_object_info_executable(mc_object_info_t info)
79 return info->flags & MC_OBJECT_INFO_EXECUTABLE;
82 /** Find the DWARF offset for this ELF object
84 * An offset is applied to address found in DWARF:
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>
96 void* MC_object_base_address(mc_object_info_t info);
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);
102 dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, void *ip);
104 void MC_post_process_object_info(mc_process_t process, mc_object_info_t info);
106 void MC_dwarf_get_variables(mc_object_info_t info);
107 void MC_dwarf_get_variables_libdw(mc_object_info_t info);
108 const char* MC_dwarf_attrname(int attr);
109 const char* MC_dwarf_tagname(int tag);
112 char* get_type_description(mc_object_info_t info, char *type_name);
114 void* mc_member_resolve(const void* base, dw_type_t type, dw_type_t member, mc_snapshot_t snapshot, int process_index);
116 struct s_dw_variable{
117 Dwarf_Off dwarf_offset; /* Global offset of the field. */
124 s_mc_location_list_t locations;
128 mc_object_info_t object_info;
137 s_mc_location_list_t frame_base;
138 xbt_dynar_t /* <dw_variable_t> */ variables; /* Cannot use dict, there may be several variables with the same name (in different lexical blocks)*/
139 unsigned long int id; /* DWARF offset of the subprogram */
140 xbt_dynar_t /* <dw_frame_t> */ scopes;
141 Dwarf_Off abstract_origin_id;
142 mc_object_info_t object_info;
145 struct s_mc_function_index_item {
146 void* low_pc, *high_pc;
150 void mc_frame_free(dw_frame_t freme);