std::string GdbSrvControllerImpl::ExecuteCommandOnMultiProcessors()

in Exdi/exdigdbsrv/GdbSrvControllerLib/GdbSrvControllerLib.cpp [873:943]


    std::string GdbSrvControllerImpl::ExecuteCommandOnMultiProcessors(_In_ LPCSTR pCommand, _In_ bool isRspWaitNeeded, _In_ size_t stringSize)
    {
        if (pCommand == nullptr)
        {
            throw _com_error(E_POINTER);
        }

        std::string result;
        if (result.max_size() < stringSize)
        {
            throw _com_error(E_INVALIDARG);
        }

        if (result.capacity() < stringSize)
        {
            result.reserve(stringSize);
        }

        if (m_pTextHandler != nullptr && m_displayCommands)
        {
            m_pTextHandler->HandleText(GdbSrvTextType::Command, pCommand, strlen(pCommand));
        }

        std::string command(pCommand);

        bool isDone = false;
        unsigned numberOfCoreConnections = static_cast<unsigned>(m_pRspClient->GetNumberOfStreamConnections());

        for (unsigned core = 0; core < numberOfCoreConnections; ++core)
        {
            isDone = m_pRspClient->SendRspPacket(command, core);
            if (!isDone)
            {
                break;
            }
        }

        if (isDone)
        {
            bool IsPollingChannelMode = true;

            //  Start checking response from the last known processor core.
            unsigned core = GetLastKnownActiveCpu();
            for (;;)
            {
                isDone = m_pRspClient->ReceiveRspPacketEx(result, core, isRspWaitNeeded, IsPollingChannelMode, true);
                if (isDone || !IsPollingChannelMode)
                {
                    //  Set the core for the first received stop reply packet.
                    SetLastKnownActiveCpu(core);
                    //  Discard any pending response, but the current one as we received.
                    m_pRspClient->DiscardResponse(core);
                    break;
                }
                core = ++core % numberOfCoreConnections;
            }
        }
        else
        {
            //  A fatal error or a communication error ocurred
            m_pRspClient->HandleRspErrors(GdbSrvTextType::CommandError);
            throw _com_error(HRESULT_FROM_WIN32(m_pRspClient->GetRspLastError()));
        }

        if (m_pTextHandler != nullptr && m_displayCommands)
        {
            const char * pResult = result.c_str(); 
            m_pTextHandler->HandleText(GdbSrvTextType::CommandOutput, pResult, strlen(pResult));
        }
        return result;
    }