diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c index f51ad4b456..7f597352f1 100644 --- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c +++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c @@ -785,7 +785,7 @@ CommandGo ( } /** - Exectue Stepping command. + Execute Stepping command. @param[in] CpuContext Pointer to saved CPU context. @@ -800,6 +800,39 @@ CommandStepping ( Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags; Eflags->Bits.TF = 1; Eflags->Bits.RF = 1; + // + // Save and clear EFLAGS.IF to avoid interrupt happen when executing Stepping + // + SetDebugFlag (DEBUG_AGENT_FLAG_INTERRUPT_FLAG, Eflags->Bits.IF); + Eflags->Bits.IF = 0; + // + // Set Stepping Flag + // + SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 1); +} + +/** + Do some cleanup after Stepping command done. + + @param[in] CpuContext Pointer to saved CPU context. + +**/ +VOID +CommandSteppingCleanup ( + IN DEBUG_CPU_CONTEXT *CpuContext + ) +{ + IA32_EFLAGS32 *Eflags; + + Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags; + // + // Restore EFLAGS.IF + // + Eflags->Bits.IF = GetDebugFlag (DEBUG_AGENT_FLAG_INTERRUPT_FLAG); + // + // Clear Stepping flag + // + SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 0); } /** @@ -2066,10 +2099,6 @@ CommandCommunication ( } mDebugMpContext.BreakAtCpuIndex = (UINT32) (-1); - // - // Set Stepping Flag - // - SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 1); ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock); // // Executing stepping command directly without sending ACK packet, @@ -2405,11 +2434,11 @@ InterruptProcess ( if (MultiProcessorDebugSupport()) { mDebugMpContext.BreakAtCpuIndex = ProcessorIndex; } + // + // Clear Stepping Flag and restore EFLAGS.IF + // + CommandSteppingCleanup (CpuContext); SendAckPacket (DEBUG_COMMAND_OK); - // - // Clear Stepping Flag - // - SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 0); CommandCommunication (Vector, CpuContext, BreakReceived); break; @@ -2582,6 +2611,10 @@ InterruptProcess ( if (MultiProcessorDebugSupport()) { mDebugMpContext.BreakAtCpuIndex = ProcessorIndex; } + // + // Clear Stepping flag and restore EFLAGS.IF + // + CommandSteppingCleanup (CpuContext); SendAckPacket (DEBUG_COMMAND_OK); } else { //