Skip to content

Commit

Permalink
Add a safe mode for the debugger that prevents launching any file
Browse files Browse the repository at this point in the history
  • Loading branch information
xusheng6 committed Apr 11, 2023
1 parent 5b46f60 commit d4df7e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions core/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ static void RegisterSettings()
"description" : "Whether to aggressively update the memory cache and analysis. If the target has self-modifying code, turning this on makes sure every function is re-analyzed every time the target stops, which gives the most accurate analysis. However, for large binaries with lots of functions, this may cause performance issues.",
"ignore" : ["SettingsProjectScope", "SettingsResourceScope"]
})");

settings->RegisterSetting("debugger.safeMode",
R"({
"title" : "Safe Mode",
"type" : "boolean",
"default" : false,
"description" : "When enabled, this prevents the debugger from launching any file.",
"ignore" : ["SettingsProjectScope", "SettingsResourceScope"]
})");
}

extern "C"
Expand Down
15 changes: 14 additions & 1 deletion core/debuggercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ bool DebuggerController::Launch()

DebugStopReason DebuggerController::LaunchAndWaitInternal()
{
if (Settings::Instance()->Get<bool>("debugger.safeMode"))
{
DebuggerEvent event;
event.type = LaunchFailureEventType;
event.data.errorData.shortError = "Safe mode enabled";
event.data.errorData.error =
fmt::format("Cannot launch the target because the debugger is in safe mode.");
PostDebuggerEvent(event);
return InternalError;
}

DebuggerEvent event;
event.type = LaunchEventType;
PostDebuggerEvent(event);
Expand Down Expand Up @@ -1116,7 +1127,9 @@ void DebuggerController::EventHandler(const DebuggerEvent& event)
{
m_inputFileLoaded = false;
m_initialBreakpointSeen = false;
m_liveView->GetFile()->UnregisterViewOfType("Debugger", m_liveView);
// The m_liveView can be nullptr if the launch attempt fails because of the safe mode
if (m_liveView)
m_liveView->GetFile()->UnregisterViewOfType("Debugger", m_liveView);
SetLiveView(nullptr);
m_currentIP = 0;
m_lastIP = 0;
Expand Down

0 comments on commit d4df7e4

Please sign in to comment.