]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/GdbStub/GdbStub.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmbeddedPkg / GdbStub / GdbStub.c
index 213038ad08c93f04a8a46472c8d1b8fb453db526..e6e07b87b642bc4463a7ad2fe4811b26b2dfa5fb 100644 (file)
@@ -2,61 +2,52 @@
   UEFI driver that implements a GDB stub\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
+  will blow out the stack. Serial IO calls DEBUG, debug calls Serial IO, ...\r
 \r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\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
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include <GdbStubInternal.h>\r
 #include <Protocol/DebugPort.h>\r
 \r
-\r
-UINTN     gMaxProcessorIndex = 0;\r
+UINTN  gMaxProcessorIndex = 0;\r
 \r
 //\r
 // Buffers for basic gdb communication\r
 //\r
-CHAR8 gInBuffer[MAX_BUF_SIZE];\r
-CHAR8 gOutBuffer[MAX_BUF_SIZE];\r
+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
 // 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
-VOID      *gGdbSymbolEventHandlerRegistration = NULL;\r
+BOOLEAN    gSymbolTableUpdate = FALSE;\r
+EFI_EVENT  gEvent;\r
+VOID       *gGdbSymbolEventHandlerRegistration = NULL;\r
 \r
 //\r
 // Globals for returning XML from qXfer:libraries:read packet\r
 //\r
-UINTN                             gPacketqXferLibraryOffset = 0;\r
-UINTN                             gEfiDebugImageTableEntry = 0;\r
-EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL;\r
-EFI_DEBUG_IMAGE_INFO              *gDebugTable = NULL;\r
-CHAR8                             gXferLibraryBuffer[2000];\r
-\r
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
+UINTN                              gPacketqXferLibraryOffset = 0;\r
+UINTN                              gEfiDebugImageTableEntry  = 0;\r
+EFI_DEBUG_IMAGE_INFO_TABLE_HEADER  *gDebugImageTableHeader   = NULL;\r
+EFI_DEBUG_IMAGE_INFO               *gDebugTable              = NULL;\r
+CHAR8                              gXferLibraryBuffer[2000];\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8  mHexToStr[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };\r
 \r
 VOID\r
 EFIAPI\r
 GdbSymbolEventHandler (\r
-  IN  EFI_EVENT       Event,\r
-  IN  VOID            *Context\r
+  IN  EFI_EVENT  Event,\r
+  IN  VOID       *Context\r
   )\r
 {\r
 }\r
 \r
-\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
@@ -97,7 +88,7 @@ GdbStubEntry (
                   &Handles\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "Debug Support Protocol not found\n"));\r
+    DEBUG ((DEBUG_ERROR, "Debug Support Protocol not found\n"));\r
 \r
     return Status;\r
   }\r
@@ -109,7 +100,7 @@ GdbStubEntry (
     Status = gBS->HandleProtocol (\r
                     Handles[HandleCount],\r
                     &gEfiDebugSupportProtocolGuid,\r
-                    (VOID **) &DebugSupport\r
+                    (VOID **)&DebugSupport\r
                     );\r
     if (!EFI_ERROR (Status)) {\r
       if (CheckIsa (DebugSupport->Isa)) {\r
@@ -119,10 +110,11 @@ GdbStubEntry (
       }\r
     }\r
   } while (HandleCount > 0);\r
+\r
   FreePool (Handles);\r
 \r
   if (!IsaSupported) {\r
-    DEBUG ((EFI_D_ERROR, "Debug Support Protocol does not support our ISA\n"));\r
+    DEBUG ((DEBUG_ERROR, "Debug Support Protocol does not support our ISA\n"));\r
 \r
     return EFI_NOT_FOUND;\r
   }\r
@@ -130,17 +122,18 @@ GdbStubEntry (
   Status = DebugSupport->GetMaximumProcessorIndex (DebugSupport, &gMaxProcessorIndex);\r
   ASSERT_EFI_ERROR (Status);\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
+  DEBUG ((DEBUG_INFO, "Debug Support Protocol ISA %x\n", DebugSupport->Isa));\r
+  DEBUG ((DEBUG_INFO, "Debug Support Protocol Processor Index %d\n", gMaxProcessorIndex));\r
 \r
   // Call processor-specific init routine\r
   InitializeProcessor ();\r
 \r
   for (Processor = 0; Processor <= gMaxProcessorIndex; Processor++) {\r
     for (Index = 0; Index < MaxEfiException (); Index++) {\r
-      Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor,  GdbExceptionHandler, gExceptionType[Index].Exception);\r
+      Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor, GdbExceptionHandler, gExceptionType[Index].Exception);\r
       ASSERT_EFI_ERROR (Status);\r
     }\r
+\r
     //\r
     // Current edk2 DebugPort is not interrupt context safe so we can not use it\r
     //\r
@@ -171,10 +164,9 @@ GdbStubEntry (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-\r
- if (PcdGetBool (PcdGdbSerial)) {\r
-   GdbInitializeSerialConsole ();\r
- }\r
+  if (PcdGetBool (PcdGdbSerial)) {\r
+    GdbInitializeSerialConsole ();\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -186,16 +178,15 @@ GdbStubEntry (
  @param     *address                the start address of the transferring/writing the memory\r
  @param     *new_data               the new data to be written to memory\r
  **/\r
-\r
 VOID\r
 TransferFromInBufToMem (\r
-  IN    UINTN                       Length,\r
-  IN    unsigned char               *Address,\r
-  IN    CHAR8                       *NewData\r
+  IN    UINTN          Length,\r
+  IN    unsigned char  *Address,\r
+  IN    CHAR8          *NewData\r
   )\r
 {\r
-  CHAR8 c1;\r
-  CHAR8 c2;\r
+  CHAR8  c1;\r
+  CHAR8  c2;\r
 \r
   while (Length-- > 0) {\r
     c1 = (CHAR8)HexCharToInt (*NewData++);\r
@@ -206,13 +197,13 @@ TransferFromInBufToMem (
       SendError (GDB_EBADMEMDATA);\r
       return;\r
     }\r
+\r
     *Address++ = (UINT8)((c1 << 4) + c2);\r
   }\r
 \r
-  SendSuccess();\r
+  SendSuccess ();\r
 }\r
 \r
-\r
 /**\r
  Transfer Length bytes of memory starting at Address to an output buffer, OutBuffer. This function will finally send the buffer\r
  as a packet.\r
@@ -220,56 +211,54 @@ TransferFromInBufToMem (
  @param     Length                  the number of the bytes to be transferred/read\r
  @param     *address                pointer to the start address of the transferring/reading the memory\r
  **/\r
-\r
 VOID\r
 TransferFromMemToOutBufAndSend (\r
-  IN    UINTN                       Length,\r
-  IN    unsigned char               *Address\r
+  IN    UINTN          Length,\r
+  IN    unsigned char  *Address\r
   )\r
 {\r
   // there are Length bytes and every byte is represented as 2 hex chars\r
-  CHAR8   OutBuffer[MAX_BUF_SIZE];\r
-  CHAR8   *OutBufPtr;             // pointer to the output buffer\r
-  CHAR8   Char;\r
+  CHAR8  OutBuffer[MAX_BUF_SIZE];\r
+  CHAR8  *OutBufPtr;              // pointer to the output buffer\r
+  CHAR8  Char;\r
 \r
-  if (ValidateAddress(Address) == FALSE) {\r
-    SendError(14);\r
+  if (ValidateAddress (Address) == FALSE) {\r
+    SendError (14);\r
     return;\r
   }\r
 \r
   OutBufPtr = OutBuffer;\r
   while (Length > 0) {\r
-\r
     Char = mHexToStr[*Address >> 4];\r
     if ((Char >= 'A') && (Char <= 'F')) {\r
       Char = Char - 'A' + 'a';\r
     }\r
+\r
     *OutBufPtr++ = Char;\r
 \r
     Char = mHexToStr[*Address & 0x0f];\r
     if ((Char >= 'A') && (Char <= 'F')) {\r
       Char = Char - 'A' + 'a';\r
     }\r
+\r
     *OutBufPtr++ = Char;\r
 \r
     Address++;\r
     Length--;\r
   }\r
 \r
-  *OutBufPtr = '\0' ;  // the end of the buffer\r
+  *OutBufPtr = '\0'  // the end of the buffer\r
   SendPacket (OutBuffer);\r
 }\r
 \r
-\r
-\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
-  the packet teminating character '#' and the two digit checksum.\r
+  the packet terminating 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
-  in an infinit loop. This is so if you unplug the debugger code just keeps running\r
+  in an infinite loop. This is so if you unplug the debugger code just keeps running\r
 \r
   @param PacketData   Payload data for the packet\r
 \r
@@ -279,20 +268,19 @@ TransferFromMemToOutBufAndSend (
 **/\r
 UINTN\r
 SendPacket (\r
-  IN  CHAR8 *PacketData\r
+  IN  CHAR8  *PacketData\r
   )\r
 {\r
-  UINT8 CheckSum;\r
-  UINTN Timeout;\r
-  CHAR8 *Ptr;\r
-  CHAR8 TestChar;\r
-  UINTN Count;\r
+  UINT8  CheckSum;\r
+  UINTN  Timeout;\r
+  CHAR8  *Ptr;\r
+  CHAR8  TestChar;\r
+  UINTN  Count;\r
 \r
   Timeout = PcdGet32 (PcdGdbMaxPacketRetryCount);\r
 \r
   Count = 0;\r
   do {\r
-\r
     Ptr = PacketData;\r
 \r
     if (Timeout-- == 0) {\r
@@ -303,7 +291,7 @@ SendPacket (
     // Packet prefix\r
     GdbPutChar ('$');\r
 \r
-    for (CheckSum = 0, Count =; *Ptr != '\0'; Ptr++, Count++) {\r
+    for (CheckSum = 0, Count = 0; *Ptr != '\0'; Ptr++, Count++) {\r
       GdbPutChar (*Ptr);\r
       CheckSum = CheckSum + *Ptr;\r
     }\r
@@ -323,9 +311,9 @@ SendPacket (
   Receive a GDB Remote Serial Protocol Packet\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
+  the packet terminating 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
+  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
   If an ack '+' is not sent resend the packet\r
@@ -337,38 +325,40 @@ SendPacket (
 **/\r
 UINTN\r
 ReceivePacket (\r
-  OUT  CHAR8 *PacketData,\r
-  IN   UINTN PacketDataSize\r
- )\r
+  OUT  CHAR8  *PacketData,\r
+  IN   UINTN  PacketDataSize\r
 )\r
 {\r
-  UINT8 CheckSum;\r
-  UINTN Index;\r
-  CHAR8 Char;\r
-  CHAR8 SumString[3];\r
-  CHAR8 TestChar;\r
+  UINT8  CheckSum;\r
+  UINTN  Index;\r
+  CHAR8  Char;\r
+  CHAR8  SumString[3];\r
+  CHAR8  TestChar;\r
 \r
   ZeroMem (PacketData, PacketDataSize);\r
 \r
-  for (;;) {\r
-      // wait for the start of a packet\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
+retry:\r
     for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) {\r
       Char = GdbGetChar ();\r
       if (Char == '$') {\r
         goto retry;\r
       }\r
+\r
       if (Char == '#') {\r
         break;\r
       }\r
 \r
       PacketData[Index] = Char;\r
-      CheckSum = CheckSum + Char;\r
+      CheckSum          = CheckSum + Char;\r
     }\r
+\r
     PacketData[Index] = '\0';\r
 \r
     if (Index == PacketDataSize) {\r
@@ -392,33 +382,31 @@ ReceivePacket (
     }\r
   }\r
 \r
-  //return 0;\r
+  // return 0;\r
 }\r
 \r
-\r
 /**\r
  Empties the given buffer\r
  @param   Buf          pointer to the first element in buffer to be emptied\r
  **/\r
 VOID\r
 EmptyBuffer (\r
-  IN  CHAR8           *Buf\r
+  IN  CHAR8  *Buf\r
   )\r
 {\r
   *Buf = '\0';\r
 }\r
 \r
-\r
 /**\r
  Converts an 8-bit Hex Char into a INTN.\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
+ @retval  a INTN, from 0 to 15, that corresponds to Char\r
  -1 if Char is not a hex character\r
  **/\r
 INTN\r
 HexCharToInt (\r
-  IN  CHAR8           Char\r
+  IN  CHAR8  Char\r
   )\r
 {\r
   if ((Char >= 'A') && (Char <= 'F')) {\r
@@ -427,13 +415,14 @@ HexCharToInt (
     return Char - 'a' + 10;\r
   } else if ((Char >= '0') && (Char <= '9')) {\r
     return Char - '0';\r
-  } else { // if not a hex value, return a negative value\r
+  } else {\r
+    // if not a hex value, return a negative value\r
     return -1;\r
   }\r
 }\r
 \r
-  // 'E' + the biggest error number is 255, so its 2 hex digits + buffer end\r
-CHAR8 *gError = "E__";\r
+// 'E' + the biggest error number is 255, so its 2 hex digits + buffer end\r
+CHAR8  *gError = "E__";\r
 \r
 /** 'E NN'\r
  Send an error with the given error number after converting to hex.\r
@@ -445,20 +434,18 @@ CHAR8 *gError = "E__";
 VOID\r
 EFIAPI\r
 SendError (\r
-  IN  UINT8              ErrorNum\r
+  IN  UINT8  ErrorNum\r
   )\r
 {\r
   //\r
   // Replace _, or old data, with current errno\r
   //\r
-  gError[1] = mHexToStr [ErrorNum >> 4];\r
-  gError[2] = mHexToStr [ErrorNum & 0x0f];\r
+  gError[1] = mHexToStr[ErrorNum >> 4];\r
+  gError[2] = mHexToStr[ErrorNum & 0x0f];\r
 \r
   SendPacket (gError); // send buffer\r
 }\r
 \r
-\r
-\r
 /**\r
  Send 'OK' when the function is done executing successfully.\r
  **/\r
@@ -471,7 +458,6 @@ SendSuccess (
   SendPacket ("OK"); // send buffer\r
 }\r
 \r
-\r
 /**\r
  Send empty packet to specify that particular command/functionality is not supported.\r
  **/\r
@@ -484,7 +470,6 @@ SendNotSupported (
   SendPacket ("");\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
@@ -497,24 +482,24 @@ GdbSendTSignal (
   IN  UINT8               GdbExceptionType\r
   )\r
 {\r
-  CHAR8 TSignalBuffer[128];\r
-  CHAR8 *TSignalPtr;\r
-  UINTN BreakpointDetected;\r
-  BREAK_TYPE BreakType;\r
-  UINTN DataAddress;\r
-  CHAR8 *WatchStrPtr = NULL;\r
-  UINTN RegSize;\r
+  CHAR8       TSignalBuffer[128];\r
+  CHAR8       *TSignalPtr;\r
+  UINTN       BreakpointDetected;\r
+  BREAK_TYPE  BreakType;\r
+  UINTN       DataAddress;\r
+  CHAR8       *WatchStrPtr = NULL;\r
+  UINTN       RegSize;\r
 \r
   TSignalPtr = &TSignalBuffer[0];\r
 \r
-  //Construct TSignal packet\r
+  // Construct TSignal packet\r
   *TSignalPtr++ = 'T';\r
 \r
   //\r
   // replace _, or previous value, with Exception type\r
   //\r
-  *TSignalPtr++ = mHexToStr [GdbExceptionType >> 4];\r
-  *TSignalPtr++ = mHexToStr [GdbExceptionType & 0x0f];\r
+  *TSignalPtr++ = mHexToStr[GdbExceptionType >> 4];\r
+  *TSignalPtr++ = mHexToStr[GdbExceptionType & 0x0f];\r
 \r
   if (GdbExceptionType == GDB_SIGTRAP) {\r
     if (gSymbolTableUpdate) {\r
@@ -525,27 +510,25 @@ GdbSendTSignal (
       while (*WatchStrPtr != '\0') {\r
         *TSignalPtr++ = *WatchStrPtr++;\r
       }\r
+\r
       gSymbolTableUpdate = FALSE;\r
     } else {\r
-\r
-\r
       //\r
       // possible n:r pairs\r
       //\r
 \r
-      //Retrieve the breakpoint number\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
+      // Figure out if the exception is happend due to watch, rwatch or awatch.\r
       BreakType = GetBreakpointType (SystemContext, BreakpointDetected);\r
 \r
-      //INFO: rwatch is not supported due to the way IA32 debug registers work\r
+      // INFO: rwatch is not supported due to the way IA32 debug registers work\r
       if ((BreakType == DataWrite) || (BreakType == DataRead) || (BreakType == DataReadWrite)) {\r
-\r
-        //Construct n:r pair\r
+        // Construct n:r pair\r
         DataAddress = GetBreakpointDataAddress (SystemContext, BreakpointDetected);\r
 \r
-        //Assign appropriate buffer to print particular watchpoint type\r
+        // Assign appropriate buffer to print particular watchpoint type\r
         if (BreakType == DataWrite) {\r
           WatchStrPtr = "watch";\r
         } else if (BreakType == DataRead) {\r
@@ -560,14 +543,14 @@ GdbSendTSignal (
 \r
         *TSignalPtr++ = ':';\r
 \r
-        //Set up series of bytes in big-endian byte order. "awatch" won't work with little-endian byte order.\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
-          RegSize = RegSize-4;\r
+          RegSize       = RegSize-4;\r
           *TSignalPtr++ = mHexToStr[(UINT8)(DataAddress >> RegSize) & 0xf];\r
         }\r
 \r
-        //Always end n:r pair with ';'\r
+        // Always end n:r pair with ';'\r
         *TSignalPtr++ = ';';\r
       }\r
     }\r
@@ -578,7 +561,6 @@ GdbSendTSignal (
   SendPacket (TSignalBuffer);\r
 }\r
 \r
-\r
 /**\r
  Translates the EFI mapping to GDB mapping\r
 \r
@@ -587,95 +569,95 @@ GdbSendTSignal (
  **/\r
 UINT8\r
 ConvertEFItoGDBtype (\r
-  IN  EFI_EXCEPTION_TYPE      EFIExceptionType\r
+  IN  EFI_EXCEPTION_TYPE  EFIExceptionType\r
   )\r
 {\r
-  UINTN Index;\r
+  UINTN  Index;\r
 \r
-  for (Index = 0; Index < MaxEfiException () ; Index++) {\r
+  for (Index = 0; Index < MaxEfiException (); Index++) {\r
     if (gExceptionType[Index].Exception == EFIExceptionType) {\r
       return gExceptionType[Index].SignalNo;\r
     }\r
   }\r
+\r
   return GDB_SIGTRAP; // this is a GDB trap\r
 }\r
 \r
-\r
 /** "m addr,length"\r
- Find the Length of the area to read and the start addres. Finally, pass them to\r
+ Find the Length of the area to read and the start address. 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
 VOID\r
 EFIAPI\r
 ReadFromMemory (\r
-  CHAR8 *PacketData\r
+  CHAR8  *PacketData\r
   )\r
 {\r
-  UINTN Address;\r
-  UINTN Length;\r
-  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
+  UINTN  Address;\r
+  UINTN  Length;\r
+  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
   AddrBufPtr = AddressBuffer;\r
-  InBufPtr = &PacketData[1];\r
+  InBufPtr   = &PacketData[1];\r
   while (*InBufPtr != ',') {\r
     *AddrBufPtr++ = *InBufPtr++;\r
   }\r
+\r
   *AddrBufPtr = '\0';\r
 \r
   InBufPtr++; // this skips ',' in the buffer\r
 \r
   /* Error checking */\r
   if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {\r
-    Print((CHAR16 *)L"Address is too long\n");\r
+    Print ((CHAR16 *)L"Address is too long\n");\r
     SendError (GDB_EBADMEMADDRBUFSIZE);\r
     return;\r
   }\r
 \r
   // 2 = 'm' + ','\r
   if (AsciiStrLen (PacketData) - AsciiStrLen (AddressBuffer) - 2 >= MAX_LENGTH_SIZE) {\r
-    Print((CHAR16 *)L"Length is too long\n");\r
+    Print ((CHAR16 *)L"Length is too long\n");\r
     SendError (GDB_EBADMEMLENGTH);\r
     return;\r
   }\r
 \r
   Address = AsciiStrHexToUintn (AddressBuffer);\r
-  Length = AsciiStrHexToUintn (InBufPtr);\r
+  Length  = AsciiStrHexToUintn (InBufPtr);\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 address. Finally, pass them to\r
  another function, TransferFromInBufToMem, that will write to that memory space the info in\r
  the input buffer.\r
  **/\r
 VOID\r
 EFIAPI\r
 WriteToMemory (\r
-  IN CHAR8 *PacketData\r
+  IN CHAR8  *PacketData\r
   )\r
 {\r
-  UINTN Address;\r
-  UINTN Length;\r
-  UINTN MessageLength;\r
-  CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the Address in hex chars\r
-  CHAR8 LengthBuffer[MAX_LENGTH_SIZE]; // the buffer that will hold the Length in hex chars\r
-  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
-  AddrBufPtr = AddressBuffer;\r
+  UINTN  Address;\r
+  UINTN  Length;\r
+  UINTN  MessageLength;\r
+  CHAR8  AddressBuffer[MAX_ADDR_SIZE];  // the buffer that will hold the Address in hex chars\r
+  CHAR8  LengthBuffer[MAX_LENGTH_SIZE]; // the buffer that will hold the Length in hex chars\r
+  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
+  AddrBufPtr   = AddressBuffer;\r
   LengthBufPtr = LengthBuffer;\r
-  InBufPtr = &PacketData[1];\r
+  InBufPtr     = &PacketData[1];\r
 \r
   while (*InBufPtr != ',') {\r
     *AddrBufPtr++ = *InBufPtr++;\r
   }\r
+\r
   *AddrBufPtr = '\0';\r
 \r
   InBufPtr++; // this skips ',' in the buffer\r
@@ -683,23 +665,24 @@ WriteToMemory (
   while (*InBufPtr != ':') {\r
     *LengthBufPtr++ = *InBufPtr++;\r
   }\r
+\r
   *LengthBufPtr = '\0';\r
 \r
   InBufPtr++; // this skips ':' in the buffer\r
 \r
   Address = AsciiStrHexToUintn (AddressBuffer);\r
-  Length = AsciiStrHexToUintn (LengthBuffer);\r
+  Length  = AsciiStrHexToUintn (LengthBuffer);\r
 \r
   /* Error checking */\r
 \r
-  //Check if Address is not too long.\r
+  // Check if Address is not too long.\r
   if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {\r
     Print ((CHAR16 *)L"Address too long..\n");\r
     SendError (GDB_EBADMEMADDRBUFSIZE);\r
     return;\r
   }\r
 \r
-  //Check if message length is not too long\r
+  // Check if message length is not too long\r
   if (AsciiStrLen (LengthBuffer) >= MAX_LENGTH_SIZE) {\r
     Print ((CHAR16 *)L"Length too long..\n");\r
     SendError (GDB_EBADMEMLENGBUFSIZE);\r
@@ -710,10 +693,11 @@ WriteToMemory (
   // 3 = 'M' + ',' + ':'\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
+    // Message too long/short. New data is not the right size.\r
     SendError (GDB_EBADMEMDATASIZE);\r
     return;\r
   }\r
+\r
   TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr);\r
 }\r
 \r
@@ -733,72 +717,74 @@ WriteToMemory (
 **/\r
 UINTN\r
 ParseBreakpointPacket (\r
-  IN  CHAR8 *PacketData,\r
-  OUT UINTN *Type,\r
-  OUT UINTN *Address,\r
-  OUT UINTN *Length\r
+  IN  CHAR8  *PacketData,\r
+  OUT UINTN  *Type,\r
+  OUT UINTN  *Address,\r
+  OUT UINTN  *Length\r
   )\r
 {\r
-  CHAR8 AddressBuffer[MAX_ADDR_SIZE];\r
-  CHAR8 *AddressBufferPtr;\r
-  CHAR8 *PacketDataPtr;\r
+  CHAR8  AddressBuffer[MAX_ADDR_SIZE];\r
+  CHAR8  *AddressBufferPtr;\r
+  CHAR8  *PacketDataPtr;\r
 \r
-  PacketDataPtr = &PacketData[1];\r
+  PacketDataPtr    = &PacketData[1];\r
   AddressBufferPtr = AddressBuffer;\r
 \r
   *Type = AsciiStrHexToUintn (PacketDataPtr);\r
 \r
-  //Breakpoint/watchpoint type should be between 0 to 4\r
+  // Breakpoint/watchpoint type should be between 0 to 4\r
   if (*Type > 4) {\r
     Print ((CHAR16 *)L"Type is invalid\n");\r
-    return 22; //EINVAL: Invalid argument.\r
+    return 22; // EINVAL: Invalid argument.\r
   }\r
 \r
-  //Skip ',' in the buffer.\r
-  while (*PacketDataPtr++ != ',');\r
+  // Skip ',' in the buffer.\r
+  while (*PacketDataPtr++ != ',') {\r
+  }\r
 \r
-  //Parse Address information\r
+  // Parse Address information\r
   while (*PacketDataPtr != ',') {\r
     *AddressBufferPtr++ = *PacketDataPtr++;\r
   }\r
+\r
   *AddressBufferPtr = '\0';\r
 \r
-  //Check if Address is not too long.\r
+  // Check if Address is not too long.\r
   if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {\r
     Print ((CHAR16 *)L"Address too long..\n");\r
-    return 40; //EMSGSIZE: Message size too long.\r
+    return 40; // EMSGSIZE: Message size too long.\r
   }\r
 \r
   *Address = AsciiStrHexToUintn (AddressBuffer);\r
 \r
-  PacketDataPtr++; //This skips , in the buffer\r
+  PacketDataPtr++; // This skips , in the buffer\r
 \r
-  //Parse Length information\r
+  // Parse Length information\r
   *Length = AsciiStrHexToUintn (PacketDataPtr);\r
 \r
-  //Length should be 1, 2 or 4 bytes\r
+  // Length should be 1, 2 or 4 bytes\r
   if (*Length > 4) {\r
     Print ((CHAR16 *)L"Length is invalid\n");\r
-    return 22; //EINVAL: Invalid argument\r
+    return 22; // EINVAL: Invalid argument\r
   }\r
 \r
-  return 0; //0 = No error\r
+  return 0; // 0 = No error\r
 }\r
 \r
 UINTN\r
 gXferObjectReadResponse (\r
-  IN  CHAR8         Type,\r
-  IN  CHAR8         *Str\r
+  IN  CHAR8  Type,\r
+  IN  CHAR8  *Str\r
   )\r
 {\r
-  CHAR8   *OutBufPtr;             // pointer to the output buffer\r
-  CHAR8   Char;\r
-  UINTN   Count;\r
+  CHAR8  *OutBufPtr;              // pointer to the output buffer\r
+  CHAR8  Char;\r
+  UINTN  Count;\r
 \r
   // Response starts with 'm' or 'l' if it is the end\r
-  OutBufPtr = gOutBuffer;\r
+  OutBufPtr    = gOutBuffer;\r
   *OutBufPtr++ = Type;\r
-  Count = 1;\r
+  Count        = 1;\r
 \r
   // Binary data encoding\r
   OutBufPtr = gOutBuffer;\r
@@ -810,17 +796,17 @@ gXferObjectReadResponse (
 \r
       Char ^= 0x20;\r
     }\r
+\r
     *OutBufPtr++ = Char;\r
     Count++;\r
   }\r
 \r
-  *OutBufPtr = '\0' ;  // the end of the buffer\r
+  *OutBufPtr = '\0'  // the end of the buffer\r
   SendPacket (gOutBuffer);\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
@@ -850,20 +836,20 @@ gXferObjectReadResponse (
 VOID *\r
 EFIAPI\r
 PeCoffLoaderGetDebuggerInfo (\r
-  IN VOID     *Pe32Data,\r
-  OUT VOID    **DebugBase\r
+  IN VOID   *Pe32Data,\r
+  OUT VOID  **DebugBase\r
   )\r
 {\r
-  EFI_IMAGE_DOS_HEADER                  *DosHdr;\r
-  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;\r
-  EFI_IMAGE_DATA_DIRECTORY              *DirectoryEntry;\r
-  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       *DebugEntry;\r
-  UINTN                                 DirCount;\r
-  VOID                                  *CodeViewEntryPointer;\r
-  INTN                                  TEImageAdjust;\r
-  UINT32                                NumberOfRvaAndSizes;\r
-  UINT16                                Magic;\r
-  UINTN                                 SizeOfHeaders;\r
+  EFI_IMAGE_DOS_HEADER                 *DosHdr;\r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
+  EFI_IMAGE_DATA_DIRECTORY             *DirectoryEntry;\r
+  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY      *DebugEntry;\r
+  UINTN                                DirCount;\r
+  VOID                                 *CodeViewEntryPointer;\r
+  INTN                                 TEImageAdjust;\r
+  UINT32                               NumberOfRvaAndSizes;\r
+  UINT16                               Magic;\r
+  UINTN                                SizeOfHeaders;\r
 \r
   ASSERT (Pe32Data   != NULL);\r
 \r
@@ -878,7 +864,7 @@ PeCoffLoaderGetDebuggerInfo (
     //\r
     // DOS image header is present, so read the PE header after the DOS image header.\r
     //\r
-    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));\r
   } else {\r
     //\r
     // DOS image header is not present, so PE header is at the image base.\r
@@ -888,91 +874,90 @@ PeCoffLoaderGetDebuggerInfo (
 \r
   if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
     if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {\r
-      DirectoryEntry  = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];\r
-      TEImageAdjust   = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;\r
-      DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +\r
-                    Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +\r
-                    TEImageAdjust);\r
+      DirectoryEntry = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];\r
+      TEImageAdjust  = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;\r
+      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN)Hdr.Te +\r
+                                                           Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +\r
+                                                           TEImageAdjust);\r
     }\r
+\r
     SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;\r
 \r
     // __APPLE__ check this math...\r
     *DebugBase = ((CHAR8 *)Pe32Data) -  TEImageAdjust;\r
   } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
-\r
     *DebugBase = Pe32Data;\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
     //       generate PE32+ image with PE32 Magic.\r
     //\r
     switch (Hdr.Pe32->FileHeader.Machine) {\r
-    case EFI_IMAGE_MACHINE_IA32:\r
-      //\r
-      // Assume PE32 image with IA32 Machine field.\r
-      //\r
-      Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;\r
-      break;\r
-    case EFI_IMAGE_MACHINE_X64:\r
-    case EFI_IMAGE_MACHINE_IA64:\r
-      //\r
-      // Assume PE32+ image with X64 or IPF Machine field\r
-      //\r
-      Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
-      break;\r
-    default:\r
-      //\r
-      // For unknow Machine field, use Magic in optional Header\r
-      //\r
-      Magic = Hdr.Pe32->OptionalHeader.Magic;\r
+      case EFI_IMAGE_MACHINE_IA32:\r
+        //\r
+        // Assume PE32 image with IA32 Machine field.\r
+        //\r
+        Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;\r
+        break;\r
+      case EFI_IMAGE_MACHINE_X64:\r
+      case EFI_IMAGE_MACHINE_IA64:\r
+        //\r
+        // Assume PE32+ image with X64 or IPF Machine field\r
+        //\r
+        Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
+        break;\r
+      default:\r
+        //\r
+        // For unknown Machine field, use Magic in optional Header\r
+        //\r
+        Magic = Hdr.Pe32->OptionalHeader.Magic;\r
     }\r
 \r
     if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       //\r
       // Use PE32 offset get Debug Directory Entry\r
       //\r
-      SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders;\r
+      SizeOfHeaders       = Hdr.Pe32->OptionalHeader.SizeOfHeaders;\r
       NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
-      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+      DirectoryEntry      = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry          = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN)Pe32Data + DirectoryEntry->VirtualAddress);\r
     } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
       //\r
       // Use PE32+ offset get Debug Directory Entry\r
       //\r
-      SizeOfHeaders = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders;\r
+      SizeOfHeaders       = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders;\r
       NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
-      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+      DirectoryEntry      = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry          = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN)Pe32Data + DirectoryEntry->VirtualAddress);\r
     }\r
 \r
     if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
       DirectoryEntry = NULL;\r
-      DebugEntry = NULL;\r
+      DebugEntry     = NULL;\r
     }\r
   } else {\r
     return NULL;\r
   }\r
 \r
-  if (DebugEntry == NULL || DirectoryEntry == NULL) {\r
+  if ((DebugEntry == NULL) || (DirectoryEntry == NULL)) {\r
     return NULL;\r
   }\r
 \r
   for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
     if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
       if (DebugEntry->SizeOfData > 0) {\r
-        CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);\r
-        switch (* (UINT32 *) CodeViewEntryPointer) {\r
-        case CODEVIEW_SIGNATURE_NB10:\r
-          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));\r
-        case CODEVIEW_SIGNATURE_RSDS:\r
-          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));\r
-        case CODEVIEW_SIGNATURE_MTOC:\r
-          *DebugBase = (VOID *)(UINTN)((UINTN)DebugBase - SizeOfHeaders);\r
-          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY));\r
-        default:\r
-          break;\r
+        CodeViewEntryPointer = (VOID *)((UINTN)DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);\r
+        switch (*(UINT32 *)CodeViewEntryPointer) {\r
+          case CODEVIEW_SIGNATURE_NB10:\r
+            return (VOID *)((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));\r
+          case CODEVIEW_SIGNATURE_RSDS:\r
+            return (VOID *)((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));\r
+          case CODEVIEW_SIGNATURE_MTOC:\r
+            *DebugBase = (VOID *)(UINTN)((UINTN)DebugBase - SizeOfHeaders);\r
+            return (VOID *)((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY));\r
+          default:\r
+            break;\r
         }\r
       }\r
     }\r
@@ -982,7 +967,6 @@ PeCoffLoaderGetDebuggerInfo (
   return NULL;\r
 }\r
 \r
-\r
 /**\r
   Process "qXfer:object:read:annex:offset,length" request.\r
 \r
@@ -1018,13 +1002,13 @@ PeCoffLoaderGetDebuggerInfo (
  **/\r
 VOID\r
 QxferLibrary (\r
-  IN  UINTN   Offset,\r
-  IN  UINTN   Length\r
+  IN  UINTN  Offset,\r
+  IN  UINTN  Length\r
   )\r
 {\r
-  VOID                              *LoadAddress;\r
-  CHAR8                             *Pdb;\r
-  UINTN                             Size;\r
+  VOID   *LoadAddress;\r
+  CHAR8  *Pdb;\r
+  UINTN  Size;\r
 \r
   if (Offset != gPacketqXferLibraryOffset) {\r
     SendError (GDB_EINVALIDARG);\r
@@ -1042,28 +1026,29 @@ QxferLibrary (
     // 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
     // returned in a tight loop. Since we are in the debugger the table should not get updated\r
-    gDebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable;\r
+    gDebugTable              = gDebugImageTableHeader->EfiDebugImageInfoTable;\r
     gEfiDebugImageTableEntry = 0;\r
     return;\r
   }\r
 \r
   if (gDebugTable != NULL) {\r
-    for (; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {\r
+    for ( ; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {\r
       if (gDebugTable->NormalImage != NULL) {\r
         if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&\r
-            (gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {\r
+            (gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL))\r
+        {\r
           Pdb = PeCoffLoaderGetDebuggerInfo (\r
-                 gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase,\r
-                 &LoadAddress\r
-                 );\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
-                    Pdb,\r
-                    LoadAddress\r
-                    );\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
@@ -1086,15 +1071,13 @@ QxferLibrary (
     }\r
   }\r
 \r
-\r
   gXferObjectReadResponse ('l', "</library-list>\n");\r
   gPacketqXferLibraryOffset = 0;\r
   return;\r
 }\r
 \r
-\r
 /**\r
- Exception Hanldler for GDB. It will be called for all exceptions\r
+ Exception Handler for GDB. It will be called for all exceptions\r
  registered via the gExceptionType[] array.\r
 \r
  @param ExceptionType     Exception that is being processed\r
@@ -1103,13 +1086,12 @@ QxferLibrary (
 VOID\r
 EFIAPI\r
 GdbExceptionHandler (\r
-  IN  EFI_EXCEPTION_TYPE        ExceptionType,\r
-  IN OUT EFI_SYSTEM_CONTEXT     SystemContext\r
+  IN  EFI_EXCEPTION_TYPE     ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT  SystemContext\r
   )\r
 {\r
-  UINT8   GdbExceptionType;\r
-  CHAR8   *Ptr;\r
-\r
+  UINT8  GdbExceptionType;\r
+  CHAR8  *Ptr;\r
 \r
   if (ValidateException (ExceptionType, SystemContext) == FALSE) {\r
     return;\r
@@ -1120,7 +1102,7 @@ GdbExceptionHandler (
   GdbExceptionType = ConvertEFItoGDBtype (ExceptionType);\r
   GdbSendTSignal (SystemContext, GdbExceptionType);\r
 \r
-  for( ; ; ) {\r
+  for ( ; ; ) {\r
     ReceivePacket (gInBuffer, MAX_BUF_SIZE);\r
 \r
     switch (gInBuffer[0]) {\r
@@ -1141,7 +1123,7 @@ GdbExceptionHandler (
         break;\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
@@ -1163,23 +1145,27 @@ GdbExceptionHandler (
       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
+          // return what we currently support, we don't parse what gdb supports\r
           AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "qXfer:libraries:read+;PacketSize=%d", MAX_BUF_SIZE);\r
           SendPacket (gOutBuffer);\r
         } else if (AsciiStrnCmp (gInBuffer, "qXfer:libraries:read::", 22) == 0) {\r
           // ‘qXfer:libraries:read::offset,length\r
           // gInBuffer[22] is offset string, ++Ptr is length string’\r
-          for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++);\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
+        }\r
+\r
+        if (AsciiStrnCmp (gInBuffer, "qOffsets", 10) == 0) {\r
           AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "Text=1000;Data=f000;Bss=f000");\r
           SendPacket (gOutBuffer);\r
         } else {\r
-          //Send empty packet\r
+          // Send empty packet\r
           SendNotSupported ();\r
         }\r
+\r
         break;\r
 \r
       case 's':\r
@@ -1195,14 +1181,13 @@ GdbExceptionHandler (
         break;\r
 \r
       default:\r
-        //Send empty packet\r
+        // Send empty packet\r
         SendNotSupported ();\r
         break;\r
     }\r
   }\r
 }\r
 \r
-\r
 /**\r
  Periodic callback for GDB. This function is used to catch a ctrl-c or other\r
  break in type command from GDB.\r
@@ -1212,7 +1197,7 @@ GdbExceptionHandler (
 VOID\r
 EFIAPI\r
 GdbPeriodicCallBack (\r
-  IN OUT EFI_SYSTEM_CONTEXT     SystemContext\r
+  IN OUT EFI_SYSTEM_CONTEXT  SystemContext\r
   )\r
 {\r
   //\r