Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Cleanup LocationListEntry
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 23 Feb 2016 15:36:39 +0000 (16:36 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 23 Feb 2016 15:39:53 +0000 (16:39 +0100)
src/mc/LocationList.cpp
src/mc/LocationList.hpp
src/mc/mc_dwarf.cpp

index 652d3f0..7ce1b1e 100644 (file)
@@ -47,7 +47,7 @@ static simgrid::dwarf::DwarfExpression const* find_expression(
 {
   for (simgrid::dwarf::LocationListEntry const& entry : locations)
     if (entry.valid_for_ip(ip))
-      return &entry.expression;
+      return &entry.expression();
   return nullptr;
 }
 
@@ -71,11 +71,11 @@ Location resolve(
           frame_pointer_address, address_space, process_index);
 }
 
-simgrid::dwarf::LocationList location_list(
+LocationList location_list(
   simgrid::mc::ObjectInformation& info,
   Dwarf_Attribute& attr)
 {
-  simgrid::dwarf::LocationList locations;
+  LocationList locations;
   std::ptrdiff_t offset = 0;
   while (1) {
 
@@ -87,26 +87,23 @@ simgrid::dwarf::LocationList location_list(
       &attr, offset, &base, &start, &end, &ops, &len);
 
     if (offset == 0)
-      return std::move(locations);
+      break;
     else if (offset == -1)
       xbt_die("Error while loading location list");
 
-    simgrid::dwarf::LocationListEntry entry;
-    entry.expression = simgrid::dwarf::DwarfExpression(ops, ops + len);
+    std::uint64_t base_address = (std::uint64_t) info.base_address();
 
-    void *base_address = info.base_address();
+    LocationListEntry::range_type range;
+    if (start == 0)
+      // If start == 0, this is not a location list:
+      range = {0, 0};
+    else
+      range =  { base_address + start, base_address + end };
 
-    // If start == 0, this is not a location list:
-    if (start == 0) {
-      entry.lowpc  = nullptr;
-      entry.highpc = nullptr;
-    } else {
-      entry.lowpc  = (char *) base_address + start;
-      entry.highpc = (char *) base_address + end;
-    }
-
-    locations.push_back(std::move(entry));
+    locations.push_back({ DwarfExpression(ops, ops+len), range });
   }
+
+  return std::move(locations);
 }
 
 
index c5c186f..289a2c1 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef SIMGRID_MC_OBJECT_LOCATION_H
 #define SIMGRID_MC_OBJECT_LOCATION_H
 
-#include <stdint.h>
+#include <cstdint>
 
 #include <vector>
 
@@ -15,6 +15,8 @@
 #include <dwarf.h>
 #include <elfutils/libdw.h>
 
+#include <xbt/range.hpp>
+
 #include "simgrid_config.h"
 #include "src/mc/mc_base.h"
 #include "src/mc/mc_forward.hpp"
@@ -27,20 +29,34 @@ namespace dwarf {
 /** \brief A DWARF expression with optional validity contraints */
 class LocationListEntry {
 public:
-  simgrid::dwarf::DwarfExpression expression;
-  void* lowpc, *highpc;
-
-  LocationListEntry() : lowpc(nullptr), highpc(nullptr) {}
-
+  typedef simgrid::xbt::range<std::uint64_t> range_type;
+private:
+  DwarfExpression expression_;
+  range_type range_ = {0, 0};
+public:
+  LocationListEntry() {}
+  LocationListEntry(DwarfExpression expression, range_type range)
+    : expression_(std::move(expression)), range_(range)
+  {}
+  LocationListEntry(DwarfExpression expression)
+    : expression_(std::move(expression)), range_({0, 0})
+  {}
+
+  DwarfExpression& expression()
+  {
+    return expression_;
+  }
+  DwarfExpression const& expression() const
+  {
+    return expression_;
+  }
   bool always_valid() const
   {
-    return this->lowpc == nullptr && this->highpc == nullptr;
+    return range_.begin() == 0 && range_.end() == 0;
   }
   bool valid_for_ip(unw_word_t ip) const
   {
-    return always_valid() || (
-      ip >= (unw_word_t) this->lowpc &&
-      ip <  (unw_word_t) this->highpc);
+    return always_valid() || range_.contain(ip);
   }
 };
 
index d5afe09..c0cac6f 100644 (file)
@@ -750,11 +750,9 @@ static std::unique_ptr<simgrid::mc::Variable> MC_die_to_variable(
         uintptr_t offset = (uintptr_t) expr[0].number;
         uintptr_t base = (uintptr_t) info->base_address();
         variable->address = (void *) (base + offset);
-      } else {
-        simgrid::dwarf::LocationListEntry entry;
-        entry.expression = {expr, expr + len};
-        variable->location_list = { std::move(entry) };
-      }
+      } else
+        variable->location_list = {
+          simgrid::dwarf::DwarfExpression(expr, expr + len) };
 
       break;
     }