Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Make ObjectInformation::file_names a std::string
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jul 2015 07:54:38 +0000 (09:54 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jul 2015 12:18:31 +0000 (14:18 +0200)
src/mc/mc_checkpoint.cpp
src/mc/mc_compare.cpp
src/mc/mc_dwarf.cpp
src/mc/mc_object_info.cpp
src/mc/mc_object_info.h

index 98f3ec7..74c26ea 100644 (file)
@@ -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.
  * */
  *
  *  `dl_iterate_phdr` would be more robust but would not work in cross-process.
  * */
-void MC_find_object_address(std::vector<simgrid::mc::VmMap> const& maps, mc_object_info_t result)
+void MC_find_object_address(
+  std::vector<simgrid::mc::VmMap> 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()
   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<simgrid::mc::VmMap> const& maps, mc_obje
   if (result->end_exec && (const void*) result->end_exec > result->end)
     result->end = result->end_exec;
 
   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);
 }
   xbt_assert(result->start_rw);
   xbt_assert(result->start_exec);
 }
index abeb22d..0663ab8 100644 (file)
@@ -584,7 +584,7 @@ int snapshot_compare(void *state1, void *state2)
     xbt_assert(region1->object_info() == region2->object_info());
     xbt_assert(region1->object_info());
 
     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)
 
 #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_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
       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();
 #endif
 
       reset_heap_information();
index 2c10779..a1ae2d8 100644 (file)
@@ -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)
 {
  */
 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);
   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;
   // For each compilation unit:
   Dwarf_Off offset = 0;
   Dwarf_Off next_offset = 0;
@@ -1135,7 +1134,7 @@ std::shared_ptr<s_mc_object_info_t> MC_find_object_info(
     std::make_shared<s_mc_object_info_t>();
   if (executable)
     result->flags |= MC_OBJECT_INFO_EXECUTABLE;
     std::make_shared<s_mc_object_info_t>();
   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());
   MC_find_object_address(maps, result.get());
   MC_dwarf_get_variables(result.get());
   MC_post_process_types(result.get());
index 6edd005..f982306 100644 (file)
@@ -70,7 +70,6 @@ Frame::Frame()
 ObjectInformation::ObjectInformation()
 {
   this->flags = 0;
 ObjectInformation::ObjectInformation()
 {
   this->flags = 0;
-  this->file_name = nullptr;
   this->start = nullptr;
   this->end = nullptr;
   this->start_exec = nullptr;
   this->start = nullptr;
   this->end = nullptr;
   this->start_exec = nullptr;
@@ -84,7 +83,6 @@ ObjectInformation::ObjectInformation()
 
 ObjectInformation::~ObjectInformation()
 {
 
 ObjectInformation::~ObjectInformation()
 {
-  xbt_free(this->file_name);
   xbt_dynar_free(&this->functions_index);
 }
 
   xbt_dynar_free(&this->functions_index);
 }
 
index 019e5e7..b195d47 100644 (file)
@@ -140,7 +140,7 @@ public:
   ObjectInformation& operator=(ObjectInformation const&) = delete;
 
   mc_object_info_flags flags;
   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;
   const void* start;
   const void *end;
   char *start_exec;