From 8b26dd0b69ea399e0a4c90907ffc6476882cce1a Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Wed, 31 Jan 2024 20:31:40 +0100 Subject: [PATCH] Fix stacktraces for binaries without debug symbols During refactoring in #58610 it had been broken since itassumes that the information about file is always available, otherwise it will not print symbol name. Signed-off-by: Azat Khuzhin --- src/Common/StackTrace.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Common/StackTrace.cpp b/src/Common/StackTrace.cpp index 4e5c9bd7893..8431630b16c 100644 --- a/src/Common/StackTrace.cpp +++ b/src/Common/StackTrace.cpp @@ -317,16 +317,19 @@ constexpr std::pair replacements[] // Demangle @c symbol_name if it's not from __functional header (as such functions don't provide any useful // information but pollute stack traces). // Replace parts from @c replacements with shorter aliases -String demangleAndCollapseNames(std::string_view file, const char * const symbol_name) +String demangleAndCollapseNames(std::optional file, const char * const symbol_name) { if (!symbol_name) return "?"; - std::string_view file_copy = file; - if (auto trim_pos = file.find_last_of('/'); trim_pos != file.npos) - file_copy.remove_suffix(file.size() - trim_pos); - if (file_copy.ends_with("functional")) - return "?"; + if (file.has_value()) + { + std::string_view file_copy = file.value(); + if (auto trim_pos = file_copy.find_last_of('/'); trim_pos != file_copy.npos) + file_copy.remove_suffix(file_copy.size() - trim_pos); + if (file_copy.ends_with("functional")) + return "?"; + } String haystack = demangle(symbol_name); @@ -393,8 +396,8 @@ toStringEveryLineImpl([[maybe_unused]] bool fatal, const StackTraceRefTriple & s if (frame.file.has_value() && frame.line.has_value()) out << *frame.file << ':' << *frame.line << ": "; - if (frame.symbol.has_value() && frame.file.has_value()) - out << demangleAndCollapseNames(*frame.file, frame.symbol->data()); + if (frame.symbol.has_value()) + out << demangleAndCollapseNames(frame.file, frame.symbol->data()); else out << "?";