Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 2 Oct 2015 12:40:54 +0000 (14:40 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 2 Oct 2015 12:40:54 +0000 (14:40 +0200)
36 files changed:
src/include/mc/mc.h
src/mc/ModelChecker.cpp
src/mc/ModelChecker.hpp
src/mc/RegionSnapshot.cpp
src/mc/RegionSnapshot.hpp
src/mc/Type.hpp
src/mc/mc_checkpoint.cpp
src/mc/mc_compare.cpp
src/mc/mc_config.cpp
src/mc/mc_diff.cpp
src/mc/mc_dwarf.cpp
src/mc/mc_dwarf_attrnames.cpp
src/mc/mc_dwarf_expression.cpp
src/mc/mc_dwarf_tagnames.cpp
src/mc/mc_global.cpp
src/mc/mc_ignore.cpp
src/mc/mc_libdw.cpp
src/mc/mc_libdw.hpp [deleted file]
src/mc/mc_location.h
src/mc/mc_member.cpp
src/mc/mc_memory.cpp
src/mc/mc_object_info.h [new file with mode: 0644]
src/mc/mc_page_snapshot.cpp
src/mc/mc_private.h
src/mc/mc_process.cpp
src/mc/mc_process.h
src/mc/mc_snapshot.cpp
src/mc/mc_snapshot.h
src/mc/mc_unw.cpp
src/mc/mc_visited.cpp
src/mc/mcer_ignore.cpp
src/simgrid/sg_config.c
teshsuite/mc/dwarf/dwarf.cpp
teshsuite/mc/dwarf_expression/dwarf_expression.cpp
tools/cmake/DefinePackages.cmake
tools/generate-dwarf-functions

index 5052281..2757e7c 100644 (file)
 SG_BEGIN_DECL()
 
 /********************************** Configuration of MC **************************************/        
+
 extern XBT_PUBLIC(int) _sg_do_model_check;
 extern XBT_PRIVATE int _sg_do_model_check_record;
 extern XBT_PRIVATE int _sg_mc_checkpoint;
 extern XBT_PUBLIC(int) _sg_mc_sparse_checkpoint;
+extern XBT_PUBLIC(int) _sg_mc_ksm;
+extern XBT_PUBLIC(int) _sg_mc_soft_dirty;
 extern XBT_PUBLIC(char*) _sg_mc_property_file;
 extern XBT_PRIVATE int _sg_mc_timeout;
 extern XBT_PRIVATE int _sg_mc_hash;
@@ -58,9 +61,12 @@ extern XBT_PRIVATE xbt_dynar_t mc_heap_comparison_ignore;
 extern XBT_PRIVATE xbt_dynar_t stacks_areas;
 
 /********************************* Global *************************************/
+
 XBT_PRIVATE void _mc_cfg_cb_reduce(const char *name, int pos);
 XBT_PRIVATE void _mc_cfg_cb_checkpoint(const char *name, int pos);
 XBT_PRIVATE void _mc_cfg_cb_sparse_checkpoint(const char *name, int pos);
+XBT_PRIVATE void _mc_cfg_cb_ksm(const char *name, int pos);
+XBT_PRIVATE void _mc_cfg_cb_soft_dirty(const char *name, int pos);
 XBT_PRIVATE void _mc_cfg_cb_property(const char *name, int pos);
 XBT_PRIVATE void _mc_cfg_cb_timeout(const char *name, int pos);
 XBT_PRIVATE void _mc_cfg_cb_snapshot_fds(const char *name, int pos);
@@ -72,6 +78,26 @@ XBT_PRIVATE void _mc_cfg_cb_comms_determinism(const char *name, int pos);
 XBT_PRIVATE void _mc_cfg_cb_send_determinism(const char *name, int pos);
 XBT_PRIVATE void _mc_cfg_cb_termination(const char *name, int pos);
 
+extern xbt_dynar_t mc_heap_comparison_ignore;
+extern xbt_dynar_t stacks_areas;
+
+/********************************* Global *************************************/
+void _mc_cfg_cb_reduce(const char *name, int pos);
+void _mc_cfg_cb_checkpoint(const char *name, int pos);
+void _mc_cfg_cb_sparse_checkpoint(const char *name, int pos);
+void _mc_cfg_cb_soft_dirty(const char *name, int pos);
+void _mc_cfg_cb_ksm(const char *name, int pos);
+void _mc_cfg_cb_property(const char *name, int pos);
+void _mc_cfg_cb_timeout(const char *name, int pos);
+void _mc_cfg_cb_hash(const char *name, int pos);
+void _mc_cfg_cb_snapshot_fds(const char *name, int pos);
+void _mc_cfg_cb_max_depth(const char *name, int pos);
+void _mc_cfg_cb_visited(const char *name, int pos);
+void _mc_cfg_cb_dot_output(const char *name, int pos);
+void _mc_cfg_cb_comms_determinism(const char *name, int pos);
+void _mc_cfg_cb_send_determinism(const char *name, int pos);
+void _mc_cfg_cb_termination(const char *name, int pos);
+
 XBT_PUBLIC(void) MC_run(void);
 XBT_PUBLIC(void) MC_init(void);
 XBT_PUBLIC(void) MC_exit(void);
index 2e41784..f0f65af 100644 (file)
@@ -17,7 +17,8 @@ namespace mc {
 ModelChecker::ModelChecker(pid_t pid, int socket) :
   hostnames_(xbt_dict_new()),
   page_store_(500),
-  process_(pid, socket)
+  process_(pid, socket),
+  parent_snapshot_(nullptr)
 {
 }
 
index 5c3f50c..846ea2b 100644 (file)
@@ -35,6 +35,9 @@ class ModelChecker {
   // This is the parent snapshot of the current state:
   PageStore page_store_;
   Process process_;
+public:
+  mc_snapshot_t parent_snapshot_;
+
 public:
   ModelChecker(ModelChecker const&) = delete;
   ModelChecker& operator=(ModelChecker const&) = delete;
index 0bcdd39..6d50ef1 100644 (file)
@@ -4,6 +4,8 @@
 /* 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 <sys/mman.h>
+
 #include "mc/mc.h"
 #include "mc_snapshot.h"
 #include "RegionSnapshot.hpp"
@@ -33,21 +35,47 @@ const char* to_cstr(RegionType region)
   }
 }
 
+void data_deleter::operator()(void* p) const
+{
+  switch(type_) {
+  case Free:
+    free(p);
+    break;
+  case Munmap:
+    munmap(p, size_);
+    break;
+  }
+}
+
 RegionSnapshot dense_region(
   RegionType region_type,
   void *start_addr, void* permanent_addr, size_t size)
 {
-  std::vector<char> data(size);
-  mc_model_checker->process().read_bytes(data.data(), size,
+  simgrid::mc::RegionSnapshot::flat_data_ptr data;
+  if (!_sg_mc_ksm)
+    data = simgrid::mc::RegionSnapshot::flat_data_ptr((char*) malloc(size));
+  else {
+    char* ptr = (char*) mmap(nullptr, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE, -1, 0);
+    if (ptr == MAP_FAILED)
+      throw std::bad_alloc();
+    simgrid::mc::data_deleter deleter(
+      simgrid::mc::data_deleter::Munmap, size);
+    data = simgrid::mc::RegionSnapshot::flat_data_ptr(ptr, deleter);
+  }
+  mc_model_checker->process().read_bytes(data.get(), size,
     remote(permanent_addr),
     simgrid::mc::ProcessIndexDisabled);
+  if (_sg_mc_ksm)
+    // Mark the region as mergeable *after* we have written into it.
+    // There no point to let KSM do the hard work before that.
+    madvise(data.get(), size, MADV_MERGEABLE);
 
   simgrid::mc::RegionSnapshot region(
     region_type, start_addr, permanent_addr, size);
   region.flat_data(std::move(data));
 
   XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu",
-            to_cstr(region_type), region.flat_data().data(), permanent_addr, size);
+            to_cstr(region_type), region.flat_data(), permanent_addr, size);
   return std::move(region);
 }
 
@@ -59,28 +87,45 @@ RegionSnapshot dense_region(
  * @param size         Size of the data*
  */
 RegionSnapshot region(
-  RegionType type, void *start_addr, void* permanent_addr, size_t size)
+  RegionType type, void *start_addr, void* permanent_addr, size_t size,
+  RegionSnapshot const* ref_region)
 {
   if (_sg_mc_sparse_checkpoint) {
-    return sparse_region(type, start_addr, permanent_addr, size);
+    return sparse_region(type, start_addr, permanent_addr, size, ref_region);
   } else  {
     return dense_region(type, start_addr, permanent_addr, size);
   }
 }
 
 RegionSnapshot sparse_region(RegionType region_type,
-  void *start_addr, void* permanent_addr, size_t size)
+  void *start_addr, void* permanent_addr, size_t size,
+  RegionSnapshot const* ref_region)
 {
   simgrid::mc::Process* process = &mc_model_checker->process();
 
+  bool use_soft_dirty = _sg_mc_sparse_checkpoint && _sg_mc_soft_dirty
+    && ref_region != nullptr
+    && ref_region->storage_type() == simgrid::mc::StorageType::Chunked;
+
   xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize-1)) == 0,
     "Not at the beginning of a page");
   xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize-1)) == 0,
     "Not at the beginning of a page");
   size_t page_count = mc_page_count(size);
 
-  simgrid::mc::PerPageCopy page_data(mc_model_checker->page_store(), *process,
-      permanent_addr, page_count);
+  std::vector<std::uint64_t> pagemap;
+  const size_t* ref_page_numbers = nullptr;
+  if (use_soft_dirty) {
+    pagemap.resize(page_count);
+    process->read_pagemap(pagemap.data(),
+      mc_page_number(nullptr, permanent_addr), page_count);
+    ref_page_numbers = ref_region->page_data().pagenos();
+  }
+
+  simgrid::mc::PerPageCopy page_data(
+    mc_model_checker->page_store(), *process, permanent_addr, page_count,
+    ref_page_numbers,
+    use_soft_dirty ? pagemap.data() : nullptr);
 
   simgrid::mc::RegionSnapshot region(
     region_type, start_addr, permanent_addr, size);
index e427a29..e54516a 100644 (file)
@@ -76,13 +76,17 @@ public:
     return pagenos_[i];
   }
 
+  const std::size_t* pagenos() const { return pagenos_.data(); }
+  std::size_t*       pagenos()       { return pagenos_.data(); }
+
   const void* page(std::size_t i) const
   {
     return store_->get_page(pagenos_[i]);
   }
 
   PerPageCopy(PageStore& store, AddressSpace& as,
-    remote_ptr<void> addr, std::size_t page_count);
+    remote_ptr<void> addr, std::size_t page_count,
+    const size_t* ref_page_numbers, const std::uint64_t* pagemap);
 };
 
 enum class RegionType {
@@ -99,6 +103,21 @@ enum class StorageType {
   Privatized = 3
 };
 
+class data_deleter {
+public:
+  enum Type {
+    Free,
+    Munmap
+  };
+private:
+  Type type_;
+  std::size_t size_;
+public:
+  data_deleter() : type_(Free) {}
+  data_deleter(Type type, std::size_t size) : type_(type), size_(size) {}
+  void operator()(void* p) const;
+};
+
 /** @brief Copy/snapshot of a given memory region
  *
  *  Different types of region snapshot storage types exist:
@@ -116,6 +135,7 @@ enum class StorageType {
  *      each type.
  */
 class RegionSnapshot {
+public:
   static const RegionType UnknownRegion = RegionType::Unknown;
   static const RegionType HeapRegion = RegionType::Heap;
   static const RegionType DataRegion = RegionType::Data;
@@ -123,6 +143,8 @@ class RegionSnapshot {
   static const StorageType FlatData = StorageType::Flat;
   static const StorageType ChunkedData = StorageType::Chunked;
   static const StorageType PrivatizedData = StorageType::Privatized;
+public:
+  typedef std::unique_ptr<char[], data_deleter> flat_data_ptr;
 private:
   RegionType region_type_;
   StorageType storage_type_;
@@ -145,7 +167,7 @@ private:
    * */
   void *permanent_addr_;
 
-  std::vector<char> flat_data_;
+  flat_data_ptr flat_data_;
   PerPageCopy page_numbers_;
   std::vector<RegionSnapshot> privatized_regions_;
 public:
@@ -204,7 +226,7 @@ public:
     storage_type_ = NoData;
     privatized_regions_.clear();
     page_numbers_.clear();
-    flat_data_.clear();
+    flat_data_.reset();
     object_info_ = nullptr;
     start_addr_ = nullptr;
     size_ = 0;
@@ -214,24 +236,24 @@ public:
   void clear_data()
   {
     storage_type_ = NoData;
-    flat_data_.clear();
+    flat_data_.reset();
     page_numbers_.clear();
     privatized_regions_.clear();
   }
   
-  void flat_data(std::vector<char> data)
+  void flat_data(flat_data_ptr data)
   {
     storage_type_ = FlatData;
     flat_data_ = std::move(data);
     page_numbers_.clear();
     privatized_regions_.clear();
   }
-  std::vector<char> const& flat_data() const { return flat_data_; }
+  const char* flat_data() const { return flat_data_.get(); }
 
   void page_data(PerPageCopy page_data)
   {
     storage_type_ = ChunkedData;
-    flat_data_.clear();
+    flat_data_.reset();
     page_numbers_ = std::move(page_data);
     privatized_regions_.clear();
   }
@@ -240,7 +262,7 @@ public:
   void privatized_data(std::vector<RegionSnapshot> data)
   {
     storage_type_ = PrivatizedData;
-    flat_data_.clear();
+    flat_data_.reset();
     page_numbers_.clear();
     privatized_regions_ = std::move(data);
   }
@@ -276,10 +298,12 @@ RegionSnapshot privatized_region(
 RegionSnapshot dense_region(
   RegionType type, void *start_addr, void* data_addr, size_t size);
 simgrid::mc::RegionSnapshot sparse_region(
-  RegionType type, void *start_addr, void* data_addr, size_t size);
+  RegionType type, void *start_addr, void* data_addr, size_t size,
+  RegionSnapshot const* ref_region);
 simgrid::mc::RegionSnapshot region(
-  RegionType type, void *start_addr, void* data_addr, size_t size);
-  
+  RegionType type, void *start_addr, void* data_addr, size_t size,
+  RegionSnapshot const* ref_region);
+
 }
 }
 
index 032ad2c..bc3cc45 100644 (file)
@@ -61,7 +61,7 @@ public:
 
   void offset(int new_offset)
   {
-    DwarfInstruction op;
+    Dwarf_Op op;
     op.atom = DW_OP_plus_uconst;
     op.number = new_offset;
     this->location_expression = { op };
index b5aba8c..97ddc26 100644 (file)
@@ -29,7 +29,7 @@
 #include <mc/mc.h>
 
 #include "mc_snapshot.h"
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc_mmu.h"
 #include "mc_unw.h"
 #include "mc_protocol.h"
@@ -50,6 +50,18 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
 /************************************  Free functions **************************************/
 /*****************************************************************************************/
 
+int MC_important_snapshot(mc_snapshot_t snapshot)
+{
+  // We need this snapshot in order to know which
+  // pages needs to be stored in the next snapshot.
+  // This field is only non-NULL when using soft-dirty
+  // page tracking.
+  if (snapshot == mc_model_checker->parent_snapshot_)
+    return true;
+
+  return false;
+}
+
 /** @brief Restore a region from a snapshot
  *
  *  @param reg     Target region
@@ -63,7 +75,7 @@ static void MC_region_restore(mc_mem_region_t region)
     break;
 
   case simgrid::mc::StorageType::Flat:
-    mc_model_checker->process().write_bytes(region->flat_data().data(),
+    mc_model_checker->process().write_bytes(region->flat_data(),
       region->size(), region->permanent_address());
     break;
 
@@ -85,7 +97,8 @@ namespace mc {
 
 #ifdef HAVE_SMPI
 simgrid::mc::RegionSnapshot privatized_region(
-    RegionType region_type, void *start_addr, void* permanent_addr, size_t size
+    RegionType region_type, void *start_addr, void* permanent_addr, size_t size,
+    const simgrid::mc::RegionSnapshot* ref_region
     )
 {
   size_t process_count = MC_smpi_process_count();
@@ -102,11 +115,13 @@ simgrid::mc::RegionSnapshot privatized_region(
 
   std::vector<simgrid::mc::RegionSnapshot> data;
   data.reserve(process_count);
-  for (size_t i = 0; i < process_count; i++)
-    data.push_back(
-      simgrid::mc::region(region_type, start_addr,
-        privatisation_regions[i].address, size)
-      );
+  for (size_t i = 0; i < process_count; i++) {
+    const simgrid::mc::RegionSnapshot* ref_privatized_region = nullptr;
+    if (ref_region && ref_region->storage_type() == StorageType::Privatized)
+      ref_privatized_region = &ref_region->privatized_data()[i];
+    data.push_back(simgrid::mc::region(region_type, start_addr,
+      privatisation_regions[i].address, size, ref_privatized_region));
+  }
 
   simgrid::mc::RegionSnapshot region = simgrid::mc::RegionSnapshot(
     region_type, start_addr, permanent_addr, size);
@@ -130,15 +145,19 @@ static void MC_snapshot_add_region(int index, mc_snapshot_t snapshot,
   else if (type == simgrid::mc::RegionType::Heap)
     xbt_assert(!object_info, "Unexpected object info for heap region.");
 
-  simgrid::mc::RegionSnapshot region;
+  simgrid::mc::RegionSnapshot const* ref_region = nullptr;
+  if (mc_model_checker->parent_snapshot_)
+    ref_region = mc_model_checker->parent_snapshot_->snapshot_regions[index].get();
 
+  simgrid::mc::RegionSnapshot region;
 #ifdef HAVE_SMPI
   const bool privatization_aware = object_info && object_info->privatized();
   if (privatization_aware && MC_smpi_process_count())
-    region = simgrid::mc::privatized_region(type, start_addr, permanent_addr, size);
+    region = simgrid::mc::privatized_region(
+      type, start_addr, permanent_addr, size, ref_region);
   else
 #endif
-    region = simgrid::mc::region(type, start_addr, permanent_addr, size);
+    region = simgrid::mc::region(type, start_addr, permanent_addr, size, ref_region);
 
   region.object_info(object_info);
   snapshot->snapshot_regions[index]
@@ -595,8 +614,12 @@ mc_snapshot_t MC_take_snapshot(int num_state)
   if (_sg_mc_snapshot_fds)
     snapshot->current_fds = MC_get_current_fds(process->pid);
 
+  const bool use_soft_dirty = _sg_mc_sparse_checkpoint && _sg_mc_soft_dirty;
+
   /* Save the std heap and the writable mapped pages of libsimgrid and binary */
   MC_get_memory_regions(mc_process, snapshot);
+  if (use_soft_dirty)
+    mc_process->reset_soft_dirty();
 
   snapshot->to_ignore = MC_take_snapshot_ignore();
 
@@ -613,6 +636,8 @@ mc_snapshot_t MC_take_snapshot(int num_state)
   }
 
   MC_snapshot_ignore_restore(snapshot);
+  if (use_soft_dirty)
+    mc_model_checker->parent_snapshot_ = snapshot;
   return snapshot;
 }
 
@@ -663,11 +688,16 @@ void MC_restore_snapshot_fds(mc_snapshot_t snapshot)
 void MC_restore_snapshot(mc_snapshot_t snapshot)
 {
   XBT_DEBUG("Restore snapshot %i", snapshot->num_state);
+  const bool use_soft_dirty = _sg_mc_sparse_checkpoint && _sg_mc_soft_dirty;
   MC_restore_snapshot_regions(snapshot);
   if (_sg_mc_snapshot_fds)
     MC_restore_snapshot_fds(snapshot);
+  if (use_soft_dirty)
+    mc_model_checker->process().reset_soft_dirty();
   MC_snapshot_ignore_restore(snapshot);
   mc_model_checker->process().cache_flags = 0;
+  if (use_soft_dirty)
+    mc_model_checker->parent_snapshot_ = snapshot;
 }
 
 mc_snapshot_t simcall_HANDLER_mc_snapshot(smx_simcall_t simcall)
index d3932f1..2d04cb8 100644 (file)
@@ -11,7 +11,7 @@
 #include <xbt/sysdep.h>
 
 #include "internal_config.h"
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc_safety.h"
 #include "mc_liveness.h"
 #include "mc_private.h"
index bd3578d..147b38a 100644 (file)
@@ -50,6 +50,8 @@ int _sg_do_model_check = 0;
 int _sg_do_model_check_record = 0;
 int _sg_mc_checkpoint = 0;
 int _sg_mc_sparse_checkpoint = 0;
+int _sg_mc_soft_dirty = 0;
+int _sg_mc_ksm = 0;
 char *_sg_mc_property_file = NULL;
 int _sg_mc_hash = 0;
 int _sg_mc_max_depth = 1000;
@@ -95,6 +97,22 @@ void _mc_cfg_cb_sparse_checkpoint(const char *name, int pos) {
   _sg_mc_sparse_checkpoint = xbt_cfg_get_boolean(_sg_cfg_set, name);
 }
 
+void _mc_cfg_cb_soft_dirty(const char *name, int pos) {
+  if (_sg_cfg_init_status && !_sg_do_model_check)
+    xbt_die("You are specifying a soft dirty value after the initialization "
+            "(through MSG_config?), but model-checking was not activated "
+            "at config time (through --cfg=model-check:1). "
+            "This won't work, sorry.");
+  _sg_mc_soft_dirty = xbt_cfg_get_boolean(_sg_cfg_set, name);
+}
+
+void _mc_cfg_cb_ksm(const char *name, int pos)
+{
+  if (_sg_cfg_init_status && !_sg_do_model_check)
+    xbt_die("You are specifying a KSM value after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
+  _sg_mc_ksm = xbt_cfg_get_boolean(_sg_cfg_set, name);
+}
+
 void _mc_cfg_cb_property(const char *name, int pos)
 {
   if (_sg_cfg_init_status && !_sg_do_model_check) {
index 48a8b0c..0887737 100644 (file)
@@ -10,7 +10,7 @@
 #include "xbt/str.h"
 #include "mc/mc.h"
 #include "xbt/mmalloc.h"
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc/datatypes.h"
 #include "mc/mc_private.h"
 #include "mc/mc_snapshot.h"
index d3a6f4f..b806b0e 100644 (file)
 
 #include <stdlib.h>
 #define DW_LANG_Objc DW_LANG_ObjC       /* fix spelling error in older dwarf.h */
+#include <dwarf.h>
+#include <elfutils/libdw.h>
 
+#include <simgrid_config.h>
 #include <simgrid/util.hpp>
 #include <xbt/log.h>
 #include <xbt/sysdep.h>
 
 #include <simgrid/util.hpp>
 
-#include "mc/mc_dwarf.hpp"
-#include "mc/mc_dwarf.hpp"
-#include "mc/mc_private.h"
-#include "mc/mc_process.h"
+#include "mc_object_info.h"
+#include "mc_private.h"
+#include "mc_process.h"
 
 #include "mc/ObjectInformation.hpp"
 #include "mc/Variable.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dwarf, mc, "DWARF processing");
 
+/** \brief The default DW_TAG_lower_bound for a given DW_AT_language.
+ *
+ *  The default for a given language is defined in the DWARF spec.
+ *
+ *  \param language consant as defined by the DWARf spec
+ */
+static uint64_t MC_dwarf_default_lower_bound(int lang);
+
+/** \brief Computes the the element_count of a DW_TAG_enumeration_type DIE
+ *
+ * This is the number of elements in a given array dimension.
+ *
+ * A reference of the compilation unit (DW_TAG_compile_unit) is
+ * needed because the default lower bound (when there is no DW_AT_lower_bound)
+ * depends of the language of the compilation unit (DW_AT_language).
+ *
+ * \param die  DIE for the DW_TAG_enumeration_type or DW_TAG_subrange_type
+ * \param unit DIE of the DW_TAG_compile_unit
+ */
+static uint64_t MC_dwarf_subrange_element_count(Dwarf_Die * die,
+                                                Dwarf_Die * unit);
+
+/** \brief Computes the number of elements of a given DW_TAG_array_type.
+ *
+ * \param die DIE for the DW_TAG_array_type
+ */
+static uint64_t MC_dwarf_array_element_count(Dwarf_Die * die, Dwarf_Die * unit);
+
+/** \brief Process a DIE
+ *
+ *  \param info the resulting object fot the library/binary file (output)
+ *  \param die  the current DIE
+ *  \param unit the DIE of the compile unit of the current DIE
+ *  \param frame containg frame if any
+ */
+static void MC_dwarf_handle_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                Dwarf_Die * unit, simgrid::mc::Frame* frame,
+                                const char *ns);
+
+/** \brief Process a type DIE
+ */
+static void MC_dwarf_handle_type_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                     Dwarf_Die * unit, simgrid::mc::Frame* frame,
+                                     const char *ns);
+
+/** \brief Calls MC_dwarf_handle_die on all childrend of the given die
+ *
+ *  \param info the resulting object fot the library/binary file (output)
+ *  \param die  the current DIE
+ *  \param unit the DIE of the compile unit of the current DIE
+ *  \param frame containg frame if any
+ */
+static void MC_dwarf_handle_children(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                     Dwarf_Die * unit, simgrid::mc::Frame* frame,
+                                     const char *ns);
+
+/** \brief Handle a variable (DW_TAG_variable or other)
+ *
+ *  \param info the resulting object fot the library/binary file (output)
+ *  \param die  the current DIE
+ *  \param unit the DIE of the compile unit of the current DIE
+ *  \param frame containg frame if any
+ */
+static void MC_dwarf_handle_variable_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                         Dwarf_Die * unit, simgrid::mc::Frame* frame,
+                                         const char *ns);
+
+/** \brief Get the DW_TAG_type of the DIE
+ *
+ *  \param die DIE
+ *  \return DW_TAG_type attribute as a new string (NULL if none)
+ */
+static std::uint64_t MC_dwarf_at_type(Dwarf_Die * die);
+
+/** \brief A class of DWARF tags (DW_TAG_*)
+ */
+typedef enum mc_tag_class {
+  mc_tag_unknown,
+  mc_tag_type,
+  mc_tag_subprogram,
+  mc_tag_variable,
+  mc_tag_scope,
+  mc_tag_namespace
+} mc_tag_class;
+
+static mc_tag_class MC_dwarf_tag_classify(int tag)
+{
+  switch (tag) {
+
+  case DW_TAG_array_type:
+  case DW_TAG_class_type:
+  case DW_TAG_enumeration_type:
+  case DW_TAG_typedef:
+  case DW_TAG_pointer_type:
+  case DW_TAG_reference_type:
+  case DW_TAG_rvalue_reference_type:
+  case DW_TAG_string_type:
+  case DW_TAG_structure_type:
+  case DW_TAG_subroutine_type:
+  case DW_TAG_union_type:
+  case DW_TAG_ptr_to_member_type:
+  case DW_TAG_set_type:
+  case DW_TAG_subrange_type:
+  case DW_TAG_base_type:
+  case DW_TAG_const_type:
+  case DW_TAG_file_type:
+  case DW_TAG_packed_type:
+  case DW_TAG_volatile_type:
+  case DW_TAG_restrict_type:
+  case DW_TAG_interface_type:
+  case DW_TAG_unspecified_type:
+  case DW_TAG_shared_type:
+    return mc_tag_type;
+
+  case DW_TAG_subprogram:
+    return mc_tag_subprogram;
+
+  case DW_TAG_variable:
+  case DW_TAG_formal_parameter:
+    return mc_tag_variable;
+
+  case DW_TAG_lexical_block:
+  case DW_TAG_try_block:
+  case DW_TAG_catch_block:
+  case DW_TAG_inlined_subroutine:
+  case DW_TAG_with_stmt:
+    return mc_tag_scope;
+
+  case DW_TAG_namespace:
+    return mc_tag_namespace;
+
+  default:
+    return mc_tag_unknown;
+
+  }
+}
+
+#define MC_DW_CLASS_UNKNOWN 0
+#define MC_DW_CLASS_ADDRESS 1   // Location in the address space of the program
+#define MC_DW_CLASS_BLOCK 2     // Arbitrary block of bytes
+#define MC_DW_CLASS_CONSTANT 3
+#define MC_DW_CLASS_STRING 3    // String
+#define MC_DW_CLASS_FLAG 4      // Boolean
+#define MC_DW_CLASS_REFERENCE 5 // Reference to another DIE
+#define MC_DW_CLASS_EXPRLOC 6   // DWARF expression/location description
+#define MC_DW_CLASS_LINEPTR 7
+#define MC_DW_CLASS_LOCLISTPTR 8
+#define MC_DW_CLASS_MACPTR 9
+#define MC_DW_CLASS_RANGELISTPTR 10
+
+/** \brief Find the DWARF data class for a given DWARF data form
+ *
+ *  This mapping is defined in the DWARF spec.
+ *
+ *  \param form The form (values taken from the DWARF spec)
+ *  \return An internal representation for the corresponding class
+ * */
+static int MC_dwarf_form_get_class(int form)
+{
+  switch (form) {
+  case DW_FORM_addr:
+    return MC_DW_CLASS_ADDRESS;
+  case DW_FORM_block2:
+  case DW_FORM_block4:
+  case DW_FORM_block:
+  case DW_FORM_block1:
+    return MC_DW_CLASS_BLOCK;
+  case DW_FORM_data1:
+  case DW_FORM_data2:
+  case DW_FORM_data4:
+  case DW_FORM_data8:
+  case DW_FORM_udata:
+  case DW_FORM_sdata:
+    return MC_DW_CLASS_CONSTANT;
+  case DW_FORM_string:
+  case DW_FORM_strp:
+    return MC_DW_CLASS_STRING;
+  case DW_FORM_ref_addr:
+  case DW_FORM_ref1:
+  case DW_FORM_ref2:
+  case DW_FORM_ref4:
+  case DW_FORM_ref8:
+  case DW_FORM_ref_udata:
+    return MC_DW_CLASS_REFERENCE;
+  case DW_FORM_flag:
+  case DW_FORM_flag_present:
+    return MC_DW_CLASS_FLAG;
+  case DW_FORM_exprloc:
+    return MC_DW_CLASS_EXPRLOC;
+    // TODO sec offset
+    // TODO indirect
+  default:
+    return MC_DW_CLASS_UNKNOWN;
+  }
+}
+
+/** \brief Get the name of the tag of a given DIE
+ *
+ *  \param die DIE
+ *  \return name of the tag of this DIE
+ */
+static inline const char *MC_dwarf_die_tagname(Dwarf_Die * die)
+{
+  return MC_dwarf_tagname(dwarf_tag(die));
+}
+
+// ***** Attributes
+
+/** \brief Get an attribute of a given DIE as a string
+ *
+ *  \param die       the DIE
+ *  \param attribute attribute
+ *  \return value of the given attribute of the given DIE
+ */
+static const char *MC_dwarf_attr_integrate_string(Dwarf_Die * die,
+                                                  int attribute)
+{
+  Dwarf_Attribute attr;
+  if (!dwarf_attr_integrate(die, attribute, &attr)) {
+    return NULL;
+  } else {
+    return dwarf_formstring(&attr);
+  }
+}
+
+/** \brief Get the linkage name of a DIE.
+ *
+ *  Use either DW_AT_linkage_name or DW_AT_MIPS_linkage_name.
+ *  DW_AT_linkage_name is standardized since DWARF 4.
+ *  Before this version of DWARF, the MIPS extensions
+ *  DW_AT_MIPS_linkage_name is used (at least by GCC).
+ *
+ *  \param  the DIE
+ *  \return linkage name of the given DIE (or NULL)
+ * */
+static const char *MC_dwarf_at_linkage_name(Dwarf_Die * die)
+{
+  const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_linkage_name);
+  if (!name)
+    name = MC_dwarf_attr_integrate_string(die, DW_AT_MIPS_linkage_name);
+  return name;
+}
+
+static Dwarf_Off MC_dwarf_attr_dieoffset(Dwarf_Die * die, int attribute)
+{
+  Dwarf_Attribute attr;
+  if (dwarf_hasattr_integrate(die, attribute) == 0)
+    return 0;
+  dwarf_attr_integrate(die, attribute, &attr);
+  Dwarf_Die subtype_die;
+  if (dwarf_formref_die(&attr, &subtype_die) == NULL)
+    xbt_die("Could not find DIE");
+  return dwarf_dieoffset(&subtype_die);
+}
+
+static Dwarf_Off MC_dwarf_attr_integrate_dieoffset(Dwarf_Die * die,
+                                                   int attribute)
+{
+  Dwarf_Attribute attr;
+  if (dwarf_hasattr_integrate(die, attribute) == 0)
+    return 0;
+  dwarf_attr_integrate(die, DW_AT_type, &attr);
+  Dwarf_Die subtype_die;
+  if (dwarf_formref_die(&attr, &subtype_die) == NULL)
+    xbt_die("Could not find DIE");
+  return dwarf_dieoffset(&subtype_die);
+}
+
+/** \brief Find the type/subtype (DW_AT_type) for a DIE
+ *
+ *  \param dit the DIE
+ *  \return DW_AT_type reference as a global offset in hexadecimal (or NULL)
+ */
+static
+std::uint64_t MC_dwarf_at_type(Dwarf_Die * die)
+{
+  return MC_dwarf_attr_integrate_dieoffset(die, DW_AT_type);
+}
+
+static uint64_t MC_dwarf_attr_integrate_addr(Dwarf_Die * die, int attribute)
+{
+  Dwarf_Attribute attr;
+  if (dwarf_attr_integrate(die, attribute, &attr) == NULL)
+    return 0;
+  Dwarf_Addr value;
+  if (dwarf_formaddr(&attr, &value) == 0)
+    return (uint64_t) value;
+  else
+    return 0;
+}
+
+static uint64_t MC_dwarf_attr_integrate_uint(Dwarf_Die * die, int attribute,
+                                             uint64_t default_value)
+{
+  Dwarf_Attribute attr;
+  if (dwarf_attr_integrate(die, attribute, &attr) == NULL)
+    return default_value;
+  Dwarf_Word value;
+  return dwarf_formudata(dwarf_attr_integrate(die, attribute, &attr),
+                         &value) == 0 ? (uint64_t) value : default_value;
+}
+
+static bool MC_dwarf_attr_flag(Dwarf_Die * die, int attribute, bool integrate)
+{
+  Dwarf_Attribute attr;
+  if ((integrate ? dwarf_attr_integrate(die, attribute, &attr)
+       : dwarf_attr(die, attribute, &attr)) == 0)
+    return false;
+
+  bool result;
+  if (dwarf_formflag(&attr, &result))
+    xbt_die("Unexpected form for attribute %s", MC_dwarf_attrname(attribute));
+  return result;
+}
+
+/** \brief Find the default lower bound for a given language
+ *
+ *  The default lower bound of an array (when DW_TAG_lower_bound
+ *  is missing) depends on the language of the compilation unit.
+ *
+ *  \param lang Language of the compilation unit (values defined in the DWARF spec)
+ *  \return     Default lower bound of an array in this compilation unit
+ * */
+static uint64_t MC_dwarf_default_lower_bound(int lang)
+{
+  switch (lang) {
+  case DW_LANG_C:
+  case DW_LANG_C89:
+  case DW_LANG_C99:
+  case DW_LANG_C_plus_plus:
+  case DW_LANG_D:
+  case DW_LANG_Java:
+  case DW_LANG_ObjC:
+  case DW_LANG_ObjC_plus_plus:
+  case DW_LANG_Python:
+  case DW_LANG_UPC:
+    return 0;
+  case DW_LANG_Ada83:
+  case DW_LANG_Ada95:
+  case DW_LANG_Fortran77:
+  case DW_LANG_Fortran90:
+  case DW_LANG_Fortran95:
+  case DW_LANG_Modula2:
+  case DW_LANG_Pascal83:
+  case DW_LANG_PL1:
+  case DW_LANG_Cobol74:
+  case DW_LANG_Cobol85:
+    return 1;
+  default:
+    xbt_die("No default DW_TAG_lower_bound for language %i and none given",
+            lang);
+    return 0;
+  }
+}
+
+/** \brief Finds the number of elements in a DW_TAG_subrange_type or DW_TAG_enumeration_type DIE
+ *
+ *  \param die  the DIE
+ *  \param unit DIE of the compilation unit
+ *  \return     number of elements in the range
+ * */
+static uint64_t MC_dwarf_subrange_element_count(Dwarf_Die * die,
+                                                Dwarf_Die * unit)
+{
+  xbt_assert(dwarf_tag(die) == DW_TAG_enumeration_type
+             || dwarf_tag(die) == DW_TAG_subrange_type,
+             "MC_dwarf_subrange_element_count called with DIE of type %s",
+             MC_dwarf_die_tagname(die));
+
+  // Use DW_TAG_count if present:
+  if (dwarf_hasattr_integrate(die, DW_AT_count))
+    return MC_dwarf_attr_integrate_uint(die, DW_AT_count, 0);
+  // Otherwise compute DW_TAG_upper_bound-DW_TAG_lower_bound + 1:
+
+  if (!dwarf_hasattr_integrate(die, DW_AT_upper_bound))
+    // This is not really 0, but the code expects this (we do not know):
+    return 0;
+
+  uint64_t upper_bound =
+      MC_dwarf_attr_integrate_uint(die, DW_AT_upper_bound, -1);
+
+  uint64_t lower_bound = 0;
+  if (dwarf_hasattr_integrate(die, DW_AT_lower_bound))
+    lower_bound = MC_dwarf_attr_integrate_uint(die, DW_AT_lower_bound, -1);
+  else
+    lower_bound = MC_dwarf_default_lower_bound(dwarf_srclang(unit));
+  return upper_bound - lower_bound + 1;
+}
+
+/** \brief Finds the number of elements in a array type (DW_TAG_array_type)
+ *
+ *  The compilation unit might be needed because the default lower
+ *  bound depends on the language of the compilation unit.
+ *
+ *  \param die the DIE of the DW_TAG_array_type
+ *  \param unit the DIE of the compilation unit
+ *  \return number of elements in this array type
+ * */
+static uint64_t MC_dwarf_array_element_count(Dwarf_Die * die, Dwarf_Die * unit)
+{
+  xbt_assert(dwarf_tag(die) == DW_TAG_array_type,
+             "MC_dwarf_array_element_count called with DIE of type %s",
+             MC_dwarf_die_tagname(die));
+
+  int result = 1;
+  Dwarf_Die child;
+  int res;
+  for (res = dwarf_child(die, &child); res == 0;
+       res = dwarf_siblingof(&child, &child)) {
+    int child_tag = dwarf_tag(&child);
+    if (child_tag == DW_TAG_subrange_type
+        || child_tag == DW_TAG_enumeration_type)
+      result *= MC_dwarf_subrange_element_count(&child, unit);
+  }
+  return result;
+}
+
+// ***** Variable
+
+/** Sort the variable by name and address.
+ *
+ *  We could use boost::container::flat_set instead.
+ */
+static bool MC_compare_variable(
+  simgrid::mc::Variable const& a, simgrid::mc::Variable const& b)
+{
+  int cmp = strcmp(a.name.c_str(), b.name.c_str());
+  if (cmp < 0)
+    return true;
+  else if (cmp > 0)
+    return false;
+  else
+    return a.address < b.address;
+}
+
+// ***** simgrid::mc::Type*
+
+/** \brief Initialize the location of a member of a type
+ * (DW_AT_data_member_location of a DW_TAG_member).
+ *
+ *  \param  type   a type (struct, class)
+ *  \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)
+{
+  if (dwarf_hasattr(child, DW_AT_data_bit_offset))
+    xbt_die("Can't groke DW_AT_data_bit_offset.");
+
+  if (!dwarf_hasattr_integrate(child, DW_AT_data_member_location)) {
+    if (type->type == DW_TAG_union_type)
+      return;
+    xbt_die
+        ("Missing DW_AT_data_member_location field in DW_TAG_member %s of type <%"
+         PRIx64 ">%s", member->name.c_str(),
+         (uint64_t) type->id, type->name.c_str());
+  }
+
+  Dwarf_Attribute attr;
+  dwarf_attr_integrate(child, DW_AT_data_member_location, &attr);
+  int form = dwarf_whatform(&attr);
+  int klass = MC_dwarf_form_get_class(form);
+  switch (klass) {
+  case MC_DW_CLASS_EXPRLOC:
+  case MC_DW_CLASS_BLOCK:
+    // Location expression:
+    {
+      Dwarf_Op *expr;
+      size_t len;
+      if (dwarf_getlocation(&attr, &expr, &len))
+        xbt_die
+            ("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);
+      break;
+    }
+  case MC_DW_CLASS_CONSTANT:
+    // Offset from the base address of the object:
+    {
+      Dwarf_Word offset;
+      if (!dwarf_formudata(&attr, &offset))
+        member->offset(offset);
+      else
+        xbt_die("Cannot get %s location <%" PRIx64 ">%s",
+                MC_dwarf_attr_integrate_string(child, DW_AT_name),
+                (uint64_t) type->id, type->name.c_str());
+      break;
+    }
+  case MC_DW_CLASS_LOCLISTPTR:
+    // Reference to a location list:
+    // TODO
+  case MC_DW_CLASS_REFERENCE:
+    // It's supposed to be possible in DWARF2 but I couldn't find its semantic
+    // in the spec.
+  default:
+    xbt_die("Can't handle form class (%i) / form 0x%x as DW_AT_member_location",
+            klass, form);
+  }
+
+}
+
+/** \brief Populate the list of members of a type
+ *
+ *  \param info ELF object containing the type DIE
+ *  \param die  DIE of the type
+ *  \param unit DIE of the compilation unit containing the type DIE
+ *  \param type the type
+ */
+static void MC_dwarf_add_members(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                 Dwarf_Die * unit, simgrid::mc::Type* type)
+{
+  int res;
+  Dwarf_Die child;
+  xbt_assert(type->members.empty());
+  for (res = dwarf_child(die, &child); res == 0;
+       res = dwarf_siblingof(&child, &child)) {
+    int tag = dwarf_tag(&child);
+    if (tag == DW_TAG_member || tag == DW_TAG_inheritance) {
+
+      // Skip declarations:
+      if (MC_dwarf_attr_flag(&child, DW_AT_declaration, false))
+        continue;
+
+      // Skip compile time constants:
+      if (dwarf_hasattr(&child, DW_AT_const_value))
+        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);
+
+      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))
+        xbt_die("Can't groke DW_AT_data_bit_offset.");
+
+      MC_dwarf_fill_member_location(type, &member, &child);
+
+      if (!member.type_id)
+        xbt_die("Missing type for member %s of <%" PRIx64 ">%s",
+                member.name.c_str(),
+                (uint64_t) type->id, type->name.c_str());
+
+      type->members.push_back(std::move(member));
+    }
+  }
+}
+
+/** \brief Create a MC type object from a DIE
+ *
+ *  \param info current object info object
+ *  \param DIE (for a given type);
+ *  \param unit compilation unit of the current DIE
+ *  \return MC representation of the type
+ */
+static simgrid::mc::Type MC_dwarf_die_to_type(
+  simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+  Dwarf_Die * unit, simgrid::mc::Frame* frame,
+  const char *ns)
+{
+  simgrid::mc::Type type;
+  type.type = dwarf_tag(die);
+  type.name = std::string();
+  type.element_count = -1;
+
+  // Global Offset
+  type.id = dwarf_dieoffset(die);
+
+  const char *prefix = "";
+  switch (type.type) {
+  case DW_TAG_structure_type:
+    prefix = "struct ";
+    break;
+  case DW_TAG_union_type:
+    prefix = "union ";
+    break;
+  case DW_TAG_class_type:
+    prefix = "class ";
+    break;
+  default:
+    prefix = "";
+  }
+
+  const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
+  if (name != NULL) {
+    char* full_name = ns ? bprintf("%s%s::%s", prefix, ns, name) :
+      bprintf("%s%s", prefix, name);
+    type.name = std::string(full_name);
+    free(full_name);
+  }
+
+  type.type_id = MC_dwarf_at_type(die);
+
+  // Some compilers do not emit DW_AT_byte_size for pointer_type,
+  // so we fill this. We currently assume that the model-checked process is in
+  // the same architecture..
+  if (type.type == DW_TAG_pointer_type)
+    type.byte_size = sizeof(void*);
+
+  // Computation of the byte_size;
+  if (dwarf_hasattr_integrate(die, DW_AT_byte_size))
+    type.byte_size = MC_dwarf_attr_integrate_uint(die, DW_AT_byte_size, 0);
+  else if (type.type == DW_TAG_array_type
+           || type.type == DW_TAG_structure_type
+           || type.type == DW_TAG_class_type) {
+    Dwarf_Word size;
+    if (dwarf_aggregate_size(die, &size) == 0)
+      type.byte_size = size;
+  }
+
+  switch (type.type) {
+  case DW_TAG_array_type:
+    type.element_count = MC_dwarf_array_element_count(die, unit);
+    // TODO, handle DW_byte_stride and (not) DW_bit_stride
+    break;
+
+  case DW_TAG_pointer_type:
+  case DW_TAG_reference_type:
+  case DW_TAG_rvalue_reference_type:
+    type.is_pointer_type = 1;
+    break;
+
+  case DW_TAG_structure_type:
+  case DW_TAG_union_type:
+  case DW_TAG_class_type:
+    MC_dwarf_add_members(info, die, unit, &type);
+    char *new_ns = ns == NULL ? xbt_strdup(type.name.c_str())
+        : bprintf("%s::%s", ns, name);
+    MC_dwarf_handle_children(info, die, unit, frame, new_ns);
+    free(new_ns);
+    break;
+  }
+
+  return std::move(type);
+}
+
+static void MC_dwarf_handle_type_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                     Dwarf_Die * unit, simgrid::mc::Frame* frame,
+                                     const char *ns)
+{
+  simgrid::mc::Type type = MC_dwarf_die_to_type(info, die, unit, frame, ns);
+  auto& t = (info->types[type.id] = std::move(type));
+  if (!t.name.empty() && type.byte_size != 0)
+    info->full_types_by_name[t.name] = &t;
+}
+
+static int mc_anonymous_variable_index = 0;
+
+static std::unique_ptr<simgrid::mc::Variable> MC_die_to_variable(
+  simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+  Dwarf_Die * unit, simgrid::mc::Frame* frame,
+  const char *ns)
+{
+  // Skip declarations:
+  if (MC_dwarf_attr_flag(die, DW_AT_declaration, false))
+    return nullptr;
+
+  // Skip compile time constants:
+  if (dwarf_hasattr(die, DW_AT_const_value))
+    return nullptr;
+
+  Dwarf_Attribute attr_location;
+  if (dwarf_attr(die, DW_AT_location, &attr_location) == NULL)
+    // No location: do not add it ?
+    return nullptr;
+
+  std::unique_ptr<simgrid::mc::Variable> variable =
+    std::unique_ptr<simgrid::mc::Variable>(new simgrid::mc::Variable());
+  variable->dwarf_offset = dwarf_dieoffset(die);
+  variable->global = frame == NULL;     // Can be override base on DW_AT_location
+  variable->object_info = info;
+
+  const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
+  if (name)
+    variable->name = name;
+  variable->type_id = MC_dwarf_at_type(die);
+
+  int form = dwarf_whatform(&attr_location);
+  int klass =
+      form ==
+      DW_FORM_sec_offset ? MC_DW_CLASS_CONSTANT : MC_dwarf_form_get_class(form);
+  switch (klass) {
+  case MC_DW_CLASS_EXPRLOC:
+  case MC_DW_CLASS_BLOCK:
+    // Location expression:
+    {
+      Dwarf_Op *expr;
+      size_t len;
+      if (dwarf_getlocation(&attr_location, &expr, &len)) {
+        xbt_die(
+          "Could not read location expression in DW_AT_location "
+          "of variable <%" PRIx64 ">%s",
+          (uint64_t) variable->dwarf_offset,
+          variable->name.c_str());
+      }
+
+      if (len == 1 && expr[0].atom == DW_OP_addr) {
+        variable->global = 1;
+        uintptr_t offset = (uintptr_t) expr[0].number;
+        uintptr_t base = (uintptr_t) info->base_address();
+        variable->address = (void *) (base + offset);
+      } else {
+        simgrid::mc::LocationListEntry entry;
+        entry.expression = {expr, expr + len};
+        variable->location_list = { std::move(entry) };
+      }
+
+      break;
+    }
+  case MC_DW_CLASS_LOCLISTPTR:
+  case MC_DW_CLASS_CONSTANT:
+    // Reference to location list:
+    mc_dwarf_location_list_init(
+      &variable->location_list, info, die,
+      &attr_location);
+    break;
+  default:
+    xbt_die("Unexpected form 0x%x (%i), class 0x%x (%i) list for location "
+            "in <%" PRIx64 ">%s",
+            form, form, klass, klass,
+            (uint64_t) variable->dwarf_offset,
+            variable->name.c_str());
+  }
+
+  // Handle start_scope:
+  if (dwarf_hasattr(die, DW_AT_start_scope)) {
+    Dwarf_Attribute attr;
+    dwarf_attr(die, DW_AT_start_scope, &attr);
+    int form = dwarf_whatform(&attr);
+    int klass = MC_dwarf_form_get_class(form);
+    switch (klass) {
+    case MC_DW_CLASS_CONSTANT:
+      {
+        Dwarf_Word value;
+        variable->start_scope =
+            dwarf_formudata(&attr, &value) == 0 ? (size_t) value : 0;
+        break;
+      }
+    case MC_DW_CLASS_RANGELISTPTR:     // TODO
+    default:
+      xbt_die
+          ("Unhandled form 0x%x, class 0x%X for DW_AT_start_scope of variable %s",
+           form, klass, name == NULL ? "?" : name);
+    }
+  }
+
+  if (ns && variable->global)
+    variable->name =
+      std::string(ns) + "::" + variable->name;
+
+  // The current code needs a variable name,
+  // generate a fake one:
+  if (variable->name.empty())
+    variable->name =
+      "@anonymous#" + std::to_string(mc_anonymous_variable_index++);
+
+  return std::move(variable);
+}
+
+static void MC_dwarf_handle_variable_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                         Dwarf_Die * unit, simgrid::mc::Frame* frame,
+                                         const char *ns)
+{
+  std::unique_ptr<simgrid::mc::Variable> variable =
+    MC_die_to_variable(info, die, unit, frame, ns);
+  if (!variable)
+    return;
+  // Those arrays are sorted later:
+  else if (variable->global)
+    info->global_variables.push_back(std::move(*variable));
+  else if (frame != nullptr)
+    frame->variables.push_back(std::move(*variable));
+  else
+    xbt_die("No frame for this local variable");
+}
+
+static void MC_dwarf_handle_scope_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                      Dwarf_Die * unit, simgrid::mc::Frame* parent_frame,
+                                      const char *ns)
+{
+  // TODO, handle DW_TAG_type/DW_TAG_location for DW_TAG_with_stmt
+  int tag = dwarf_tag(die);
+  mc_tag_class klass = MC_dwarf_tag_classify(tag);
+
+  // (Template) Subprogram declaration:
+  if (klass == mc_tag_subprogram
+      && MC_dwarf_attr_flag(die, DW_AT_declaration, false))
+    return;
+
+  if (klass == mc_tag_scope)
+    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 == mc_tag_subprogram) {
+    const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
+    if(ns)
+      frame.name  = std::string(ns) + "::" + name;
+    else if (name)
+      frame.name = name;
+    else
+      frame.name.clear();
+  }
+
+  frame.abstract_origin_id =
+    MC_dwarf_attr_dieoffset(die, DW_AT_abstract_origin);
+
+  // 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();
+
+  // 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;
+  if (low_pc) {
+    // DW_AT_high_pc:
+    Dwarf_Attribute attr;
+    if (!dwarf_attr_integrate(die, DW_AT_high_pc, &attr)) {
+      xbt_die("Missing DW_AT_high_pc matching with DW_AT_low_pc");
+    }
+
+    Dwarf_Sword offset;
+    Dwarf_Addr high_pc;
+
+    switch (MC_dwarf_form_get_class(dwarf_whatform(&attr))) {
+
+      // DW_AT_high_pc if an offset from the low_pc:
+    case MC_DW_CLASS_CONSTANT:
+
+      if (dwarf_formsdata(&attr, &offset) != 0)
+        xbt_die("Could not read constant");
+      frame.high_pc = (void *) ((char *) frame.low_pc + offset);
+      break;
+
+      // DW_AT_high_pc is a relocatable address:
+    case MC_DW_CLASS_ADDRESS:
+      if (dwarf_formaddr(&attr, &high_pc) != 0)
+        xbt_die("Could not read address");
+      frame.high_pc = ((char *) base) + high_pc;
+      break;
+
+    default:
+      xbt_die("Unexpected class for DW_AT_high_pc");
+
+    }
+  }
+
+  if (klass == mc_tag_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);
+  }
+
+  // Handle children:
+  MC_dwarf_handle_children(info, die, unit, &frame, ns);
+
+  // Someone needs this to be sorted but who?
+  std::sort(frame.variables.begin(), frame.variables.end(),
+    MC_compare_variable);
+
+  // Register it:
+  if (klass == mc_tag_subprogram)
+    info->subprograms[frame.id] = frame;
+  else if (klass == mc_tag_scope)
+    parent_frame->scopes.push_back(std::move(frame));
+}
+
+static void mc_dwarf_handle_namespace_die(simgrid::mc::ObjectInformation* info,
+                                          Dwarf_Die * die, Dwarf_Die * unit,
+                                          simgrid::mc::Frame* frame,
+                                          const char *ns)
+{
+  const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
+  if (frame)
+    xbt_die("Unexpected namespace in a subprogram");
+  char *new_ns = ns == NULL ? xbt_strdup(name)
+      : bprintf("%s::%s", ns, name);
+  MC_dwarf_handle_children(info, die, unit, frame, new_ns);
+  xbt_free(new_ns);
+}
+
+static void MC_dwarf_handle_children(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                     Dwarf_Die * unit, simgrid::mc::Frame* frame,
+                                     const char *ns)
+{
+  // For each child DIE:
+  Dwarf_Die child;
+  int res;
+  for (res = dwarf_child(die, &child); res == 0;
+       res = dwarf_siblingof(&child, &child)) {
+    MC_dwarf_handle_die(info, &child, unit, frame, ns);
+  }
+}
+
+static void MC_dwarf_handle_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
+                                Dwarf_Die * unit, simgrid::mc::Frame* frame,
+                                const char *ns)
+{
+  int tag = dwarf_tag(die);
+  mc_tag_class klass = MC_dwarf_tag_classify(tag);
+  switch (klass) {
+
+    // Type:
+  case mc_tag_type:
+    MC_dwarf_handle_type_die(info, die, unit, frame, ns);
+    break;
+
+    // Subprogram or scope:
+  case mc_tag_subprogram:
+  case mc_tag_scope:
+    MC_dwarf_handle_scope_die(info, die, unit, frame, ns);
+    return;
+
+    // Variable:
+  case mc_tag_variable:
+    MC_dwarf_handle_variable_die(info, die, unit, frame, ns);
+    break;
+
+  case mc_tag_namespace:
+    mc_dwarf_handle_namespace_die(info, die, unit, frame, ns);
+    break;
+
+  default:
+    break;
+
+  }
+}
+
+/** \brief Populate the debugging informations of the given ELF object
+ *
+ *  Read the DWARf information of the EFFL object and populate the
+ *  lists of types, variables, functions.
+ */
+void MC_dwarf_get_variables(simgrid::mc::ObjectInformation* info)
+{
+  int fd = open(info->file_name.c_str(), O_RDONLY);
+  if (fd < 0)
+    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("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;
+  Dwarf_Off next_offset = 0;
+  size_t length;
+
+  while (dwarf_nextcu(dwarf, offset, &next_offset, &length, NULL, NULL, NULL) ==
+         0) {
+    Dwarf_Die unit_die;
+    if (dwarf_offdie(dwarf, offset + length, &unit_die) != NULL)
+      MC_dwarf_handle_children(info, &unit_die, &unit_die, NULL, NULL);
+    offset = next_offset;
+  }
+
+  dwarf_end(dwarf);
+  close(fd);
+}
+
 // ***** Functions index
 
 static int MC_compare_frame_index_items(simgrid::mc::FunctionIndexEntry* a,
@@ -78,8 +1058,7 @@ static void MC_post_process_variables(simgrid::mc::ObjectInformation* info)
         info->types, variable.type_id);
 }
 
-static void mc_post_process_scope(
-  simgrid::mc::ObjectInformation* info, simgrid::mc::Frame* scope)
+static void mc_post_process_scope(simgrid::mc::ObjectInformation* info, simgrid::mc::Frame* scope)
 {
 
   if (scope->tag == DW_TAG_inlined_subroutine) {
@@ -105,8 +1084,7 @@ static void mc_post_process_scope(
 
 /** \brief Fill/lookup the "subtype" field.
  */
-static void MC_resolve_subtype(
-  simgrid::mc::ObjectInformation* info, simgrid::mc::Type* type)
+static void MC_resolve_subtype(simgrid::mc::ObjectInformation* info, simgrid::mc::Type* type)
 {
   if (!type->type_id)
     return;
index 348cb60..17e4446 100644 (file)
@@ -9,6 +9,8 @@
 #include <xbt/base.h>
 #include <dwarf.h>
 
+#include "mc_object_info.h"
+
 /** \brief Get the name of an attribute (DW_AT_*) from its code
  *
  *  \param attr attribute code (see the DWARF specification)
index bf80037..7bf2335 100644 (file)
@@ -4,14 +4,13 @@
 /* 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 <cstdint>
-
 #include <stdint.h>
 #include <stdarg.h>
 
 #include <dwarf.h>
+#include <elfutils/libdw.h>
 
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc_private.h"
 #include "mc_location.h"
 #include "mc/AddressSpace.hpp"
@@ -22,7 +21,7 @@ using simgrid::mc::remote;
 
 extern "C" {
 
-static int mc_dwarf_push_value(mc_expression_state_t state, std::uint64_t value)
+static int mc_dwarf_push_value(mc_expression_state_t state, Dwarf_Off value)
 {
   if (state->stack_size >= MC_EXPRESSION_STACK_SIZE)
     return MC_EXPRESSION_E_STACK_OVERFLOW;
@@ -102,12 +101,12 @@ static int mc_dwarf_register_to_libunwind(int dwarf_register)
 #endif
 }
 
-int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* ops,
+int mc_dwarf_execute_expression(size_t n, const Dwarf_Op * ops,
                                 mc_expression_state_t state)
 {
   for (size_t i = 0; i != n; ++i) {
     int error = 0;
-    const simgrid::mc::DwarfInstruction *op = ops + i;
+    const Dwarf_Op *op = ops + i;
     uint8_t atom = op->atom;
 
     switch (atom) {
@@ -234,7 +233,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
         return MC_EXPRESSION_E_NO_BASE_ADDRESS;
       if (state->stack_size == MC_EXPRESSION_STACK_SIZE)
         return MC_EXPRESSION_E_STACK_OVERFLOW;
-      std::uint64_t addr = (std::uint64_t) (uintptr_t)
+      Dwarf_Off addr = (Dwarf_Off) (uintptr_t)
         state->object_info->base_address() + op->number;
       error = mc_dwarf_push_value(state, addr);
       break;
@@ -541,4 +540,36 @@ void *mc_find_frame_base(simgrid::mc::Frame* frame, simgrid::mc::ObjectInformati
   }
 }
 
+void mc_dwarf_location_list_init(
+  simgrid::mc::LocationList* list, simgrid::mc::ObjectInformation* info,
+  Dwarf_Die * die, Dwarf_Attribute * attr)
+{
+  list->clear();
+
+  ptrdiff_t offset = 0;
+  Dwarf_Addr base, start, end;
+  Dwarf_Op *ops;
+  size_t len;
+
+  while (1) {
+
+    offset = dwarf_getlocations(attr, offset, &base, &start, &end, &ops, &len);
+    if (offset == 0)
+      return;
+    else if (offset == -1)
+      xbt_die("Error while loading location list");
+
+    simgrid::mc::LocationListEntry entry;
+    entry.expression = simgrid::mc::DwarfExpression(ops, ops + len);
+
+    void *base = info->base_address();
+    // If start == 0, this is not a location list:
+    entry.lowpc = start == 0 ? NULL : (char *) base + start;
+    entry.highpc = start == 0 ? NULL : (char *) base + end;
+
+    list->push_back(std::move(entry));
+  }
+
+}
+
 }
index e17cf2f..983f111 100644 (file)
@@ -7,8 +7,10 @@
 /* Warning: autogenerated, do not edit! */
 
 #include <dwarf.h>
+#include <elfutils/libdw.h>
 
 #include <xbt/base.h>
+#include "mc_object_info.h"
 
 /** \brief Get the name of a dwarf tag (DW_TAG_*) from its code
  *
@@ -93,6 +95,8 @@ const char *MC_dwarf_tagname(int tag)
   case 0x4109: return "DW_TAG_GNU_call_site";
   case 0x410a: return "DW_TAG_GNU_call_site_parameter";
   case 0xffff: return "DW_TAG_hi_user";
+  case DW_TAG_invalid:
+    return "DW_TAG_invalid";
   default:
     return "DW_TAG_unknown";
   }
index 86039ca..d9680d8 100644 (file)
@@ -31,7 +31,7 @@
 #include <libunwind.h>
 #include <xbt/mmalloc.h>
 #include "../xbt/mmalloc/mmprivate.h"
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc_comm_pattern.h"
 #include "mc_request.h"
 #include "mc_safety.h"
@@ -507,6 +507,8 @@ void MC_print_statistics(mc_stats_t stats)
     if (_sg_mc_comms_determinism)
       XBT_INFO("Recv-deterministic : %s", !initial_global_state->recv_deterministic ? "No" : "Yes");
   }
+  if (getenv("SIMGRID_MC_SYSTEM_STATISTICS"))
+    system("free");
 }
 
 void MC_automaton_load(const char *file)
index 8ae16f4..0c973ed 100644 (file)
@@ -5,7 +5,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "internal_config.h"
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc_private.h"
 #include "smpi/private.h"
 #include "mc/mc_snapshot.h"
index fcd5add..2e55f15 100644 (file)
@@ -13,7 +13,6 @@
 #include <utility>
 
 #include <dwarf.h>
-#include <elfutils/libdw.h>
 
 #include <xbt/log.h>
 
@@ -293,7 +292,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),
              (std::uint64_t) type->id, type->name.c_str());
-      member->location_expression = MC_dwarf_expression(expr, len);
+      MC_dwarf_expression(expr, len);
       break;
     }
   case MC_DW_CLASS_CONSTANT:
diff --git a/src/mc/mc_libdw.hpp b/src/mc/mc_libdw.hpp
deleted file mode 100644 (file)
index fb73202..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/* Copyright (c) 2008-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. */
-
-#if !defined(SIMGRID_MC_LIBDW_HPP)
-#define SIMGRID_MC_LIBDW_HPP
-
-#include <stdint.h>
-
-#include <dwarf.h>
-#include <elfutils/libdw.h>
-
-#include "mc/Frame.hpp"
-#include "mc/ObjectInformation.hpp"
-#include "mc/Variable.hpp"
-
-/** \brief Computes the the element_count of a DW_TAG_enumeration_type DIE
- *
- * This is the number of elements in a given array dimension.
- *
- * A reference of the compilation unit (DW_TAG_compile_unit) is
- * needed because the default lower bound (when there is no DW_AT_lower_bound)
- * depends of the language of the compilation unit (DW_AT_language).
- *
- * \param die  DIE for the DW_TAG_enumeration_type or DW_TAG_subrange_type
- * \param unit DIE of the DW_TAG_compile_unit
- */
-static std::uint64_t MC_dwarf_subrange_element_count(Dwarf_Die * die,
-                                                Dwarf_Die * unit);
-
-/** \brief Computes the number of elements of a given DW_TAG_array_type.
- *
- * \param die DIE for the DW_TAG_array_type
- */
-static std::uint64_t MC_dwarf_array_element_count(Dwarf_Die * die, Dwarf_Die * unit);
-
-/** \brief Process a DIE
- *
- *  \param info the resulting object fot the library/binary file (output)
- *  \param die  the current DIE
- *  \param unit the DIE of the compile unit of the current DIE
- *  \param frame containg frame if any
- */
-static void MC_dwarf_handle_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
-                                Dwarf_Die * unit, simgrid::mc::Frame* frame,
-                                const char *ns);
-
-/** \brief Process a type DIE
- */
-static void MC_dwarf_handle_type_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
-                                     Dwarf_Die * unit, simgrid::mc::Frame* frame,
-                                     const char *ns);
-
-/** \brief Calls MC_dwarf_handle_die on all childrend of the given die
- *
- *  \param info the resulting object fot the library/binary file (output)
- *  \param die  the current DIE
- *  \param unit the DIE of the compile unit of the current DIE
- *  \param frame containg frame if any
- */
-static void MC_dwarf_handle_children(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
-                                     Dwarf_Die * unit, simgrid::mc::Frame* frame,
-                                     const char *ns);
-
-/** \brief Handle a variable (DW_TAG_variable or other)
- *
- *  \param info the resulting object fot the library/binary file (output)
- *  \param die  the current DIE
- *  \param unit the DIE of the compile unit of the current DIE
- *  \param frame containg frame if any
- */
-static void MC_dwarf_handle_variable_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
-                                         Dwarf_Die * unit, simgrid::mc::Frame* frame,
-                                         const char *ns);
-
-/** \brief Get the DW_TAG_type of the DIE
- *
- *  \param die DIE
- *  \return DW_TAG_type attribute as a new string (NULL if none)
- */
-static std::uint64_t MC_dwarf_at_type(Dwarf_Die * die);
-
-#endif
index 455a716..1f82a16 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <libunwind.h>
 #include <dwarf.h>
+#include <elfutils/libdw.h>
 
 #include <simgrid_config.h>
 #include "mc_base.h"
 namespace simgrid {
 namespace mc {
 
-typedef struct
-{
-  uint8_t atom;
-  std::uint64_t number;
-  std::uint64_t number2;
-  std::uint64_t offset;
-} DwarfInstruction;
+typedef std::vector<Dwarf_Op> DwarfExpression;
 
-typedef std::vector<DwarfInstruction> DwarfExpression;
 
 /** \brief A DWARF expression with optional validity contraints */
 class LocationListEntry {
@@ -107,6 +101,10 @@ void mc_dwarf_resolve_locations(
   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);
+
 #define MC_EXPRESSION_STACK_SIZE 64
 
 #define MC_EXPRESSION_OK 0
@@ -128,9 +126,8 @@ typedef struct s_mc_expression_state {
   int process_index;
 } s_mc_expression_state_t, *mc_expression_state_t;
 
-int mc_dwarf_execute_expression(
-  size_t n, const simgrid::mc::DwarfInstruction* ops, mc_expression_state_t state);
-
+XBT_PUBLIC(int) mc_dwarf_execute_expression(
+  size_t n, const Dwarf_Op* ops, mc_expression_state_t state);
 void* mc_find_frame_base(
   simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info, unw_cursor_t* unw_cursor);
 
index 3697e3a..29fe1f5 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <xbt/misc.h>
 
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc_private.h"
 #include "mc/Type.hpp"
 
index 504ec57..1148634 100644 (file)
@@ -12,7 +12,7 @@
 #include "xbt/virtu.h"
 
 #include "mc/mc.h"
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc_private.h"
 
 extern "C" {
diff --git a/src/mc/mc_object_info.h b/src/mc/mc_object_info.h
new file mode 100644 (file)
index 0000000..1da12e8
--- /dev/null
@@ -0,0 +1,32 @@
+/* Copyright (c) 2007-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_INFO_H
+#define SIMGRID_MC_OBJECT_INFO_H
+
+#include <vector>
+#include <memory>
+
+#include <xbt/base.h>
+
+#include "mc_forward.hpp"
+#include "mc_memory_map.h"
+
+XBT_PRIVATE std::shared_ptr<simgrid::mc::ObjectInformation> MC_find_object_info(
+  std::vector<simgrid::mc::VmMap> const& maps, const char* name, int executable);
+XBT_PRIVATE  void MC_post_process_object_info(simgrid::mc::Process* process, simgrid::mc::ObjectInformation* info);
+
+XBT_PRIVATE  void MC_dwarf_get_variables(simgrid::mc::ObjectInformation* info);
+XBT_PRIVATE  void MC_dwarf_get_variables_libdw(simgrid::mc::ObjectInformation* info);
+
+XBT_PRIVATE  const char* MC_dwarf_attrname(int attr);
+XBT_PRIVATE  const char* MC_dwarf_tagname(int tag);
+
+XBT_PRIVATE  void* mc_member_resolve(
+  const void* base, simgrid::mc::Type* type, simgrid::mc::Type* member,
+  simgrid::mc::AddressSpace* snapshot, int process_index);
+
+#endif
index 2efe58b..b180c40 100644 (file)
@@ -15,6 +15,9 @@
 
 #include <xbt/mmalloc.h>
 
+#define SOFT_DIRTY_BIT_NUMBER 55
+#define SOFT_DIRTY (((uint64_t)1) << SOFT_DIRTY_BIT_NUMBER)
+
 using simgrid::mc::remote;
 
 namespace simgrid {
@@ -27,7 +30,8 @@ namespace mc {
  *  @return                Snapshot page numbers of this new snapshot
  */
 PerPageCopy::PerPageCopy(PageStore& store, AddressSpace& as,
-    remote_ptr<void> addr, std::size_t page_count)
+    remote_ptr<void> addr, std::size_t page_count,
+    const size_t* ref_page_numbers, const std::uint64_t* pagemap)
 {
   store_ = &store;
   this->pagenos_.resize(page_count);
@@ -35,6 +39,13 @@ PerPageCopy::PerPageCopy(PageStore& store, AddressSpace& as,
 
   for (size_t i = 0; i != page_count; ++i) {
 
+    // We don't have to compare soft-clean pages:
+    if (ref_page_numbers && pagemap && !(pagemap[i] & SOFT_DIRTY)) {
+      pagenos_[i] = ref_page_numbers[i];
+      store_->ref_page(ref_page_numbers[i]);
+      continue;
+    }
+
       remote_ptr<void> page = remote(addr.address() + (i << xbt_pagebits));
       xbt_assert(mc_page_offset((void*)page.address())==0,
         "Not at the beginning of a page");
index 909267d..f88c5c4 100644 (file)
@@ -16,6 +16,7 @@
 #ifndef WIN32
 #include <sys/mman.h>
 #endif
+#include <elfutils/libdw.h>
 
 #include "mc/mc.h"
 #include "mc_base.h"
@@ -117,6 +118,8 @@ XBT_PRIVATE void MC_report_assertion_error(void);
 
 XBT_PRIVATE void MC_invalidate_cache(void);
 
+XBT_PRIVATE int MC_important_snapshot(mc_snapshot_t snapshot);
+
 SG_END_DECL()
 
 #endif
index dec40ac..2a70cb5 100644 (file)
@@ -28,7 +28,7 @@
 #include <xbt/mmalloc.h>
 
 #include "mc_process.h"
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc_unw.h"
 #include "mc_snapshot.h"
 #include "mc_ignore.h"
@@ -131,6 +131,7 @@ static ssize_t pread_whole(int fd, void *buf, size_t count, std::uint64_t offset
     } else if (res==0) {
       return -1;
     } else if (errno != EINTR) {
+      perror("pread_whole");
       return -1;
     }
   }
@@ -171,6 +172,14 @@ static void MC_zero_buffer_init(void)
   close(fd);
 }
 
+static
+int open_process_file(pid_t pid, const char* file, int flags)
+{
+  char buff[50];
+  snprintf(buff, sizeof(buff), "/proc/%li/%s", (long) pid, file);
+  return open(buff, flags);
+}
+
 }
 
 namespace simgrid {
@@ -213,6 +222,8 @@ Process::Process(pid_t pid, int sockfd)
   process->heap = NULL;
   process->heap_info = NULL;
   process->init_memory_map_info();
+  process->clear_refs_fd_ = -1;
+  process->pagemap_fd_ = -1;
 
   // Open the memory file
   if (process->is_self())
@@ -284,6 +295,11 @@ Process::~Process()
 
   free(process->heap_info);
   process->heap_info = NULL;
+
+  if (process->clear_refs_fd_ >= 0)
+    close(process->clear_refs_fd_);
+  if (process->pagemap_fd_ >= 0)
+    close(process->pagemap_fd_);
 }
 
 /** Refresh the information about the process
@@ -642,5 +658,29 @@ void Process::ignore_region(std::uint64_t addr, std::size_t size)
     ignored_regions_.begin() + position, region);
 }
 
+void Process::reset_soft_dirty()
+{
+  if (this->clear_refs_fd_ < 0) {
+    this->clear_refs_fd_ = open_process_file(pid_, "clear_refs", O_WRONLY|O_CLOEXEC);
+    if (this->clear_refs_fd_ < 0)
+      xbt_die("Could not open clear_refs file for soft-dirty tracking. Run as root?");
+  }
+  if(::write(this->clear_refs_fd_, "4\n", 2) != 2)
+    xbt_die("Could not reset softdirty bits");
+}
+
+void Process::read_pagemap(uint64_t* pagemap, size_t page_start, size_t page_count)
+{
+  if (pagemap_fd_ < 0) {
+    pagemap_fd_ = open_process_file(pid_, "pagemap", O_RDONLY|O_CLOEXEC);
+    if (pagemap_fd_ < 0)
+      xbt_die("Could not open pagemap file for soft-dirty tracking. Run as root?");
+  }
+  ssize_t bytesize = sizeof(uint64_t) * page_count;
+  off_t offset = sizeof(uint64_t) * page_start;
+  if (pread_whole(pagemap_fd_, pagemap, bytesize, offset) != bytesize)
+    xbt_die("Could not read pagemap");
+}
+
 }
 }
index 570d84b..4c21485 100644 (file)
@@ -158,6 +158,9 @@ public:
     return MC_receive_message(this->socket_, &m, sizeof(M), 0);
   }
 
+  void reset_soft_dirty();
+  void read_pagemap(uint64_t* pagemap, size_t start_page, size_t page_count);
+
 private:
   void init_memory_map_info();
   void refresh_heap();
@@ -172,7 +175,8 @@ private:
   remote_ptr<void> maestro_stack_start_, maestro_stack_end_;
   int memory_file;
   std::vector<IgnoredRegion> ignored_regions_;
-
+  int clear_refs_fd_;
+  int pagemap_fd_;
 public: // object info
   // TODO, make private (first, objectify simgrid::mc::ObjectInformation*)
   std::vector<std::shared_ptr<simgrid::mc::ObjectInformation>> object_infos;
index 3aabd13..c4662ec 100644 (file)
@@ -243,12 +243,12 @@ static void test_snapshot(bool sparse_checkpoint) {
     // Init memory and take snapshots:
     init_memory(source, byte_size);
     simgrid::mc::RegionSnapshot region0 = simgrid::mc::sparse_region(
-      simgrid::mc::RegionType::Unknown, source, source, byte_size);
+      simgrid::mc::RegionType::Unknown, source, source, byte_size, nullptr);
     for(int i=0; i<n; i+=2) {
       init_memory((char*) source + i*xbt_pagesize, xbt_pagesize);
     }
     simgrid::mc::RegionSnapshot region = simgrid::mc::sparse_region(
-      simgrid::mc::RegionType::Unknown, source, source, byte_size);
+      simgrid::mc::RegionType::Unknown, source, source, byte_size, nullptr);
 
     void* destination = mmap(NULL, byte_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
     xbt_assert(source!=MAP_FAILED, "Could not allocate destination memory");
@@ -283,7 +283,7 @@ static void test_snapshot(bool sparse_checkpoint) {
       xbt_test_add("Read pointer for %i page(s)", n);
       memcpy(source, &mc_model_checker, sizeof(void*));
       simgrid::mc::RegionSnapshot region2 = simgrid::mc::sparse_region(
-        simgrid::mc::RegionType::Unknown, source, source, byte_size);
+        simgrid::mc::RegionType::Unknown, source, source, byte_size, nullptr);
       xbt_test_assert(MC_region_read_pointer(&region2, source) == mc_model_checker,
         "Mismtach in MC_region_read_pointer()");
     }
index 7ef1870..72965f4 100644 (file)
@@ -54,7 +54,7 @@ void* mc_translate_address_region(uintptr_t addr, mc_mem_region_t region, int pr
   case simgrid::mc::StorageType::Flat:
     {
       uintptr_t offset = (uintptr_t) addr - (uintptr_t) region->start().address();
-      return (void *) ((uintptr_t) region->flat_data().data() + offset);
+      return (void *) ((uintptr_t) region->flat_data() + offset);
     }
 
   case simgrid::mc::StorageType::Chunked:
@@ -227,7 +227,7 @@ const void* MC_region_read(mc_mem_region_t region, void* target, const void* add
     xbt_die("Storage type not supported");
 
   case simgrid::mc::StorageType::Flat:
-    return (char*) region->flat_data().data() + offset;
+    return (char*) region->flat_data() + offset;
 
   case simgrid::mc::StorageType::Chunked:
     {
index cac27c1..899b403 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <libunwind.h>
 
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc_process.h"
 #include "mc_unw.h"
 #include "mc/Frame.hpp"
index edcfcff..104576b 100644 (file)
@@ -349,7 +349,7 @@ mc_visited_state_t is_visited_state(mc_state_t graph_state)
       unsigned int cursor2 = 0;
       unsigned int index2 = 0;
       xbt_dynar_foreach(visited_states, cursor2, state_test){
-        if (state_test->num < min2) {
+        if (!MC_important_snapshot(state_test->system_state) && state_test->num < min2) {
           index2 = cursor2;
           min2 = state_test->num;
         }
@@ -466,7 +466,8 @@ int is_visited_pair(mc_visited_pair_t visited_pair, mc_pair_t pair) {
       unsigned int cursor2 = 0;
       unsigned int index2 = 0;
       xbt_dynar_foreach(visited_pairs, cursor2, pair_test) {
-        if (pair_test->num < min2) {
+        if (!MC_important_snapshot(pair_test->graph_state->system_state)
+            && pair_test->num < min2) {
           index2 = cursor2;
           min2 = pair_test->num;
         }
index 6d898a2..5b0b6c7 100644 (file)
@@ -7,7 +7,7 @@
 #include <xbt/base.h>
 
 #include "internal_config.h"
-#include "mc_dwarf.hpp"
+#include "mc_object_info.h"
 #include "mc/mc_private.h"
 #include "smpi/private.h"
 #include "mc/mc_snapshot.h"
index 0455482..2ce94c9 100644 (file)
@@ -625,6 +625,17 @@ void sg_config_init(int *argc, char **argv)
                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_sparse_checkpoint, NULL);
     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/sparse-checkpoint", "no");
 
+    /* do stateful model-checking */
+    xbt_cfg_register(&_sg_cfg_set, "model-check/soft-dirty",
+                     "Use sparse per-page snapshots.",
+                     xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_soft_dirty, NULL);
+    xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/soft-dirty", "no");
+
+    xbt_cfg_register(&_sg_cfg_set, "model-check/ksm",
+                     "Kernel same-page merging",
+                     xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_ksm, NULL);
+    xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/ksm", "no");
+
     /* do liveness model-checking */
     xbt_cfg_register(&_sg_cfg_set, "model-check/property",
                      "Specify the name of the file containing the property. It must be the result of the ltl2ba program.",
index 1de1de7..ee7138c 100644 (file)
@@ -15,7 +15,7 @@
 #include <mc/mc.h>
 
 #include "mc/datatypes.h"
-#include "mc/mc_dwarf.hpp"
+#include "mc/mc_object_info.h"
 #include "mc/mc_private.h"
 #include "mc/mc_process.h"
 
index 5184e48..32798ad 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "mc/mc_process.h"
 #include "mc/mc_private.h"
-#include "mc/mc_dwarf.hpp"
+#include "mc/mc_object_info.h"
 
 #include "mc/Type.hpp"
 #include "mc/ObjectInformation.hpp"
@@ -26,7 +26,7 @@ static
 uintptr_t eval_binary_operation(mc_expression_state_t state, int op, uintptr_t a, uintptr_t b) {
   state->stack_size = 0;
 
-  simgrid::mc::DwarfInstruction ops[15];
+  Dwarf_Op ops[15];
   ops[0].atom = DW_OP_const8u;
   ops[0].number = a;
   ops[1].atom = DW_OP_const8u;
@@ -40,7 +40,7 @@ uintptr_t eval_binary_operation(mc_expression_state_t state, int op, uintptr_t a
 
 static
 void basic_test(mc_expression_state_t state) {
-  simgrid::mc::DwarfInstruction ops[60];
+  Dwarf_Op ops[60];
 
   uintptr_t a = rand();
   uintptr_t b = rand();
@@ -108,7 +108,7 @@ static
 void test_deref(mc_expression_state_t state) {
   uintptr_t foo = 42;
 
-  simgrid::mc::DwarfInstruction ops[60];
+  Dwarf_Op ops[60];
   ops[0].atom = DW_OP_const8u;
   ops[0].number = (uintptr_t) &foo;
   ops[1].atom = DW_OP_deref;
index 76a90bf..e251a0e 100644 (file)
@@ -622,7 +622,7 @@ set(MC_SRC
   src/mc/mc_unw.cpp
   src/mc/mc_unw_vmread.cpp
   src/mc/mc_mmalloc.h
-  src/mc/mc_dwarf.hpp
+  src/mc/mc_object_info.h
   src/mc/mc_checkpoint.cpp
   src/mc/mc_snapshot.h
   src/mc/mc_snapshot.cpp
@@ -633,9 +633,6 @@ set(MC_SRC
   src/mc/mc_compare.cpp
   src/mc/mc_diff.cpp
   src/mc/mc_dwarf.cpp
-  src/mc/mc_dwarf.hpp
-  src/mc/mc_libdw.cpp
-  src/mc/mc_libdw.hpp
   src/mc/mc_dwarf_attrnames.cpp
   src/mc/mc_dwarf_expression.cpp
   src/mc/mc_dwarf_tagnames.cpp
index addd60b..984287c 100755 (executable)
@@ -3,7 +3,7 @@
 # Usage: tools/generate-dwarf-functions /usr/include/dwarf.h
 
 cat - > src/mc/mc_dwarf_tagnames.cpp <<EOF
-/* Copyright (c) 2014-2015. The SimGrid Team.
+/* Copyright (c) 2014. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -12,8 +12,10 @@ cat - > src/mc/mc_dwarf_tagnames.cpp <<EOF
 /* Warning: autogenerated, do not edit! */
 
 #include <dwarf.h>
+#include <elfutils/libdw.h>
 
 #include <xbt/base.h>
+#include "mc_object_info.h"
 
 /** \brief Get the name of a dwarf tag (DW_TAG_*) from its code
  *
@@ -25,6 +27,8 @@ const char *MC_dwarf_tagname(int tag)
 {
   switch (tag) {
 $(cat "$1" | grep DW_TAG_ | sed 's/.*\(DW_TAG_[^ ]*\) = \(0x[0-9a-f]*\).*/  case \2: return "\1";/')
+  case DW_TAG_invalid:
+    return "DW_TAG_invalid";
   default:
     return "DW_TAG_unknown";
   }
@@ -32,7 +36,7 @@ $(cat "$1" | grep DW_TAG_ | sed 's/.*\(DW_TAG_[^ ]*\) = \(0x[0-9a-f]*\).*/  case
 EOF
 
 cat - > src/mc/mc_dwarf_attrnames.cpp << EOF
-/* Copyright (c) 2014-2015. The SimGrid Team.
+/* Copyright (c) 2014. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -43,6 +47,8 @@ cat - > src/mc/mc_dwarf_attrnames.cpp << EOF
 #include <xbt/base.h>
 #include <dwarf.h>
 
+#include "mc_object_info.h"
+
 /** \brief Get the name of an attribute (DW_AT_*) from its code
  *
  *  \param attr attribute code (see the DWARF specification)