Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Cleanup/documentation for simgrid::mc::Frame
[simgrid.git] / src / mc / mc_dwarf.cpp
index 5151a7a..d5afe09 100644 (file)
 #include <elfutils/libdw.h>
 
 #include <simgrid_config.h>
-#include <simgrid/util.hpp>
+#include "src/simgrid/util.hpp"
 #include <xbt/log.h>
 #include <xbt/sysdep.h>
 
-#include <simgrid/util.hpp>
+#include "src/mc/mc_object_info.h"
+#include "src/mc/mc_private.h"
+#include "src/mc/mc_dwarf.hpp"
 
-#include "mc_object_info.h"
-#include "mc_private.h"
-#include "mc_dwarf.hpp"
-
-#include "mc/Process.hpp"
-#include "mc/ObjectInformation.hpp"
-#include "mc/Variable.hpp"
+#include "src/mc/Process.hpp"
+#include "src/mc/ObjectInformation.hpp"
+#include "src/mc/Variable.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dwarf, mc, "DWARF processing");
 
@@ -134,7 +132,7 @@ enum class FormClass {
   RangeListPtr
 };
 
-XBT_PRIVATE
+static
 TagClass classify_tag(int tag)
 {
   switch (tag) {
@@ -193,7 +191,7 @@ TagClass classify_tag(int tag)
  *  \param form The form (values taken from the DWARF spec)
  *  \return An internal representation for the corresponding class
  * */
-XBT_PRIVATE
+static
 FormClass classify_form(int form)
 {
   switch (form) {
@@ -764,9 +762,8 @@ static std::unique_ptr<simgrid::mc::Variable> MC_die_to_variable(
   case simgrid::dwarf::FormClass::LocListPtr:
   case simgrid::dwarf::FormClass::Constant:
     // Reference to location list:
-    mc_dwarf_location_list_init(
-      &variable->location_list, info, die,
-      &attr_location);
+    variable->location_list = simgrid::dwarf::location_list(
+      *info, attr_location);
     break;
 
   default:
@@ -847,19 +844,16 @@ static void MC_dwarf_handle_scope_die(simgrid::mc::ObjectInformation* info, Dwar
     xbt_assert(parent_frame, "No parent scope for this scope");
 
   simgrid::mc::Frame frame;
-
   frame.tag = tag;
   frame.id = dwarf_dieoffset(die);
   frame.object_info = info;
 
   if (klass == simgrid::dwarf::TagClass::Subprogram) {
     const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
-    if(ns)
+    if (ns)
       frame.name  = std::string(ns) + "::" + name;
     else if (name)
       frame.name = name;
-    else
-      frame.name.clear();
   }
 
   frame.abstract_origin_id =
@@ -868,11 +862,11 @@ static void MC_dwarf_handle_scope_die(simgrid::mc::ObjectInformation* info, Dwar
   // This is the base address for DWARF addresses.
   // Relocated addresses are offset from this base address.
   // See DWARF4 spec 7.5
-  void *base = info->base_address();
+  std::uint64_t base = (std::uint64_t) info->base_address();
 
   // TODO, support DW_AT_ranges
   uint64_t low_pc = MC_dwarf_attr_integrate_addr(die, DW_AT_low_pc);
-  frame.low_pc = low_pc ? ((char *) base) + low_pc : 0;
+  frame.range.begin() = low_pc ? (std::uint64_t) base + low_pc : 0;
   if (low_pc) {
     // DW_AT_high_pc:
     Dwarf_Attribute attr;
@@ -890,14 +884,14 @@ static void MC_dwarf_handle_scope_die(simgrid::mc::ObjectInformation* info, Dwar
 
       if (dwarf_formsdata(&attr, &offset) != 0)
         xbt_die("Could not read constant");
-      frame.high_pc = (void *) ((char *) frame.low_pc + offset);
+      frame.range.end() = frame.range.begin() + offset;
       break;
 
       // DW_AT_high_pc is a relocatable address:
     case simgrid::dwarf::FormClass::Address:
       if (dwarf_formaddr(&attr, &high_pc) != 0)
         xbt_die("Could not read address");
-      frame.high_pc = ((char *) base) + high_pc;
+      frame.range.begin() = base + high_pc;
       break;
 
     default:
@@ -909,20 +903,21 @@ static void MC_dwarf_handle_scope_die(simgrid::mc::ObjectInformation* info, Dwar
   if (klass == simgrid::dwarf::TagClass::Subprogram) {
     Dwarf_Attribute attr_frame_base;
     if (dwarf_attr_integrate(die, DW_AT_frame_base, &attr_frame_base))
-      mc_dwarf_location_list_init(&frame.frame_base, info, die,
-                                  &attr_frame_base);
+      frame.frame_base_location = simgrid::dwarf::location_list(*info,
+                                  attr_frame_base);
   }
 
   // Handle children:
   MC_dwarf_handle_children(info, die, unit, &frame, ns);
 
-  // Someone needs this to be sorted but who?
+  // We sort them in order to have an (somewhat) efficient by name
+  // lookup:
   std::sort(frame.variables.begin(), frame.variables.end(),
     MC_compare_variable);
 
   // Register it:
   if (klass == simgrid::dwarf::TagClass::Subprogram)
-    info->subprograms[frame.id] = frame;
+    info->subprograms[frame.id] = std::move(frame);
   else if (klass == simgrid::dwarf::TagClass::Scope)
     parent_frame->scopes.push_back(std::move(frame));
 }
@@ -1058,10 +1053,10 @@ static void MC_make_functions_index(simgrid::mc::ObjectInformation* info)
   info->functions_index.clear();
 
   for (auto& e : info->subprograms) {
-    if (e.second.low_pc == nullptr)
+    if (e.second.range.begin() == 0)
       continue;
     simgrid::mc::FunctionIndexEntry entry;
-    entry.low_pc = e.second.low_pc;
+    entry.low_pc = (void*) e.second.range.begin();
     entry.function = &e.second;
     info->functions_index.push_back(entry);
   }
@@ -1152,7 +1147,7 @@ static void MC_post_process_types(simgrid::mc::ObjectInformation* info)
 
 /** \brief Finds informations about a given shared object/executable */
 std::shared_ptr<simgrid::mc::ObjectInformation> MC_find_object_info(
-  std::vector<simgrid::mc::VmMap> const& maps, const char *name)
+  std::vector<simgrid::xbt::VmMap> const& maps, const char *name)
 {
   std::shared_ptr<simgrid::mc::ObjectInformation> result =
     std::make_shared<simgrid::mc::ObjectInformation>();
@@ -1273,4 +1268,4 @@ int dwarf_register_to_libunwind(int dwarf_register)
 }
 
 }
-}
\ No newline at end of file
+}