From 8c9c129ca25c813a4c39476c9b35a3d5d1ddeccf Mon Sep 17 00:00:00 2001 From: Xusheng Date: Fri, 18 Oct 2024 15:46:49 +0800 Subject: [PATCH] Improve stack trace symbolization. Fix https://github.com/Vector35/debugger/issues/631 --- core/debuggerstate.cpp | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/core/debuggerstate.cpp b/core/debuggerstate.cpp index ffce244..530e383 100644 --- a/core/debuggerstate.cpp +++ b/core/debuggerstate.cpp @@ -168,13 +168,37 @@ void DebuggerThreads::SymbolizeFrames(std::vector& frames) if (!func) continue; - frame.m_functionStart = func->GetStart(); - auto symbol = func->GetSymbol(); - if (symbol) - frame.m_functionName = symbol->GetShortName(); + if (func->GetStart() != frame.m_functionStart) + { + // Found a better function start from the analysis, use it + frame.m_functionStart = func->GetStart(); + auto symbol = func->GetSymbol(); + if (symbol) + frame.m_functionName = symbol->GetShortName(); + else + frame.m_functionName = fmt::format("sub_{:x}", func->GetStart()); + } else - frame.m_functionName = fmt::format("sub_{:x}", func->GetStart()); - + { + std::string symName; + auto symbol = func->GetSymbol(); + if (symbol) + symName = symbol->GetShortName(); + + auto defaultName = fmt::format("sub_{:x}", func->GetStart()); + if (frame.m_functionName.empty()) + { + if (!symName.empty()) + frame.m_functionName = symName; + else + frame.m_functionName = defaultName; + } + else + { + if ((!symName.empty()) && symName != defaultName) + frame.m_functionName = symName; + } + } continue; } }