Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of github.com:mquinson/simgrid
[simgrid.git] / src / mc / mc_dwarf.cpp
index 3b8e900..4d1aef5 100644 (file)
@@ -5,11 +5,12 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <cinttypes>
+#include <cstdint>
 
 #include <algorithm>
 #include <memory>
 
-#include <stdlib.h>
+#include <cstdlib>
 #define DW_LANG_Objc DW_LANG_ObjC       /* fix spelling error in older dwarf.h */
 #include <dwarf.h>
 #include <elfutils/libdw.h>
@@ -23,8 +24,8 @@
 
 #include "mc_object_info.h"
 #include "mc_private.h"
-#include "mc_process.h"
 
+#include "mc/Process.hpp"
 #include "mc/ObjectInformation.hpp"
 #include "mc/Variable.hpp"
 
@@ -474,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.");
@@ -505,7 +506,7 @@ static void MC_dwarf_fill_member_location(simgrid::mc::Type* type, simgrid::mc::
             ("Could not read location expression DW_AT_data_member_location in DW_TAG_member %s of type <%"
              PRIx64 ">%s", MC_dwarf_attr_integrate_string(child, DW_AT_name),
              (uint64_t) type->id, type->name.c_str());
-      simgrid::mc::DwarfExpression(expr, expr+len);
+      member->location_expression = simgrid::mc::DwarfExpression(expr, expr+len);
       break;
     }
   case MC_DW_CLASS_CONSTANT:
@@ -560,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))
@@ -987,7 +984,9 @@ void MC_dwarf_get_variables(simgrid::mc::ObjectInformation* info)
     xbt_die("Could not open file %s", info->file_name.c_str());
   Dwarf *dwarf = dwarf_begin(fd, DWARF_C_READ);
   if (dwarf == NULL)
-    xbt_die("Your program must be compiled with -g (%s)",
+    xbt_die("Missing debugging information in %s\n"
+      "Your program and its dependencies must have debugging information.\n"
+      "You might want to recompile with -g or install the suitable debugging package.\n",
       info->file_name.c_str());
   // For each compilation unit:
   Dwarf_Off offset = 0;
@@ -1063,7 +1062,7 @@ static void mc_post_process_scope(simgrid::mc::ObjectInformation* info, simgrid:
     auto i = info->subprograms.find(scope->abstract_origin_id);
     xbt_assert(i != info->subprograms.end(),
       "Could not lookup abstract origin %" PRIx64,
-      (uint64_t) scope->abstract_origin_id);
+      (std::uint64_t) scope->abstract_origin_id);
     scope->name = i->second.name;
   }
 
@@ -1079,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);
   }
 }