1 /* Copyright (c) 2008-2015. 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. */
7 #if !defined(SIMGRID_MC_DWARF_HPP)
8 #define SIMGRID_MC_DWARF_HPP
14 #include <xbt/sysdep.h>
16 #define DW_LANG_Objc DW_LANG_ObjC /* fix spelling error in older dwarf.h */
19 #include "mc/Variable.hpp"
20 #include "mc/mc_memory_map.h"
22 /** \brief A class of DWARF tags (DW_TAG_*)
24 typedef enum mc_tag_class {
33 static mc_tag_class MC_dwarf_tag_classify(int tag)
37 case DW_TAG_array_type:
38 case DW_TAG_class_type:
39 case DW_TAG_enumeration_type:
41 case DW_TAG_pointer_type:
42 case DW_TAG_reference_type:
43 case DW_TAG_rvalue_reference_type:
44 case DW_TAG_string_type:
45 case DW_TAG_structure_type:
46 case DW_TAG_subroutine_type:
47 case DW_TAG_union_type:
48 case DW_TAG_ptr_to_member_type:
50 case DW_TAG_subrange_type:
51 case DW_TAG_base_type:
52 case DW_TAG_const_type:
53 case DW_TAG_file_type:
54 case DW_TAG_packed_type:
55 case DW_TAG_volatile_type:
56 case DW_TAG_restrict_type:
57 case DW_TAG_interface_type:
58 case DW_TAG_unspecified_type:
59 case DW_TAG_shared_type:
62 case DW_TAG_subprogram:
63 return mc_tag_subprogram;
66 case DW_TAG_formal_parameter:
67 return mc_tag_variable;
69 case DW_TAG_lexical_block:
70 case DW_TAG_try_block:
71 case DW_TAG_catch_block:
72 case DW_TAG_inlined_subroutine:
73 case DW_TAG_with_stmt:
76 case DW_TAG_namespace:
77 return mc_tag_namespace;
80 return mc_tag_unknown;
85 #define MC_DW_CLASS_UNKNOWN 0
86 #define MC_DW_CLASS_ADDRESS 1 // Location in the address space of the program
87 #define MC_DW_CLASS_BLOCK 2 // Arbitrary block of bytes
88 #define MC_DW_CLASS_CONSTANT 3
89 #define MC_DW_CLASS_STRING 3 // String
90 #define MC_DW_CLASS_FLAG 4 // Boolean
91 #define MC_DW_CLASS_REFERENCE 5 // Reference to another DIE
92 #define MC_DW_CLASS_EXPRLOC 6 // DWARF expression/location description
93 #define MC_DW_CLASS_LINEPTR 7
94 #define MC_DW_CLASS_LOCLISTPTR 8
95 #define MC_DW_CLASS_MACPTR 9
96 #define MC_DW_CLASS_RANGELISTPTR 10
98 /** \brief Find the DWARF data class for a given DWARF data form
100 * This mapping is defined in the DWARF spec.
102 * \param form The form (values taken from the DWARF spec)
103 * \return An internal representation for the corresponding class
105 static int MC_dwarf_form_get_class(int form)
109 return MC_DW_CLASS_ADDRESS;
114 return MC_DW_CLASS_BLOCK;
121 return MC_DW_CLASS_CONSTANT;
124 return MC_DW_CLASS_STRING;
125 case DW_FORM_ref_addr:
130 case DW_FORM_ref_udata:
131 return MC_DW_CLASS_REFERENCE;
133 case DW_FORM_flag_present:
134 return MC_DW_CLASS_FLAG;
135 case DW_FORM_exprloc:
136 return MC_DW_CLASS_EXPRLOC;
140 return MC_DW_CLASS_UNKNOWN;
144 /** \brief Find the default lower bound for a given language
146 * The default lower bound of an array (when DW_TAG_lower_bound
147 * is missing) depends on the language of the compilation unit.
149 * \param lang Language of the compilation unit (values defined in the DWARF spec)
150 * \return Default lower bound of an array in this compilation unit
153 uint64_t MC_dwarf_default_lower_bound(int lang)
159 case DW_LANG_C_plus_plus:
163 case DW_LANG_ObjC_plus_plus:
169 case DW_LANG_Fortran77:
170 case DW_LANG_Fortran90:
171 case DW_LANG_Fortran95:
172 case DW_LANG_Modula2:
173 case DW_LANG_Pascal83:
175 case DW_LANG_Cobol74:
176 case DW_LANG_Cobol85:
179 xbt_die("No default DW_TAG_lower_bound for language %i and none given",
185 /** Sort the variable by name and address.
187 * We could use boost::container::flat_set instead.
190 bool MC_compare_variable(
191 simgrid::mc::Variable const& a, simgrid::mc::Variable const& b)
193 int cmp = a.name.compare(b.name);
199 return a.address < b.address;
202 XBT_PRIVATE std::shared_ptr<simgrid::mc::ObjectInformation> MC_find_object_info(
203 std::vector<simgrid::mc::VmMap> const& maps, const char* name, int executable);
204 XBT_PRIVATE void MC_post_process_object_info(simgrid::mc::Process* process, simgrid::mc::ObjectInformation* info);
206 XBT_PRIVATE void MC_dwarf_get_variables(simgrid::mc::ObjectInformation* info);
207 XBT_PRIVATE void MC_dwarf_get_variables_libdw(simgrid::mc::ObjectInformation* info);
209 XBT_PRIVATE const char* MC_dwarf_attrname(int attr);
210 XBT_PRIVATE const char* MC_dwarf_tagname(int tag);
212 XBT_PRIVATE void* mc_member_resolve(
213 const void* base, simgrid::mc::Type* type, simgrid::mc::Type* member,
214 simgrid::mc::AddressSpace* snapshot, int process_index);