Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move start_text, start_data, start_bss into mc_object_info_t
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 24 Dec 2013 14:07:43 +0000 (15:07 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Thu, 9 Jan 2014 13:15:40 +0000 (14:15 +0100)
src/mc/mc_checkpoint.c
src/mc/mc_compare.c
src/mc/mc_global.c
src/mc/mc_private.h

index 42e9509..ae02621 100644 (file)
@@ -21,9 +21,6 @@ void *start_got_plt_libsimgrid, *end_got_plt_libsimgrid;
 void *start_plt_binary, *end_plt_binary;
 void *start_got_plt_binary, *end_got_plt_binary;
 char *libsimgrid_path;
-void *start_data_libsimgrid, *start_bss_libsimgrid;
-void *start_data_binary, *start_bss_binary;
-void *start_text_binary;
 
 /************************************  Free functions **************************************/
 /*****************************************************************************************/
@@ -213,47 +210,64 @@ void MC_init_memory_map_info(){
   s_map_region_t reg;
   memory_map_t maps = MC_get_memory_map();
 
+  maestro_stack_start = NULL;
+  maestro_stack_end = NULL;
+  libsimgrid_path = NULL;
+
   while (i < maps->mapsize) {
     reg = maps->regions[i];
-    if ((reg.prot & PROT_WRITE)){
-      if (maps->regions[i].pathname != NULL){
-        if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
-          start_data_libsimgrid = reg.start_addr;
-          i++;
-          reg = maps->regions[i];
-          if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && i < maps->mapsize)
-            start_bss_libsimgrid = reg.start_addr;
-        }else if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
-          start_data_binary = reg.start_addr;
-          i++;
-          reg = maps->regions[i];
-          if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && reg.start_addr != std_heap && reg.start_addr != raw_heap && i < maps->mapsize){
-            start_bss_binary = reg.start_addr;
-            i++;
-          }
-        }else if(!memcmp(maps->regions[i].pathname, "[stack]", 7)){
+    if (maps->regions[i].pathname == NULL) {
+      // Nothing to do
+    }
+    else if ((reg.prot & PROT_WRITE) && !memcmp(maps->regions[i].pathname, "[stack]", 7)){
           maestro_stack_start = reg.start_addr;
           maestro_stack_end = reg.end_addr;
-          i++;
-        }
-      }
-    }else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)){
-      if (maps->regions[i].pathname != NULL){
-        if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
-          start_text_libsimgrid = reg.start_addr;
+    }else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC) && !memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
+      if(libsimgrid_path == NULL)
           libsimgrid_path = strdup(maps->regions[i].pathname);
-        }else if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
-          start_text_binary = reg.start_addr;
-        }
-      }
     }
     i++;
   }
-   
+
+  xbt_assert(maestro_stack_start, "maestro_stack_start");
+  xbt_assert(maestro_stack_end, "maestro_stack_end");
+  xbt_assert(libsimgrid_path, "libsimgrid_path&");
+
   MC_free_memory_map(maps);
 
 }
 
+mc_object_info_t MC_find_object_address(memory_map_t maps, char* name) {
+  mc_object_info_t result = MC_new_object_info();
+  result->file_name = xbt_strdup(name);
+  result->start_data = NULL;
+  result->start_text = NULL;
+
+  unsigned int i = 0;
+  s_map_region_t reg;
+  int len = strlen(basename(name));
+  while (i < maps->mapsize) {
+    reg = maps->regions[i];
+    if (maps->regions[i].pathname == NULL || memcmp(basename(maps->regions[i].pathname), basename(name), len)){
+      // Nothing to do
+    }
+    else if ((reg.prot & PROT_WRITE)){
+          result->start_data = reg.start_addr;
+          i++;
+          reg = maps->regions[i];
+    }else if (reg.prot & PROT_READ) {
+          result->start_text = reg.start_addr;
+    }
+    i++;
+  }
+
+  xbt_assert(result->file_name);
+  xbt_assert(result->start_data);
+  xbt_assert(result->start_text);
+
+  return result;
+}
+
 void MC_get_libsimgrid_plt_section(){
 
   FILE *fp;
@@ -517,7 +531,7 @@ static xbt_dynar_t MC_get_local_variables_values(void *stack_context){
     if(!strcmp(frame_name, "smx_ctx_sysv_wrapper")) /* Stop before context switch with maestro */
       stop = 1;
 
-    if((long)ip > (long)start_text_libsimgrid)
+    if((long)ip > (long) mc_libsimgrid_info->start_text)
       frame = xbt_dict_get_or_null(mc_libsimgrid_info->local_variables, frame_name);
     else
       frame = xbt_dict_get_or_null(mc_binary_info->local_variables, frame_name);
@@ -577,7 +591,7 @@ static xbt_dynar_t MC_get_local_variables_values(void *stack_context){
 
     xbt_dynar_foreach(frame->variables, cursor, current_variable){
       
-      if((long)ip > (long)start_text_libsimgrid)
+      if((long)ip > (long)mc_libsimgrid_info->start_text)
         region_type = 1;
       else
         region_type = 2;
index 41cc772..6184754 100644 (file)
@@ -248,6 +248,8 @@ static int compare_global_variables(int region_type, mc_mem_region_t r1, mc_mem_
   dw_variable_t current_var;
   size_t offset;
   void *start_data;
+  void* start_data_binary = mc_binary_info->start_data;
+  void* start_data_libsimgrid = mc_libsimgrid_info->start_data;
 
   mc_object_info_t object_info = NULL;
   mc_object_info_t other_object_info = NULL;
@@ -289,6 +291,8 @@ static int compare_global_variables(int region_type, mc_mem_region_t r1, mc_mem_
 }
 
 static int compare_local_variables(mc_snapshot_stack_t stack1, mc_snapshot_stack_t stack2, void *heap1, void *heap2){
+  void* start_data_binary = mc_binary_info->start_data;
+  void* start_data_libsimgrid = mc_libsimgrid_info->start_data;
 
   if(!compared_pointers){
     compared_pointers = xbt_dynar_new(sizeof(pointers_pair_t), pointers_pair_free_voidp);
index 457776c..e2999d6 100644 (file)
@@ -8,6 +8,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/time.h>
+#include <libgen.h>
 
 #include "simgrid/sg_config.h"
 #include "../surf/surf_private.h"
@@ -177,6 +178,8 @@ static void dw_variable_free_voidp(void *t){
 mc_object_info_t MC_new_object_info() {
   mc_object_info_t res = xbt_new(s_mc_object_info_t, 1);
   res->file_name = NULL;
+  res->start_text = NULL;
+  res->start_data = NULL;
   res->local_variables = xbt_dict_new_homogeneous(NULL);
   res->global_variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
   res->types = xbt_dict_new_homogeneous(NULL);
@@ -518,7 +521,9 @@ static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *a
 
 }
 
-static mc_object_info_t MC_dwarf_get_variables(const char *elf_file){
+static void MC_dwarf_get_variables(mc_object_info_t info){
+  mc_object_info_t result = info;
+  const char *elf_file = info->file_name;
 
   xbt_dict_t location_list = MC_dwarf_get_location_list(elf_file);
 
@@ -529,9 +534,6 @@ static mc_object_info_t MC_dwarf_get_variables(const char *elf_file){
   if(fp == NULL)
     perror("popen for objdump failed");
 
-  mc_object_info_t result = MC_new_object_info();
-  result->file_name = xbt_strdup(elf_file);
-
   xbt_dict_t *local_variables = &result->local_variables;
   xbt_dynar_t *global_variables = &result->global_variables;
   xbt_dict_t *types = &result->types;
@@ -781,8 +783,9 @@ static mc_object_info_t MC_dwarf_get_variables(const char *elf_file){
                   xbt_dynar_free(&split2);
                   split2 = xbt_str_split(loc_expr, " ");
                   if(strcmp(elf_file, xbt_binary_name) != 0)
-                    var->address.address = (char *)start_text_libsimgrid + (long)((void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16));
+                    var->address.address = (char *) info->start_text + (long)((void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16));
                   else
+                    // Why is it different ?
                     var->address.address = (void *)strtoul(xbt_dynar_get_as(split2, xbt_dynar_length(split2) - 1, char*), NULL, 16);
                 }else{
                   var->address.location = MC_dwarf_get_location(NULL, loc_expr);
@@ -794,8 +797,9 @@ static mc_object_info_t MC_dwarf_get_variables(const char *elf_file){
               global_address = xbt_strdup(xbt_dynar_get_as(split, xbt_dynar_length(split) - 1, char *));
               xbt_str_rtrim(global_address, ")");
               if(strcmp(elf_file, xbt_binary_name) != 0)
-                var->address.address = (char *)start_text_libsimgrid + (long)((void *)strtoul(global_address, NULL, 16));
+                var->address.address = (char *) info->start_text + (long)((void *)strtoul(global_address, NULL, 16));
               else
+                // Why is it different ?
                 var->address.address = (void *)strtoul(global_address, NULL, 16);
               xbt_free(global_address);
               global_address = NULL;
@@ -1258,7 +1262,6 @@ static mc_object_info_t MC_dwarf_get_variables(const char *elf_file){
   xbt_dict_free(&location_list);
 
   pclose(fp);
-  return result;
 }
 
 
@@ -1749,9 +1752,15 @@ void MC_init(){
 
   XBT_INFO("Get debug information ...");
 
+  memory_map_t maps = MC_get_memory_map();
+
   /* Get local variables for state equality detection */
-  mc_binary_info = MC_dwarf_get_variables(xbt_binary_name);
-  mc_libsimgrid_info = MC_dwarf_get_variables(libsimgrid_path);
+
+  mc_binary_info = MC_find_object_address(maps, xbt_binary_name);
+  MC_dwarf_get_variables(mc_binary_info);
+
+  mc_libsimgrid_info = MC_find_object_address(maps, libsimgrid_path);
+  MC_dwarf_get_variables(mc_libsimgrid_info);
 
   XBT_INFO("Get debug information done !");
 
@@ -1766,6 +1775,8 @@ void MC_init(){
    /* Init parmap */
   parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
 
+  MC_free_memory_map(maps);
+
   MC_UNSET_RAW_MEM;
 
    /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
index d381612..f1e802f 100644 (file)
@@ -221,13 +221,7 @@ void MC_free_memory_map(memory_map_t map);
 void MC_get_libsimgrid_plt_section(void);
 void MC_get_binary_plt_section(void);
 
-extern void *start_data_libsimgrid;
-extern void *start_data_binary;
-extern void *start_bss_binary;
 extern char *libsimgrid_path;
-extern void *start_text_libsimgrid;
-extern void *start_text_binary;
-extern void *start_bss_libsimgrid;
 extern void *start_plt_libsimgrid;
 extern void *end_plt_libsimgrid;
 extern void *start_plt_binary;
@@ -237,7 +231,6 @@ extern void *end_got_plt_libsimgrid;
 extern void *start_got_plt_binary;
 extern void *end_got_plt_binary;
 
-
 /********************************** Snapshot comparison **********************************/
 
 typedef struct s_mc_comparison_times{
@@ -335,6 +328,8 @@ void MC_dump_stack_liveness(xbt_fifo_t stack);
 
 typedef struct s_mc_object_info {
   char* file_name;
+  char* start_text;
+  char* start_data;
   xbt_dict_t local_variables;
   xbt_dynar_t global_variables;
   xbt_dict_t types;
@@ -342,6 +337,7 @@ typedef struct s_mc_object_info {
 } s_mc_object_info_t, *mc_object_info_t;
 
 mc_object_info_t MC_new_object_info();
+mc_object_info_t MC_find_object_address(memory_map_t maps, char* name);
 void MC_free_object_info(mc_object_info_t* p);
 
 extern mc_object_info_t mc_libsimgrid_info;