Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Remove useless declarations
[simgrid.git] / src / mc / mc_dwarf_expression.cpp
index bf80037..cc9b6a6 100644 (file)
@@ -5,13 +5,12 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <cstdint>
-
-#include <stdint.h>
-#include <stdarg.h>
+#include <cstdarg>
 
 #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,13 +101,13 @@ 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;
-    uint8_t atom = op->atom;
+    const Dwarf_Op *op = ops + i;
+    std::uint8_t atom = op->atom;
 
     switch (atom) {
 
@@ -182,7 +181,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
       {
         if (!state->frame_base)
           return MC_EXPRESSION_E_MISSING_FRAME_BASE;
-        uintptr_t fb = ((uintptr_t) state->frame_base) + op->number;
+        std::uintptr_t fb = ((std::uintptr_t) state->frame_base) + op->number;
         error = mc_dwarf_push_value(state, fb);
         break;
       }
@@ -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) (std::uintptr_t)
         state->object_info->base_address() + op->number;
       error = mc_dwarf_push_value(state, addr);
       break;
@@ -280,7 +279,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
       if (state->stack_size < 2)
         return MC_EXPRESSION_E_STACK_UNDERFLOW;
       {
-        uintptr_t temp = state->stack[state->stack_size - 2];
+        std::uintptr_t temp = state->stack[state->stack_size - 2];
         state->stack[state->stack_size - 2] =
             state->stack[state->stack_size - 1];
         state->stack[state->stack_size - 1] = temp;
@@ -303,7 +302,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
       if (state->stack_size < 2)
         return MC_EXPRESSION_E_STACK_UNDERFLOW;
       {
-        uintptr_t result =
+        std::uintptr_t result =
             state->stack[state->stack_size - 2] +
             state->stack[state->stack_size - 1];
         state->stack[state->stack_size - 2] = result;
@@ -315,7 +314,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
       if (state->stack_size < 2)
         return MC_EXPRESSION_E_STACK_UNDERFLOW;
       {
-        uintptr_t result =
+        std::uintptr_t result =
             state->stack[state->stack_size - 2] -
             state->stack[state->stack_size - 1];
         state->stack[state->stack_size - 2] = result;
@@ -351,7 +350,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
       if (state->stack_size < 2)
         return MC_EXPRESSION_E_STACK_UNDERFLOW;
       {
-        uintptr_t result =
+        std::uintptr_t result =
             state->stack[state->stack_size - 2] -
             state->stack[state->stack_size - 1];
         state->stack[state->stack_size - 2] = result;
@@ -363,7 +362,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
       if (state->stack_size < 2)
         return MC_EXPRESSION_E_STACK_UNDERFLOW;
       {
-        uintptr_t result =
+        std::uintptr_t result =
             state->stack[state->stack_size -
                          2] & state->stack[state->stack_size - 1];
         state->stack[state->stack_size - 2] = result;
@@ -375,7 +374,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
       if (state->stack_size < 2)
         return MC_EXPRESSION_E_STACK_UNDERFLOW;
       {
-        uintptr_t result =
+        std::uintptr_t result =
             state->stack[state->stack_size -
                          2] | state->stack[state->stack_size - 1];
         state->stack[state->stack_size - 2] = result;
@@ -387,7 +386,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
       if (state->stack_size < 2)
         return MC_EXPRESSION_E_STACK_UNDERFLOW;
       {
-        uintptr_t result =
+        std::uintptr_t result =
             state->stack[state->stack_size -
                          2] ^ state->stack[state->stack_size - 1];
         state->stack[state->stack_size - 2] = result;
@@ -408,7 +407,7 @@ int mc_dwarf_execute_expression(size_t n, const simgrid::mc::DwarfInstruction* o
         return MC_EXPRESSION_E_STACK_UNDERFLOW;
       {
         // Computed address:
-        uintptr_t address = (uintptr_t) state->stack[state->stack_size - 1];
+        std::uintptr_t address = (std::uintptr_t) state->stack[state->stack_size - 1];
         if (!state->address_space)
           xbt_die("Missing address space");
         state->address_space->read_bytes(
@@ -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();
+
+  std::ptrdiff_t offset = 0;
+  Dwarf_Addr base, start, end;
+  Dwarf_Op *ops;
+  std::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));
+  }
+
+}
+
 }