Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] OOPify/C++ify Type (cont)
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 20 Jul 2015 09:14:41 +0000 (11:14 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jul 2015 12:18:30 +0000 (14:18 +0200)
Make location expression a std::vector.

src/mc/mc_diff.cpp
src/mc/mc_dwarf.cpp
src/mc/mc_location.h
src/mc/mc_member.cpp
src/mc/mc_object_info.cpp
src/mc/mc_object_info.h
teshsuite/mc/dwarf/dwarf.cpp

index b3940c2..7e3bb37 100644 (file)
@@ -1108,9 +1108,9 @@ static mc_type_t get_offset_type(void *real_base_address, mc_type_t type,
       mc_type_t member;
       xbt_dynar_foreach(type->members, cursor, member) {
 
-        if (!member->location.size) {
+        if (member->has_offset_location()) {
           // We have the offset, use it directly (shortcut):
-          if (member->offset == offset)
+          if (member->offset() == offset)
             return member->subtype;
         } else {
           void *real_member =
index 7bdc76e..ea43d50 100644 (file)
@@ -496,11 +496,7 @@ static void MC_dwarf_fill_member_location(mc_type_t type, mc_type_t member,
              PRIx64 ">%s", MC_dwarf_attr_integrate_string(child, DW_AT_name),
              (uint64_t) type->id, type->name.c_str());
       }
-      if (len == 1 && expr[0].atom == DW_OP_plus_uconst) {
-        member->offset = expr[0].number;
-      } else {
-        mc_dwarf_expression_init(&member->location, len, expr);
-      }
+      simgrid::mc::DwarfExpression(expr, expr+len);
       break;
     }
   case MC_DW_CLASS_CONSTANT:
@@ -508,7 +504,7 @@ static void MC_dwarf_fill_member_location(mc_type_t type, mc_type_t member,
     {
       Dwarf_Word offset;
       if (!dwarf_formudata(&attr, &offset))
-        member->offset = offset;
+        member->offset(offset);
       else
         xbt_die("Cannot get %s location <%" PRIx64 ">%s",
                 MC_dwarf_attr_integrate_string(child, DW_AT_name),
index d6f6fe4..1bafe6c 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <stdint.h>
 
+#include <vector>
+
 #include <libunwind.h>
 #include <dwarf.h>
 #include <elfutils/libdw.h>
 #include "mc_forward.h"
 #include "AddressSpace.hpp"
 
+namespace simgrid {
+namespace mc {
+
+typedef std::vector<Dwarf_Op> DwarfExpression;
+
+}
+}
+
 SG_BEGIN_DECL()
 
 /** \brief a DWARF expression with optional validity contraints */
@@ -115,4 +125,17 @@ MC_SHOULD_BE_INTERNAL void* mc_find_frame_base(
 
 SG_END_DECL()
 
+namespace simgrid {
+namespace mc {
+
+inline
+int execute(DwarfExpression const& expression, mc_expression_state_t state)
+{
+  return mc_dwarf_execute_expression(
+    expression.size(), expression.data(), state);
+}
+
+}
+}
+
 #endif
index 1fde63e..b96a30f 100644 (file)
@@ -20,9 +20,9 @@
 void *mc_member_resolve(const void *base, mc_type_t type, mc_type_t member,
                         mc_address_space_t address_space, int process_index)
 {
-  if (!member->location.size) {
-    return ((char *) base) + member->offset;
-  }
+  // TODO, get rid of this?
+  if (!member->has_offset_location())
+    return ((char *) base) + member->offset();
 
   s_mc_expression_state_t state;
   memset(&state, 0, sizeof(s_mc_expression_state_t));
@@ -33,8 +33,8 @@ void *mc_member_resolve(const void *base, mc_type_t type, mc_type_t member,
   state.stack[0] = (uintptr_t) base;
   state.process_index = process_index;
 
-  if (mc_dwarf_execute_expression
-      (member->location.size, member->location.ops, &state))
+  if (simgrid::mc::execute(
+      member->location_expression, &state))
     xbt_die("Error evaluating DWARF expression");
   if (state.stack_size == 0)
     xbt_die("No value on the stack");
index 67e4d35..8301068 100644 (file)
@@ -20,13 +20,10 @@ Type::Type()
 {
   this->type = 0;
   this->id = 0;
-  this->name = std::string();
   this->byte_size = 0;
   this->element_count = 0;
   this->members = nullptr;
   this->is_pointer_type = 0;
-  this->location = {0, 0, 0, 0};
-  this->offset = 0;
   this->subtype = nullptr;
   this->full_type = nullptr;
 }
@@ -34,7 +31,6 @@ Type::Type()
 Type::~Type()
 {
   xbt_dynar_free(&this->members);
-  mc_dwarf_expression_clear(&this->location);
 }
 
 // ObjectInformations
index 553bee1..9dbbf53 100644 (file)
@@ -19,6 +19,8 @@
 #include <xbt/dict.h>
 #include <xbt/dynar.h>
 
+#include <elfutils/libdw.h>
+
 #include "mc_forward.h"
 #include "mc_location.h"
 #include "mc_process.h"
@@ -31,6 +33,10 @@ typedef int e_mc_type_type;
 namespace simgrid {
 namespace mc {
 
+/** Represents a type in the program
+ *
+ *  It is currently used to represent members of structs and unions as well.
+ */
 class Type {
 public:
   Type();
@@ -48,11 +54,31 @@ public:
   int is_pointer_type;
 
   // Location (for members) is either of:
-  struct s_mc_expression location;
-  int offset;
+  simgrid::mc::DwarfExpression location_expression;
 
   mc_type_t subtype; // DW_AT_type
   mc_type_t full_type; // The same (but more complete) type
+
+  bool has_offset_location() const
+  {
+    return location_expression.size() == 1 &&
+      location_expression[0].atom == DW_OP_plus_uconst;
+  }
+
+  // TODO, check if this shortcut is really necessary
+  int offset() const
+  {
+    xbt_assert(this->has_offset_location());
+    return this->location_expression[0].number;
+  }
+
+  void offset(int new_offset)
+  {
+    Dwarf_Op op;
+    op.atom = DW_OP_plus_uconst;
+    op.number = new_offset;
+    this->location_expression = { op };
+  }
 };
 
 }
index cf95adf..399795a 100644 (file)
@@ -136,8 +136,8 @@ int main(int argc, char** argv)
   var = test_global_variable(process, process->binary_info.get(),
     "test_some_struct", &test_some_struct, sizeof(test_some_struct));
   type = (mc_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin);
-  assert(find_member(process->binary_info.get(), "first", type)->offset == 0);
-  assert(find_member(process->binary_info.get(), "second", type)->offset
+  assert(find_member(process->binary_info.get(), "first", type)->offset() == 0);
+  assert(find_member(process->binary_info.get(), "second", type)->offset()
       == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct);
 
   unw_context_t context;