32 #if !defined(STX_NO_STD_THREAD_MUTEX) 40 #if defined(STX_ENABLE_PANIC_BACKTRACE) 63 static constexpr
const int kFmtBufferSize = 64;
65 #if !defined(STX_NO_STD_THREAD_MUTEX) 67 static constexpr
const auto kThreadIdHasher = std::hash<std::thread::id>{};
69 static std::mutex stderr_lock;
74 static char fmt_buffer[kFmtBufferSize];
78 thread_local
size_t const thread_id_hash =
79 kThreadIdHasher(std::this_thread::get_id());
85 char fmt_buffer[kFmtBufferSize];
89 std::fputs(
"\nthread", stderr);
91 #if !defined(STX_NO_STD_THREAD_MUTEX) 93 std::fputs(
" with hash: '", stderr);
99 std::fputs(
"' panicked with: '", stderr);
101 for (
char c : info) {
102 std::fputc(c, stderr);
105 if (!payload.data().empty()) {
106 std::fputs(
": ", stderr);
108 for (
auto c : payload.data()) {
109 std::fputc(c, stderr);
113 std::fputs(
"' at function: '", stderr);
115 std::fputs(location.function_name(), stderr);
117 std::fputs(
"' [", stderr);
119 std::fputs(location.file_name(), stderr);
121 std::fputc(
':', stderr);
123 auto line = location.line();
128 std::fputs(
"unknown", stderr);
131 std::fputc(
':', stderr);
133 auto column = location.column();
138 std::fputs(
"unknown", stderr);
141 std::fputs(
"]\n", stderr);
145 #if defined(STX_ENABLE_PANIC_BACKTRACE) 148 "\nBacktrace:\nip: Instruction Pointer, sp: Stack " 154 auto const print_none = []() { std::fputs(
"unknown", stderr); };
156 auto const print_ptr = [](uintptr_t ip) {
165 for (
char c : sym.
raw()) {
166 std::fputc(c, stderr);
171 std::fputs(
"\t (ip: ", stderr);
173 frame.
ip.
match(print_ptr, print_none);
175 std::fputs(
", sp: ", stderr);
177 frame.
sp.
match(print_ptr, print_none);
179 std::fputs(
")\n", stderr);
187 R
"(WARNING >> The stack frames couldn't be identified, debug information was possibly stripped, unavailable, or elided by compiler 192 std::fputs("\n", stderr);
196 #if !defined(STX_NO_STD_THREAD_MUTEX) 198 stderr_lock.unlock();
constexpr auto match(SomeFn &&some_fn, NoneFn &&none_fn) &&-> invoke_result< SomeFn &&, T &&>
Definition: option_result.h:1470
Option< uintptr_t > sp
address on the call stack
Definition: backtrace.h:102
int trace(Callback callback, int skip_count=0)
Option< Symbol > symbol
function's symbol name. possibly demangled.
Definition: backtrace.h:106
auto raw() const noexcept -> std::string_view
gets the raw symbol name, the symbol is pre-demangled if possible.
reperesents an active stack frame.
Definition: backtrace.h:98
void panic_default(std::string_view const &info, ReportPayload const &payload, SourceLocation const &location) noexcept
Definition: default.h:58
#define STX_PANIC_EPRINTF(STX_ARG_STR_SIZE, STX_ARG_FORMAT, STX_ARG_VALUE)
printf, makes own buffer
Definition: print.h:54
Option< uintptr_t > ip
instruction pointer
Definition: backtrace.h:100
#define STX_END_NAMESPACE
Definition: config.h:329
constexpr int kI32FmtSize
10 digits + 1 sign
Definition: common.h:118
constexpr int kxPtrFmtSize
Definition: common.h:110
Definition: backtrace.h:82
Definition: source_location.h:48
#define STX_PANIC_EPRINTF_WITH(STX_ARG_BUFFER, STX_ARG_BUFFER_SIZE, STX_ARG_FORMAT, STX_ARG_VALUE)
printf using a provided buffer
Definition: print.h:39
#define STX_BEGIN_NAMESPACE
Definition: config.h:325