static int writeBinaryBufferToByteMemory(Buffer* pBuffer, void* pvMemory, uint32_t writeByteCount) { uint8_t* p = (uint8_t*) pvMemory; while (writeByteCount-- > 0) { char currChar; __try { __throwing_func( currChar = Buffer_ReadChar(pBuffer) ); __throwing_func( currChar = unescapeCharIfNecessary(pBuffer, currChar) ); } __catch { __rethrow_and_return(0); } Platform_MemWrite8(p++, (uint8_t)currChar); if (Platform_WasMemoryFaultEncountered()) return 0; } return 1; }
int Platform_CommReceiveChar(void) { waitForReceiveData(); int character = Buffer_ReadChar(&g_receiveBuffer); clearExceptionCode(); return character; }
static char readNextCharAndUnescape(Buffer* pBuffer) { char nextChar; __try nextChar = Buffer_ReadChar(pBuffer); __catch __rethrow_and_return('\0'); return unescapeByte(nextChar); }
static int handleGDBCommand(void) { Buffer* pBuffer = GetBuffer(); uint32_t handlerResult = 0; char commandChar; size_t i; static const struct { uint32_t (*Handler)(void); char commandChar; } commandTable[] = { {Send_T_StopResponse, '?'}, {HandleContinueCommand, 'c'}, {HandleContinueWithSignalCommand, 'C'}, {HandleFileIOCommand, 'F'}, {HandleRegisterReadCommand, 'g'}, {HandleRegisterWriteCommand, 'G'}, {HandleMemoryReadCommand, 'm'}, {HandleMemoryWriteCommand, 'M'}, {HandleQueryCommand, 'q'}, {HandleSingleStepCommand, 's'}, {HandleSingleStepWithSignalCommand, 'S'}, {HandleBinaryMemoryWriteCommand, 'X'}, {HandleBreakpointWatchpointRemoveCommand, 'z'}, {HandleBreakpointWatchpointSetCommand, 'Z'} }; getPacketFromGDB(); commandChar = Buffer_ReadChar(pBuffer); for (i = 0 ; i < ARRAY_SIZE(commandTable) ; i++) { if (commandTable[i].commandChar == commandChar) { handlerResult = commandTable[i].Handler(); if (handlerResult & HANDLER_RETURN_RETURN_IMMEDIATELY) { return handlerResult & HANDLER_RETURN_RESUME_PROGRAM; } else { break; } } } if (ARRAY_SIZE(commandTable) == i) PrepareEmptyResponseForUnknownCommand(); SendPacketToGdb(); return (handlerResult & HANDLER_RETURN_RESUME_PROGRAM); }
static void parseBreakpointWatchpointCommandArguments(BreakpointWatchpointArguments* pArguments) { Buffer* pBuffer = GetBuffer(); __try { __throwing_func( pArguments->type = Buffer_ReadChar(pBuffer) ); __throwing_func( ThrowIfNextCharIsNotEqualTo(pBuffer, ',') ); __throwing_func( pArguments->address = ReadUIntegerArgument(pBuffer) ); __throwing_func( ThrowIfNextCharIsNotEqualTo(pBuffer, ',') ); __throwing_func( pArguments->kind = ReadUIntegerArgument(pBuffer) ); } __catch { __rethrow; } }
static int readBytesFromBinaryBuffer(Buffer* pBuffer, void* pvMemory, uint32_t writeByteCount) { uint8_t* p = (uint8_t*) pvMemory; while (writeByteCount-- > 0) { char currChar; __try { __throwing_func( currChar = Buffer_ReadChar(pBuffer) ); __throwing_func( currChar = unescapeCharIfNecessary(pBuffer, currChar) ); } __catch { __rethrow_and_return(0); } *p++ = (uint8_t)currChar; } return 1; }