Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Make type_is an integer instead of a string and use std:: containers
[simgrid.git] / src / mc / mc_object_info.cpp
index e88aee0..7324681 100644 (file)
@@ -16,15 +16,14 @@ namespace mc {
 
 // Free functions
 
-static void mc_variable_free_voidp(void *t)
+static void mc_frame_free(void* frame)
 {
-  delete *(simgrid::mc::Variable**)t;
+  delete (simgrid::mc::Frame*)frame;
 }
 
-static void mc_frame_free_voipd(void** p)
+static void mc_type_free(void* t)
 {
-  delete *(mc_frame_t**)p;
-  *p = nullptr;
+  delete (simgrid::mc::Type*)t;
 }
 
 // Type
@@ -36,6 +35,7 @@ Type::Type()
   this->byte_size = 0;
   this->element_count = 0;
   this->is_pointer_type = 0;
+  this->type_id = 0;
   this->subtype = nullptr;
   this->full_type = nullptr;
 }
@@ -47,18 +47,12 @@ Variable::Variable()
   this->dwarf_offset = 0;
   this->global = 0;
   this->type = nullptr;
-  this->location_list = {0, nullptr};
+  this->type_id = 0;
   this->address = nullptr;
   this->start_scope = 0;
   this->object_info = nullptr;
 }
 
-Variable::~Variable()
-{
-  if (this->location_list.locations)
-    mc_dwarf_location_list_clear(&this->location_list);
-}
-
 // Frame
 
 Frame::Frame()
@@ -66,24 +60,62 @@ Frame::Frame()
   this->tag = 0;
   this->low_pc = nullptr;
   this->high_pc = nullptr;
-  this->frame_base = {0, nullptr};
-  this->variables = xbt_dynar_new(
-    sizeof(mc_variable_t), mc_variable_free_voidp);
   this->id = 0;
-  this->scopes = xbt_dynar_new(
-    sizeof(mc_frame_t), (void_f_pvoid_t) mc_frame_free_voipd);
   this->abstract_origin_id = 0;
   this->object_info = nullptr;
 }
 
-Frame::~Frame()
+// ObjectInformations
+
+ObjectInformation::ObjectInformation()
 {
-  mc_dwarf_location_list_clear(&(this->frame_base));
-  xbt_dynar_free(&(this->variables));
-  xbt_dynar_free(&(this->scopes));
+  this->flags = 0;
+  this->file_name = nullptr;
+  this->start = nullptr;
+  this->end = nullptr;
+  this->start_exec = nullptr;
+  this->end_exec = nullptr;
+  this->start_rw = nullptr;
+  this->end_rw = nullptr;
+  this->start_ro = nullptr;
+  this->end_ro = nullptr;
+  this->subprograms = xbt_dict_new_homogeneous(mc_frame_free);
+  this->functions_index = nullptr;
 }
 
-// ObjectInformations
+ObjectInformation::~ObjectInformation()
+{
+  xbt_free(this->file_name);
+  xbt_dict_free(&this->subprograms);
+  xbt_dynar_free(&this->functions_index);
+}
+
+/** Find the DWARF offset for this ELF object
+ *
+ *  An offset is applied to address found in DWARF:
+ *
+ *  <ul>
+ *    <li>for an executable obejct, addresses are virtual address
+ *        (there is no offset) i.e. \f$\text{virtual address} = \{dwarf address}\f$;</li>
+ *    <li>for a shared object, the addreses are offset from the begining
+ *        of the shared object (the base address of the mapped shared
+ *        object must be used as offset
+ *        i.e. \f$\text{virtual address} = \text{shared object base address}
+ *             + \text{dwarf address}\f$.</li>
+ *
+ */
+void *ObjectInformation::base_address() const
+{
+  if (this->executable())
+    return nullptr;
+
+  void *result = this->start_exec;
+  if (this->start_rw != NULL && result > (void *) this->start_rw)
+    result = this->start_rw;
+  if (this->start_ro != NULL && result > (void *) this->start_ro)
+    result = this->start_ro;
+  return result;
+}
 
 mc_frame_t ObjectInformation::find_function(const void *ip) const
 {
@@ -105,13 +137,11 @@ mc_frame_t ObjectInformation::find_function(const void *ip) const
   return nullptr;
 }
 
-mc_variable_t ObjectInformation::find_variable(const char* name) const
+simgrid::mc::Variable* ObjectInformation::find_variable(const char* name) const
 {
-  unsigned int cursor = 0;
-  mc_variable_t variable;
-  xbt_dynar_foreach(this->global_variables, cursor, variable)
-    if(variable->name == name)
-      return variable;
+  for (simgrid::mc::Variable& variable : this->global_variables)
+    if(variable.name == name)
+      return &variable;
   return nullptr;
 }