Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Create a Member for for structure/class/union member
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 6 Oct 2015 11:54:43 +0000 (13:54 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 9 Oct 2015 12:11:23 +0000 (14:11 +0200)
instead of using Type (which is now only used for types).

src/mc/Type.hpp
src/mc/mc_compare.cpp
src/mc/mc_diff.cpp
src/mc/mc_dwarf.cpp
src/mc/mc_dwarf.hpp
src/mc/mc_forward.hpp
src/mc/mc_member.cpp
src/mc/mc_object_info.h
teshsuite/mc/dwarf/dwarf.cpp

index bc3cc45..540bf4c 100644 (file)
 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 {
+/** Represent a member of  a structure (or inheritance) */
+class Member {
 public:
-  Type();
-  Type(Type const& type) = default;
-  Type& operator=(Type const&) = default;
-  Type(Type&& type) = default;
-  Type& operator=(Type&&) = default;
-
-  /** The DWARF TAG of the type (e.g. DW_TAG_array_type) */
-  int type;
-  unsigned id; /* Offset in the section (in hexadecimal form) */
-  std::string name; /* Name of the type */
-  int byte_size; /* Size in bytes */
-  int element_count; /* Number of elements for array type */
-  unsigned type_id; /* DW_AT_type id */
-  std::vector<Type> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
-  int is_pointer_type;
+  Member() : inheritance(false), byte_size(0), type_id(0) {}
 
-  // Location (for members) is either of:
+  bool inheritance;
+  std::string name;
   simgrid::mc::DwarfExpression location_expression;
-
-  simgrid::mc::Type* subtype; // DW_AT_type
-  simgrid::mc::Type* full_type; // The same (but more complete) type
+  std::size_t byte_size; // Do we really need this?
+  unsigned type_id;
+  simgrid::mc::Type* type;
 
   bool has_offset_location() const
   {
@@ -68,6 +52,32 @@ public:
   }
 };
 
+/** Represents a type in the program
+ *
+ *  It is currently used to represent members of structs and unions as well.
+ */
+class Type {
+public:
+  Type();
+  Type(Type const& type) = default;
+  Type& operator=(Type const&) = default;
+  Type(Type&& type) = default;
+  Type& operator=(Type&&) = default;
+
+  /** The DWARF TAG of the type (e.g. DW_TAG_array_type) */
+  int type;
+  unsigned id; /* Offset in the section (in hexadecimal form) */
+  std::string name; /* Name of the type */
+  int byte_size; /* Size in bytes */
+  int element_count; /* Number of elements for array type */
+  unsigned type_id; /* DW_AT_type id */
+  std::vector<Member> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
+  int is_pointer_type;
+
+  simgrid::mc::Type* subtype; // DW_AT_type
+  simgrid::mc::Type* full_type; // The same (but more complete) type
+};
+
 inline
 Type::Type()
 {
index 2d04cb8..49ca977 100644 (file)
@@ -16,6 +16,7 @@
 #include "mc_liveness.h"
 #include "mc_private.h"
 #include "mc_smx.h"
+#include "mc_dwarf.hpp"
 
 #include "mc/Frame.hpp"
 #include "mc/ObjectInformation.hpp"
@@ -236,7 +237,7 @@ static int compare_areas_with_type(struct mc_compare_state& state,
   }
   case DW_TAG_structure_type:
   case DW_TAG_class_type:
-    for(simgrid::mc::Type& member : type->members) {
+    for(simgrid::mc::Member& member : type->members) {
       void *member1 =
         mc_member_resolve(real_area1, type, &member, snapshot1, process_index);
       void *member2 =
@@ -247,7 +248,7 @@ static int compare_areas_with_type(struct mc_compare_state& state,
           compare_areas_with_type(state, process_index,
                                   member1, snapshot1, subregion1,
                                   member2, snapshot2, subregion2,
-                                  member.subtype, pointer_level);
+                                  member.type, pointer_level);
       if (res == 1)
         return res;
     }
index fc96ef0..c942bdd 100644 (file)
@@ -14,6 +14,7 @@
 #include "mc/datatypes.h"
 #include "mc/mc_private.h"
 #include "mc/mc_snapshot.h"
+#include "mc/mc_dwarf.hpp"
 #include "mc/Type.hpp"
 
 using simgrid::mc::remote;
@@ -929,7 +930,7 @@ top:
         return -1;
       }
     } else {
-      for(simgrid::mc::Type& member : type->members) {
+      for(simgrid::mc::Member& member : type->members) {
         // TODO, optimize this? (for the offset case)
         void *real_member1 =
             mc_member_resolve(real_area1, type, &member, (simgrid::mc::AddressSpace*) snapshot1, process_index);
@@ -938,7 +939,7 @@ top:
         res =
             compare_heap_area_with_type(state, process_index, real_member1, real_member2,
                                         snapshot1, snapshot2,
-                                        previous, member.subtype, -1,
+                                        previous, member.type, -1,
                                         check_ignore, 0);
         if (res == 1) {
           return res;
@@ -990,18 +991,18 @@ static simgrid::mc::Type* get_offset_type(void *real_base_address, simgrid::mc::
       else
         return NULL;
     } else {
-      for(simgrid::mc::Type& member : type->members) {
+      for(simgrid::mc::Member& member : type->members) {
 
         if (member.has_offset_location()) {
           // We have the offset, use it directly (shortcut):
           if (member.offset() == offset)
-            return member.subtype;
+            return member.type;
         } else {
           void *real_member =
             mc_member_resolve(real_base_address, type, &member,
               snapshot, process_index);
           if ((char*) real_member - (char *) real_base_address == offset)
-            return member.subtype;
+            return member.type;
         }
 
       }
index b4eece9..4d1aef5 100644 (file)
@@ -475,8 +475,8 @@ static bool MC_compare_variable(
  *  \param  member the member of the type
  *  \param  child  DIE of the member (DW_TAG_member)
  */
-static void MC_dwarf_fill_member_location(simgrid::mc::Type* type, simgrid::mc::Type* member,
-                                          Dwarf_Die * child)
+static void MC_dwarf_fill_member_location(
+  simgrid::mc::Type* type, simgrid::mc::Member* member, Dwarf_Die * child)
 {
   if (dwarf_hasattr(child, DW_AT_data_bit_offset))
     xbt_die("Can't groke DW_AT_data_bit_offset.");
@@ -561,18 +561,14 @@ static void MC_dwarf_add_members(simgrid::mc::ObjectInformation* info, Dwarf_Die
         continue;
 
       // TODO, we should use another type (because is is not a type but a member)
-      simgrid::mc::Type member;
-      member.type = tag;
-
-      // Global Offset:
-      member.id = dwarf_dieoffset(&child);
+      simgrid::mc::Member member;
+      member.inheritance = tag == DW_TAG_inheritance;
 
       const char *name = MC_dwarf_attr_integrate_string(&child, DW_AT_name);
       if (name)
         member.name = name;
       member.byte_size =
           MC_dwarf_attr_integrate_uint(&child, DW_AT_byte_size, 0);
-      member.element_count = -1;
       member.type_id = MC_dwarf_at_type(&child);
 
       if (dwarf_hasattr(&child, DW_AT_data_bit_offset))
@@ -1082,34 +1078,40 @@ static void mc_post_process_scope(simgrid::mc::ObjectInformation* info, simgrid:
 
 }
 
-/** \brief Fill/lookup the "subtype" field.
- */
-static void MC_resolve_subtype(simgrid::mc::ObjectInformation* info, simgrid::mc::Type* type)
+static
+simgrid::mc::Type* MC_resolve_type(
+  simgrid::mc::ObjectInformation* info, unsigned type_id)
 {
-  if (!type->type_id)
-    return;
-  type->subtype = simgrid::util::find_map_ptr(info->types, type->type_id);
-  if (type->subtype == nullptr)
-    return;
-  if (type->subtype->byte_size != 0)
-    return;
-  if (type->subtype->name.empty())
-    return;
+  if (!type_id)
+    return nullptr;
+  simgrid::mc::Type* type = simgrid::util::find_map_ptr(info->types, type_id);
+  if (type == nullptr)
+    return nullptr;
+
+  // We already have the information on the type:
+  if (type->byte_size != 0)
+    return type;
+
+  // Don't have a name, we can't find a more complete version:
+  if (type->name.empty())
+    return type;
+
   // Try to find a more complete description of the type:
   // We need to fix in order to support C++.
   simgrid::mc::Type** subtype = simgrid::util::find_map_ptr(
-    info->full_types_by_name, type->subtype->name);
+    info->full_types_by_name, type->name);
   if (subtype)
-    type->subtype = *subtype;
+    type = *subtype;
+  return type;
 }
 
 static void MC_post_process_types(simgrid::mc::ObjectInformation* info)
 {
   // Lookup "subtype" field:
   for(auto& i : info->types) {
-    MC_resolve_subtype(info, &(i.second));
-    for (simgrid::mc::Type& member : i.second.members)
-      MC_resolve_subtype(info, &member);
+    i.second.subtype = MC_resolve_type(info, i.second.type_id);
+    for (simgrid::mc::Member& member : i.second.members)
+      member.type = MC_resolve_type(info, member.type_id);
   }
 }
 
index 192c68a..41d4841 100644 (file)
@@ -210,7 +210,7 @@ XBT_PRIVATE const char* MC_dwarf_attrname(int attr);
 XBT_PRIVATE const char* MC_dwarf_tagname(int tag);
 
 XBT_PRIVATE void* mc_member_resolve(
-  const void* base, simgrid::mc::Type* type, simgrid::mc::Type* member,
+  const void* base, simgrid::mc::Type* type, simgrid::mc::Member* member,
   simgrid::mc::AddressSpace* snapshot, int process_index);
 
 #endif
index f3b032b..5c704d4 100644 (file)
@@ -21,6 +21,7 @@ class AddressSpace;
 class Process;
 class Snapshot;
 class ObjectInformation;
+class Member;
 class Type;
 class Variable;
 class Frame;
index 29fe1f5..2dc276b 100644 (file)
@@ -18,8 +18,9 @@
  * @param snapshot Snapshot (or NULL)
  * @return Process address of the given member of the 'object' struct/class
  */
-void *mc_member_resolve(const void *base, simgrid::mc::Type* type, simgrid::mc::Type* member,
-                        simgrid::mc::AddressSpace* address_space, int process_index)
+void *mc_member_resolve(
+    const void *base, simgrid::mc::Type* type, simgrid::mc::Member* member,
+    simgrid::mc::AddressSpace* address_space, int process_index)
 {
   // TODO, get rid of this?
   if (!member->has_offset_location())
index 1da12e8..019c758 100644 (file)
@@ -25,8 +25,4 @@ XBT_PRIVATE  void MC_dwarf_get_variables_libdw(simgrid::mc::ObjectInformation* i
 XBT_PRIVATE  const char* MC_dwarf_attrname(int attr);
 XBT_PRIVATE  const char* MC_dwarf_tagname(int tag);
 
-XBT_PRIVATE  void* mc_member_resolve(
-  const void* base, simgrid::mc::Type* type, simgrid::mc::Type* member,
-  simgrid::mc::AddressSpace* snapshot, int process_index);
-
 #endif
index d110ac6..91693d3 100644 (file)
@@ -100,9 +100,9 @@ static simgrid::mc::Variable* test_global_variable(simgrid::mc::Process* process
   return variable;
 }
 
-static simgrid::mc::Type* find_member(simgrid::mc::ObjectInformation* info, const char* name, simgrid::mc::Type* type)
+static simgrid::mc::Member* find_member(simgrid::mc::Type& type, const char* name)
 {
-  for (simgrid::mc::Type& member : type->members)
+  for (simgrid::mc::Member& member : type.members)
     if(member.name == name)
       return &member;
   return nullptr;
@@ -146,8 +146,10 @@ int main(int argc, char** argv)
   i = process->binary_info->types.find(var->type_id);
   xbt_assert(i != process->binary_info->types.end(), "Missing type");
   type = &i->second;
-  assert(find_member(process->binary_info.get(), "first", type)->offset() == 0);
-  assert(find_member(process->binary_info.get(), "second", type)->offset()
+
+  assert(type);
+  assert(find_member(*type, "first")->offset() == 0);
+  assert(find_member(*type, "second")->offset()
       == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct);
 
   unw_context_t context;