]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
PeCoffGetEntryPointLib: Fix spelling issue
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / DebugAgent.c
index fc40112b54e9285fe7e381f918ed24d2a4073023..f156fe24db2d3578e2766d96cc147b84a01ef80e 100644 (file)
@@ -4,7 +4,7 @@
   read/write debug packet to communication with HOST based on transfer\r
   protocol.\r
 \r
   read/write debug packet to communication with HOST based on transfer\r
   protocol.\r
 \r
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -19,7 +19,7 @@
 #include "Ia32/DebugException.h"\r
 \r
 GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgVersionAlert[]       = "\rThe SourceLevelDebugPkg you are using requires a newer version of the Intel(R) UDK Debugger Tool.\r\n";\r
 #include "Ia32/DebugException.h"\r
 \r
 GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgVersionAlert[]       = "\rThe SourceLevelDebugPkg you are using requires a newer version of the Intel(R) UDK Debugger Tool.\r\n";\r
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgSendInitPacket[]     = "\rSend INIT break packet and try to connect the HOST (Intel(R) UDK Debugger Tool v1.4) ...\r\n";\r
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgSendInitPacket[]     = "\rSend INIT break packet and try to connect the HOST (Intel(R) UDK Debugger Tool v1.5) ...\r\n";\r
 GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgConnectOK[]          = "HOST connection is successful!\r\n";\r
 GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgConnectFail[]        = "HOST connection is failed!\r\n";\r
 GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mWarningMsgIngoreBreakpoint[] = "Ignore break point in SMM for SMI issued during DXE debugging!\r\n";\r
 GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgConnectOK[]          = "HOST connection is successful!\r\n";\r
 GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgConnectFail[]        = "HOST connection is failed!\r\n";\r
 GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mWarningMsgIngoreBreakpoint[] = "Ignore break point in SMM for SMI issued during DXE debugging!\r\n";\r
@@ -201,55 +201,17 @@ FindAndReportModuleImageInfo (
   )\r
 {\r
   UINTN                                Pe32Data;\r
   )\r
 {\r
   UINTN                                Pe32Data;\r
-  EFI_IMAGE_DOS_HEADER                 *DosHdr;\r
-  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
   PE_COFF_LOADER_IMAGE_CONTEXT         ImageContext;\r
 \r
   //\r
   // Find Image Base\r
   //\r
   PE_COFF_LOADER_IMAGE_CONTEXT         ImageContext;\r
 \r
   //\r
   // Find Image Base\r
   //\r
-  Pe32Data = ((UINTN)mErrorMsgVersionAlert) & ~(AlignSize - 1);\r
-  while (Pe32Data != 0) {\r
-    DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;\r
-    if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
-      //\r
-      // DOS image header is present, so read the PE header after the DOS image header.\r
-      //\r
-      Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
-      //\r
-      // Make sure PE header address does not overflow and is less than the initial address.\r
-      //\r
-      if (((UINTN)Hdr.Pe32 > Pe32Data) && ((UINTN)Hdr.Pe32 < (UINTN)mErrorMsgVersionAlert)) {\r
-        if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
-          //\r
-          // It's PE image.\r
-          //\r
-          break;\r
-        }\r
-      }\r
-    } else {\r
-      //\r
-      // DOS image header is not present, TE header is at the image base.\r
-      //\r
-      Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
-      if ((Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) &&\r
-          ((Hdr.Te->Machine == IMAGE_FILE_MACHINE_I386) || Hdr.Te->Machine == IMAGE_FILE_MACHINE_X64)) {\r
-        //\r
-        // It's TE image, it TE header and Machine type match\r
-        //\r
-        break;\r
-      }\r
-    }\r
-\r
-    //\r
-    // Not found the image base, check the previous aligned address\r
-    //\r
-    Pe32Data -= AlignSize;\r
+  Pe32Data = PeCoffSearchImageBase ((UINTN) mErrorMsgVersionAlert);\r
+  if (Pe32Data != 0) {\r
+    ImageContext.ImageAddress = Pe32Data;\r
+    ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);\r
+    PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
   }\r
   }\r
-\r
-  ImageContext.ImageAddress = Pe32Data;\r
-  ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);\r
-  PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -381,7 +343,7 @@ UpdateMailboxContent (
     Mailbox->HostSequenceNo = (UINT8) Value;\r
     break;\r
   case DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY:\r
     Mailbox->HostSequenceNo = (UINT8) Value;\r
     break;\r
   case DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY:\r
-    Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->HostSequenceNo, sizeof(UINT32))\r
+    Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->DebugTimerFrequency, sizeof(UINT32))\r
                                               - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT32));\r
     Mailbox->DebugTimerFrequency = (UINT32) Value;\r
     break;\r
                                               - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT32));\r
     Mailbox->DebugTimerFrequency = (UINT32) Value;\r
     break;\r
@@ -785,7 +747,7 @@ CommandGo (
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
-  Exectue Stepping command.\r
+  Execute Stepping command.\r
 \r
   @param[in] CpuContext        Pointer to saved CPU context.\r
 \r
 \r
   @param[in] CpuContext        Pointer to saved CPU context.\r
 \r
@@ -800,6 +762,39 @@ CommandStepping (
   Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags;\r
   Eflags->Bits.TF = 1;\r
   Eflags->Bits.RF = 1;\r
   Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags;\r
   Eflags->Bits.TF = 1;\r
   Eflags->Bits.RF = 1;\r
+  //\r
+  // Save and clear EFLAGS.IF to avoid interrupt happen when executing Stepping\r
+  //\r
+  SetDebugFlag (DEBUG_AGENT_FLAG_INTERRUPT_FLAG, Eflags->Bits.IF);\r
+  Eflags->Bits.IF = 0;\r
+  //\r
+  // Set Stepping Flag\r
+  //\r
+  SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 1);\r
+}\r
+\r
+/**\r
+  Do some cleanup after Stepping command done.\r
+\r
+  @param[in] CpuContext        Pointer to saved CPU context.\r
+\r
+**/\r
+VOID\r
+CommandSteppingCleanup (\r
+  IN DEBUG_CPU_CONTEXT          *CpuContext\r
+  )\r
+{\r
+  IA32_EFLAGS32                *Eflags;\r
+\r
+  Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags;\r
+  //\r
+  // Restore EFLAGS.IF\r
+  //\r
+  Eflags->Bits.IF = GetDebugFlag (DEBUG_AGENT_FLAG_INTERRUPT_FLAG);\r
+  //\r
+  // Clear Stepping flag\r
+  //\r
+  SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 0);\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -1302,8 +1297,12 @@ GetBreakCause (
       if ((CpuContext->Dr6 & BIT14) != 0) {\r
         Cause = DEBUG_DATA_BREAK_CAUSE_STEPPING;\r
         //\r
       if ((CpuContext->Dr6 & BIT14) != 0) {\r
         Cause = DEBUG_DATA_BREAK_CAUSE_STEPPING;\r
         //\r
-        // If it's single step, no need to check DR0, to ensure single step work in PeCoffExtraActionLib\r
-        // (right after triggering a breakpoint to report image load/unload).\r
+        // DR6.BIT14 Indicates (when set) that the debug exception was\r
+        // triggered by the single step execution mode.\r
+        // The single-step mode is the highest priority debug exception.\r
+        // This is single step, no need to check DR0, to ensure single step\r
+        // work in PeCoffExtraActionLib (right after triggering a breakpoint\r
+        // to report image load/unload).\r
         //\r
         return Cause;\r
 \r
         //\r
         return Cause;\r
 \r
@@ -1434,31 +1433,32 @@ CopyMemByWidth (
   2. Compute the CRC of the compressed data buffer;\r
   3. Compress the data and send to the debug channel.\r
 \r
   2. Compute the CRC of the compressed data buffer;\r
   3. Compress the data and send to the debug channel.\r
 \r
+  @param[in]  Handle           The debug channel handle to send the compressed data buffer.\r
   @param[in]  Data             The data buffer.\r
   @param[in]  Length           The length of the data buffer.\r
   @param[in]  Data             The data buffer.\r
   @param[in]  Length           The length of the data buffer.\r
+  @param[in]  Send             TRUE to send the compressed data buffer.\r
   @param[out] CompressedLength Return the length of the compressed data buffer.\r
                                It may be larger than the Length in some cases.\r
   @param[out] CompressedCrc    Return the CRC of the compressed data buffer.\r
   @param[out] CompressedLength Return the length of the compressed data buffer.\r
                                It may be larger than the Length in some cases.\r
   @param[out] CompressedCrc    Return the CRC of the compressed data buffer.\r
-  @param[in]  Handle           The debug channel handle to send the compressed data buffer.\r
 **/\r
 VOID\r
 **/\r
 VOID\r
-CompressDataThenSend (\r
+CompressData (\r
+  IN  DEBUG_PORT_HANDLE Handle,\r
   IN  UINT8             *Data,\r
   IN  UINT8             Length,\r
   IN  UINT8             *Data,\r
   IN  UINT8             Length,\r
+  IN  BOOLEAN           Send,\r
   OUT UINTN             *CompressedLength,  OPTIONAL\r
   OUT UINTN             *CompressedLength,  OPTIONAL\r
-  OUT UINT16            *CompressedCrc,     OPTIONAL\r
-  IN  DEBUG_PORT_HANDLE Handle              OPTIONAL\r
+  OUT UINT16            *CompressedCrc      OPTIONAL\r
   )\r
 {\r
   )\r
 {\r
-  UINTN  Index;\r
-  UINT8  LastChar;\r
-  UINT8  LastCharCount;\r
-  UINT8  CurrentChar;\r
-  UINTN  CompressedIndex;\r
+  UINTN                 Index;\r
+  UINT8                 LastChar;\r
+  UINT8                 LastCharCount;\r
+  UINT8                 CurrentChar;\r
+  UINTN                 CompressedIndex;\r
 \r
   ASSERT (Length > 0);\r
 \r
   ASSERT (Length > 0);\r
-\r
-  LastChar = Data[0] + 1; // Just ensure it's different from the first byte.\r
+  LastChar      = Data[0] + 1; // Just ensure it's different from the first byte.\r
   LastCharCount = 0;\r
 \r
   for (Index = 0, CompressedIndex = 0; Index <= Length; Index++) {\r
   LastCharCount = 0;\r
 \r
   for (Index = 0, CompressedIndex = 0; Index <= Length; Index++) {\r
@@ -1473,7 +1473,7 @@ CompressDataThenSend (
         if (CompressedCrc != NULL) {\r
           *CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);\r
         }\r
         if (CompressedCrc != NULL) {\r
           *CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);\r
         }\r
-        if (Handle != NULL) {\r
+        if (Send) {\r
           DebugPortWriteBuffer (Handle, &LastChar, 1);\r
         }\r
         \r
           DebugPortWriteBuffer (Handle, &LastChar, 1);\r
         }\r
         \r
@@ -1485,7 +1485,7 @@ CompressDataThenSend (
           *CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);\r
           *CompressedCrc = CalculateCrc16 (&LastCharCount, 1, *CompressedCrc);\r
         }\r
           *CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);\r
           *CompressedCrc = CalculateCrc16 (&LastCharCount, 1, *CompressedCrc);\r
         }\r
-        if (Handle != NULL) {\r
+        if (Send) {\r
           DebugPortWriteBuffer (Handle, &LastChar, 1);\r
           DebugPortWriteBuffer (Handle, &LastChar, 1);\r
           DebugPortWriteBuffer (Handle, &LastCharCount, 1);\r
           DebugPortWriteBuffer (Handle, &LastChar, 1);\r
           DebugPortWriteBuffer (Handle, &LastChar, 1);\r
           DebugPortWriteBuffer (Handle, &LastCharCount, 1);\r
@@ -1568,11 +1568,12 @@ ReadMemoryAndSendResponsePacket (
       //\r
       // Get the compressed data size without modifying the packet.\r
       //\r
       //\r
       // Get the compressed data size without modifying the packet.\r
       //\r
-      CompressDataThenSend (\r
+      CompressData (\r
+        Handle,\r
         (UINT8 *) (DebugHeader + 1),\r
         CurrentDataSize,\r
         (UINT8 *) (DebugHeader + 1),\r
         CurrentDataSize,\r
+        FALSE,\r
         &CompressedDataSize,\r
         &CompressedDataSize,\r
-        NULL,\r
         NULL\r
         );\r
     } else {\r
         NULL\r
         );\r
     } else {\r
@@ -1585,12 +1586,13 @@ ReadMemoryAndSendResponsePacket (
       // Compute the CRC of the packet head without modifying the packet.\r
       //\r
       DebugHeader->Crc = CalculateCrc16 ((UINT8 *) DebugHeader, sizeof (DEBUG_PACKET_HEADER), 0);\r
       // Compute the CRC of the packet head without modifying the packet.\r
       //\r
       DebugHeader->Crc = CalculateCrc16 ((UINT8 *) DebugHeader, sizeof (DEBUG_PACKET_HEADER), 0);\r
-      CompressDataThenSend (\r
+      CompressData (\r
+        Handle,\r
         (UINT8 *) (DebugHeader + 1),\r
         CurrentDataSize,\r
         (UINT8 *) (DebugHeader + 1),\r
         CurrentDataSize,\r
+        FALSE,\r
         NULL,\r
         NULL,\r
-        &DebugHeader->Crc,\r
-        NULL\r
+        &DebugHeader->Crc\r
         );\r
       //\r
       // Send out the packet head.\r
         );\r
       //\r
       // Send out the packet head.\r
@@ -1599,12 +1601,13 @@ ReadMemoryAndSendResponsePacket (
       //\r
       // Compress and send out the packet data.\r
       //\r
       //\r
       // Compress and send out the packet data.\r
       //\r
-      CompressDataThenSend (\r
+      CompressData (\r
+        Handle,\r
         (UINT8 *) (DebugHeader + 1),\r
         CurrentDataSize,\r
         (UINT8 *) (DebugHeader + 1),\r
         CurrentDataSize,\r
+        TRUE,\r
         NULL,\r
         NULL,\r
-        NULL,\r
-        Handle\r
+        NULL\r
         );\r
     } else {\r
 \r
         );\r
     } else {\r
 \r
@@ -1818,7 +1821,6 @@ CommandCommunication (
   DEBUG_DATA_SET_VIEWPOINT          *SetViewPoint;\r
   BOOLEAN                           HaltDeferred;\r
   UINT32                            ProcessorIndex;\r
   DEBUG_DATA_SET_VIEWPOINT          *SetViewPoint;\r
   BOOLEAN                           HaltDeferred;\r
   UINT32                            ProcessorIndex;\r
-  DEBUG_PORT_HANDLE                 Handle;\r
   DEBUG_AGENT_EXCEPTION_BUFFER      AgentExceptionBuffer;\r
   UINT32                            IssuedViewPoint;\r
   DEBUG_AGENT_MAILBOX               *Mailbox;\r
   DEBUG_AGENT_EXCEPTION_BUFFER      AgentExceptionBuffer;\r
   UINT32                            IssuedViewPoint;\r
   DEBUG_AGENT_MAILBOX               *Mailbox;\r
@@ -1846,8 +1848,6 @@ CommandCommunication (
     SetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS, 1);\r
   }\r
 \r
     SetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS, 1);\r
   }\r
 \r
-  Handle = GetDebugPortHandle();\r
-\r
   while (TRUE) {\r
 \r
     if (MultiProcessorDebugSupport()) {\r
   while (TRUE) {\r
 \r
     if (MultiProcessorDebugSupport()) {\r
@@ -1952,10 +1952,6 @@ CommandCommunication (
       if (Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD || Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD) {\r
         CpuContext->Dr0 = 0;\r
       }\r
       if (Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD || Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD) {\r
         CpuContext->Dr0 = 0;\r
       }\r
-      //\r
-      // Clear Stepping Flag\r
-      //\r
-      SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 0);\r
 \r
       if (!HaltDeferred) {\r
         //\r
 \r
       if (!HaltDeferred) {\r
         //\r
@@ -2070,10 +2066,6 @@ CommandCommunication (
       }\r
 \r
       mDebugMpContext.BreakAtCpuIndex = (UINT32) (-1);\r
       }\r
 \r
       mDebugMpContext.BreakAtCpuIndex = (UINT32) (-1);\r
-      //\r
-      // Set Stepping Flag\r
-      //\r
-      SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 1);\r
       ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);\r
       //\r
       // Executing stepping command directly without sending ACK packet,\r
       ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);\r
       //\r
       // Executing stepping command directly without sending ACK packet,\r
@@ -2367,9 +2359,16 @@ InterruptProcess (
     // Check if this exception is issued by Debug Agent itself\r
     // If yes, fill the debug agent exception buffer and LongJump() back to\r
     // the saved CPU content in CommandCommunication()\r
     // Check if this exception is issued by Debug Agent itself\r
     // If yes, fill the debug agent exception buffer and LongJump() back to\r
     // the saved CPU content in CommandCommunication()\r
+    // If exception is issued when executing Stepping, will be handled in\r
+    // exception handle procedure.\r
     //\r
     if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) {\r
     //\r
     if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) {\r
-      DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "Debug agent meet one Exception, ExceptionNum is %d, EIP = 0x%x.\n", Vector, (UINTN)CpuContext->Eip);\r
+      DebugAgentMsgPrint (\r
+        DEBUG_AGENT_ERROR,\r
+        "Debug agent meet one Exception, ExceptionNum is %d, EIP = 0x%x.\n",\r
+        Vector,\r
+        (UINTN)CpuContext->Eip\r
+        );\r
       ExceptionBuffer = (DEBUG_AGENT_EXCEPTION_BUFFER *) (UINTN) GetMailboxPointer()->ExceptionBufferPointer;\r
       ExceptionBuffer->ExceptionContent.ExceptionNum  = (UINT8) Vector;\r
       ExceptionBuffer->ExceptionContent.ExceptionData = (UINT32) CpuContext->ExceptionData;\r
       ExceptionBuffer = (DEBUG_AGENT_EXCEPTION_BUFFER *) (UINTN) GetMailboxPointer()->ExceptionBufferPointer;\r
       ExceptionBuffer->ExceptionContent.ExceptionNum  = (UINT8) Vector;\r
       ExceptionBuffer->ExceptionContent.ExceptionData = (UINT32) CpuContext->ExceptionData;\r
@@ -2409,6 +2408,10 @@ InterruptProcess (
       if (MultiProcessorDebugSupport()) {\r
         mDebugMpContext.BreakAtCpuIndex = ProcessorIndex;\r
       }\r
       if (MultiProcessorDebugSupport()) {\r
         mDebugMpContext.BreakAtCpuIndex = ProcessorIndex;\r
       }\r
+      //\r
+      // Clear Stepping Flag and restore EFLAGS.IF\r
+      //\r
+      CommandSteppingCleanup (CpuContext);\r
       SendAckPacket (DEBUG_COMMAND_OK);\r
       CommandCommunication (Vector, CpuContext, BreakReceived);\r
       break;\r
       SendAckPacket (DEBUG_COMMAND_OK);\r
       CommandCommunication (Vector, CpuContext, BreakReceived);\r
       break;\r
@@ -2490,7 +2493,8 @@ InterruptProcess (
         //\r
         CurrentDebugTimerInitCount = GetApicTimerInitCount ();\r
         if (mDebugMpContext.DebugTimerInitCount != CurrentDebugTimerInitCount) {\r
         //\r
         CurrentDebugTimerInitCount = GetApicTimerInitCount ();\r
         if (mDebugMpContext.DebugTimerInitCount != CurrentDebugTimerInitCount) {\r
-          InitializeDebugTimer (NULL);\r
+          InitializeDebugTimer (NULL, FALSE);\r
+          SaveAndSetDebugTimerInterrupt (TRUE);\r
         }\r
       }\r
 \r
         }\r
       }\r
 \r
@@ -2575,13 +2579,24 @@ InterruptProcess (
 \r
   default:\r
     if (Vector <= DEBUG_EXCEPT_SIMD) {\r
 \r
   default:\r
     if (Vector <= DEBUG_EXCEPT_SIMD) {\r
+      DebugAgentMsgPrint (\r
+        DEBUG_AGENT_ERROR,\r
+        "Exception happened, ExceptionNum is %d, EIP = 0x%x.\n",\r
+        Vector,\r
+        (UINTN) CpuContext->Eip\r
+        );\r
       if (BreakCause == DEBUG_DATA_BREAK_CAUSE_STEPPING) {\r
         //\r
       if (BreakCause == DEBUG_DATA_BREAK_CAUSE_STEPPING) {\r
         //\r
-        // Stepping is finished, send Ack package.\r
+        // If exception happened when executing Stepping, send Ack package.\r
+        // HOST consider Stepping command was finished.\r
         //\r
         if (MultiProcessorDebugSupport()) {\r
           mDebugMpContext.BreakAtCpuIndex = ProcessorIndex;\r
         }\r
         //\r
         if (MultiProcessorDebugSupport()) {\r
           mDebugMpContext.BreakAtCpuIndex = ProcessorIndex;\r
         }\r
+        //\r
+        // Clear Stepping flag and restore EFLAGS.IF\r
+        //\r
+        CommandSteppingCleanup (CpuContext);\r
         SendAckPacket (DEBUG_COMMAND_OK);\r
       } else {\r
         //\r
         SendAckPacket (DEBUG_COMMAND_OK);\r
       } else {\r
         //\r