Echo Writes Code

backtrace.hpp

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef CRUCIBLE_PROCESS_BACKTRACE_HPP
#define CRUCIBLE_PROCESS_BACKTRACE_HPP

#include "crucible/process/errors.hpp"

#include <cstddef>
#include <string>
#include <vector>

namespace crucible::process::backtrace {
  class DetailedStackFrame final {
  public:
    DetailedStackFrame(std::string const &function, std::string const &file, std::size_t const line);

    [[nodiscard]]
    auto get_function() const -> std::string;

    [[nodiscard]]
    auto get_file() const -> std::string;

    [[nodiscard]]
    auto get_line() const -> std::size_t;

    [[nodiscard]]
    auto describe() const -> std::string;

    [[nodiscard]]
    auto format() const -> std::string;

  private:
    std::string my_function {};

    std::string my_file {};

    std::size_t my_line { 0 };
  };

  class SimpleStackFrame final {
  public:
    SimpleStackFrame(std::string const &function, std::string const &details);

    [[nodiscard]]
    auto get_function() const -> std::string;

    [[nodiscard]]
    auto get_details() const -> std::string;

    [[nodiscard]]
    auto describe() const -> std::string;

    [[nodiscard]]
    auto format() const -> std::string;

  private:
    std::string my_function {};

    std::string my_details {};
  };

  [[nodiscard]]
  auto take_detailed_snapshot() -> core::result::Result<process::errors::Error, std::vector<DetailedStackFrame>>;

  [[nodiscard]]
  auto take_simple_snapshot() -> core::result::Result<process::errors::Error, std::vector<SimpleStackFrame>>;

  [[noreturn]]
  auto terminate_handler() -> void;
}

#endif // CRUCIBLE_PROCESS_BACKTRACE_HPP