aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/vm/Stacktrace.hpp
blob: 35f8a0cec89a4cc3ebed3d33254b61b424528371 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include <optional>

#include "Utility.hpp"
#include <lauf/runtime/stacktrace.h>

namespace OpenVic::Vm {
   struct RuntimeFiber;

   struct StacktraceRef : utility::HandleBase<lauf_runtime_stacktrace> {
      using HandleBase<lauf_runtime_stacktrace>::HandleBase;

      std::optional<StacktraceRef> get_parent() {
         auto result = lauf_runtime_stacktrace_parent(_handle);
         if (result == nullptr) {
            _handle = nullptr;
            return std::nullopt;
         }
         return StacktraceRef(result);
      }
   };

   struct Stacktrace : utility::MoveOnlyHandleDerived<Stacktrace, StacktraceRef> {
      using MoveOnlyHandleDerived::MoveOnlyHandleDerived;
      using MoveOnlyHandleDerived::operator=;

      ~Stacktrace() {
         if (_handle == nullptr) {
            return;
         }
         lauf_runtime_destroy_stacktrace(_handle);
         _handle = nullptr;
      }
   };
}