/** ‘G XX...’ Writes the new values received into the input buffer to the general registers @param SystemContext Register content at time of the exception @param InBuffer Pointer to the input buffer received from gdb server **/ VOID EFIAPI WriteGeneralRegisters ( IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *InBuffer ) { UINTN i; CHAR8 *InBufPtr; /// pointer to the input buffer // check to see if the buffer is the right size which is // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129 if (AsciiStrLen(InBuffer) != 129) { // 16 regs, 8 hex chars each, and the end '\0' (escape seq) //Bad message. Message is not the right length SendError (GDB_EBADBUFSIZE); return; } InBufPtr = &InBuffer[1]; // Read the new values for the registers from the input buffer to an array, NewValueArray. // The values in the array are in the gdb ordering for(i=0; i < sizeof (gRegisterOffsets)/sizeof (UINTN); i++) { // there are only 16 registers to write InBufPtr = BasicWriteRegister(SystemContext, i, InBufPtr); } SendSuccess(); }
/** ‘P n...=r...’ Writes the new value of n-th register received into the input buffer to the n-th register @param SystemContext Register content at time of the exception @param InBuffer Ponter to the input buffer received from gdb server **/ VOID EFIAPI WriteNthRegister ( IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *InBuffer ) { UINTN RegNumber; CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array CHAR8 *RegNumBufPtr; CHAR8 *InBufPtr; // pointer to the input buffer // find the register number to write InBufPtr = &InBuffer[1]; RegNumBufPtr = RegNumBuffer; while (*InBufPtr != '=') { *RegNumBufPtr++ = *InBufPtr++; } *RegNumBufPtr = '\0'; RegNumber = AsciiStrHexToUintn (RegNumBuffer); // check if this is a valid Register Number if ((RegNumber < 0) || (RegNumber >= sizeof (gRegisterOffsets)/sizeof (UINTN))) { SendError (GDB_EINVALIDREGNUM); return; } InBufPtr++; // skips the '=' character BasicWriteRegister (SystemContext, RegNumber, InBufPtr); SendSuccess(); }
VOID EFIAPI WriteGeneralRegisters ( IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *InBuffer ) { UINTN i; CHAR8 *InBufPtr; /// pointer to the input buffer UINTN MinLength; UINTN RegisterCount = (sizeof (gRegisterOffsets)/sizeof (UINTN)); MinLength = (RegisterCount * 8) + 1; // 'G' plus the registers in ASCII format if (AsciiStrLen(InBuffer) < MinLength) { //Bad message. Message is not the right length SendError (GDB_EBADBUFSIZE); return; } InBufPtr = &InBuffer[1]; // Read the new values for the registers from the input buffer to an array, NewValueArray. // The values in the array are in the gdb ordering for(i = 0; i < RegisterCount; i++) { InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr); } SendSuccess (); }
VOID EFIAPI RemoveBreakPoint ( IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData ) { UINTN Type; UINTN Address; UINTN Length; UINTN ErrorCode; //Parse breakpoint packet data ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length); if (ErrorCode > 0) { SendError ((UINT8)ErrorCode); return; } switch (Type) { case 0: //Software breakpoint break; default: SendError (GDB_EINVALIDBRKPOINTTYPE); return; } ClearBreakpoint (Address); SendSuccess (); }
VOID EFIAPI InsertBreakPoint ( IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData ) { UINTN Type; UINTN Address; UINTN Length; UINTN ErrorCode; ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length); if (ErrorCode > 0) { SendError ((UINT8)ErrorCode); return; } switch (Type) { case 0: //Software breakpoint break; default : DEBUG((EFI_D_ERROR, "Insert breakpoint default: %x\n", Type)); SendError (GDB_EINVALIDBRKPOINTTYPE); return; } SetBreakpoint (Address); SendSuccess (); }
void CubeSession::authHandler(Value &v) { reqArg(v, 1, "key", "str"); if (v["key"].GetString() == Server.ServerKey || !Server.NeedAuth) { Authed = true; SendSuccess(); } else { SendError(_SE(ERROR_AUTH_FAILED)); } }
VOID TransferFromInBufToMem ( IN UINTN Length, IN unsigned char *Address, IN CHAR8 *NewData ) { CHAR8 c1; CHAR8 c2; while (Length-- > 0) { c1 = (CHAR8)HexCharToInt (*NewData++); c2 = (CHAR8)HexCharToInt (*NewData++); if ((c1 < 0) || (c2 < 0)) { SendError (GDB_EBADMEMDATA); return; } *Address++ = (UINT8)((c1 << 4) + c2); } SendSuccess(); }
/** ‘z1, [addr], [length]’ ‘z2, [addr], [length]’ ‘z3, [addr], [length]’ ‘z4, [addr], [length]’ Remove hardware breakpoint/watchpoint at address addr of size length @param *PacketData Pointer to the Payload data for the packet **/ VOID EFIAPI RemoveBreakPoint ( IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData ) { UINTN Type; UINTN Address; UINTN Length; UINTN Register; BREAK_TYPE BreakType = NotSupported; EFI_STATUS Status; UINTN ErrorCode; //Parse breakpoint packet data ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length); if (ErrorCode > 0) { SendError ((UINT8)ErrorCode); return; } switch (Type) { case 0: //Software breakpoint BreakType = SoftwareBreakpoint; break; case 1: //Hardware breakpoint BreakType = InstructionExecution; break; case 2: //Write watchpoint BreakType = DataWrite; break; case 3: //Read watchpoint BreakType = DataRead; break; case 4: //Access watchpoint BreakType = DataReadWrite; break; default : SendError (GDB_EINVALIDBRKPOINTTYPE); return; } //Find matching debug register Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register); if (EFI_ERROR(Status)) { if (Status == EFI_UNSUPPORTED) { SendNotSupported(); return; } SendError (GDB_ENOSPACE); return; } //Remove breakpoint Status = DisableDebugRegister(SystemContext, Register); if (EFI_ERROR(Status)) { SendError (GDB_EINVALIDARG); return; } SendSuccess (); }
/** ‘Z1, [addr], [length]’ ‘Z2, [addr], [length]’ ‘Z3, [addr], [length]’ ‘Z4, [addr], [length]’ Insert hardware breakpoint/watchpoint at address addr of size length @param SystemContext Register content at time of the exception @param *PacketData Pointer to the Payload data for the packet **/ VOID EFIAPI InsertBreakPoint ( IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData ) { UINTN Type; UINTN Address; UINTN Length; UINTN Register; EFI_STATUS Status; BREAK_TYPE BreakType = NotSupported; UINTN ErrorCode; ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length); if (ErrorCode > 0) { SendError ((UINT8)ErrorCode); return; } switch (Type) { case 0: //Software breakpoint BreakType = SoftwareBreakpoint; break; case 1: //Hardware breakpoint BreakType = InstructionExecution; break; case 2: //Write watchpoint BreakType = DataWrite; break; case 3: //Read watchpoint BreakType = DataRead; break; case 4: //Access watchpoint BreakType = DataReadWrite; break; default : Print ((CHAR16 *)L"Insert breakpoint default: %x\n", Type); SendError (GDB_EINVALIDBRKPOINTTYPE); return; } // Find next free debug register Status = FindNextFreeDebugRegister (SystemContext, &Register); if (EFI_ERROR(Status)) { Print ((CHAR16 *)L"No space left on device\n"); SendError (GDB_ENOSPACE); return; } // Write Address, length data at particular DR register Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType); if (EFI_ERROR(Status)) { if (Status == EFI_UNSUPPORTED) { SendNotSupported(); return; } SendError (GDB_EINVALIDARG); return; } SendSuccess (); }