Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Use simgrid::xbt::range for program-counter ranges
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 22 Feb 2016 12:34:19 +0000 (13:34 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 22 Feb 2016 15:08:31 +0000 (16:08 +0100)
include/xbt/range.hpp [new file with mode: 0644]
src/mc/Frame.hpp
src/mc/ObjectInformation.cpp
src/mc/mc_checkpoint.cpp
src/mc/mc_dwarf.cpp
src/mc/mc_unw.cpp
tools/cmake/DefinePackages.cmake

diff --git a/include/xbt/range.hpp b/include/xbt/range.hpp
new file mode 100644 (file)
index 0000000..7e13722
--- /dev/null
@@ -0,0 +1,32 @@
+/* Copyright (c) 2016. 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_XBT_RANGE_HPP
+#define SIMGRID_XBT_RANGE_HPP
+
+namespace simgrid {
+namespace xbt {
+
+/** Describes a contiguous inclusive-exclusive [a,b) range of values */
+template<class T> class range {
+  T begin_;
+  T end_;
+public:
+  range()               : begin_(), end_() {}
+  range(T begin, T end) : begin_(std::move(begin)), end_(std::move(end)) {}
+  range(T value) : begin_(value), end_(value + 1) {}
+  T& begin()             { return begin_; }
+  T& end()               { return end_; }
+  const T& begin() const { return begin_; }
+  const T& end() const   { return end_; }
+  bool empty() const     { return begin_ >= end_; }
+  bool contain(T const& x) const { return begin_ <= x && end_ > x; }
+};
+
+}
+}
+
+#endif
index ee39960..2d3e6d6 100644 (file)
@@ -10,6 +10,7 @@
 #include <string>
 
 #include <xbt/base.h>
 #include <string>
 
 #include <xbt/base.h>
+#include <xbt/range.hpp>
 
 #include "src/mc/mc_forward.h"
 #include "src/mc/LocationList.hpp"
 
 #include "src/mc/mc_forward.h"
 #include "src/mc/LocationList.hpp"
 namespace simgrid {
 namespace mc {
 
 namespace simgrid {
 namespace mc {
 
+/** Debug information about a given function or scope within a function */
 class Frame {
 public:
   Frame();
 
   int tag;
   std::string name;
 class Frame {
 public:
   Frame();
 
   int tag;
   std::string name;
-  void *low_pc;
-  void *high_pc;
+  /** Range of instruction addresses for which this scope is valid */
+  simgrid::xbt::range<std::uint64_t> range;
   simgrid::dwarf::LocationList frame_base_location;
   std::vector<Variable> variables;
   unsigned long int id; /* DWARF offset of the subprogram */
   simgrid::dwarf::LocationList frame_base_location;
   std::vector<Variable> variables;
   unsigned long int id; /* DWARF offset of the subprogram */
@@ -42,8 +44,7 @@ inline
 Frame::Frame()
 {
   this->tag = 0;
 Frame::Frame()
 {
   this->tag = 0;
-  this->low_pc = nullptr;
-  this->high_pc = nullptr;
+  this->range = {0, 0};
   this->id = 0;
   this->abstract_origin_id = 0;
   this->object_info = nullptr;
   this->id = 0;
   this->abstract_origin_id = 0;
   this->object_info = nullptr;
index 08a75fa..6418c0a 100644 (file)
@@ -84,7 +84,7 @@ simgrid::mc::Frame* ObjectInformation::find_function(const void *ip) const
      * Either we have found the correct function or we do not know
      * any function corresponding to this instruction address.
      * Only at the point do we derefernce the function pointer. */
      * Either we have found the correct function or we do not know
      * any function corresponding to this instruction address.
      * Only at the point do we derefernce the function pointer. */
-    else if (ip < base[k].function->high_pc)
+    else if ((std::uint64_t) ip < base[k].function->range.end())
       return base[k].function;
     else
       return nullptr;
       return base[k].function;
     else
       return nullptr;
index ef98cce..0bfaf47 100644 (file)
@@ -269,7 +269,7 @@ static bool mc_valid_variable(simgrid::mc::Variable* var,
                               const void *ip)
 {
   // The variable is not yet valid:
                               const void *ip)
 {
   // The variable is not yet valid:
-  if ((const void *) ((const char *) scope->low_pc + var->start_scope) > ip)
+  if (scope->range.begin() + var->start_scope > (std::uint64_t) ip)
     return false;
   else
     return true;
     return false;
   else
     return true;
@@ -282,8 +282,7 @@ static void mc_fill_local_variables_values(mc_stack_frame_t stack_frame,
 {
   simgrid::mc::Process* process = &mc_model_checker->process();
 
 {
   simgrid::mc::Process* process = &mc_model_checker->process();
 
-  void *ip = (void *) stack_frame->ip;
-  if (ip < scope->low_pc || ip >= scope->high_pc)
+  if (!scope->range.contain(stack_frame->ip))
     return;
 
   for(simgrid::mc::Variable& current_variable :
     return;
 
   for(simgrid::mc::Variable& current_variable :
index 3886239..a6fb218 100644 (file)
@@ -865,11 +865,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
   // 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);
 
   // 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;
   if (low_pc) {
     // DW_AT_high_pc:
     Dwarf_Attribute attr;
@@ -887,14 +887,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");
 
       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");
       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:
       break;
 
     default:
@@ -1055,10 +1055,10 @@ static void MC_make_functions_index(simgrid::mc::ObjectInformation* info)
   info->functions_index.clear();
 
   for (auto& e : info->subprograms) {
   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;
       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);
   }
     entry.function = &e.second;
     info->functions_index.push_back(entry);
   }
index aab93dd..bb6053a 100644 (file)
@@ -168,7 +168,7 @@ static int get_proc_name(unw_addr_space_t as,
   simgrid::mc::Frame* frame = context->process->find_function(remote(addr));
   if (!frame)
     return - UNW_ENOINFO;
   simgrid::mc::Frame* frame = context->process->find_function(remote(addr));
   if (!frame)
     return - UNW_ENOINFO;
-  *offp = (unw_word_t) frame->low_pc - addr;
+  *offp = (unw_word_t) frame->range.begin() - addr;
 
   strncpy(bufp, frame->name.c_str(), buf_len);
   if (bufp[buf_len - 1]) {
 
   strncpy(bufp, frame->name.c_str(), buf_len);
   if (bufp[buf_len - 1]) {
index 7d2d45f..bad8e31 100644 (file)
@@ -703,6 +703,7 @@ set(headers_to_install
   include/xbt/mmalloc.h
   include/xbt/module.h
   include/xbt/parmap.h
   include/xbt/mmalloc.h
   include/xbt/module.h
   include/xbt/parmap.h
+  include/xbt/range.hpp
   include/xbt/replay.h
   include/xbt/str.h
   include/xbt/strbuff.h
   include/xbt/replay.h
   include/xbt/str.h
   include/xbt/strbuff.h