From 3f5a22ee597719eb48bef0979b0628f7b76bfbe9 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 21 Jul 2015 09:54:38 +0200 Subject: [PATCH] [mc] Make ObjectInformation::file_names a std::string --- src/mc/mc_checkpoint.cpp | 7 ++++--- src/mc/mc_compare.cpp | 10 +++++----- src/mc/mc_dwarf.cpp | 15 +++++++-------- src/mc/mc_object_info.cpp | 2 -- src/mc/mc_object_info.h | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/mc/mc_checkpoint.cpp b/src/mc/mc_checkpoint.cpp index 98f3ec78c4..74c26ea9fd 100644 --- a/src/mc/mc_checkpoint.cpp +++ b/src/mc/mc_checkpoint.cpp @@ -196,9 +196,11 @@ static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot) * * `dl_iterate_phdr` would be more robust but would not work in cross-process. * */ -void MC_find_object_address(std::vector const& maps, mc_object_info_t result) +void MC_find_object_address( + std::vector const& maps, mc_object_info_t result) { - const char *name = basename(result->file_name); + const char* file_name = xbt_strdup(result->file_name.c_str()); + const char *name = basename(file_name); for (size_t i = 0; i < maps.size(); ++i) { simgrid::mc::VmMap const& reg = maps[i]; if (maps[i].pathname.empty() @@ -243,7 +245,6 @@ void MC_find_object_address(std::vector const& maps, mc_obje if (result->end_exec && (const void*) result->end_exec > result->end) result->end = result->end_exec; - xbt_assert(result->file_name); xbt_assert(result->start_rw); xbt_assert(result->start_exec); } diff --git a/src/mc/mc_compare.cpp b/src/mc/mc_compare.cpp index abeb22dc37..0663ab8a3b 100644 --- a/src/mc/mc_compare.cpp +++ b/src/mc/mc_compare.cpp @@ -584,7 +584,7 @@ int snapshot_compare(void *state1, void *state2) xbt_assert(region1->object_info() == region2->object_info()); xbt_assert(region1->object_info()); - const char* name = region1->object_info()->file_name; + std::string const& name = region1->object_info()->file_name; #ifdef MC_DEBUG if (is_diff == 0) @@ -604,13 +604,13 @@ int snapshot_compare(void *state1, void *state2) xbt_os_walltimer_stop(timer); mc_comp_times->global_variables_comparison_time += xbt_os_timer_elapsed(timer); - XBT_DEBUG("(%d - %d) Different global variables in %s", num1, num2, - name); + XBT_DEBUG("(%d - %d) Different global variables in %s", + num1, num2, name.c_str()); errors++; #else #ifdef MC_VERBOSE - XBT_VERB("(%d - %d) Different global variables in %s", num1, num2, - name); + XBT_VERB("(%d - %d) Different global variables in %s", + num1, num2, name.c_str()); #endif reset_heap_information(); diff --git a/src/mc/mc_dwarf.cpp b/src/mc/mc_dwarf.cpp index 2c107799a6..a1ae2d8ee4 100644 --- a/src/mc/mc_dwarf.cpp +++ b/src/mc/mc_dwarf.cpp @@ -973,14 +973,13 @@ static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die * die, */ void MC_dwarf_get_variables(mc_object_info_t info) { - int fd = open(info->file_name, O_RDONLY); - if (fd < 0) { - xbt_die("Could not open file %s", info->file_name); - } + int fd = open(info->file_name.c_str(), O_RDONLY); + if (fd < 0) + xbt_die("Could not open file %s", info->file_name.c_str()); Dwarf *dwarf = dwarf_begin(fd, DWARF_C_READ); - if (dwarf == NULL) { - xbt_die("Your program must be compiled with -g (%s)", info->file_name); - } + if (dwarf == NULL) + xbt_die("Your program must be compiled with -g (%s)", + info->file_name.c_str()); // For each compilation unit: Dwarf_Off offset = 0; Dwarf_Off next_offset = 0; @@ -1135,7 +1134,7 @@ std::shared_ptr MC_find_object_info( std::make_shared(); if (executable) result->flags |= MC_OBJECT_INFO_EXECUTABLE; - result->file_name = xbt_strdup(name); + result->file_name = name; MC_find_object_address(maps, result.get()); MC_dwarf_get_variables(result.get()); MC_post_process_types(result.get()); diff --git a/src/mc/mc_object_info.cpp b/src/mc/mc_object_info.cpp index 6edd005ccc..f982306806 100644 --- a/src/mc/mc_object_info.cpp +++ b/src/mc/mc_object_info.cpp @@ -70,7 +70,6 @@ Frame::Frame() ObjectInformation::ObjectInformation() { this->flags = 0; - this->file_name = nullptr; this->start = nullptr; this->end = nullptr; this->start_exec = nullptr; @@ -84,7 +83,6 @@ ObjectInformation::ObjectInformation() ObjectInformation::~ObjectInformation() { - xbt_free(this->file_name); xbt_dynar_free(&this->functions_index); } diff --git a/src/mc/mc_object_info.h b/src/mc/mc_object_info.h index 019e5e7eab..b195d47750 100644 --- a/src/mc/mc_object_info.h +++ b/src/mc/mc_object_info.h @@ -140,7 +140,7 @@ public: ObjectInformation& operator=(ObjectInformation const&) = delete; mc_object_info_flags flags; - char* file_name; + std::string file_name; const void* start; const void *end; char *start_exec; -- 2.20.1