]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/GdbStub/GdbStub.c
BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / EmbeddedPkg / GdbStub / GdbStub.c
index 8a13cc8a193d11894a84fce610fc4ee32c150fb4..a75e7751af8dca3489bd9844925120f2503eaeff 100644 (file)
@@ -1,12 +1,12 @@
 /** @file\r
   UEFI driver that implements a GDB stub\r
-  \r
+\r
   Note: Any code in the path of the Serial IO output can not call DEBUG as will\r
   will blow out the stack. Serial IO calls DEBUG, debug calls Serail IO, ...\r
-  \r
+\r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
-  \r
+\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
@@ -29,7 +29,7 @@ UINTN     gMaxProcessorIndex = 0;
 CHAR8 gInBuffer[MAX_BUF_SIZE];\r
 CHAR8 gOutBuffer[MAX_BUF_SIZE];\r
 \r
-// Assume gdb does a "qXfer:libraries:read::offset,length" when it connects so we can default \r
+// Assume gdb does a "qXfer:libraries:read::offset,length" when it connects so we can default\r
 // this value to FALSE. Since gdb can reconnect its self a global default is not good enough\r
 BOOLEAN   gSymbolTableUpdate = FALSE;\r
 EFI_EVENT gEvent;\r
@@ -59,12 +59,12 @@ GdbSymbolEventHandler (
 \r
 /**\r
   The user Entry Point for Application. The user code starts with this function\r
-  as the real entry point for the image goes into a library that calls this \r
+  as the real entry point for the image goes into a library that calls this\r
   function.\r
 \r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
   @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \r
+\r
   @retval EFI_SUCCESS       The entry point is executed successfully.\r
   @retval other             Some error occurs when executing this entry point.\r
 \r
@@ -75,17 +75,15 @@ GdbStubEntry (
   IN EFI_HANDLE        ImageHandle,\r
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
-\r
 {\r
-  EFI_STATUS                  Status;  \r
+  EFI_STATUS                  Status;\r
   EFI_DEBUG_SUPPORT_PROTOCOL  *DebugSupport;\r
   UINTN                       HandleCount;\r
   EFI_HANDLE                  *Handles;\r
   UINTN                       Index;\r
   UINTN                       Processor;\r
   BOOLEAN                     IsaSupported;\r
\r
-   \r
+\r
   Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&gDebugImageTableHeader);\r
   if (EFI_ERROR (Status)) {\r
     gDebugImageTableHeader = NULL;\r
@@ -103,7 +101,7 @@ GdbStubEntry (
 \r
     return Status;\r
   }\r
-  \r
+\r
   DebugSupport = NULL;\r
   IsaSupported = FALSE;\r
   do {\r
@@ -122,24 +120,23 @@ GdbStubEntry (
     }\r
   } while (HandleCount > 0);\r
   FreePool (Handles);\r
-  \r
+\r
   if (!IsaSupported) {\r
     DEBUG ((EFI_D_ERROR, "Debug Support Protocol does not support our ISA\n"));\r
 \r
     return EFI_NOT_FOUND;\r
   }\r
-  \r
+\r
   Status = DebugSupport->GetMaximumProcessorIndex (DebugSupport, &gMaxProcessorIndex);\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
   DEBUG ((EFI_D_INFO, "Debug Support Protocol ISA %x\n", DebugSupport->Isa));\r
   DEBUG ((EFI_D_INFO, "Debug Support Protocol Processor Index %d\n", gMaxProcessorIndex));\r
-  \r
+\r
   // Call processor-specific init routine\r
-  InitializeProcessor();\r
+  InitializeProcessor ();\r
 \r
   for (Processor = 0; Processor <= gMaxProcessorIndex; Processor++) {\r
-    \r
     for (Index = 0; Index < MaxEfiException (); Index++) {\r
       Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor,  GdbExceptionHandler, gExceptionType[Index].Exception);\r
       ASSERT_EFI_ERROR (Status);\r
@@ -150,10 +147,10 @@ GdbStubEntry (
     Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, Processor, GdbPeriodicCallBack);\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
\r
+\r
   //\r
   // This even fires every time an image is added. This allows the stub to know when gdb needs\r
-  // to update the symbol table. \r
+  // to update the symbol table.\r
   //\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_SIGNAL,\r
@@ -165,7 +162,7 @@ GdbStubEntry (
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Register for protocol notifactions on this event\r
+  // Register for protocol notifications on this event\r
   //\r
   Status = gBS->RegisterProtocolNotify (\r
                   &gEfiLoadedImageProtocolGuid,\r
@@ -174,16 +171,14 @@ GdbStubEntry (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
\r
+\r
  if (PcdGetBool (PcdGdbSerial)) {\r
    GdbInitializeSerialConsole ();\r
  }\r
-   \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
-\r
 /**\r
  Transfer length bytes of input buffer, starting at Address, to memory.\r
 \r
@@ -201,14 +196,14 @@ TransferFromInBufToMem (
 {\r
   CHAR8 c1;\r
   CHAR8 c2;\r
-   \r
+\r
   while (Length-- > 0) {\r
     c1 = (CHAR8)HexCharToInt (*NewData++);\r
     c2 = (CHAR8)HexCharToInt (*NewData++);\r
 \r
     if ((c1 < 0) || (c2 < 0)) {\r
       Print ((CHAR16 *)L"Bad message from write to memory..\n");\r
-      SendError (GDB_EBADMEMDATA); \r
+      SendError (GDB_EBADMEMDATA);\r
       return;\r
     }\r
     *Address++ = (UINT8)((c1 << 4) + c2);\r
@@ -244,7 +239,7 @@ TransferFromMemToOutBufAndSend (
 \r
   OutBufPtr = OutBuffer;\r
   while (Length > 0) {\r
-    \r
+\r
     Char = mHexToStr[*Address >> 4];\r
     if ((Char >= 'A') && (Char <= 'F')) {\r
       Char = Char - 'A' + 'a';\r
@@ -269,16 +264,16 @@ TransferFromMemToOutBufAndSend (
 \r
 /**\r
   Send a GDB Remote Serial Protocol Packet\r
-  \r
-  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', \r
+\r
+  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$',\r
   the packet teminating character '#' and the two digit checksum.\r
-  \r
-  If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up \r
+\r
+  If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up\r
   in an infinit loop. This is so if you unplug the debugger code just keeps running\r
 \r
-  @param PacketData   Payload data for the packet  \r
+  @param PacketData   Payload data for the packet\r
+\r
 \r
-  \r
   @retval             Number of bytes of packet data sent.\r
 \r
 **/\r
@@ -292,7 +287,7 @@ SendPacket (
   CHAR8 *Ptr;\r
   CHAR8 TestChar;\r
   UINTN Count;\r
-  \r
+\r
   Timeout = PcdGet32 (PcdGdbMaxPacketRetryCount);\r
 \r
   Count = 0;\r
@@ -304,38 +299,38 @@ SendPacket (
       // Only try a finite number of times so we don't get stuck in the loop\r
       return Count;\r
     }\r
-  \r
+\r
     // Packet prefix\r
     GdbPutChar ('$');\r
-  \r
+\r
     for (CheckSum = 0, Count =0 ; *Ptr != '\0'; Ptr++, Count++) {\r
       GdbPutChar (*Ptr);\r
       CheckSum = CheckSum + *Ptr;\r
     }\r
-  \r
-    // Packet terminating character and checksum \r
+\r
+    // Packet terminating character and checksum\r
     GdbPutChar ('#');\r
     GdbPutChar (mHexToStr[CheckSum >> 4]);\r
     GdbPutChar (mHexToStr[CheckSum & 0x0F]);\r
-    \r
+\r
     TestChar =  GdbGetChar ();\r
   } while (TestChar != '+');\r
-  \r
+\r
   return Count;\r
 }\r
 \r
 /**\r
   Receive a GDB Remote Serial Protocol Packet\r
-  \r
-  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', \r
+\r
+  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$',\r
   the packet teminating character '#' and the two digit checksum.\r
\r
-  If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed.\r
+\r
+  If host re-starts sending a packet without ending the previous packet, only the last valid packet is processed.\r
   (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)\r
\r
+\r
   If an ack '+' is not sent resend the packet\r
 \r
-  @param PacketData   Payload data for the packet  \r
+  @param PacketData   Payload data for the packet\r
 \r
   @retval             Number of bytes of packet data received.\r
 \r
@@ -351,16 +346,16 @@ ReceivePacket (
   CHAR8 Char;\r
   CHAR8 SumString[3];\r
   CHAR8 TestChar;\r
-  \r
+\r
   ZeroMem (PacketData, PacketDataSize);\r
-  \r
+\r
   for (;;) {\r
       // wait for the start of a packet\r
     TestChar = GdbGetChar ();\r
     while (TestChar != '$') {\r
       TestChar = GdbGetChar ();\r
     };\r
-    \r
+\r
   retry:\r
     for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) {\r
       Char = GdbGetChar ();\r
@@ -380,14 +375,14 @@ ReceivePacket (
       continue;\r
     }\r
 \r
-    SumString[0] = GdbGetChar ();  \r
+    SumString[0] = GdbGetChar ();\r
     SumString[1] = GdbGetChar ();\r
     SumString[2] = '\0';\r
-    \r
+\r
     if (AsciiStrHexToUintn (SumString) == CheckSum) {\r
       // Ack: Success\r
       GdbPutChar ('+');\r
-  \r
+\r
       // Null terminate the callers string\r
       PacketData[Index] = '\0';\r
       return Index;\r
@@ -396,27 +391,27 @@ ReceivePacket (
       GdbPutChar ('-');\r
     }\r
   }\r
-  \r
+\r
   //return 0;\r
 }\r
 \r
 \r
 /**\r
- Empties the given buffer \r
+ Empties the given buffer\r
  @param   Buf          pointer to the first element in buffer to be emptied\r
  **/\r
 VOID\r
-EmptyBuffer ( \r
+EmptyBuffer (\r
   IN  CHAR8           *Buf\r
   )\r
-{ \r
+{\r
   *Buf = '\0';\r
 }\r
 \r
 \r
 /**\r
  Converts an 8-bit Hex Char into a INTN.\r
\r
+\r
  @param   Char the hex character to be converted into UINTN\r
  @retval  a INTN, from 0 to 15, that corressponds to Char\r
  -1 if Char is not a hex character\r
@@ -433,7 +428,7 @@ HexCharToInt (
   } else if ((Char >= '0') && (Char <= '9')) {\r
     return Char - '0';\r
   } else { // if not a hex value, return a negative value\r
-    return -1; \r
+    return -1;\r
   }\r
 }\r
 \r
@@ -444,7 +439,7 @@ CHAR8 *gError = "E__";
  Send an error with the given error number after converting to hex.\r
  The error number is put into the buffer in hex. '255' is the biggest errno we can send.\r
  ex: 162 will be sent as A2.\r
\r
+\r
  @param   errno           the error number that will be sent\r
  **/\r
 VOID\r
@@ -458,7 +453,7 @@ SendError (
   //\r
   gError[1] = mHexToStr [ErrorNum >> 4];\r
   gError[2] = mHexToStr [ErrorNum & 0x0f];\r
-    \r
+\r
   SendPacket (gError); // send buffer\r
 }\r
 \r
@@ -471,7 +466,7 @@ VOID
 EFIAPI\r
 SendSuccess (\r
   VOID\r
-  ) \r
+  )\r
 {\r
   SendPacket ("OK"); // send buffer\r
 }\r
@@ -480,20 +475,19 @@ SendSuccess (
 /**\r
  Send empty packet to specify that particular command/functionality is not supported.\r
  **/\r
-VOID        \r
-EFIAPI      \r
+VOID\r
+EFIAPI\r
 SendNotSupported (\r
-  VOID          \r
-  )             \r
-{       \r
+  VOID\r
+  )\r
+{\r
   SendPacket ("");\r
 }\r
 \r
 \r
-\r
 /**\r
  Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints\r
\r
+\r
  @param  SystemContext        Register content at time of the exception\r
  @param  GdbExceptionType     GDB exception type\r
  **/\r
@@ -519,9 +513,9 @@ GdbSendTSignal (
   //\r
   // replace _, or previous value, with Exception type\r
   //\r
-  *TSignalPtr++ = mHexToStr [GdbExceptionType >> 4]; \r
+  *TSignalPtr++ = mHexToStr [GdbExceptionType >> 4];\r
   *TSignalPtr++ = mHexToStr [GdbExceptionType & 0x0f];\r
-  \r
+\r
   if (GdbExceptionType == GDB_SIGTRAP) {\r
     if (gSymbolTableUpdate) {\r
       //\r
@@ -537,17 +531,17 @@ GdbSendTSignal (
 \r
       //\r
       // possible n:r pairs\r
-      // \r
+      //\r
 \r
       //Retrieve the breakpoint number\r
       BreakpointDetected = GetBreakpointDetected (SystemContext);\r
 \r
       //Figure out if the exception is happend due to watch, rwatch or awatch.\r
-      BreakType = GetBreakpointType (SystemContext, BreakpointDetected); \r
+      BreakType = GetBreakpointType (SystemContext, BreakpointDetected);\r
 \r
       //INFO: rwatch is not supported due to the way IA32 debug registers work\r
       if ((BreakType == DataWrite) || (BreakType == DataRead) || (BreakType == DataReadWrite)) {\r
-        \r
+\r
         //Construct n:r pair\r
         DataAddress = GetBreakpointDataAddress (SystemContext, BreakpointDetected);\r
 \r
@@ -565,7 +559,7 @@ GdbSendTSignal (
         }\r
 \r
         *TSignalPtr++ = ':';\r
-        \r
+\r
         //Set up series of bytes in big-endian byte order. "awatch" won't work with little-endian byte order.\r
         RegSize = REG_SIZE;\r
         while (RegSize > 0) {\r
@@ -581,26 +575,26 @@ GdbSendTSignal (
 \r
   *TSignalPtr = '\0';\r
 \r
-  SendPacket (TSignalBuffer); \r
+  SendPacket (TSignalBuffer);\r
 }\r
 \r
 \r
 /**\r
  Translates the EFI mapping to GDB mapping\r
\r
+\r
  @param   EFIExceptionType    EFI Exception that is being processed\r
  @retval  UINTN that corresponds to EFIExceptionType's GDB exception type number\r
  **/\r
 UINT8\r
-ConvertEFItoGDBtype ( \r
+ConvertEFItoGDBtype (\r
   IN  EFI_EXCEPTION_TYPE      EFIExceptionType\r
   )\r
-{ \r
-  UINTN i;\r
-  \r
-  for (i=0; i < MaxEfiException() ; i++) {\r
-    if (gExceptionType[i].Exception == EFIExceptionType) {\r
-      return gExceptionType[i].SignalNo;\r
+{\r
+  UINTN Index;\r
+\r
+  for (Index = 0; Index < MaxEfiException () ; Index++) {\r
+    if (gExceptionType[Index].Exception == EFIExceptionType) {\r
+      return gExceptionType[Index].SignalNo;\r
     }\r
   }\r
   return GDB_SIGTRAP; // this is a GDB trap\r
@@ -608,8 +602,8 @@ ConvertEFItoGDBtype (
 \r
 \r
 /** "m addr,length"\r
- Find the Length of the area to read and the start addres. Finally, pass them to \r
- another function, TransferFromMemToOutBufAndSend, that will read from that memory space and \r
+ Find the Length of the area to read and the start addres. Finally, pass them to\r
+ another function, TransferFromMemToOutBufAndSend, that will read from that memory space and\r
  send it as a packet.\r
  **/\r
 \r
@@ -624,39 +618,39 @@ ReadFromMemory (
   CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the address in hex chars\r
   CHAR8 *AddrBufPtr; // pointer to the address buffer\r
   CHAR8 *InBufPtr; /// pointer to the input buffer\r
-  \r
+\r
   AddrBufPtr = AddressBuffer;\r
   InBufPtr = &PacketData[1];\r
   while (*InBufPtr != ',') {\r
     *AddrBufPtr++ = *InBufPtr++;\r
   }\r
   *AddrBufPtr = '\0';\r
-  \r
+\r
   InBufPtr++; // this skips ',' in the buffer\r
-  \r
+\r
   /* Error checking */\r
-  if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) {\r
+  if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {\r
     Print((CHAR16 *)L"Address is too long\n");\r
-    SendError (GDB_EBADMEMADDRBUFSIZE); \r
+    SendError (GDB_EBADMEMADDRBUFSIZE);\r
     return;\r
   }\r
-  \r
+\r
   // 2 = 'm' + ','\r
-  if (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - 2 >= MAX_LENGTH_SIZE) {\r
+  if (AsciiStrLen (PacketData) - AsciiStrLen (AddressBuffer) - 2 >= MAX_LENGTH_SIZE) {\r
     Print((CHAR16 *)L"Length is too long\n");\r
-    SendError (GDB_EBADMEMLENGTH); \r
+    SendError (GDB_EBADMEMLENGTH);\r
     return;\r
   }\r
-  \r
+\r
   Address = AsciiStrHexToUintn (AddressBuffer);\r
   Length = AsciiStrHexToUintn (InBufPtr);\r
-  \r
+\r
   TransferFromMemToOutBufAndSend (Length, (unsigned char *)Address);\r
 }\r
 \r
 \r
 /** "M addr,length :XX..."\r
- Find the Length of the area in bytes to write and the start addres. Finally, pass them to \r
+ Find the Length of the area in bytes to write and the start addres. Finally, pass them to\r
  another function, TransferFromInBufToMem, that will write to that memory space the info in\r
  the input buffer.\r
  **/\r
@@ -674,50 +668,50 @@ WriteToMemory (
   CHAR8 *AddrBufPtr; // pointer to the Address buffer\r
   CHAR8 *LengthBufPtr; // pointer to the Length buffer\r
   CHAR8 *InBufPtr; /// pointer to the input buffer\r
-  \r
+\r
   AddrBufPtr = AddressBuffer;\r
   LengthBufPtr = LengthBuffer;\r
   InBufPtr = &PacketData[1];\r
-  \r
+\r
   while (*InBufPtr != ',') {\r
     *AddrBufPtr++ = *InBufPtr++;\r
   }\r
   *AddrBufPtr = '\0';\r
-  \r
+\r
   InBufPtr++; // this skips ',' in the buffer\r
-  \r
+\r
   while (*InBufPtr != ':') {\r
     *LengthBufPtr++ = *InBufPtr++;\r
   }\r
   *LengthBufPtr = '\0';\r
-  \r
+\r
   InBufPtr++; // this skips ':' in the buffer\r
-  \r
+\r
   Address = AsciiStrHexToUintn (AddressBuffer);\r
   Length = AsciiStrHexToUintn (LengthBuffer);\r
-  \r
+\r
   /* Error checking */\r
-  \r
+\r
   //Check if Address is not too long.\r
-  if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) {\r
+  if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {\r
     Print ((CHAR16 *)L"Address too long..\n");\r
-    SendError (GDB_EBADMEMADDRBUFSIZE); \r
+    SendError (GDB_EBADMEMADDRBUFSIZE);\r
     return;\r
   }\r
-  \r
+\r
   //Check if message length is not too long\r
-  if (AsciiStrLen(LengthBuffer) >= MAX_LENGTH_SIZE) {\r
+  if (AsciiStrLen (LengthBuffer) >= MAX_LENGTH_SIZE) {\r
     Print ((CHAR16 *)L"Length too long..\n");\r
-    SendError (GDB_EBADMEMLENGBUFSIZE); \r
+    SendError (GDB_EBADMEMLENGBUFSIZE);\r
     return;\r
   }\r
-  \r
+\r
   // Check if Message is not too long/short.\r
   // 3 = 'M' + ',' + ':'\r
-  MessageLength = (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - AsciiStrLen(LengthBuffer) - 3);\r
+  MessageLength = (AsciiStrLen (PacketData) - AsciiStrLen (AddressBuffer) - AsciiStrLen (LengthBuffer) - 3);\r
   if (MessageLength != (2*Length)) {\r
     //Message too long/short. New data is not the right size.\r
-    SendError (GDB_EBADMEMDATASIZE);   \r
+    SendError (GDB_EBADMEMDATASIZE);\r
     return;\r
   }\r
   TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr);\r
@@ -770,7 +764,7 @@ ParseBreakpointPacket (
   *AddressBufferPtr = '\0';\r
 \r
   //Check if Address is not too long.\r
-  if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) {\r
+  if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {\r
     Print ((CHAR16 *)L"Address too long..\n");\r
     return 40; //EMSGSIZE: Message size too long.\r
   }\r
@@ -801,12 +795,12 @@ gXferObjectReadResponse (
   CHAR8   Char;\r
   UINTN   Count;\r
 \r
-  // responce starts with 'm' or 'l' if it is the end\r
+  // Response starts with 'm' or 'l' if it is the end\r
   OutBufPtr = gOutBuffer;\r
   *OutBufPtr++ = Type;\r
   Count = 1;\r
 \r
-  // Binary data encoding \r
+  // Binary data encoding\r
   OutBufPtr = gOutBuffer;\r
   while (*Str != '\0') {\r
     Char = *Str++;\r
@@ -822,17 +816,17 @@ gXferObjectReadResponse (
 \r
   *OutBufPtr = '\0' ;  // the end of the buffer\r
   SendPacket (gOutBuffer);\r
-  \r
+\r
   return Count;\r
 }\r
 \r
 \r
 /**\r
-  Note: This should be a library function.  In the Apple case you have to add \r
-  the size of the PE/COFF header into the starting address to make things work \r
+  Note: This should be a library function.  In the Apple case you have to add\r
+  the size of the PE/COFF header into the starting address to make things work\r
   right as there is no way to pad the Mach-O for the size of the PE/COFF header.\r
-  \r
-  \r
+\r
+\r
   Returns a pointer to the PDB file name for a PE/COFF image that has been\r
   loaded into system memory with the PE/COFF Loader Library functions.\r
 \r
@@ -850,7 +844,7 @@ gXferObjectReadResponse (
 \r
   @return The PDB file name for the PE/COFF image specified by Pe32Data or NULL\r
           if it cannot be retrieved. DebugBase is only valid if PDB file name is\r
-          valid. \r
+          valid.\r
 \r
 **/\r
 VOID *\r
@@ -901,14 +895,14 @@ PeCoffLoaderGetDebuggerInfo (
                     TEImageAdjust);\r
     }\r
     SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;\r
-    \r
+\r
     // __APPLE__ check this math...\r
     *DebugBase = ((CHAR8 *)Pe32Data) -  TEImageAdjust;\r
   } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
-    \r
+\r
     *DebugBase = Pe32Data;\r
-    \r
-    \r
+\r
+\r
     //\r
     // NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.\r
     //       It is due to backward-compatibility, for some system might\r
@@ -989,39 +983,38 @@ PeCoffLoaderGetDebuggerInfo (
 }\r
 \r
 \r
-\r
-/** \r
+/**\r
   Process "qXfer:object:read:annex:offset,length" request.\r
-  \r
-  Returns an XML document that contains loaded libraries. In our case it is \r
-  infomration in the EFI Debug Inmage Table converted into an XML document.\r
-  \r
-  GDB will call with an arbitrary length (it can't know the real length and \r
-  will reply with chunks of XML that are easy for us to deal with. Gdb will \r
+\r
+  Returns an XML document that contains loaded libraries. In our case it is\r
+  information in the EFI Debug Image Table converted into an XML document.\r
+\r
+  GDB will call with an arbitrary length (it can't know the real length and\r
+  will reply with chunks of XML that are easy for us to deal with. Gdb will\r
   keep calling until we say we are done. XML doc looks like:\r
-  \r
+\r
   <library-list>\r
     <library name="/a/a/c/d.dSYM"><segment address="0x10000000"/></library>\r
     <library name="/a/m/e/e.pdb"><segment address="0x20000000"/></library>\r
     <library name="/a/l/f/f.dll"><segment address="0x30000000"/></library>\r
   </library-list>\r
-  \r
-  Since we can not allocate memory in interupt context this module has \r
+\r
+  Since we can not allocate memory in interrupt context this module has\r
   assumptions about how it will get called:\r
   1) Length will generally be max remote packet size (big enough)\r
   2) First Offset of an XML document read needs to be 0\r
   3) This code will return back small chunks of the XML document on every read.\r
-     Each subseqent call will ask for the next availble part of the document.\r
-     \r
+     Each subsequent call will ask for the next available part of the document.\r
+\r
   Note: The only variable size element in the XML is:\r
-  "  <library name=\"%s\"><segment address=\"%p\"/></library>\n" and it is \r
+  "  <library name=\"%s\"><segment address=\"%p\"/></library>\n" and it is\r
   based on the file path and name of the symbol file. If the symbol file name\r
   is bigger than the max gdb remote packet size we could update this code\r
   to respond back in chunks.\r
 \r
  @param Offset  offset into special data area\r
- @param Length  number of bytes to read starting at Offset  \r
-  \r
+ @param Length  number of bytes to read starting at Offset\r
+\r
  **/\r
 VOID\r
 QxferLibrary (\r
@@ -1036,49 +1029,50 @@ QxferLibrary (
   if (Offset != gPacketqXferLibraryOffset) {\r
     SendError (GDB_EINVALIDARG);\r
     Print (L"\nqXferLibrary (%d, %d) != %d\n", Offset, Length, gPacketqXferLibraryOffset);\r
-    \r
-    // Force a retry from the beginning \r
+\r
+    // Force a retry from the beginning\r
     gPacketqXferLibraryOffset = 0;\r
+\r
     return;\r
   }\r
 \r
   if (Offset == 0) {\r
     gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', "<library-list>\n");\r
-    \r
+\r
     // The owner of the table may have had to ralloc it so grab a fresh copy every time\r
-    // we assume qXferLibrary will get called over and over again until the entire XML table is \r
+    // we assume qXferLibrary will get called over and over again until the entire XML table is\r
     // returned in a tight loop. Since we are in the debugger the table should not get updated\r
     gDebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable;\r
     gEfiDebugImageTableEntry = 0;\r
     return;\r
   }\r
-  \r
+\r
   if (gDebugTable != NULL) {\r
     for (; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {\r
       if (gDebugTable->NormalImage != NULL) {\r
-        if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && \r
+        if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&\r
             (gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {\r
           Pdb = PeCoffLoaderGetDebuggerInfo (\r
-                 gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase, \r
+                 gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase,\r
                  &LoadAddress\r
                  );\r
           if (Pdb != NULL) {\r
             Size = AsciiSPrint (\r
-                    gXferLibraryBuffer, \r
-                    sizeof (gXferLibraryBuffer), \r
-                    "  <library name=\"%a\"><segment address=\"0x%p\"/></library>\n", \r
+                    gXferLibraryBuffer,\r
+                    sizeof (gXferLibraryBuffer),\r
+                    "  <library name=\"%a\"><segment address=\"0x%p\"/></library>\n",\r
                     Pdb,\r
                     LoadAddress\r
                     );\r
             if ((Size != 0) && (Size != (sizeof (gXferLibraryBuffer) - 1))) {\r
               gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', gXferLibraryBuffer);\r
-              \r
+\r
               // Update loop variables so we are in the right place when we get back\r
               gEfiDebugImageTableEntry++;\r
               gDebugTable++;\r
               return;\r
             } else {\r
-              // We could handle <library> entires larger than sizeof (gXferLibraryBuffer) here if \r
+              // We could handle <library> entires larger than sizeof (gXferLibraryBuffer) here if\r
               // needed by breaking up into N packets\r
               // "<library name=\"%s\r
               // the rest of the string (as many packets as required\r
@@ -1086,13 +1080,13 @@ QxferLibrary (
               //\r
               // But right now we just skip any entry that is too big\r
             }\r
-          }           \r
+          }\r
         }\r
-      }  \r
+      }\r
     }\r
   }\r
-  \r
-  \r
+\r
+\r
   gXferObjectReadResponse ('l', "</library-list>\n");\r
   gPacketqXferLibraryOffset = 0;\r
   return;\r
@@ -1102,55 +1096,55 @@ QxferLibrary (
 /**\r
  Exception Hanldler for GDB. It will be called for all exceptions\r
  registered via the gExceptionType[] array.\r
\r
+\r
  @param ExceptionType     Exception that is being processed\r
- @param SystemContext     Register content at time of the exception  \r
+ @param SystemContext     Register content at time of the exception\r
  **/\r
 VOID\r
 EFIAPI\r
-GdbExceptionHandler ( \r
-  IN  EFI_EXCEPTION_TYPE        ExceptionType, \r
-  IN OUT EFI_SYSTEM_CONTEXT     SystemContext \r
+GdbExceptionHandler (\r
+  IN  EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT     SystemContext\r
   )\r
 {\r
   UINT8   GdbExceptionType;\r
   CHAR8   *Ptr;\r
-      \r
-  \r
-  if (ValidateException(ExceptionType, SystemContext) == FALSE) {\r
+\r
+\r
+  if (ValidateException (ExceptionType, SystemContext) == FALSE) {\r
     return;\r
   }\r
 \r
   RemoveSingleStep (SystemContext);\r
-  \r
+\r
   GdbExceptionType = ConvertEFItoGDBtype (ExceptionType);\r
   GdbSendTSignal (SystemContext, GdbExceptionType);\r
-  \r
+\r
   for( ; ; ) {\r
     ReceivePacket (gInBuffer, MAX_BUF_SIZE);\r
-    \r
+\r
     switch (gInBuffer[0]) {\r
       case '?':\r
         GdbSendTSignal (SystemContext, GdbExceptionType);\r
         break;\r
-          \r
+\r
       case 'c':\r
-        ContinueAtAddress (SystemContext, gInBuffer);          \r
+        ContinueAtAddress (SystemContext, gInBuffer);\r
         return;\r
 \r
       case 'g':\r
         ReadGeneralRegisters (SystemContext);\r
         break;\r
-          \r
+\r
       case 'G':\r
         WriteGeneralRegisters (SystemContext, gInBuffer);\r
         break;\r
-          \r
+\r
       case 'H':\r
-        //Return "OK" packet since we don't have more than one thread. \r
+        //Return "OK" packet since we don't have more than one thread.\r
         SendSuccess ();\r
         break;\r
-          \r
+\r
       case 'm':\r
         ReadFromMemory (gInBuffer);\r
         break;\r
@@ -1166,7 +1160,7 @@ GdbExceptionHandler (
       //\r
       // Still debugging this code. Not used in Darwin\r
       //\r
-      case 'q': \r
+      case 'q':\r
         // General Query Packets\r
         if (AsciiStrnCmp (gInBuffer, "qSupported", 10) == 0) {\r
           // return what we currently support, we don't parse what gdb suports\r
@@ -1176,7 +1170,7 @@ GdbExceptionHandler (
           // ‘qXfer:libraries:read::offset,length\r
           // gInBuffer[22] is offset string, ++Ptr is length string’\r
           for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++);\r
-        \r
+\r
           // Not sure if multi-radix support is required. Currently only support decimal\r
           QxferLibrary (AsciiStrHexToUintn (&gInBuffer[22]), AsciiStrHexToUintn (++Ptr));\r
         } if (AsciiStrnCmp (gInBuffer, "qOffsets", 10) == 0) {\r
@@ -1189,18 +1183,18 @@ GdbExceptionHandler (
         break;\r
 \r
       case 's':\r
-        SingleStep (SystemContext, gInBuffer);          \r
+        SingleStep (SystemContext, gInBuffer);\r
         return;\r
-          \r
+\r
       case 'z':\r
         RemoveBreakPoint (SystemContext, gInBuffer);\r
         break;\r
-  \r
+\r
       case 'Z':\r
         InsertBreakPoint (SystemContext, gInBuffer);\r
         break;\r
-                  \r
-      default:  \r
+\r
+      default:\r
         //Send empty packet\r
         SendNotSupported ();\r
         break;\r
@@ -1210,28 +1204,28 @@ GdbExceptionHandler (
 \r
 \r
 /**\r
- Periodic callback for GDB. This function is used to catch a ctrl-c or other \r
+ Periodic callback for GDB. This function is used to catch a ctrl-c or other\r
  break in type command from GDB.\r
\r
- @param SystemContext     Register content at time of the call  \r
+\r
+ @param SystemContext     Register content at time of the call\r
  **/\r
 VOID\r
 EFIAPI\r
-GdbPeriodicCallBack ( \r
-  IN OUT EFI_SYSTEM_CONTEXT     SystemContext \r
+GdbPeriodicCallBack (\r
+  IN OUT EFI_SYSTEM_CONTEXT     SystemContext\r
   )\r
 {\r
   //\r
-  // gCtrlCBreakFlag may have been set from a previous F response package \r
-  // and we set the global as we need to process it at a point where we \r
+  // gCtrlCBreakFlag may have been set from a previous F response package\r
+  // and we set the global as we need to process it at a point where we\r
   // can update the system context. If we are in the middle of processing\r
   // a F Packet it is not safe to read the GDB serial stream so we need\r
   // to skip it on this check\r
   //\r
   if (!gCtrlCBreakFlag && !gProcessingFPacket) {\r
     //\r
-    // Ctrl-C was not pending so grab any pending characters and see if they \r
-    // are a Ctrl-c (0x03). If so set the Ctrl-C global. \r
+    // Ctrl-C was not pending so grab any pending characters and see if they\r
+    // are a Ctrl-c (0x03). If so set the Ctrl-C global.\r
     //\r
     while (TRUE) {\r
       if (!GdbIsCharAvailable ()) {\r
@@ -1240,7 +1234,7 @@ GdbPeriodicCallBack (
         //\r
         break;\r
       }\r
-      \r
+\r
       if (GdbGetChar () == 0x03) {\r
         gCtrlCBreakFlag = TRUE;\r
         //\r
@@ -1250,11 +1244,11 @@ GdbPeriodicCallBack (
       }\r
     }\r
   }\r
-  \r
+\r
   if (gCtrlCBreakFlag) {\r
     //\r
     // Update the context to force a single step trap when we exit the GDB\r
-    // stub. This will trasfer control to GdbExceptionHandler () and let\r
+    // stub. This will transfer control to GdbExceptionHandler () and let\r
     // us break into the program. We don't want to break into the GDB stub.\r
     //\r
     AddSingleStep (SystemContext);\r