Skip to content

Commit

Permalink
Do not run the loaded module detection for a second time if the modul…
Browse files Browse the repository at this point in the history
…e is already loaded
  • Loading branch information
xusheng6 committed Apr 11, 2023
1 parent 225964d commit feeb1f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/debuggercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ bool DebuggerController::Launch()
if (!CreateDebugAdapter())
return false;

m_inputFileLoaded = false;
m_state->MarkDirty();
bool result = Execute();
if (result)
Expand All @@ -144,6 +145,7 @@ bool DebuggerController::Attach(int32_t pid)
if (!CreateDebugAdapter())
return false;

m_inputFileLoaded = false;
m_state->MarkDirty();
bool result = m_adapter->Attach(pid);
if (result)
Expand Down Expand Up @@ -640,7 +642,10 @@ void DebuggerController::DetectLoadedModule()
{
// Rebase the binary and create DebugView
uint64_t remoteBase;
if (!m_state->GetRemoteBase(remoteBase))
// Right now we only support applying the analysis info from one module into the debugger view, So we use a bool
// here. In the future, we would like to support loading multiple modules, and we will need a more
// robust mechanism.
if (m_inputFileLoaded || (!m_state->GetRemoteBase(remoteBase)))
return;

FileMetadataRef fileMetadata = m_data->GetFile();
Expand All @@ -663,6 +668,8 @@ void DebuggerController::DetectLoadedModule()
});
if (!ok)
LogWarn("create snapshoted view failed");

m_inputFileLoaded = true;
}


Expand Down Expand Up @@ -733,6 +740,7 @@ void DebuggerController::Connect()
if (!CreateDebugAdapter())
return;

m_inputFileLoaded = false;
m_state->MarkDirty();

m_state->SetConnectionStatus(DebugAdapterConnectingStatus);
Expand Down
2 changes: 2 additions & 0 deletions core/debuggercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ namespace BinaryNinjaDebugger {

bool m_lastAdapterStopEventConsumed = true;

bool m_inputFileLoaded = false;

void EventHandler(const DebuggerEvent& event);
void UpdateStackVariables();
void AddRegisterValuesToExpressionParser();
Expand Down
3 changes: 3 additions & 0 deletions core/debuggerstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ bool DebuggerModules::GetModuleBase(const std::string& name, uint64_t& address)
if (IsDirty())
Update();

if (name.empty())
return false;

for (const DebugModule& module : m_modules)
{
if (module.IsSameBaseModule(name))
Expand Down

0 comments on commit feeb1f5

Please sign in to comment.