From 3634f7ecfe3ef208f42f6096083bc4cbb9a610be Mon Sep 17 00:00:00 2001 From: Xusheng Date: Fri, 18 Oct 2024 15:02:55 +0800 Subject: [PATCH] Properly display the stack trace when the instruction pointer is not in any loaded modules. Fix https://github.com/Vector35/debugger/issues/631 --- api/python/debuggercontroller.py | 5 ++++- core/adapters/dbgengadapter.cpp | 21 +++++++++++---------- core/debugadapter.h | 12 ++++++------ ui/threadframes.h | 6 ++++-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/api/python/debuggercontroller.py b/api/python/debuggercontroller.py index c2b3e8d..e42c77b 100644 --- a/api/python/debuggercontroller.py +++ b/api/python/debuggercontroller.py @@ -349,7 +349,10 @@ def __setattr__(self, name, value): def __repr__(self): offset = self.pc - self.func_start - return f"" + if self.func_name != '': + return f"" + else: + return f"" class TargetStoppedEventData: diff --git a/core/adapters/dbgengadapter.cpp b/core/adapters/dbgengadapter.cpp index 0e97179..56d944a 100644 --- a/core/adapters/dbgengadapter.cpp +++ b/core/adapters/dbgengadapter.cpp @@ -1597,17 +1597,18 @@ std::vector DbgEngAdapter::GetFramesOfThread(uint32_t tid) // Get module info ULONG moduleIndex = 0; uint64_t moduleBase = 0; - m_debugSymbols->GetModuleByOffset(engineFrame.InstructionOffset, 0, &moduleIndex, &moduleBase); - - char name[1024]; - char short_name[1024]; - char loaded_image_name[1024]; - if (this->m_debugSymbols->GetModuleNames(moduleIndex, 0, - name, 1024, nullptr, - short_name, 1024, nullptr, - loaded_image_name, 1024, nullptr) == S_OK) + if (m_debugSymbols->GetModuleByOffset(engineFrame.InstructionOffset, 0, &moduleIndex, &moduleBase) == S_OK) { - frame.m_module = short_name; + char name[1024]; + char short_name[1024]; + char loaded_image_name[1024]; + if (this->m_debugSymbols->GetModuleNames(moduleIndex, 0, + name, 1024, nullptr, + short_name, 1024, nullptr, + loaded_image_name, 1024, nullptr) == S_OK) + { + frame.m_module = short_name; + } } // Get function info diff --git a/core/debugadapter.h b/core/debugadapter.h index 037969f..da77c0d 100644 --- a/core/debugadapter.h +++ b/core/debugadapter.h @@ -170,13 +170,13 @@ namespace BinaryNinjaDebugger { struct DebugFrame { - size_t m_index; - uint64_t m_pc; - uint64_t m_sp; - uint64_t m_fp; + size_t m_index = 0; + uint64_t m_pc = 0; + uint64_t m_sp = 0; + uint64_t m_fp = 0; std::string m_functionName; - uint64_t m_functionStart; - std::string m_module; + uint64_t m_functionStart = 0; + std::string m_module = ""; DebugFrame() = default; DebugFrame(size_t index, uint64_t pc, uint64_t sp, uint64_t fp, const std::string& functionName, diff --git a/ui/threadframes.h b/ui/threadframes.h index 348f3af..7d9349e 100644 --- a/ui/threadframes.h +++ b/ui/threadframes.h @@ -58,10 +58,12 @@ class FrameItem // Only show the offset if it is not 0x0 uint64_t offset = frame.m_pc - frame.m_functionStart; - if (offset != 0) + if (offset != 0 && !trimmedFunctionName.empty()) m_function = fmt::format("{} + {:#x}", trimmedFunctionName, offset); - else + else if (offset == 0) m_function = trimmedFunctionName; + else + m_function = fmt::format("{:#x}", offset); } ~FrameItem();