in Exdi/exdigdbsrv/GdbSrvControllerLib/GdbSrvControllerLib.cpp [1933:2023]
bool GdbSrvControllerImpl::HandleAsynchronousCommandResponse(_In_ const std::string & cmdResponse,
_Out_ StopReplyPacketStruct * pRspPacket)
{
assert(pRspPacket != nullptr);
bool isParsed = false;
if (!cmdResponse.empty())
{
memset(pRspPacket, 0x00, sizeof(StopReplyPacketStruct));
if (cmdResponse[0] == 'O')
{
// this is just a console message to wait for the real stop reply
// so exit to handle the console message
pRspPacket->status.isOXXPacket = true;
return true;
}
string::size_type startPosition = cmdResponse.find("T");
if (startPosition == string::npos)
{
startPosition = cmdResponse.find("S");
pRspPacket->status.isSAAPacket = true;
}
else
{
pRspPacket->status.isTAAPacket = true;
}
if (startPosition != string::npos)
{
if (sscanf_s(&cmdResponse[startPosition + 1], "%2x", &pRspPacket->stopReason) != 1)
{
pRspPacket->stopReason = TARGET_MARKER;
}
// Extract the thread/processor number
string::size_type pos = cmdResponse.find("thread:");
if (pos != string::npos)
{
pRspPacket->status.isThreadFound = true;
string::size_type regValueStartPos = pos + strlen("thread:");
string::size_type threadEndPos = cmdResponse.find(";", regValueStartPos);
if (threadEndPos != string::npos)
{
std::string processorNumber = cmdResponse.substr(regValueStartPos, threadEndPos - regValueStartPos);
if (!m_targetProcessorIds.empty())
{
std::vector<std::string>::iterator it = std::find(m_targetProcessorIds.begin(), m_targetProcessorIds.end(), processorNumber);
if (it != m_targetProcessorIds.end())
{
processorNumber = *it;
}
}
std::vector<std::string> processorIds;
TargetArchitectureHelpers::TokenizeThreadId(processorNumber, ";", &processorIds);
assert(processorIds.size() == 1);
if (m_targetProcessorIds.empty())
{
m_targetProcessorIds.push_back(processorIds[0]);
}
pRspPacket->processorNumber = GetProcessorNumberByThreadId(processorIds[0]);
}
}
// Extract the current instruction address
if (FindPcAddressFromStopReply(cmdResponse, &pRspPacket->currentAddress))
{
pRspPacket->status.isPcRegFound = true;
}
else
{
// Try to find if this has been a power down or target running packet
if (pRspPacket->status.isSAAPacket)
{
pRspPacket->status.isPowerDown = (cmdResponse.find("S00") != string::npos) ? true : false;
}
}
}
else if (cmdResponse[0] == 'W')
{
pRspPacket->stopReason = TARGET_PROCESS_EXIT;
}
else if (cmdResponse.find("OK") != string::npos)
{
pRspPacket->status.isCoreRunning = true;
}
isParsed = true;
}
return isParsed;
}