aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/vm/Stacktrace.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/vm/Stacktrace.hpp')
-rw-r--r--src/openvic-simulation/vm/Stacktrace.hpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/openvic-simulation/vm/Stacktrace.hpp b/src/openvic-simulation/vm/Stacktrace.hpp
new file mode 100644
index 0000000..016443a
--- /dev/null
+++ b/src/openvic-simulation/vm/Stacktrace.hpp
@@ -0,0 +1,65 @@
+#pragma once
+
+#include <optional>
+
+#include <lauf/runtime/stacktrace.h>
+
+namespace OpenVic::Vm {
+ struct RuntimeFiber;
+
+ struct StacktraceRef {
+ lauf_runtime_stacktrace* handle() {
+ return _handle;
+ }
+
+ const lauf_runtime_stacktrace* handle() const {
+ return _handle;
+ }
+
+ operator lauf_runtime_stacktrace*() {
+ return _handle;
+ }
+
+ operator const lauf_runtime_stacktrace*() const {
+ return _handle;
+ }
+
+ std::optional<StacktraceRef> get_parent() {
+ auto result = lauf_runtime_stacktrace_parent(_handle);
+ if (result == nullptr) {
+ return std::nullopt;
+ }
+ return StacktraceRef(result);
+ }
+
+ protected:
+ friend struct RuntimeFiber;
+ StacktraceRef(lauf_runtime_stacktrace* stacktrace) : _handle(stacktrace) {}
+
+ lauf_runtime_stacktrace* _handle;
+ };
+
+ struct Stacktrace : StacktraceRef {
+ Stacktrace(Stacktrace&&) = default;
+ Stacktrace& operator=(Stacktrace&&) = default;
+
+ StacktraceRef& as_ref() {
+ return *this;
+ }
+
+ StacktraceRef const& as_ref() const {
+ return *this;
+ }
+
+ Stacktrace(Stacktrace const&) = delete;
+ Stacktrace& operator=(Stacktrace const&) = delete;
+
+ ~Stacktrace() {
+ lauf_runtime_destroy_stacktrace(_handle);
+ }
+
+ private:
+ friend struct RuntimeFiber;
+ Stacktrace(lauf_runtime_stacktrace* stacktrace) : StacktraceRef(stacktrace) {}
+ };
+}