8#include "cpptrace/cpptrace.hpp"
12bool stacktrace_enabled =
true;
14void print_stacktrace(std::size_t skip = 0)
16 const auto trace = cpptrace::generate_trace(skip + 1);
20void print_panic_header(
const std::filesystem::path &path, std::uint_least32_t line, std::string_view msg)
22 std::cerr <<
"---------------------------------" << std::endl;
23 std::cerr <<
"| PANIC |" << std::endl;
24 std::cerr <<
"---------------------------------" << std::endl;
25 std::cerr << std::format(
"{}:{}: {}", path.filename().string(), line, msg) << std::endl;
26 std::cerr << std::endl;
35 stacktrace_enabled = enabled;
40 return stacktrace_enabled;
45 const std::filesystem::path path{s.
loc_.file_name()};
46 print_panic_header(path, s.
loc_.line(), s.
msg_);
47 if (stacktrace_enabled) {
56 const std::filesystem::path path{s.
loc_.file_name()};
57 print_panic_header(path, s.
loc_.line(), s.
msg_);
58 if (stacktrace_enabled) {
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
void assert_or_panic(bool condition, const StringViewSourceLoc &s)
Conditionally panics if the given condition is false.
bool is_panic_stacktrace_enabled()
Returns whether stacktrace generation is enabled on panic.
void set_panic_stacktrace_enabled(bool enabled)
Enables or disables stacktrace generation on panic.
A wrapper for std::string_view with a taggable std::source_location.
std::source_location loc_