From: Gabriel Corona Date: Mon, 20 Jul 2015 14:38:36 +0000 (+0200) Subject: [mc] Make Process::subprograms a std::unordered_map X-Git-Tag: v3_12~438^2~28 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1d2b3b745feba3c5069fe4fdab54a1832fde11e6?hp=0f86d3285f605e43ba3f845eb2f5ee2502b2aed4 [mc] Make Process::subprograms a std::unordered_map --- diff --git a/src/mc/mc_dwarf.cpp b/src/mc/mc_dwarf.cpp index fb1303108c..2c107799a6 100644 --- a/src/mc/mc_dwarf.cpp +++ b/src/mc/mc_dwarf.cpp @@ -899,13 +899,9 @@ static void MC_dwarf_handle_scope_die(mc_object_info_t info, Dwarf_Die * die, MC_dwarf_handle_children(info, die, unit, &frame, ns); // Register it: - if (klass == mc_tag_subprogram) { - char *key = bprintf("%" PRIx64, (uint64_t) frame.id); - - xbt_dict_set(info->subprograms, key, - new simgrid::mc::Frame(std::move(frame)), NULL); - xbt_free(key); - } else if (klass == mc_tag_scope) + if (klass == mc_tag_subprogram) + info->subprograms[frame.id] = frame; + else if (klass == mc_tag_scope) parent_frame->scopes.push_back(std::move(frame)); } @@ -1027,17 +1023,13 @@ static void MC_make_functions_index(mc_object_info_t info) { xbt_dynar_t index = xbt_dynar_new(sizeof(s_mc_function_index_item_t), NULL); - // Populate the array: - mc_frame_t frame = NULL; - xbt_dict_cursor_t cursor; - char *key; - xbt_dict_foreach(info->subprograms, cursor, key, frame) { - if (frame->low_pc == NULL) + for (auto& e : info->subprograms) { + if (e.second.low_pc == nullptr) continue; s_mc_function_index_item_t entry; - entry.low_pc = frame->low_pc; - entry.high_pc = frame->high_pc; - entry.function = frame; + entry.low_pc = e.second.low_pc; + entry.high_pc = e.second.high_pc; + entry.function = &e.second; xbt_dynar_push(index, &entry); } @@ -1069,13 +1061,12 @@ static void mc_post_process_scope(mc_object_info_t info, mc_frame_t scope) { if (scope->tag == DW_TAG_inlined_subroutine) { - // Attach correct namespaced name in inlined subroutine: - char *key = bprintf("%" PRIx64, (uint64_t) scope->abstract_origin_id); - mc_frame_t abstract_origin = (mc_frame_t) xbt_dict_get_or_null(info->subprograms, key); - xbt_assert(abstract_origin, "Could not lookup abstract origin %s", key); - xbt_free(key); - scope->name = abstract_origin->name; + auto i = info->subprograms.find(scope->abstract_origin_id); + xbt_assert(i != info->subprograms.end(), + "Could not lookup abstract origin %" PRIx64, + (uint64_t) scope->abstract_origin_id); + scope->name = i->second.name; } // Direct: @@ -1096,12 +1087,8 @@ static void mc_post_process_scope(mc_object_info_t info, mc_frame_t scope) static void MC_post_process_functions(mc_object_info_t info) { - xbt_dict_cursor_t cursor; - char *key; - mc_frame_t subprogram = NULL; - xbt_dict_foreach(info->subprograms, cursor, key, subprogram) { - mc_post_process_scope(info, subprogram); - } + for (auto& entry : info->subprograms) + mc_post_process_scope(info, &entry.second); } diff --git a/src/mc/mc_object_info.cpp b/src/mc/mc_object_info.cpp index 7324681e74..6edd005ccc 100644 --- a/src/mc/mc_object_info.cpp +++ b/src/mc/mc_object_info.cpp @@ -79,14 +79,12 @@ ObjectInformation::ObjectInformation() this->end_rw = nullptr; this->start_ro = nullptr; this->end_ro = nullptr; - this->subprograms = xbt_dict_new_homogeneous(mc_frame_free); this->functions_index = nullptr; } ObjectInformation::~ObjectInformation() { xbt_free(this->file_name); - xbt_dict_free(&this->subprograms); xbt_dynar_free(&this->functions_index); } diff --git a/src/mc/mc_object_info.h b/src/mc/mc_object_info.h index bb0baad48c..019e5e7eab 100644 --- a/src/mc/mc_object_info.h +++ b/src/mc/mc_object_info.h @@ -97,6 +97,41 @@ typedef int mc_object_info_flags; namespace simgrid { namespace mc { +class Variable { +public: + Variable(); + + Dwarf_Off dwarf_offset; /* Global offset of the field. */ + int global; + std::string name; + std::uint64_t type_id; + mc_type_t type; + + // Use either of: + simgrid::mc::LocationList location_list; + void* address; + + size_t start_scope; + mc_object_info_t object_info; + +}; + +class Frame { +public: + Frame(); + + int tag; + std::string name; + void *low_pc; + void *high_pc; + simgrid::mc::LocationList frame_base; + std::vector variables; + unsigned long int id; /* DWARF offset of the subprogram */ + std::vector scopes; + Dwarf_Off abstract_origin_id; + mc_object_info_t object_info; +}; + class ObjectInformation { public: ObjectInformation(); @@ -114,7 +149,7 @@ public: char *end_rw; // Read-write segment char *start_ro; char *end_ro; // read-only segment - xbt_dict_t subprograms; // xbt_dict_t + std::unordered_map subprograms; // TODO, remove the mutable (to remove it we'll have to add a lot of const everywhere) mutable std::vector global_variables; std::unordered_map types; @@ -143,41 +178,6 @@ public: }; -class Variable { -public: - Variable(); - - Dwarf_Off dwarf_offset; /* Global offset of the field. */ - int global; - std::string name; - std::uint64_t type_id; - mc_type_t type; - - // Use either of: - simgrid::mc::LocationList location_list; - void* address; - - size_t start_scope; - mc_object_info_t object_info; - -}; - -class Frame { -public: - Frame(); - - int tag; - std::string name; - void *low_pc; - void *high_pc; - simgrid::mc::LocationList frame_base; - std::vector variables; - unsigned long int id; /* DWARF offset of the subprogram */ - std::vector scopes; - Dwarf_Off abstract_origin_id; - mc_object_info_t object_info; -}; - } } diff --git a/src/mc/mcer_ignore.cpp b/src/mc/mcer_ignore.cpp index bf75f7d2cb..4c752035be 100644 --- a/src/mc/mcer_ignore.cpp +++ b/src/mc/mcer_ignore.cpp @@ -161,12 +161,9 @@ static void MC_ignore_local_variable_in_object(const char *var_name, const char *subprogram_name, mc_object_info_t info) { - xbt_dict_cursor_t cursor2; - mc_frame_t frame; - char *key; - xbt_dict_foreach(info->subprograms, cursor2, key, frame) { - mc_ignore_local_variable_in_scope(var_name, subprogram_name, frame, frame); - } + for (auto& entry : info->subprograms) + mc_ignore_local_variable_in_scope( + var_name, subprogram_name, &entry.second, &entry.second); } /** \brief Ignore a local variable in a scope diff --git a/teshsuite/mc/dwarf/dwarf.cpp b/teshsuite/mc/dwarf/dwarf.cpp index b8fb469c9f..40f99bb9d7 100644 --- a/teshsuite/mc/dwarf/dwarf.cpp +++ b/teshsuite/mc/dwarf/dwarf.cpp @@ -32,12 +32,9 @@ static mc_type_t find_type_by_name(mc_object_info_t info, const char* name) static mc_frame_t find_function_by_name( mc_object_info_t info, const char* name) { - xbt_dict_cursor_t cursor = 0; - mc_frame_t subprogram; - char* key; - xbt_dict_foreach(info->subprograms, cursor, key, subprogram) - if(subprogram->name == name) - return subprogram; + for (auto& entry : info->subprograms) + if(entry.second.name == name) + return &entry.second; return nullptr; }