Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : MUTEX_UNLOCK is invisible for MC
[simgrid.git] / src / mc / mc_dwarf_expression.c
index b1f0ac5..7653210 100644 (file)
@@ -10,6 +10,8 @@
 #include <dwarf.h>
 #include <elfutils/libdw.h>
 
+#include "mc_object_info.h"
+#include "mc_snapshot.h"
 #include "mc_private.h"
 
 static int mc_dwarf_push_value(mc_expression_state_t state, Dwarf_Off value)
@@ -382,7 +384,7 @@ int mc_dwarf_execute_expression(size_t n, const Dwarf_Op * ops,
         // Computed address:
         uintptr_t address = (uintptr_t) state->stack[state->stack_size - 1];
         uintptr_t temp;
-        uintptr_t* res = (uintptr_t*) mc_snapshot_read((void*) address, state->snapshot, &temp, sizeof(uintptr_t));
+        uintptr_t* res = (uintptr_t*) mc_snapshot_read((void*) address, state->snapshot, state->process_index, &temp, sizeof(uintptr_t));
         state->stack[state->stack_size - 1] = *res;
       }
       break;
@@ -403,11 +405,12 @@ int mc_dwarf_execute_expression(size_t n, const Dwarf_Op * ops,
 /** \brief Resolve a location expression
  *  \deprecated Use mc_dwarf_resolve_expression
  */
-uintptr_t mc_dwarf_resolve_location(mc_expression_t expression,
-                                    mc_object_info_t object_info,
-                                    unw_cursor_t * c,
-                                    void *frame_pointer_address,
-                                    mc_snapshot_t snapshot)
+void mc_dwarf_resolve_location(mc_location_t location,
+                               mc_expression_t expression,
+                               mc_object_info_t object_info,
+                               unw_cursor_t * c,
+                               void *frame_pointer_address,
+                               mc_snapshot_t snapshot, int process_index)
 {
   s_mc_expression_state_t state;
   memset(&state, 0, sizeof(s_mc_expression_state_t));
@@ -415,38 +418,64 @@ uintptr_t mc_dwarf_resolve_location(mc_expression_t expression,
   state.cursor = c;
   state.snapshot = snapshot;
   state.object_info = object_info;
+  state.process_index = process_index;
+
+  if (expression->size >= 1
+    && expression->ops[0].atom >=DW_OP_reg0 && expression->ops[0].atom <= DW_OP_reg31) {
+    int dwarf_register = expression->ops[0].atom - DW_OP_reg0;
+    xbt_assert(c, "Missing frame context for register operation DW_OP_reg%i",
+      dwarf_register);
+    location->memory_location = NULL;
+    location->cursor = c;
+    location->register_id = mc_dwarf_register_to_libunwind(dwarf_register);
+    return;
+  }
 
   if (mc_dwarf_execute_expression(expression->size, expression->ops, &state))
     xbt_die("Error evaluating DWARF expression");
   if (state.stack_size == 0)
     xbt_die("No value on the stack");
-  else
-    return state.stack[state.stack_size - 1];
+  else {
+    location->memory_location = (void*) state.stack[state.stack_size - 1];
+    location->cursor = NULL;
+    location->register_id = 0;
+  }
+}
+
+static mc_expression_t mc_find_expression(mc_location_list_t locations, unw_word_t ip) {
+  for (size_t i = 0; i != locations->size; ++i) {
+    mc_expression_t expression = locations->locations + i;
+    if ((expression->lowpc == NULL && expression->highpc == NULL)
+        || (ip && ip >= (unw_word_t) expression->lowpc
+            && ip < (unw_word_t) expression->highpc)) {
+      return expression;
+    }
+  }
+  return NULL;
 }
 
-uintptr_t mc_dwarf_resolve_locations(mc_location_list_t locations,
+void mc_dwarf_resolve_locations(mc_location_t location,
+                                     mc_location_list_t locations,
                                      mc_object_info_t object_info,
                                      unw_cursor_t * c,
                                      void *frame_pointer_address,
-                                     mc_snapshot_t snapshot)
+                                     mc_snapshot_t snapshot, int process_index)
 {
 
-  unw_word_t ip;
+  unw_word_t ip = 0;
   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, object_info, c,
-                                       frame_pointer_address, snapshot);
-    }
+  mc_expression_t expression = mc_find_expression(locations, ip);
+  if (expression) {
+    mc_dwarf_resolve_location(location,
+                              expression, object_info, c,
+                              frame_pointer_address, snapshot, process_index);
+  } else {
+    xbt_die("Could not resolve location");
   }
-  xbt_die("Could not resolve location");
 }
 
 /** \brief Find the frame base of a given frame
@@ -457,8 +486,29 @@ uintptr_t mc_dwarf_resolve_locations(mc_location_list_t locations,
 void *mc_find_frame_base(dw_frame_t frame, mc_object_info_t object_info,
                          unw_cursor_t * unw_cursor)
 {
-  return (void *) mc_dwarf_resolve_locations(&frame->frame_base, object_info,
-                                             unw_cursor, NULL, NULL);
+  s_mc_location_t location;
+  mc_dwarf_resolve_locations(&location,
+                             &frame->frame_base, object_info,
+                             unw_cursor, NULL, NULL, -1);
+  switch(mc_get_location_type(&location)) {
+  case MC_LOCATION_TYPE_ADDRESS:
+    return location.memory_location;
+
+  case MC_LOCATION_TYPE_REGISTER: {
+      // This is a special case.
+      // The register if not the location of the frame base
+      // (a frame base cannot be located in a register)
+      // Instead, DWARF defines this to mean that the register
+      // contains the address of the frame base.
+      unw_word_t word;
+      unw_get_reg(location.cursor, location.register_id, &word);
+      return (void*) word;
+    }
+
+  default:
+    xbt_die("Cannot handle non-address frame base");
+    return NULL; // Unreachable
+  }
 }
 
 void mc_dwarf_expression_clear(mc_expression_t expression)