66
77#include < array>
88#include < cstddef>
9+ #include < cstdint>
910#include < format>
11+ #include < span>
12+ #include < utility>
1013
1114#include " runtime-common/core/runtime-core.h"
1215#include " runtime-light/k2-platform/k2-api.h"
1316#include " runtime-light/stdlib/diagnostics/backtrace.h"
1417#include " runtime-light/utils/logs.h"
1518
1619namespace error_handling_impl_ {
20+ inline constexpr std::string_view FUNCTION_KEY = " function" ;
21+ inline constexpr std::string_view FILENAME_KEY = " file" ;
22+ inline constexpr std::string_view LINE_KEY = " line" ;
1723
1824inline array<array<string>> format_backtrace_symbols (std::span<void * const > backtrace) noexcept {
25+
1926 auto resolved_backtrace{kphp::diagnostic::backtrace_symbols (backtrace)};
2027 if (resolved_backtrace.empty ()) {
2128 return {};
2229 }
2330
2431 array<array<string>> backtrace_symbols{array_size{static_cast <int64_t >(backtrace.size ()), true }};
25- const string function_key{" function " };
26- const string filename_key{" file " };
27- const string line_key{" line " };
32+ const string function_key{FUNCTION_KEY. data (), FUNCTION_KEY. size () };
33+ const string filename_key{FILENAME_KEY. data (), FILENAME_KEY. size () };
34+ const string line_key{LINE_KEY. data (), LINE_KEY. size () };
2835
2936 for (const k2::SymbolInfo& symbol_info : resolved_backtrace) {
3037 array<string> frame_info{array_size{3 , false }};
@@ -47,11 +54,12 @@ inline array<array<string>> format_backtrace_addresses(std::span<void* const> ba
4754 }
4855
4956 array<array<string>> backtrace_addresses{array_size{static_cast <int64_t >(backtrace.size ()), true }};
50- const string function_key{" function " };
57+ const string function_key{FUNCTION_KEY. data (), FUNCTION_KEY. size () };
5158
5259 for (const auto & address : resolved_backtrace) {
5360 std::array<char , LOG_BUFFER_SIZE> log_buffer{};
54- const auto [_, recorded]{std::format_to_n (log_buffer.data (), log_buffer.size () - 1 , " {}" , address)};
61+ const auto [out, recorded]{std::format_to_n (log_buffer.data (), log_buffer.size () - 1 , " {}" , address)};
62+ *out = ' \0 ' ;
5563 array<string> frame_info{array_size{1 , false }};
5664 frame_info.set_value (function_key, string{log_buffer.data (), static_cast <string::size_type>(recorded)});
5765
0 commit comments