diff --git a/src/utils/BacktraceManager.cpp b/src/utils/BacktraceManager.cpp index 0ba95d6a6edd0e52b059e0b28638384eec13b602..a7142a45c141cbc203c9a2c2247c706223ac301b 100644 --- a/src/utils/BacktraceManager.cpp +++ b/src/utils/BacktraceManager.cpp @@ -25,7 +25,7 @@ BacktraceManager::BacktraceManager() char** ptr = backtrace_symbols(buffer, ret); for (int i = 2; i < ret; ++i) { - m_lines.push_back(ptr[i]); + m_stack_lines.push_back(ptr[i]); } free(ptr); @@ -35,27 +35,35 @@ std::ostream& operator<<(std::ostream& os, const BacktraceManager& btm) { if (BacktraceManager::s_show) { - const std::vector<std::string>& lines = btm.m_lines; + const std::vector<std::string>& stack_lines = btm.m_stack_lines; const std::regex mangled_function(R"%(\(.*\+)%"); - const int width = std::log10(lines.size()) + 1; + const int width = std::log10(stack_lines.size()) + 1; - for (size_t i_line = 0; i_line < lines.size(); ++i_line) { - const auto& line = lines[i_line]; - os << rang::fg::green << "[" << std::setw(width) << i_line + 1 << '/' << lines.size() << "] " << rang::fg::reset; + for (size_t i_stack_line = 0; i_stack_line < stack_lines.size(); ++i_stack_line) { + const size_t i_line = stack_lines.size() - i_stack_line - 1; + const auto& stack_line = stack_lines[i_line]; + os << rang::fg::green << "[" << std::setw(width) << i_line + 1 << '/' << stack_lines.size() << "] " + << rang::fg::reset; std::smatch matchex; - if (std::regex_search(line, matchex, mangled_function)) { + if (std::regex_search(stack_line, matchex, mangled_function)) { std::string prefix = matchex.prefix().str(); - std::string function = line.substr(matchex.position() + 1, matchex.length() - 2); + std::string function = stack_line.substr(matchex.position() + 1, matchex.length() - 2); std::string suffix = matchex.suffix().str(); - os << prefix << '('; + os << prefix << '\n'; + os << std::setw(5 + 2 * width) << "from " << '('; if (function.size() > 0) { - os << rang::style::bold << demangle(function) << rang::style::reset; + std::string function_full_name = demangle(function); + if (function_full_name.size() > 80) { + function_full_name.resize(75); + function_full_name += "[...]"; + } + os << rang::style::bold << function_full_name << rang::style::reset; } os << '+' << suffix << '\n'; } else { - os << line << '\n'; + os << stack_line << '\n'; } } } else { diff --git a/src/utils/BacktraceManager.hpp b/src/utils/BacktraceManager.hpp index e990ffd3b4060f71370a0f8b7386cdfcd6c03ea8..3f5ac23f8a830f20fa36071285d239bb01cd6c26 100644 --- a/src/utils/BacktraceManager.hpp +++ b/src/utils/BacktraceManager.hpp @@ -8,7 +8,7 @@ class BacktraceManager { private: static bool s_show; - std::vector<std::string> m_lines; + std::vector<std::string> m_stack_lines; public: static void setShow(bool show_backtrace);