X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EmbeddedPkg%2FLibrary%2FGdbDebugAgent%2FGdbDebugAgent.c;h=2e67de6f996b77b6c68e81b8c2647a3928ad8a8f;hp=e12a5ac38e1ea2b3246fbbd2e4e142144c2fd2fb;hb=ccca560b4f22f5f731a11abdb3f79fe7306bfd72;hpb=60274ccab831d7874129a6b6c271969418296960 diff --git a/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.c b/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.c old mode 100755 new mode 100644 index e12a5ac38e..2e67de6f99 --- a/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.c +++ b/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.c @@ -34,8 +34,8 @@ CHAR8 gXferLibraryBuffer[2000]; GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; -// add-symbol-file c:/work/edk2/Build/BeagleBoard/DEBUG_ARMGCC/ARM/BeagleBoardPkg/Sec/Sec/DEBUG/BeagleBoardSec.dll 0x80008360 -CHAR8 *qXferHack = ""; +// add-symbol-file c:/work/edk2/Build/BeagleBoard/DEBUG_GCC48/ARM/BeagleBoardPkg/Sec/Sec/DEBUG/BeagleBoardSec.dll 0x80008360 +CHAR8 *qXferHack = ""; UINTN gXferObjectReadResponse ( @@ -52,7 +52,7 @@ gXferObjectReadResponse ( *OutBufPtr++ = Type; Count = 1; - // Binary data encoding + // Binary data encoding OutBufPtr = gOutBuffer; while (*Str != '\0') { Char = *Str++; @@ -68,42 +68,42 @@ gXferObjectReadResponse ( *OutBufPtr = '\0' ; // the end of the buffer SendPacket (gOutBuffer); - + return Count; } -/** +/** Process "qXfer:object:read:annex:offset,length" request. - - Returns an XML document that contains loaded libraries. In our case it is + + Returns an XML document that contains loaded libraries. In our case it is infomration in the EFI Debug Inmage Table converted into an XML document. - - GDB will call with an arbitrary length (it can't know the real length and - will reply with chunks of XML that are easy for us to deal with. Gdb will + + GDB will call with an arbitrary length (it can't know the real length and + will reply with chunks of XML that are easy for us to deal with. Gdb will keep calling until we say we are done. XML doc looks like: - + - - Since we can not allocate memory in interupt context this module has + + Since we can not allocate memory in interupt context this module has assumptions about how it will get called: 1) Length will generally be max remote packet size (big enough) 2) First Offset of an XML document read needs to be 0 3) This code will return back small chunks of the XML document on every read. Each subseqent call will ask for the next availble part of the document. - + Note: The only variable size element in the XML is: - " \n" and it is + " \n" and it is based on the file path and name of the symbol file. If the symbol file name is bigger than the max gdb remote packet size we could update this code to respond back in chunks. @param Offset offset into special data area - @param Length number of bytes to read starting at Offset - + @param Length number of bytes to read starting at Offset + **/ VOID QxferLibrary ( @@ -134,13 +134,13 @@ TransferFromInBufToMem ( { CHAR8 c1; CHAR8 c2; - + while (Length-- > 0) { c1 = (CHAR8)HexCharToInt (*NewData++); c2 = (CHAR8)HexCharToInt (*NewData++); if ((c1 < 0) || (c2 < 0)) { - SendError (GDB_EBADMEMDATA); + SendError (GDB_EBADMEMDATA); return; } *Address++ = (UINT8)((c1 << 4) + c2); @@ -171,7 +171,7 @@ TransferFromMemToOutBufAndSend ( OutBufPtr = OutBuffer; while (Length > 0) { - + Char = mHexToStr[*Address >> 4]; if ((Char >= 'A') && (Char <= 'F')) { Char = Char - 'A' + 'a'; @@ -196,16 +196,16 @@ TransferFromMemToOutBufAndSend ( /** Send a GDB Remote Serial Protocol Packet - - $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', + + $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', the packet teminating character '#' and the two digit checksum. - - If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up + + If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up in an infinit loop. This is so if you unplug the debugger code just keeps running - @param PacketData Payload data for the packet + @param PacketData Payload data for the packet + - @retval Number of bytes of packet data sent. **/ @@ -219,7 +219,7 @@ SendPacket ( CHAR8 *Ptr; CHAR8 TestChar; UINTN Count; - + Timeout = PcdGet32 (PcdGdbMaxPacketRetryCount); Count = 0; @@ -231,38 +231,38 @@ SendPacket ( // Only try a finite number of times so we don't get stuck in the loop return Count; } - + // Packet prefix GdbPutChar ('$'); - + for (CheckSum = 0, Count =0 ; *Ptr != '\0'; Ptr++, Count++) { GdbPutChar (*Ptr); CheckSum = CheckSum + *Ptr; } - - // Packet terminating character and checksum + + // Packet terminating character and checksum GdbPutChar ('#'); GdbPutChar (mHexToStr[CheckSum >> 4]); GdbPutChar (mHexToStr[CheckSum & 0x0F]); - + TestChar = GdbGetChar (); } while (TestChar != '+'); - + return Count; } /** Receive a GDB Remote Serial Protocol Packet - - $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', + + $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', the packet teminating character '#' and the two digit checksum. - + If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed. (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.) - + If an ack '+' is not sent resend the packet - @param PacketData Payload data for the packet + @param PacketData Payload data for the packet @retval Number of bytes of packet data received. @@ -278,16 +278,16 @@ ReceivePacket ( CHAR8 Char; CHAR8 SumString[3]; CHAR8 TestChar; - + ZeroMem (PacketData, PacketDataSize); - + for (;;) { // wait for the start of a packet TestChar = GdbGetChar (); while (TestChar != '$') { TestChar = GdbGetChar (); }; - + retry: for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) { Char = GdbGetChar (); @@ -307,14 +307,14 @@ ReceivePacket ( continue; } - SumString[0] = GdbGetChar (); + SumString[0] = GdbGetChar (); SumString[1] = GdbGetChar (); SumString[2] = '\0'; - + if (AsciiStrHexToUintn (SumString) == CheckSum) { // Ack: Success GdbPutChar ('+'); - + // Null terminate the callers string PacketData[Index] = '\0'; return Index; @@ -323,27 +323,27 @@ ReceivePacket ( GdbPutChar ('-'); } } - + //return 0; } /** - Empties the given buffer + Empties the given buffer @param Buf pointer to the first element in buffer to be emptied **/ VOID -EmptyBuffer ( +EmptyBuffer ( IN CHAR8 *Buf ) -{ +{ *Buf = '\0'; } /** Converts an 8-bit Hex Char into a INTN. - + @param Char the hex character to be converted into UINTN @retval a INTN, from 0 to 15, that corressponds to Char -1 if Char is not a hex character @@ -360,7 +360,7 @@ HexCharToInt ( } else if ((Char >= '0') && (Char <= '9')) { return Char - '0'; } else { // if not a hex value, return a negative value - return -1; + return -1; } } @@ -371,7 +371,7 @@ CHAR8 *gError = "E__"; Send an error with the given error number after converting to hex. The error number is put into the buffer in hex. '255' is the biggest errno we can send. ex: 162 will be sent as A2. - + @param errno the error number that will be sent **/ VOID @@ -385,7 +385,7 @@ SendError ( // gError[1] = mHexToStr [ErrorNum >> 4]; gError[2] = mHexToStr [ErrorNum & 0x0f]; - + SendPacket (gError); // send buffer } @@ -398,7 +398,7 @@ VOID EFIAPI SendSuccess ( VOID - ) + ) { SendPacket ("OK"); // send buffer } @@ -407,12 +407,12 @@ SendSuccess ( /** Send empty packet to specify that particular command/functionality is not supported. **/ -VOID -EFIAPI +VOID +EFIAPI SendNotSupported ( - VOID - ) -{ + VOID + ) +{ SendPacket (""); } @@ -422,17 +422,17 @@ SendNotSupported ( /** Translates the EFI mapping to GDB mapping - + @param EFIExceptionType EFI Exception that is being processed @retval UINTN that corresponds to EFIExceptionType's GDB exception type number **/ UINT8 -ConvertEFItoGDBtype ( +ConvertEFItoGDBtype ( IN EFI_EXCEPTION_TYPE EFIExceptionType ) -{ +{ UINTN i; - + for (i=0; i < MaxEfiException() ; i++) { if (gExceptionType[i].Exception == EFIExceptionType) { return gExceptionType[i].SignalNo; @@ -443,8 +443,8 @@ ConvertEFItoGDBtype ( /** "m addr,length" - Find the Length of the area to read and the start addres. Finally, pass them to - another function, TransferFromMemToOutBufAndSend, that will read from that memory space and + Find the Length of the area to read and the start addres. Finally, pass them to + another function, TransferFromMemToOutBufAndSend, that will read from that memory space and send it as a packet. **/ @@ -459,37 +459,37 @@ ReadFromMemory ( CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the address in hex chars CHAR8 *AddrBufPtr; // pointer to the address buffer CHAR8 *InBufPtr; /// pointer to the input buffer - + AddrBufPtr = AddressBuffer; InBufPtr = &PacketData[1]; while (*InBufPtr != ',') { *AddrBufPtr++ = *InBufPtr++; } *AddrBufPtr = '\0'; - + InBufPtr++; // this skips ',' in the buffer - + /* Error checking */ if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) { - SendError (GDB_EBADMEMADDRBUFSIZE); + SendError (GDB_EBADMEMADDRBUFSIZE); return; } - + // 2 = 'm' + ',' if (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - 2 >= MAX_LENGTH_SIZE) { - SendError (GDB_EBADMEMLENGTH); + SendError (GDB_EBADMEMLENGTH); return; } - + Address = AsciiStrHexToUintn (AddressBuffer); Length = AsciiStrHexToUintn (InBufPtr); - + TransferFromMemToOutBufAndSend (Length, (unsigned char *)Address); } /** "M addr,length :XX..." - Find the Length of the area in bytes to write and the start addres. Finally, pass them to + Find the Length of the area in bytes to write and the start addres. Finally, pass them to another function, TransferFromInBufToMem, that will write to that memory space the info in the input buffer. **/ @@ -507,48 +507,48 @@ WriteToMemory ( CHAR8 *AddrBufPtr; // pointer to the Address buffer CHAR8 *LengthBufPtr; // pointer to the Length buffer CHAR8 *InBufPtr; /// pointer to the input buffer - + AddrBufPtr = AddressBuffer; LengthBufPtr = LengthBuffer; InBufPtr = &PacketData[1]; - + while (*InBufPtr != ',') { *AddrBufPtr++ = *InBufPtr++; } *AddrBufPtr = '\0'; - + InBufPtr++; // this skips ',' in the buffer - + while (*InBufPtr != ':') { *LengthBufPtr++ = *InBufPtr++; } *LengthBufPtr = '\0'; - + InBufPtr++; // this skips ':' in the buffer - + Address = AsciiStrHexToUintn (AddressBuffer); Length = AsciiStrHexToUintn (LengthBuffer); - + /* Error checking */ - + //Check if Address is not too long. if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) { - SendError (GDB_EBADMEMADDRBUFSIZE); + SendError (GDB_EBADMEMADDRBUFSIZE); return; } - + //Check if message length is not too long if (AsciiStrLen(LengthBuffer) >= MAX_LENGTH_SIZE) { - SendError (GDB_EBADMEMLENGBUFSIZE); + SendError (GDB_EBADMEMLENGBUFSIZE); return; } - + // Check if Message is not too long/short. // 3 = 'M' + ',' + ':' MessageLength = (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - AsciiStrLen(LengthBuffer) - 3); if (MessageLength != (2*Length)) { //Message too long/short. New data is not the right size. - SendError (GDB_EBADMEMDATASIZE); + SendError (GDB_EBADMEMDATASIZE); return; } TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr); @@ -623,7 +623,7 @@ ParseBreakpointPacket ( /** Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints - + @param SystemContext Register content at time of the exception @param GdbExceptionType GDB exception type **/ @@ -644,12 +644,12 @@ GdbSendTSignal ( // // replace _, or previous value, with Exception type // - *TSignalPtr++ = mHexToStr [GdbExceptionType >> 4]; + *TSignalPtr++ = mHexToStr [GdbExceptionType >> 4]; *TSignalPtr++ = mHexToStr [GdbExceptionType & 0x0f]; - + ProcessorSendTSignal (SystemContext, GdbExceptionType, TSignalPtr, sizeof (TSignalBuffer) - 2); - SendPacket (TSignalBuffer); + SendPacket (TSignalBuffer); } VOID @@ -666,7 +666,7 @@ GdbFWrite ( for( ; ; ) { ReceivePacket (gInBuffer, MAX_BUF_SIZE); - + switch (gInBuffer[0]) { case 'm': ReadFromMemory (gInBuffer); @@ -678,7 +678,6 @@ GdbFWrite ( case 'F': return; - break; } } } @@ -698,20 +697,20 @@ GdbFPutString ( /** Exception Hanldler for GDB. It will be called for all exceptions registered via the gExceptionType[] array. - + @param ExceptionType Exception that is being processed - @param SystemContext Register content at time of the exception + @param SystemContext Register content at time of the exception **/ VOID EFIAPI -GdbExceptionHandler ( - IN EFI_EXCEPTION_TYPE ExceptionType, - IN OUT EFI_SYSTEM_CONTEXT SystemContext +GdbExceptionHandler ( + IN EFI_EXCEPTION_TYPE ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext ) { UINT8 GdbExceptionType; CHAR8 *Ptr; - + if (ProcessorControlC (ExceptionType, SystemContext)) { // We tried to process a control C handler and there is nothing to do return; @@ -719,37 +718,37 @@ GdbExceptionHandler ( GdbExceptionType = ConvertEFItoGDBtype (ExceptionType); GdbSendTSignal (SystemContext, GdbExceptionType); - + for( ; ; ) { ReceivePacket (gInBuffer, MAX_BUF_SIZE); - + switch (gInBuffer[0]) { case '?': GdbSendTSignal (SystemContext, GdbExceptionType); break; - + case 'c': - ContinueAtAddress (SystemContext, gInBuffer); + ContinueAtAddress (SystemContext, gInBuffer); return; case 'D': - // gdb wants to disconnect so return "OK" packet since. + // gdb wants to disconnect so return "OK" packet since. SendSuccess (); return; case 'g': ReadGeneralRegisters (SystemContext); break; - + case 'G': WriteGeneralRegisters (SystemContext, gInBuffer); break; - + case 'H': - //Return "OK" packet since we don't have more than one thread. + //Return "OK" packet since we don't have more than one thread. SendSuccess (); break; - + case 'm': ReadFromMemory (gInBuffer); break; @@ -765,7 +764,7 @@ GdbExceptionHandler ( // // Still debugging this code. Not used in Darwin // - case 'q': + case 'q': // General Query Packets if (AsciiStrnCmp (gInBuffer, "qSupported", 10) == 0) { // return what we currently support, we don't parse what gdb suports @@ -775,7 +774,7 @@ GdbExceptionHandler ( // ‘qXfer:libraries:read::offset,length // gInBuffer[22] is offset string, ++Ptr is length string’ for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++); - + // Not sure if multi-radix support is required. Currently only support decimal QxferLibrary (AsciiStrHexToUintn (&gInBuffer[22]), AsciiStrHexToUintn (++Ptr)); } else if (AsciiStrnCmp (gInBuffer, "qOffsets", 8) == 0) { @@ -791,18 +790,18 @@ GdbExceptionHandler ( break; case 's': - SingleStep (SystemContext, gInBuffer); + SingleStep (SystemContext, gInBuffer); return; - + case 'z': RemoveBreakPoint (SystemContext, gInBuffer); break; - + case 'Z': InsertBreakPoint (SystemContext, gInBuffer); break; - - default: + + default: //Send empty packet SendNotSupported (); break;