X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7bf4da31d5d3b1940d0166da655136ccf6af8148..09abefeb928cd7ea4679407a6b4387d4f75beaa9:/src/mc/inspect/mc_dwarf.cpp diff --git a/src/mc/inspect/mc_dwarf.cpp b/src/mc/inspect/mc_dwarf.cpp index a6d44f9254..a11a069d7a 100644 --- a/src/mc/inspect/mc_dwarf.cpp +++ b/src/mc/inspect/mc_dwarf.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2008-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2008-2021. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -13,18 +13,22 @@ #include "src/mc/inspect/Variable.hpp" #include "src/mc/inspect/mc_dwarf.hpp" #include "src/mc/mc_private.hpp" -#include "src/mc/remote/RemoteSimulation.hpp" +#include "src/mc/remote/RemoteProcess.hpp" +#include +#include #include #include #include #include #include +#include #include #include #include +#include #include @@ -122,52 +126,32 @@ enum class FormClass { static TagClass classify_tag(int tag) { - switch (tag) { - case DW_TAG_array_type: - case DW_TAG_class_type: - case DW_TAG_enumeration_type: - case DW_TAG_typedef: - case DW_TAG_pointer_type: - case DW_TAG_reference_type: - case DW_TAG_rvalue_reference_type: - case DW_TAG_string_type: - case DW_TAG_structure_type: - case DW_TAG_subroutine_type: - case DW_TAG_union_type: - case DW_TAG_ptr_to_member_type: - case DW_TAG_set_type: - case DW_TAG_subrange_type: - case DW_TAG_base_type: - case DW_TAG_const_type: - case DW_TAG_file_type: - case DW_TAG_packed_type: - case DW_TAG_volatile_type: - case DW_TAG_restrict_type: - case DW_TAG_interface_type: - case DW_TAG_unspecified_type: - case DW_TAG_shared_type: - return TagClass::Type; - - case DW_TAG_subprogram: - return TagClass::Subprogram; - - case DW_TAG_variable: - case DW_TAG_formal_parameter: - return TagClass::Variable; - - case DW_TAG_lexical_block: - case DW_TAG_try_block: - case DW_TAG_catch_block: - case DW_TAG_inlined_subroutine: - case DW_TAG_with_stmt: - return TagClass::Scope; - - case DW_TAG_namespace: - return TagClass::Namespace; - - default: - return TagClass::Unknown; - } + static const std::unordered_map map = { + {DW_TAG_array_type, TagClass::Type}, {DW_TAG_class_type, TagClass::Type}, + {DW_TAG_enumeration_type, TagClass::Type}, {DW_TAG_typedef, TagClass::Type}, + {DW_TAG_pointer_type, TagClass::Type}, {DW_TAG_reference_type, TagClass::Type}, + {DW_TAG_rvalue_reference_type, TagClass::Type}, {DW_TAG_string_type, TagClass::Type}, + {DW_TAG_structure_type, TagClass::Type}, {DW_TAG_subroutine_type, TagClass::Type}, + {DW_TAG_union_type, TagClass::Type}, {DW_TAG_ptr_to_member_type, TagClass::Type}, + {DW_TAG_set_type, TagClass::Type}, {DW_TAG_subrange_type, TagClass::Type}, + {DW_TAG_base_type, TagClass::Type}, {DW_TAG_const_type, TagClass::Type}, + {DW_TAG_file_type, TagClass::Type}, {DW_TAG_packed_type, TagClass::Type}, + {DW_TAG_volatile_type, TagClass::Type}, {DW_TAG_restrict_type, TagClass::Type}, + {DW_TAG_interface_type, TagClass::Type}, {DW_TAG_unspecified_type, TagClass::Type}, + {DW_TAG_shared_type, TagClass::Type}, + + {DW_TAG_subprogram, TagClass::Subprogram}, + + {DW_TAG_variable, TagClass::Variable}, {DW_TAG_formal_parameter, TagClass::Variable}, + + {DW_TAG_lexical_block, TagClass::Scope}, {DW_TAG_try_block, TagClass::Scope}, + {DW_TAG_catch_block, TagClass::Scope}, {DW_TAG_inlined_subroutine, TagClass::Scope}, + {DW_TAG_with_stmt, TagClass::Scope}, + + {DW_TAG_namespace, TagClass::Namespace}}; + + auto res = map.find(tag); + return res != map.end() ? res->second : TagClass::Unknown; } /** @brief Find the DWARF data class for a given DWARF data form @@ -179,41 +163,35 @@ static TagClass classify_tag(int tag) * */ static FormClass classify_form(int form) { - switch (form) { - case DW_FORM_addr: - return FormClass::Address; - case DW_FORM_block2: - case DW_FORM_block4: - case DW_FORM_block: - case DW_FORM_block1: - return FormClass::Block; - case DW_FORM_data1: - case DW_FORM_data2: - case DW_FORM_data4: - case DW_FORM_data8: - case DW_FORM_udata: - case DW_FORM_sdata: - return FormClass::Constant; - case DW_FORM_string: - case DW_FORM_strp: - return FormClass::String; - case DW_FORM_ref_addr: - case DW_FORM_ref1: - case DW_FORM_ref2: - case DW_FORM_ref4: - case DW_FORM_ref8: - case DW_FORM_ref_udata: - return FormClass::Reference; - case DW_FORM_flag: - case DW_FORM_flag_present: - return FormClass::Flag; - case DW_FORM_exprloc: - return FormClass::ExprLoc; + static const std::unordered_map map = { + {DW_FORM_addr, FormClass::Address}, + + {DW_FORM_block2, FormClass::Block}, {DW_FORM_block4, FormClass::Block}, + {DW_FORM_block, FormClass::Block}, {DW_FORM_block1, FormClass::Block}, + + {DW_FORM_data1, FormClass::Constant}, {DW_FORM_data2, FormClass::Constant}, + {DW_FORM_data4, FormClass::Constant}, {DW_FORM_data8, FormClass::Constant}, + {DW_FORM_udata, FormClass::Constant}, {DW_FORM_sdata, FormClass::Constant}, +#if _ELFUTILS_PREREQ(0, 171) + {DW_FORM_implicit_const, FormClass::Constant}, +#endif + + {DW_FORM_string, FormClass::String}, {DW_FORM_strp, FormClass::String}, + + {DW_FORM_ref_addr, FormClass::Reference}, {DW_FORM_ref1, FormClass::Reference}, + {DW_FORM_ref2, FormClass::Reference}, {DW_FORM_ref4, FormClass::Reference}, + {DW_FORM_ref8, FormClass::Reference}, {DW_FORM_ref_udata, FormClass::Reference}, + + {DW_FORM_flag, FormClass::Flag}, {DW_FORM_flag_present, FormClass::Flag}, + + {DW_FORM_exprloc, FormClass::ExprLoc} + // TODO sec offset // TODO indirect - default: - return FormClass::Unknown; - } + }; + + auto res = map.find(form); + return res != map.end() ? res->second : FormClass::Unknown; } /** @brief Get the name of the tag of a given DIE @@ -302,7 +280,7 @@ static uint64_t MC_dwarf_attr_integrate_uint(Dwarf_Die* die, int attribute, uint static bool MC_dwarf_attr_flag(Dwarf_Die* die, int attribute, bool integrate) { Dwarf_Attribute attr; - if ((integrate ? dwarf_attr_integrate(die, attribute, &attr) : dwarf_attr(die, attribute, &attr)) == 0) + if ((integrate ? dwarf_attr_integrate(die, attribute, &attr) : dwarf_attr(die, attribute, &attr)) == nullptr) return false; bool result; @@ -321,33 +299,19 @@ static bool MC_dwarf_attr_flag(Dwarf_Die* die, int attribute, bool integrate) * */ static uint64_t MC_dwarf_default_lower_bound(int lang) { - switch (lang) { - case DW_LANG_C: - case DW_LANG_C89: - case DW_LANG_C99: - case DW_LANG_C_plus_plus: - case DW_LANG_D: - case DW_LANG_Java: - case DW_LANG_ObjC: - case DW_LANG_ObjC_plus_plus: - case DW_LANG_Python: - case DW_LANG_UPC: - return 0; - case DW_LANG_Ada83: - case DW_LANG_Ada95: - case DW_LANG_Fortran77: - case DW_LANG_Fortran90: - case DW_LANG_Fortran95: - case DW_LANG_Modula2: - case DW_LANG_Pascal83: - case DW_LANG_PL1: - case DW_LANG_Cobol74: - case DW_LANG_Cobol85: - return 1; - default: - xbt_die("No default DW_TAG_lower_bound for language %i and none given", lang); - return 0; - } + const std::unordered_map map = { + {DW_LANG_C, 0}, {DW_LANG_C89, 0}, {DW_LANG_C99, 0}, {DW_LANG_C11, 0}, + {DW_LANG_C_plus_plus, 0}, {DW_LANG_C_plus_plus_11, 0}, {DW_LANG_C_plus_plus_14, 0}, {DW_LANG_D, 0}, + {DW_LANG_Java, 0}, {DW_LANG_ObjC, 0}, {DW_LANG_ObjC_plus_plus, 0}, {DW_LANG_Python, 0}, + {DW_LANG_UPC, 0}, + + {DW_LANG_Ada83, 1}, {DW_LANG_Ada95, 1}, {DW_LANG_Fortran77, 1}, {DW_LANG_Fortran90, 1}, + {DW_LANG_Fortran95, 1}, {DW_LANG_Fortran03, 1}, {DW_LANG_Fortran08, 1}, {DW_LANG_Modula2, 1}, + {DW_LANG_Pascal83, 1}, {DW_LANG_PL1, 1}, {DW_LANG_Cobol74, 1}, {DW_LANG_Cobol85, 1}}; + + auto res = map.find(lang); + xbt_assert(res != map.end(), "No default DW_TAG_lower_bound for language %i and none given", lang); + return res->second; } /** @brief Finds the number of elements in a DW_TAG_subrange_type or DW_TAG_enumeration_type DIE @@ -380,7 +344,7 @@ static uint64_t MC_dwarf_subrange_element_count(Dwarf_Die* die, Dwarf_Die* unit) return upper_bound - lower_bound + 1; } -/** @brief Finds the number of elements in a array type (DW_TAG_array_type) +/** @brief Finds the number of elements in an array type (DW_TAG_array_type) * * The compilation unit might be needed because the default lower * bound depends on the language of the compilation unit. @@ -639,8 +603,6 @@ static void MC_dwarf_handle_type_die(simgrid::mc::ObjectInformation* info, Dwarf info->full_types_by_name[t.name] = &t; } -static int mc_anonymous_variable_index = 0; - static std::unique_ptr MC_die_to_variable(simgrid::mc::ObjectInformation* info, Dwarf_Die* die, const Dwarf_Die* /*unit*/, const simgrid::mc::Frame* frame, const char* ns) @@ -730,6 +692,7 @@ static std::unique_ptr MC_die_to_variable(simgrid::mc::Ob // The current code needs a variable name, // generate a fake one: + static int mc_anonymous_variable_index = 0; if (variable->name.empty()) { variable->name = "@anonymous#" + std::to_string(mc_anonymous_variable_index); mc_anonymous_variable_index++; @@ -961,11 +924,11 @@ static std::vector get_build_id(Elf* elf) return std::vector(); } -static char hexdigits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; - /** Binary data to hexadecimal */ static inline std::array to_hex(std::uint8_t byte) { + constexpr std::array hexdigits{ + {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}}; // Horrid double braces! // Apparently, this is needed in C++11 (not in C++14). return {{hexdigits[byte >> 4], hexdigits[byte & 0xF]}}; @@ -976,11 +939,8 @@ static std::string to_hex(const char* data, std::size_t count) { std::string res; res.resize(2 * count); - for (std::size_t i = 0; i < count; i++) { - std::array hex_byte = to_hex(data[i]); - for (int j = 0; j < 2; ++j) - res[2 * i + j] = hex_byte[j]; - } + for (std::size_t i = 0; i < count; i++) + std::copy_n(cbegin(to_hex(data[i])), 2, &res[2 * i]); return res; } @@ -991,7 +951,7 @@ static std::string to_hex(std::vector const& data) } /** Base directories for external debug files */ -static const char* debug_paths[] = { +static constexpr auto debug_paths = { "/usr/lib/debug/", "/usr/local/lib/debug/", }; @@ -1017,7 +977,7 @@ static std::string find_by_build_id(std::vector id) return filename; } } - XBT_DEBUG("Not debuf info found for build ID %s\n", hex.data()); + XBT_DEBUG("No debug info found for build ID %s\n", hex.data()); return std::string(); } @@ -1204,7 +1164,7 @@ std::shared_ptr createObjectInformation(std::vectortypes) { Type* type = &(t.second); @@ -1250,58 +1210,14 @@ int dwarf_register_to_libunwind(int dwarf_register) #elif defined(__i386__) // Couldn't find the authoritative source of information for this. // This is inspired from http://source.winehq.org/source/dlls/dbghelp/cpu_i386.c#L517. - switch (dwarf_register) { - case 0: - return UNW_X86_EAX; - case 1: - return UNW_X86_ECX; - case 2: - return UNW_X86_EDX; - case 3: - return UNW_X86_EBX; - case 4: - return UNW_X86_ESP; - case 5: - return UNW_X86_EBP; - case 6: - return UNW_X86_ESI; - case 7: - return UNW_X86_EDI; - case 8: - return UNW_X86_EIP; - case 9: - return UNW_X86_EFLAGS; - case 10: - return UNW_X86_CS; - case 11: - return UNW_X86_SS; - case 12: - return UNW_X86_DS; - case 13: - return UNW_X86_ES; - case 14: - return UNW_X86_FS; - case 15: - return UNW_X86_GS; - case 16: - return UNW_X86_ST0; - case 17: - return UNW_X86_ST1; - case 18: - return UNW_X86_ST2; - case 19: - return UNW_X86_ST3; - case 20: - return UNW_X86_ST4; - case 21: - return UNW_X86_ST5; - case 22: - return UNW_X86_ST6; - case 23: - return UNW_X86_ST7; - default: - xbt_die("Bad/unknown register number."); - } + constexpr std::array regs{ + {/* 0 */ UNW_X86_EAX, /* 1 */ UNW_X86_ECX, /* 2 */ UNW_X86_EDX, /* 3 */ UNW_X86_EBX, + /* 4 */ UNW_X86_ESP, /* 5 */ UNW_X86_EBP, /* 6 */ UNW_X86_ESI, /* 7 */ UNW_X86_EDI, + /* 8 */ UNW_X86_EIP, /* 9 */ UNW_X86_EFLAGS, /* 10 */ UNW_X86_CS, /* 11 */ UNW_X86_SS, + /* 12 */ UNW_X86_DS, /* 13 */ UNW_X86_ES, /* 14 */ UNW_X86_FS, /* 15 */ UNW_X86_GS, + /* 16 */ UNW_X86_ST0, /* 17 */ UNW_X86_ST1, /* 18 */ UNW_X86_ST2, /* 19 */ UNW_X86_ST3, + /* 20 */ UNW_X86_ST4, /* 21 */ UNW_X86_ST5, /* 22 */ UNW_X86_ST6, /* 23 */ UNW_X86_ST7}}; + return regs.at(dwarf_register); #else #error This architecture is not supported yet for DWARF expression evaluation. #endif