Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Use new DWARF expression code for variables
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 7 Mar 2014 10:29:07 +0000 (11:29 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 7 Mar 2014 10:29:10 +0000 (11:29 +0100)
src/mc/mc_checkpoint.c
src/mc/mc_dwarf.c
src/mc/mc_dwarf_expression.c
src/mc/mc_global.c
src/mc/mc_hash.c
src/mc/mc_private.h

index 3e1f4cb..6e86b81 100644 (file)
@@ -275,9 +275,9 @@ static xbt_dynar_t MC_get_local_variables_values(xbt_dynar_t stack_frames){
       /* if(current_variable->address!=NULL) {
         new_var->address = current_variable->address;
       } else */
       /* if(current_variable->address!=NULL) {
         new_var->address = current_variable->address;
       } else */
-      if(current_variable->location != NULL){
-        new_var->address = (void*) MC_dwarf_resolve_location(
-          &(stack_frame->unw_cursor), current_variable->location, (void*)stack_frame->frame_base);
+      if(current_variable->locations.size != 0){
+        new_var->address = (void*) mc_dwarf_resolve_locations(&current_variable->locations,
+          &(stack_frame->unw_cursor), (void*)stack_frame->frame_base);
       }
 
       xbt_dynar_push(variables, &new_var);
       }
 
       xbt_dynar_push(variables, &new_var);
index aa5f9f0..9395335 100644 (file)
@@ -951,7 +951,7 @@ static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die* die, D
         Dwarf_Off base = strcmp(info->file_name, xbt_binary_name) !=0 ? (Dwarf_Off) info->start_exec : 0;
         variable->address = (void*) (base + offset);
       } else {
         Dwarf_Off base = strcmp(info->file_name, xbt_binary_name) !=0 ? (Dwarf_Off) info->start_exec : 0;
         variable->address = (void*) (base + offset);
       } else {
-        variable->location = MC_dwarf_get_expression(expr, len);
+        mc_dwarf_location_list_init_from_expression(&variable->locations, len, expr);
       }
 
       break;
       }
 
       break;
@@ -959,7 +959,7 @@ static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die* die, D
   case MC_DW_CLASS_LOCLISTPTR:
   case MC_DW_CLASS_CONSTANT:
     // Reference to location list:
   case MC_DW_CLASS_LOCLISTPTR:
   case MC_DW_CLASS_CONSTANT:
     // Reference to location list:
-    variable->location = MC_dwarf_get_location_list(info, die, &attr_location);
+    mc_dwarf_location_list_init(&variable->locations, info, die, &attr_location);
     break;
   default:
     xbt_die("Unexpected form 0x%x (%i), class 0x%x (%i) list for location in <%p>%s",
     break;
   default:
     xbt_die("Unexpected form 0x%x (%i), class 0x%x (%i) list for location in <%p>%s",
index a73ac2f..54f0d22 100644 (file)
@@ -236,3 +236,91 @@ Dwarf_Off mc_dwarf_resolve_location(mc_expression_t expression, unw_cursor_t* c,
     return (Dwarf_Off) state.stack[state.stack_size-1];
 }
 
     return (Dwarf_Off) state.stack[state.stack_size-1];
 }
 
+Dwarf_Off mc_dwarf_resolve_locations(mc_location_list_t locations, unw_cursor_t* c, void* frame_pointer_address) {
+
+  unw_word_t ip;
+  if(c) {
+    if(unw_get_reg(c, UNW_REG_IP, &ip))
+      xbt_die("Could not resolve IP");
+  }
+
+  for(size_t i=0; i!=locations->size; ++i) {
+    mc_expression_t expression = locations->locations + i;
+    if( (expression->lowpc==NULL && expression->highpc==NULL)
+      || (c && ip >= (unw_word_t) expression->lowpc && ip < (unw_word_t) expression->highpc)) {
+      return mc_dwarf_resolve_location(expression, c, frame_pointer_address);
+    }
+  }
+  xbt_die("Could not resolve location");
+}
+
+static
+void mc_dwarf_expression_clear(mc_expression_t expression) {
+  free(expression->ops);
+  expression->ops = NULL;
+  expression->size = 0;
+  expression->lowpc = NULL;
+  expression->highpc = NULL;
+}
+
+void mc_dwarf_location_list_clear(mc_location_list_t list) {
+  for(size_t i=0; i!=list->size; ++i) {
+    mc_dwarf_expression_clear(list->locations + i);
+  }
+  free(list->locations);
+  list->locations = NULL;
+  list->size = 0;
+}
+
+static
+void mc_dwarf_expression_init(mc_expression_t expression, size_t len, Dwarf_Op* ops) {
+  if(expression->ops) {
+    free(expression->ops);
+  }
+  expression->lowpc = NULL;
+  expression->highpc = NULL;
+  expression->size = len;
+  expression->ops = xbt_malloc(len*sizeof(Dwarf_Op));
+  memcpy(expression->ops, ops, len*sizeof(Dwarf_Op));
+}
+
+void mc_dwarf_location_list_init_from_expression(mc_location_list_t target, size_t len, Dwarf_Op* ops) {
+  if(target->locations) {
+    mc_dwarf_location_list_clear(target);
+  }
+  target->size = 1;
+  target->locations = (mc_expression_t) xbt_malloc(sizeof(s_mc_expression_t));
+  mc_dwarf_expression_init(target->locations, len, ops);
+}
+
+void mc_dwarf_location_list_init(mc_location_list_t list, mc_object_info_t info, Dwarf_Die* die, Dwarf_Attribute* attr) {
+  if(list->locations) {
+    mc_dwarf_location_list_clear(list);
+  }
+  list->size = 0;
+
+  ptrdiff_t offset = 0;
+  Dwarf_Addr base, start, end;
+  Dwarf_Op *ops;
+  size_t len;
+
+  while (1) {
+
+    offset = dwarf_getlocations(attr, offset, &base, &start, &end, &ops, &len);
+    if (offset==0)
+      return;
+    else if (offset==-1)
+      xbt_die("Error while loading location list");
+
+    int i = list->size;
+    list->size++;
+    list->locations = (mc_expression_t) realloc(list->locations, list->size*sizeof(s_mc_expression_t));
+    mc_expression_t expression = list->locations + i;
+
+    void* base = info->flags & MC_OBJECT_INFO_EXECUTABLE ? 0 : MC_object_base_address(info);
+    mc_dwarf_expression_init(expression, len, ops);
+    expression->lowpc = (char*) base + start;
+    expression->highpc = (char*) base + end;
+  }
+
+}
index 133343e..c551c72 100644 (file)
@@ -185,8 +185,9 @@ void dw_variable_free(dw_variable_t v){
   if(v){
     xbt_free(v->name);
     xbt_free(v->type_origin);
   if(v){
     xbt_free(v->name);
     xbt_free(v->type_origin);
-    if(!v->global)
-      dw_location_free(v->location);
+
+    if(v->locations.locations)
+      mc_dwarf_location_list_clear(&v->locations);
     xbt_free(v);
   }
 }
     xbt_free(v);
   }
 }
index 627e708..87e724a 100644 (file)
@@ -233,14 +233,14 @@ static void mc_hash_stack_frame(
       XBT_DEBUG("Hash local variable %s without type", variable->name);
       continue;
     }
       XBT_DEBUG("Hash local variable %s without type", variable->name);
       continue;
     }
-    if(variable->location == NULL) {
+    if(variable->locations.size == 0) {
       XBT_DEBUG("Hash local variable %s without location", variable->name);
       continue;
     }
 
     XBT_DEBUG("Hash local variable %s", variable->name);
 
       XBT_DEBUG("Hash local variable %s without location", variable->name);
       continue;
     }
 
     XBT_DEBUG("Hash local variable %s", variable->name);
 
-    void* variable_address = (void*) MC_dwarf_resolve_location(unw_cursor, variable->location, frame_pointer);
+    void* variable_address = (void*) mc_dwarf_resolve_location(&variable->locations, unw_cursor, frame_pointer);
 
     dw_type_t type = variable->type;
     if(type==NULL) {
 
     dw_type_t type = variable->type;
     if(type==NULL) {
index f8519a5..63a4b38 100644 (file)
@@ -386,6 +386,14 @@ typedef struct s_mc_location_list {
   mc_expression_t locations;
 } s_mc_location_list_t, *mc_location_list_t;
 
   mc_expression_t locations;
 } s_mc_location_list_t, *mc_location_list_t;
 
+Dwarf_Off mc_dwarf_resolve_location(mc_expression_t expression, unw_cursor_t* c, void* frame_pointer_address);
+Dwarf_Off mc_dwarf_resolve_locations(mc_location_list_t locations, unw_cursor_t* c, void* frame_pointer_address);
+
+void mc_dwarf_location_list_clear(mc_location_list_t list);
+
+void mc_dwarf_location_list_init_from_expression(mc_location_list_t target, size_t len, Dwarf_Op* ops);
+void mc_dwarf_location_list_init(mc_location_list_t target, mc_object_info_t info, Dwarf_Die* die, Dwarf_Attribute* attr);
+
 // ***** Deprecated locations:
 
 typedef enum {
 // ***** Deprecated locations:
 
 typedef enum {
@@ -460,7 +468,7 @@ typedef struct s_dw_variable{
   dw_type_t type;
 
   // Use either of:
   dw_type_t type;
 
   // Use either of:
-  dw_location_t location;
+  s_mc_location_list_t locations;
   void* address;
 
   size_t start_scope;
   void* address;
 
   size_t start_scope;