Skip to content

Commit

Permalink
Fix race condition when the user pauses a running target in a headles…
Browse files Browse the repository at this point in the history
…s script. Fix Vector35#609
  • Loading branch information
xusheng6 committed Aug 15, 2024
1 parent 51f3b38 commit 4677199
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions core/debuggercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ bool DebuggerController::Launch()

DebugStopReason DebuggerController::LaunchAndWaitInternal()
{
m_userRequestedBreak = false;

if (Settings::Instance()->Get<bool>("debugger.safeMode"))
{
DebuggerEvent event;
Expand Down Expand Up @@ -162,7 +164,7 @@ DebugStopReason DebuggerController::LaunchAndWait()
return InternalError;

auto reason = LaunchAndWaitInternal();
if ((reason != ProcessExited) && (reason != InternalError))
if (!m_userRequestedBreak && (reason != ProcessExited) && (reason != InternalError))
NotifyStopped(reason);

m_targetControlMutex.unlock();
Expand All @@ -179,6 +181,8 @@ bool DebuggerController::Attach()

DebugStopReason DebuggerController::AttachAndWaitInternal()
{
m_userRequestedBreak = false;

DebuggerEvent event;
event.type = LaunchEventType;
PostDebuggerEvent(event);
Expand All @@ -202,7 +206,7 @@ DebugStopReason DebuggerController::AttachAndWait()
return InternalError;

auto reason = AttachAndWaitInternal();
if ((reason != ProcessExited) && (reason != InternalError))
if (!m_userRequestedBreak && (reason != ProcessExited) && (reason != InternalError))
NotifyStopped(reason);

m_targetControlMutex.unlock();
Expand All @@ -219,6 +223,8 @@ bool DebuggerController::Connect()

DebugStopReason DebuggerController::ConnectAndWaitInternal()
{
m_userRequestedBreak = false;

DebuggerEvent event;
event.type = LaunchEventType;
PostDebuggerEvent(event);
Expand All @@ -242,7 +248,7 @@ DebugStopReason DebuggerController::ConnectAndWait()
return InternalError;

auto reason = ConnectAndWaitInternal();
if ((reason != ProcessExited) && (reason != InternalError))
if (!m_userRequestedBreak && (reason != ProcessExited) && (reason != InternalError))
NotifyStopped(reason);

m_targetControlMutex.unlock();
Expand Down Expand Up @@ -591,6 +597,7 @@ DebugStopReason DebuggerController::StepIntoReverseIL(BNFunctionGraphType il)

DebugStopReason DebuggerController::StepIntoReverseAndWaitInternal()
{
m_userRequestedBreak = false;
// TODO: check if StepInto() succeeds
return ExecuteAdapterAndWait(DebugAdapterStepIntoReverse);
}
Expand Down Expand Up @@ -921,6 +928,8 @@ DebugStopReason DebuggerController::EmulateStepReturnAndWait()

DebugStopReason DebuggerController::StepReturnAndWaitInternal()
{
m_userRequestedBreak = false;

if (true /* StepReturnAvailable() */)
{
return ExecuteAdapterAndWait(DebugAdapterStepReturn);
Expand All @@ -935,6 +944,8 @@ DebugStopReason DebuggerController::StepReturnAndWaitInternal()

DebugStopReason DebuggerController::StepReturnReverseAndWaitInternal()
{
m_userRequestedBreak = false;

if (true /* StepReturnReverseAvailable() */)
{
return ExecuteAdapterAndWait(DebugAdapterStepReturnReverse);
Expand Down Expand Up @@ -994,6 +1005,8 @@ DebugStopReason DebuggerController::StepReturnReverseAndWait()

DebugStopReason DebuggerController::RunToAndWaitInternal(const std::vector<uint64_t>& remoteAddresses)
{
m_userRequestedBreak = false;

for (uint64_t remoteAddress : remoteAddresses)
{
if (!m_state->GetBreakpoints()->ContainsAbsolute(remoteAddress))
Expand Down Expand Up @@ -1264,9 +1277,7 @@ bool DebuggerController::Pause()
DebugStopReason DebuggerController::PauseAndWaitInternal()
{
m_userRequestedBreak = true;
auto ret = ExecuteAdapterAndWait(DebugAdapterPause);
m_userRequestedBreak = false;
return ret;
return ExecuteAdapterAndWait(DebugAdapterPause);
}


Expand All @@ -1280,17 +1291,20 @@ DebugStopReason DebuggerController::PauseAndWait()

DebugStopReason DebuggerController::GoAndWaitInternal()
{
m_userRequestedBreak = false;
return ExecuteAdapterAndWait(DebugAdapterGo);
}

DebugStopReason DebuggerController::GoReverseAndWaitInternal()
{
m_userRequestedBreak = false;
return ExecuteAdapterAndWait(DebugAdapterGoReverse);
}


DebugStopReason DebuggerController::StepIntoAndWaitInternal()
{
m_userRequestedBreak = false;
// TODO: check if StepInto() succeeds
return ExecuteAdapterAndWait(DebugAdapterStepInto);
}
Expand Down Expand Up @@ -1340,6 +1354,8 @@ DebugStopReason DebuggerController::EmulateStepOverAndWait()

DebugStopReason DebuggerController::StepOverAndWaitInternal()
{
m_userRequestedBreak = false;

if (true /* StepOverAvailable() */)
{
return ExecuteAdapterAndWait(DebugAdapterStepOver);
Expand All @@ -1353,6 +1369,8 @@ DebugStopReason DebuggerController::StepOverAndWaitInternal()

DebugStopReason DebuggerController::StepOverReverseAndWaitInternal()
{
m_userRequestedBreak = false;

if (true /* StepOverAvailable() */)
{
return ExecuteAdapterAndWait(DebugAdapterStepOverReverse);
Expand Down

0 comments on commit 4677199

Please sign in to comment.