Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] OOify LocationLists, Location
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 12 Oct 2015 21:59:10 +0000 (23:59 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Thu, 15 Oct 2015 09:18:31 +0000 (11:18 +0200)
12 files changed:
src/mc/DwarfExpression.cpp
src/mc/Frame.hpp
src/mc/LocationList.cpp [new file with mode: 0644]
src/mc/LocationList.hpp [new file with mode: 0644]
src/mc/Type.hpp
src/mc/Variable.hpp
src/mc/mc_checkpoint.cpp
src/mc/mc_dwarf.cpp
src/mc/mc_dwarf.hpp
src/mc/mc_location.h [deleted file]
teshsuite/mc/dwarf/dwarf.cpp
tools/cmake/DefinePackages.cmake

index 924b5f2..5e89864 100644 (file)
 
 #include "mc_object_info.h"
 #include "mc_private.h"
 
 #include "mc_object_info.h"
 #include "mc_private.h"
-#include "mc_location.h"
+#include "mc/LocationList.hpp"
 #include "mc/AddressSpace.hpp"
 #include "mc/Frame.hpp"
 #include "mc/ObjectInformation.hpp"
 #include "mc/DwarfExpression.hpp"
 #include "mc/AddressSpace.hpp"
 #include "mc/Frame.hpp"
 #include "mc/ObjectInformation.hpp"
 #include "mc/DwarfExpression.hpp"
+#include "mc_dwarf.hpp"
 
 using simgrid::mc::remote;
 
 
 using simgrid::mc::remote;
 
@@ -28,81 +29,6 @@ evaluation_error::~evaluation_error() {}
 }
 }
 
 }
 }
 
-extern "C" {
-
-/** Convert a DWARF register into a libunwind register
- *
- *  DWARF and libunwind does not use the same convention for numbering the
- *  registers on some architectures. The function makes the necessary
- *  convertion.
- */
-static int mc_dwarf_register_to_libunwind(int dwarf_register)
-{
-#if defined(__x86_64__)
-  // It seems for this arch, DWARF and libunwind agree in the numbering:
-  return dwarf_register;
-#elif defined(__i386__)
-  // Could't find the authoritative source of information for this.
-  // This is inspired from http://source.winehq.org/source/dlls/dbghelp/cpu_i386.c#L517.
-  switch (dwarf_register) {
-  case 0:
-    return UNW_X86_EAX;
-  case 1:
-    return UNW_X86_ECX;
-  case 2:
-    return UNW_X86_EDX;
-  case 3:
-    return UNW_X86_EBX;
-  case 4:
-    return UNW_X86_ESP;
-  case 5:
-    return UNW_X86_EBP;
-  case 6:
-    return UNW_X86_ESI;
-  case 7:
-    return UNW_X86_EDI;
-  case 8:
-    return UNW_X86_EIP;
-  case 9:
-    return UNW_X86_EFLAGS;
-  case 10:
-    return UNW_X86_CS;
-  case 11:
-    return UNW_X86_SS;
-  case 12:
-    return UNW_X86_DS;
-  case 13:
-    return UNW_X86_ES;
-  case 14:
-    return UNW_X86_FS;
-  case 15:
-    return UNW_X86_GS;
-  case 16:
-    return UNW_X86_ST0;
-  case 17:
-    return UNW_X86_ST1;
-  case 18:
-    return UNW_X86_ST2;
-  case 19:
-    return UNW_X86_ST3;
-  case 20:
-    return UNW_X86_ST4;
-  case 21:
-    return UNW_X86_ST5;
-  case 22:
-    return UNW_X86_ST6;
-  case 23:
-    return UNW_X86_ST7;
-  default:
-    xbt_die("Bad/unknown register number.");
-  }
-#else
-#error This architecture is not supported yet for DWARF expression evaluation.
-#endif
-}
-
-}
-
 namespace simgrid {
 namespace dwarf {
 
 namespace simgrid {
 namespace dwarf {
 
@@ -150,8 +76,8 @@ void execute(
     case DW_OP_breg29:
     case DW_OP_breg30:
     case DW_OP_breg31:{
     case DW_OP_breg29:
     case DW_OP_breg30:
     case DW_OP_breg31:{
-        int register_id =
-            mc_dwarf_register_to_libunwind(op->atom - DW_OP_breg0);
+        int register_id = simgrid::dwarf::dwarf_register_to_libunwind(
+          op->atom - DW_OP_breg0);
         unw_word_t res;
         if (!context.cursor)
           throw evaluation_error("Missin stack context");
         unw_word_t res;
         if (!context.cursor)
           throw evaluation_error("Missin stack context");
@@ -339,87 +265,11 @@ void execute(
   }
 }
 
   }
 }
 
-// ***** Location
-
-/** \brief Resolve a location expression
- *  \deprecated Use mc_dwarf_resolve_expression
- */
-void resolve_location(mc_location_t location,
-                      simgrid::dwarf::DwarfExpression const& expression,
-                      simgrid::mc::ObjectInformation* object_info,
-                      unw_cursor_t * c,
-                      void *frame_pointer_address,
-                      simgrid::mc::AddressSpace* address_space, int process_index)
-{
-  simgrid::dwarf::ExpressionContext context;
-  context.frame_base = frame_pointer_address;
-  context.cursor = c;
-  context.address_space = address_space;
-  context.object_info = object_info;
-  context.process_index = process_index;
-
-  if (!expression.empty()
-      && expression[0].atom >= DW_OP_reg0
-      && expression[0].atom <= DW_OP_reg31) {
-    int dwarf_register = expression[0].atom - DW_OP_reg0;
-    xbt_assert(c,
-      "Missing frame context for register operation DW_OP_reg%i",
-      dwarf_register);
-    location->memory_location = NULL;
-    location->cursor = c;
-    location->register_id = mc_dwarf_register_to_libunwind(dwarf_register);
-    return;
-  }
-
-  simgrid::dwarf::ExpressionStack stack;
-  simgrid::dwarf::execute(expression, context, stack);
-
-  location->memory_location = (void*) stack.top();
-  location->cursor = NULL;
-  location->register_id = 0;
 }
 }
-
-}
-}
-
-// TODO, move this in a method of LocationList
-static simgrid::dwarf::DwarfExpression* mc_find_expression(
-    simgrid::mc::LocationList* locations, unw_word_t ip)
-{
-  for (simgrid::mc::LocationListEntry& entry : *locations)
-    if (entry.valid_for_ip(ip))
-      return &entry.expression;
-  return nullptr;
 }
 
 extern "C" {
 
 }
 
 extern "C" {
 
-void mc_dwarf_resolve_locations(mc_location_t location,
-                                simgrid::mc::LocationList* locations,
-                                simgrid::mc::ObjectInformation* object_info,
-                                unw_cursor_t * c,
-                                void *frame_pointer_address,
-                                simgrid::mc::AddressSpace* address_space,
-                                int process_index)
-{
-
-  unw_word_t ip = 0;
-  if (c) {
-    if (unw_get_reg(c, UNW_REG_IP, &ip))
-      xbt_die("Could not resolve IP");
-  }
-
-  simgrid::dwarf::DwarfExpression* expression =
-    mc_find_expression(locations, ip);
-  if (expression) {
-    simgrid::dwarf::resolve_location(location,
-                              *expression, object_info, c,
-                              frame_pointer_address, address_space, process_index);
-  } else {
-    xbt_die("Could not resolve location");
-  }
-}
-
 /** \brief Find the frame base of a given frame
  *
  *  \param frame
 /** \brief Find the frame base of a given frame
  *
  *  \param frame
@@ -428,33 +278,27 @@ void mc_dwarf_resolve_locations(mc_location_t location,
 void *mc_find_frame_base(simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info,
                          unw_cursor_t * unw_cursor)
 {
 void *mc_find_frame_base(simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info,
                          unw_cursor_t * unw_cursor)
 {
-  s_mc_location_t location;
-  mc_dwarf_resolve_locations(&location,
-                             &frame->frame_base, object_info,
+  simgrid::dwarf::Location location = simgrid::dwarf::resolve(
+                             frame->frame_base, object_info,
                              unw_cursor, NULL, NULL, -1);
                              unw_cursor, NULL, NULL, -1);
-  switch(mc_get_location_type(&location)) {
-  case MC_LOCATION_TYPE_ADDRESS:
-    return location.memory_location;
-
-  case MC_LOCATION_TYPE_REGISTER: {
-      // This is a special case.
-      // The register if not the location of the frame base
-      // (a frame base cannot be located in a register)
-      // Instead, DWARF defines this to mean that the register
-      // contains the address of the frame base.
-      unw_word_t word;
-      unw_get_reg(location.cursor, location.register_id, &word);
-      return (void*) word;
-    }
-
-  default:
-    xbt_die("Cannot handle non-address frame base");
-    return NULL; // Unreachable
+  if (location.in_memory())
+    return location.address();
+  else if (location.in_register()) {
+    // This is a special case.
+    // The register if not the location of the frame base
+    // (a frame base cannot be located in a register)
+    // Instead, DWARF defines this to mean that the register
+    // contains the address of the frame base.
+    unw_word_t word;
+    unw_get_reg(unw_cursor, location.register_id(), &word);
+    return (void*) word;
   }
   }
+  else xbt_die("Unexpected location type");
+
 }
 
 void mc_dwarf_location_list_init(
 }
 
 void mc_dwarf_location_list_init(
-  simgrid::mc::LocationList* list, simgrid::mc::ObjectInformation* info,
+  simgrid::dwarf::LocationList* list, simgrid::mc::ObjectInformation* info,
   Dwarf_Die * die, Dwarf_Attribute * attr)
 {
   list->clear();
   Dwarf_Die * die, Dwarf_Attribute * attr)
 {
   list->clear();
@@ -472,7 +316,7 @@ void mc_dwarf_location_list_init(
     else if (offset == -1)
       xbt_die("Error while loading location list");
 
     else if (offset == -1)
       xbt_die("Error while loading location list");
 
-    simgrid::mc::LocationListEntry entry;
+    simgrid::dwarf::LocationListEntry entry;
     entry.expression = simgrid::dwarf::DwarfExpression(ops, ops + len);
 
     void *base = info->base_address();
     entry.expression = simgrid::dwarf::DwarfExpression(ops, ops + len);
 
     void *base = info->base_address();
index 64b4848..589a11d 100644 (file)
@@ -12,7 +12,7 @@
 #include <xbt/base.h>
 
 #include "mc_forward.h"
 #include <xbt/base.h>
 
 #include "mc_forward.h"
-#include "mc_location.h"
+#include "mc/LocationList.hpp"
 #include "mc/Variable.hpp"
 #include "mc/Frame.hpp"
 
 #include "mc/Variable.hpp"
 #include "mc/Frame.hpp"
 
@@ -27,7 +27,7 @@ public:
   std::string name;
   void *low_pc;
   void *high_pc;
   std::string name;
   void *low_pc;
   void *high_pc;
-  simgrid::mc::LocationList frame_base;
+  simgrid::dwarf::LocationList frame_base;
   std::vector<Variable> variables;
   unsigned long int id; /* DWARF offset of the subprogram */
   std::vector<Frame> scopes;
   std::vector<Variable> variables;
   unsigned long int id; /* DWARF offset of the subprogram */
   std::vector<Frame> scopes;
diff --git a/src/mc/LocationList.cpp b/src/mc/LocationList.cpp
new file mode 100644 (file)
index 0000000..03e4161
--- /dev/null
@@ -0,0 +1,75 @@
+/* Copyright (c) 2004-2015. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "mc_dwarf.hpp"
+#include <mc/ObjectInformation.hpp>
+#include <mc/LocationList.hpp>
+
+namespace simgrid {
+namespace dwarf {
+
+/** Resolve a location expression */
+Location resolve(
+                      simgrid::dwarf::DwarfExpression const& expression,
+                      simgrid::mc::ObjectInformation* object_info,
+                      unw_cursor_t * c,
+                      void *frame_pointer_address,
+                      simgrid::mc::AddressSpace* address_space, int process_index)
+{
+  simgrid::dwarf::ExpressionContext context;
+  context.frame_base = frame_pointer_address;
+  context.cursor = c;
+  context.address_space = address_space;
+  context.object_info = object_info;
+  context.process_index = process_index;
+
+  if (!expression.empty()
+      && expression[0].atom >= DW_OP_reg0
+      && expression[0].atom <= DW_OP_reg31) {
+    int dwarf_register = expression[0].atom - DW_OP_reg0;
+    xbt_assert(c,
+      "Missing frame context for register operation DW_OP_reg%i",
+      dwarf_register);
+    return Location(dwarf_register_to_libunwind(dwarf_register));
+  }
+
+  simgrid::dwarf::ExpressionStack stack;
+  simgrid::dwarf::execute(expression, context, stack);
+  return Location((void*) stack.top());
+}
+
+// TODO, move this in a method of LocationList
+static simgrid::dwarf::DwarfExpression const* find_expression(
+    simgrid::dwarf::LocationList const& locations, unw_word_t ip)
+{
+  for (simgrid::dwarf::LocationListEntry const& entry : locations)
+    if (entry.valid_for_ip(ip))
+      return &entry.expression;
+  return nullptr;
+}
+
+Location resolve(
+  simgrid::dwarf::LocationList const& locations,
+  simgrid::mc::ObjectInformation* object_info,
+  unw_cursor_t * c,
+  void *frame_pointer_address,
+  simgrid::mc::AddressSpace* address_space,
+  int process_index)
+{
+  unw_word_t ip = 0;
+  if (c && unw_get_reg(c, UNW_REG_IP, &ip))
+    xbt_die("Could not resolve IP");
+  simgrid::dwarf::DwarfExpression const* expression =
+    find_expression(locations, ip);
+  if (!expression)
+    xbt_die("Could not resolve location");
+  return simgrid::dwarf::resolve(
+          *expression, object_info, c,
+          frame_pointer_address, address_space, process_index);
+}
+
+}
+}
\ No newline at end of file
diff --git a/src/mc/LocationList.hpp b/src/mc/LocationList.hpp
new file mode 100644 (file)
index 0000000..2e04e01
--- /dev/null
@@ -0,0 +1,99 @@
+/* Copyright (c) 2004-2015. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef SIMGRID_MC_OBJECT_LOCATION_H
+#define SIMGRID_MC_OBJECT_LOCATION_H
+
+#include <stdint.h>
+
+#include <vector>
+
+#include <libunwind.h>
+#include <dwarf.h>
+#include <elfutils/libdw.h>
+
+#include <simgrid_config.h>
+#include "mc_base.h"
+#include "mc_forward.hpp"
+#include "mc/AddressSpace.hpp"
+#include "mc/DwarfExpression.hpp"
+
+namespace simgrid {
+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) {}
+
+  bool always_valid() const
+  {
+    return this->lowpc == nullptr && this->highpc == nullptr;
+  }
+  bool valid_for_ip(unw_word_t ip) const
+  {
+    return always_valid() || (
+      ip >= (unw_word_t) this->lowpc &&
+      ip <  (unw_word_t) this->highpc);
+  }
+};
+
+typedef std::vector<LocationListEntry> LocationList;
+
+/** Location of some variable in memory
+ *
+ *  The variable is located either in memory of a register.
+ */
+class Location {
+private:
+  void* memory_;
+  int register_id_;
+public:
+  Location(void* x) :memory_(x) {}
+  Location(int register_id) :
+    memory_(nullptr), register_id_(register_id) {}
+  // Type of location:
+  bool in_register() const { return memory_ == nullptr; }
+  bool in_memory()   const { return memory_ != nullptr; }
+
+  // Get the location:
+  void* address()    const { return memory_; }
+  int register_id()  const { return register_id_;     }
+};
+
+XBT_PRIVATE
+Location resolve(
+  simgrid::dwarf::DwarfExpression const& expression,
+  simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
+  void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
+  int process_index);
+
+Location resolve(
+  simgrid::dwarf::LocationList const& locations,
+  simgrid::mc::ObjectInformation* object_info,
+  unw_cursor_t * c,
+  void *frame_pointer_address,
+  simgrid::mc::AddressSpace* address_space,
+  int process_index);
+
+}
+}
+
+SG_BEGIN_DECL()
+
+XBT_PRIVATE void mc_dwarf_location_list_init(
+  simgrid::dwarf::LocationList*, simgrid::mc::ObjectInformation* info,
+  Dwarf_Die* die, Dwarf_Attribute* attr);
+
+void* mc_find_frame_base(
+  simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info, unw_cursor_t* unw_cursor);
+
+SG_END_DECL()
+
+#endif
index 42978af..2c2d817 100644 (file)
@@ -13,7 +13,7 @@
 #include <xbt/base.h>
 
 #include "mc_forward.h"
 #include <xbt/base.h>
 
 #include "mc_forward.h"
-#include "mc_location.h"
+#include "mc/LocationList.hpp"
 
 namespace simgrid {
 namespace mc {
 
 namespace simgrid {
 namespace mc {
index 31f49c9..9b57dbc 100644 (file)
@@ -12,7 +12,7 @@
 #include <xbt/base.h>
 
 #include "mc_forward.h"
 #include <xbt/base.h>
 
 #include "mc_forward.h"
-#include "mc_location.h"
+#include "mc/LocationList.hpp"
 
 namespace simgrid {
 namespace mc {
 
 namespace simgrid {
 namespace mc {
@@ -28,7 +28,7 @@ public:
   simgrid::mc::Type* type;
 
   // Use either of:
   simgrid::mc::Type* type;
 
   // Use either of:
-  simgrid::mc::LocationList location_list;
+  simgrid::dwarf::LocationList location_list;
   void* address;
 
   size_t start_scope;
   void* address;
 
   size_t start_scope;
index 763e116..1ea719c 100644 (file)
@@ -305,22 +305,17 @@ static void mc_fill_local_variables_values(mc_stack_frame_t stack_frame,
     if (current_variable.address != NULL) {
       new_var.address = current_variable.address;
     } else if (!current_variable.location_list.empty()) {
     if (current_variable.address != NULL) {
       new_var.address = current_variable.address;
     } else if (!current_variable.location_list.empty()) {
-      s_mc_location_t location;
-      mc_dwarf_resolve_locations(
-        &location, &current_variable.location_list,
-        current_variable.object_info,
-        &(stack_frame->unw_cursor),
-        (void *) stack_frame->frame_base,
-        &mc_model_checker->process(), process_index);
-
-      switch(mc_get_location_type(&location)) {
-      case MC_LOCATION_TYPE_ADDRESS:
-        new_var.address = location.memory_location;
-        break;
-      case MC_LOCATION_TYPE_REGISTER:
-      default:
+      simgrid::dwarf::Location location =
+        simgrid::dwarf::resolve(
+          current_variable.location_list,
+          current_variable.object_info,
+          &(stack_frame->unw_cursor),
+          (void *) stack_frame->frame_base,
+          &mc_model_checker->process(), process_index);
+
+      if (!location.in_memory())
         xbt_die("Cannot handle non-address variable");
         xbt_die("Cannot handle non-address variable");
-      }
+      new_var.address = location.address();
 
     } else {
       xbt_die("No address");
 
     } else {
       xbt_die("No address");
index 9d30fcf..5151a7a 100644 (file)
@@ -753,7 +753,7 @@ static std::unique_ptr<simgrid::mc::Variable> MC_die_to_variable(
         uintptr_t base = (uintptr_t) info->base_address();
         variable->address = (void *) (base + offset);
       } else {
         uintptr_t base = (uintptr_t) info->base_address();
         variable->address = (void *) (base + offset);
       } else {
-        simgrid::mc::LocationListEntry entry;
+        simgrid::dwarf::LocationListEntry entry;
         entry.expression = {expr, expr + len};
         variable->location_list = { std::move(entry) };
       }
         entry.expression = {expr, expr + len};
         variable->location_list = { std::move(entry) };
       }
@@ -1197,3 +1197,80 @@ void MC_post_process_object_info(simgrid::mc::Process* process, simgrid::mc::Obj
 
   }
 }
 
   }
 }
+
+namespace simgrid {
+namespace dwarf {
+
+/** Convert a DWARF register into a libunwind register
+ *
+ *  DWARF and libunwind does not use the same convention for numbering the
+ *  registers on some architectures. The function makes the necessary
+ *  convertion.
+ */
+int dwarf_register_to_libunwind(int dwarf_register)
+{
+#if defined(__x86_64__)
+  // It seems for this arch, DWARF and libunwind agree in the numbering:
+  return dwarf_register;
+#elif defined(__i386__)
+  // Could't find the authoritative source of information for this.
+  // This is inspired from http://source.winehq.org/source/dlls/dbghelp/cpu_i386.c#L517.
+  switch (dwarf_register) {
+  case 0:
+    return UNW_X86_EAX;
+  case 1:
+    return UNW_X86_ECX;
+  case 2:
+    return UNW_X86_EDX;
+  case 3:
+    return UNW_X86_EBX;
+  case 4:
+    return UNW_X86_ESP;
+  case 5:
+    return UNW_X86_EBP;
+  case 6:
+    return UNW_X86_ESI;
+  case 7:
+    return UNW_X86_EDI;
+  case 8:
+    return UNW_X86_EIP;
+  case 9:
+    return UNW_X86_EFLAGS;
+  case 10:
+    return UNW_X86_CS;
+  case 11:
+    return UNW_X86_SS;
+  case 12:
+    return UNW_X86_DS;
+  case 13:
+    return UNW_X86_ES;
+  case 14:
+    return UNW_X86_FS;
+  case 15:
+    return UNW_X86_GS;
+  case 16:
+    return UNW_X86_ST0;
+  case 17:
+    return UNW_X86_ST1;
+  case 18:
+    return UNW_X86_ST2;
+  case 19:
+    return UNW_X86_ST3;
+  case 20:
+    return UNW_X86_ST4;
+  case 21:
+    return UNW_X86_ST5;
+  case 22:
+    return UNW_X86_ST6;
+  case 23:
+    return UNW_X86_ST7;
+  default:
+    xbt_die("Bad/unknown register number.");
+  }
+#else
+#error This architecture is not supported yet for DWARF expression evaluation.
+#endif
+}
+
+}
+}
\ No newline at end of file
index 11d3ce7..b7ebf39 100644 (file)
@@ -29,6 +29,9 @@ XBT_PRIVATE void* resolve_member(
   const void* base, simgrid::mc::Type* type, simgrid::mc::Member* member,
   simgrid::mc::AddressSpace* snapshot, int process_index);
 
   const void* base, simgrid::mc::Type* type, simgrid::mc::Member* member,
   simgrid::mc::AddressSpace* snapshot, int process_index);
 
+XBT_PRIVATE
+int dwarf_register_to_libunwind(int dwarf_register);
+
 }
 }
 
 }
 }
 
diff --git a/src/mc/mc_location.h b/src/mc/mc_location.h
deleted file mode 100644 (file)
index 06be71b..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/* Copyright (c) 2004-2015. The SimGrid Team.
- * All rights reserved.                                                     */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef SIMGRID_MC_OBJECT_LOCATION_H
-#define SIMGRID_MC_OBJECT_LOCATION_H
-
-#include <stdint.h>
-
-#include <vector>
-
-#include <libunwind.h>
-#include <dwarf.h>
-#include <elfutils/libdw.h>
-
-#include <simgrid_config.h>
-#include "mc_base.h"
-#include "mc_forward.hpp"
-#include "mc/AddressSpace.hpp"
-#include "mc/DwarfExpression.hpp"
-
-namespace simgrid {
-namespace mc {
-
-
-/** \brief A DWARF expression with optional validity contraints */
-class LocationListEntry {
-public:
-  simgrid::dwarf::DwarfExpression expression;
-  void* lowpc, *highpc;
-
-  LocationListEntry() : lowpc(nullptr), highpc(nullptr) {}
-
-  bool valid_for_ip(unw_word_t ip)
-  {
-    return (this->lowpc == nullptr && this->highpc == nullptr)
-        || (ip >= (unw_word_t) this->lowpc
-            && ip < (unw_word_t) this->highpc);
-  }
-};
-
-typedef std::vector<LocationListEntry> LocationList;
-
-}
-}
-
-SG_BEGIN_DECL()
-
-/** A location is either a location in memory of a register location
- *
- *  Usage:
- *
- *    * mc_dwarf_resolve_locations or mc_dwarf_resolve_location is used
- *      to find the location of a given location expression or location list;
- *
- *    * mc_get_location_type MUST be used to find the location type;
- *
- *    * for MC_LOCATION_TYPE_ADDRESS, memory_address is the resulting address
- *
- *    * for MC_LOCATION_TYPE_REGISTER, unw_get_reg(l.cursor, l.register_id, value)
- *        and unw_get_reg(l.cursor, l.register_id, value) can be used to read/write
- *        the value.
- *  </ul>
- */
-typedef struct s_mc_location {
-  void* memory_location;
-  unw_cursor_t* cursor;
-  int register_id;
-} s_mc_location_t, *mc_location_t;
-
-/** Type of a given location
- *
- *  Use `mc_get_location_type(location)` to find the type.
- * */
-typedef enum mc_location_type {
-  MC_LOCATION_TYPE_ADDRESS,
-  MC_LOCATION_TYPE_REGISTER
-} mc_location_type;
-
-/** Find the type of a location */
-static inline __attribute__ ((always_inline))
-enum mc_location_type mc_get_location_type(mc_location_t location) {
-  if (location->cursor) {
-    return MC_LOCATION_TYPE_REGISTER;
-  } else {
-    return MC_LOCATION_TYPE_ADDRESS;
-  }
-}
-
-SG_END_DECL()
-
-namespace simgrid {
-namespace dwarf {
-
-XBT_PRIVATE void resolve_location(
-  mc_location_t location, simgrid::dwarf::DwarfExpression const& expression,
-  simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
-  void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
-  int process_index);
-
-}
-}
-
-SG_BEGIN_DECL()
-
-void mc_dwarf_resolve_locations(
-  mc_location_t location, simgrid::mc::LocationList* locations,
-  simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
-  void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
-  int process_index);
-
-XBT_PRIVATE void mc_dwarf_location_list_init(
-  simgrid::mc::LocationList*, simgrid::mc::ObjectInformation* info, Dwarf_Die* die,
-  Dwarf_Attribute* attr);
-
-void* mc_find_frame_base(
-  simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info, unw_cursor_t* unw_cursor);
-
-SG_END_DECL()
-
-#endif
index 91693d3..9af2e2f 100644 (file)
@@ -69,15 +69,13 @@ static void test_local_variable(simgrid::mc::ObjectInformation* info, const char
   assert(var);
 
   void* frame_base = mc_find_frame_base(subprogram, info, cursor);
   assert(var);
 
   void* frame_base = mc_find_frame_base(subprogram, info, cursor);
-  s_mc_location_t location;
+  simgrid::dwarf::Location location = simgrid::dwarf::resolve(
+    var->location_list, info, cursor, frame_base, NULL, -1);
 
 
-  mc_dwarf_resolve_locations(&location,
-    &var->location_list, info, cursor, frame_base, NULL, -1);
-
-  xbt_assert(mc_get_location_type(&location)==MC_LOCATION_TYPE_ADDRESS,
-    "Unexpected location type for variable %s of %s", variable, function);
-
-  xbt_assert(location.memory_location == address,
+  xbt_assert(location.in_memory(),
+    "Expected the variable %s of function %s to be in memory",
+    variable, function);
+  xbt_assert(location.address() == address,
     "Bad resolution of local variable %s of %s", variable, function);
 
 }
     "Bad resolution of local variable %s of %s", variable, function);
 
 }
index 32ab76f..a244369 100644 (file)
@@ -656,7 +656,8 @@ set(MC_SRC
   src/mc/mcer_ignore.h
   src/mc/mc_ignore.h
   src/mc/mc_liveness.h
   src/mc/mcer_ignore.h
   src/mc/mc_ignore.h
   src/mc/mc_liveness.h
-  src/mc/mc_location.h
+  src/mc/LocationList.hpp
+  src/mc/LocationList.cpp
   src/mc/mc_liveness.cpp
   src/mc/mc_record.cpp
   src/mc/mc_member.cpp
   src/mc/mc_liveness.cpp
   src/mc/mc_record.cpp
   src/mc/mc_member.cpp