From 176ef214f2a9cb6713e2131d024acbe949620838 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 6 Jul 2021 20:54:37 -0500 Subject: [PATCH] [ox/std] Make symbolicate return more flexible data --- deps/ox/src/ox/std/stacktrace.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/deps/ox/src/ox/std/stacktrace.cpp b/deps/ox/src/ox/std/stacktrace.cpp index 6fc21044..ca1e8193 100644 --- a/deps/ox/src/ox/std/stacktrace.cpp +++ b/deps/ox/src/ox/std/stacktrace.cpp @@ -26,20 +26,20 @@ namespace ox { #if defined(OX_USE_STDLIB) && __has_include() [[nodiscard]] -static String symbolicate([[maybe_unused]]const char **frames, [[maybe_unused]]std::size_t symbolsLen, [[maybe_unused]]const char *linePrefix) { +static Vector symbolicate([[maybe_unused]]const char **frames, [[maybe_unused]]std::size_t symbolsLen, [[maybe_unused]]const char *linePrefix) { #if __has_include() - String out; + Vector out; for (auto i = 0u; i < symbolsLen; ++i) { Dl_info info; if (dladdr(frames[i], &info) && info.dli_sname) { int status = -1; const auto name = abi::__cxa_demangle(info.dli_sname, nullptr, 0, &status); if (status == 0) { - out += sfmt("\t{}: {}\n", i, name); + out.emplace_back(sfmt("{}: {}", i, name)); continue; } } - out += sfmt("\t{}\n", frames[i]); + out.emplace_back(sfmt("{}", frames[i])); } return move(out); #else // __has_include() @@ -56,7 +56,10 @@ void printStackTrace([[maybe_unused]]unsigned shave) noexcept { const auto symbols = backtrace_symbols(frames.data() + shave, frames.size() - shave); const auto symbolicatedStacktrace = symbolicate(bit_cast(frames.data() + shave), frames.size() - shave, "\t"); free(symbols); - oxErrf("Stacktrace:\n{}", symbolicatedStacktrace); + oxErr("Stacktrace:\n"); + for (const auto &s : symbolicatedStacktrace) { + oxErrf("\t{}\n", s); + } } #endif }