diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index a717f75e232456eed5d8d177a2de26255fdbacb6..fc6ab6a1a879423487dcea85f8635b09ea6462b3 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -197,28 +197,12 @@ static inline bool isCreatorConsole(const DebuggerRunParameters &sp) class CdbCommand { public: - CdbCommand() - : token(0) - {} - - CdbCommand(int token, CdbEngine::CommandHandler h) - : token(token), handler(h) - {} - - int token; + CdbCommand() {} + CdbCommand(CdbEngine::CommandHandler h) : handler(h) {} CdbEngine::CommandHandler handler; }; -int indexOfCommand(const QList > &l, int token) -{ - const int count = l.size(); - for (int i = 0; i < count; i++) - if (l.at(i)->token == token) - return i; - return -1; -} - static inline bool validMode(DebuggerStartMode sm) { return sm != NoStartMode; @@ -306,7 +290,7 @@ void CdbEngine::init() m_wow64State = wow64Uninitialized; m_outputBuffer.clear(); - m_commandQueue.clear(); + m_commandForToken.clear(); m_currentBuiltinResponse.clear(); m_extensionMessageBuffer.clear(); m_pendingBreakpointMap.clear(); @@ -780,7 +764,7 @@ void CdbEngine::runEngine() bool CdbEngine::commandsPending() const { - return !m_commandQueue.isEmpty(); + return !m_commandForToken.isEmpty(); } void CdbEngine::shutdownInferior() @@ -1193,9 +1177,9 @@ void CdbEngine::postBuiltinCommand(const QByteArray &cmd, return; } const int token = m_nextCommandToken++; - CdbCommandPtr pendingCommand(new CdbCommand(token, handler)); + CdbCommandPtr pendingCommand(new CdbCommand(handler)); - m_commandQueue.push_back(pendingCommand); + m_commandForToken.insert(token, pendingCommand); // Enclose command in echo-commands for token QByteArray fullCmd; ByteArrayInputStream str(fullCmd); @@ -1204,7 +1188,7 @@ void CdbEngine::postBuiltinCommand(const QByteArray &cmd, if (debug) qDebug("CdbEngine::postBuiltinCommand %dms '%s' token=%d %s, pending=%d", elapsedLogTime(), cmd.constData(), token, stateName(state()), - m_commandQueue.size()); + m_commandForToken.size()); if (debug > 1) qDebug("CdbEngine::postBuiltinCommand: resulting command '%s'\n", fullCmd.constData()); @@ -1233,14 +1217,14 @@ void CdbEngine::postExtensionCommand(const QByteArray &cmd, if (!arguments.isEmpty()) str << ' ' << arguments; - CdbCommandPtr pendingCommand(new CdbCommand(token, handler)); + CdbCommandPtr pendingCommand(new CdbCommand(handler)); - m_commandQueue.push_back(pendingCommand); + m_commandForToken.insert(token, pendingCommand); // Enclose command in echo-commands for token if (debug) qDebug("CdbEngine::postExtensionCommand %dms '%s' token=%d %s, pending=%d", elapsedLogTime(), fullCmd.constData(), token, stateName(state()), - m_commandQueue.size()); + m_commandForToken.size()); postCommand(fullCmd); } @@ -2254,13 +2238,12 @@ void CdbEngine::handleExtensionMessage(char t, int token, const QByteArray &what showMessage(QString::fromLatin1(message), LogMisc); return; } - const int index = indexOfCommand(m_commandQueue, token); - if (index != -1) { - // Did the command finish? Take off queue and complete, invoke CB - const CdbCommandPtr command = m_commandQueue.takeAt(index); + // Did the command finish? Take off queue and complete, invoke CB + const CdbCommandPtr command = m_commandForToken.take(token); + if (!command.isNull()) { if (debug) qDebug("### Completed extension command for token=%d, pending=%d", - command->token, m_commandQueue.size()); + token, m_commandForToken.size()); if (!command->handler) return; @@ -2441,13 +2424,12 @@ void CdbEngine::parseOutputLine(QByteArray line) if (debug) qDebug("### Completed builtin command for token=%d, %d lines, pending=%d", m_currentBuiltinResponseToken, m_currentBuiltinResponse.count('\n'), - m_commandQueue.size() - 1); + m_commandForToken.size() - 1); QTC_ASSERT(token == m_currentBuiltinResponseToken, return); if (boolSetting(VerboseLog)) showMessage(QLatin1String(m_currentBuiltinResponse), LogMisc); - const int commandIndex = indexOfCommand(m_commandQueue, m_currentBuiltinResponseToken); - QTC_ASSERT(commandIndex >= 0 && commandIndex < m_commandQueue.size(), return); - const CdbCommandPtr ¤tCommand = m_commandQueue.at(commandIndex); + const CdbCommandPtr ¤tCommand = m_commandForToken.take(token); + QTC_ASSERT(!currentCommand.isNull(), return); DebuggerResponse response; response.token = token; response.data.m_name = "data"; @@ -2456,7 +2438,6 @@ void CdbEngine::parseOutputLine(QByteArray line) response.resultClass = ResultDone; if (currentCommand->handler) currentCommand->handler(response); - m_commandQueue.removeAt(commandIndex); m_currentBuiltinResponseToken = -1; m_currentBuiltinResponse.clear(); } else { diff --git a/src/plugins/debugger/cdb/cdbengine.h b/src/plugins/debugger/cdb/cdbengine.h index 01de8ec52156391362ad6950fe59c485e385b288..7b730f7c897132692df193af856bcec9447e224a 100644 --- a/src/plugins/debugger/cdb/cdbengine.h +++ b/src/plugins/debugger/cdb/cdbengine.h @@ -245,7 +245,7 @@ private: SpecialStopMode m_specialStopMode; ProjectExplorer::DeviceProcessSignalOperation::Ptr m_signalOperation; int m_nextCommandToken; - QList m_commandQueue; + QHash m_commandForToken; QByteArray m_currentBuiltinResponse; int m_currentBuiltinResponseToken; QMap m_normalizedFileCache;