Skip to content

Commit

Permalink
Properly display the stack trace when the instruction pointer is not …
Browse files Browse the repository at this point in the history
…in any loaded modules. Fix Vector35#631
  • Loading branch information
xusheng6 committed Oct 18, 2024
1 parent 74ef283 commit 3634f7e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
5 changes: 4 additions & 1 deletion api/python/debuggercontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,10 @@ def __setattr__(self, name, value):

def __repr__(self):
offset = self.pc - self.func_start
return f"<DebugFrame: {self.module}`{self.func_name} + {offset:#x}, sp: {self.sp:#x}, fp: {self.fp:#x}>"
if self.func_name != '':
return f"<DebugFrame: {self.module}`{self.func_name} + {offset:#x}, sp: {self.sp:#x}, fp: {self.fp:#x}>"
else:
return f"<DebugFrame: {self.module} + {offset:#x}, sp: {self.sp:#x}, fp: {self.fp:#x}>"


class TargetStoppedEventData:
Expand Down
21 changes: 11 additions & 10 deletions core/adapters/dbgengadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1597,17 +1597,18 @@ std::vector<DebugFrame> 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
Expand Down
12 changes: 6 additions & 6 deletions core/debugadapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<unknown>";

DebugFrame() = default;
DebugFrame(size_t index, uint64_t pc, uint64_t sp, uint64_t fp, const std::string& functionName,
Expand Down
6 changes: 4 additions & 2 deletions ui/threadframes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3634f7e

Please sign in to comment.