Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mc: move some files related to ELF, DWARF or unwind reading into their own directory
[simgrid.git] / src / mc / inspect / Frame.cpp
diff --git a/src/mc/inspect/Frame.cpp b/src/mc/inspect/Frame.cpp
new file mode 100644 (file)
index 0000000..2d8620f
--- /dev/null
@@ -0,0 +1,36 @@
+/* Copyright (c) 2007-2019. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <libunwind.h>
+
+#include "xbt/sysdep.h"
+
+#include "src/mc/Frame.hpp"
+
+namespace simgrid {
+namespace mc {
+
+void* Frame::frame_base(unw_cursor_t& unw_cursor) const
+{
+  simgrid::dwarf::Location location =
+      simgrid::dwarf::resolve(frame_base_location, object_info, &unw_cursor, nullptr, nullptr, -1);
+  if (location.in_memory())
+    return location.address();
+  else if (location.in_register()) {
+    // This is a special case.
+    // The register is not the location of the frame base
+    // (a frame base cannot be located in a register).
+    // Instead, DWARF defines this to mean that the register
+    // contains the address of the frame base.
+    unw_word_t word;
+    unw_get_reg(&unw_cursor, location.register_id(), &word);
+    return (void*)word;
+  } else
+    xbt_die("Unexpected location type");
+}
+
+} // namespace mc
+} // namespace simgrid