From d582b73a649eadfe8fb154837fbea45e4000e277 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 14 Aug 2015 10:15:20 +0200 Subject: [PATCH] Cdb: Unify builtin and extension command queue. Change-Id: I2dd85201cbab9095987be61146a16d516bfd114f Reviewed-by: David Schulz Reviewed-by: Niels Weber --- src/plugins/debugger/cdb/cdbengine.cpp | 32 ++++++++++++-------------- src/plugins/debugger/cdb/cdbengine.h | 3 +-- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index 2b1beeeb17b..a717f75e232 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -210,8 +210,7 @@ public: CdbEngine::CommandHandler handler; }; -template -int indexOfCommand(const QList &l, int token) +int indexOfCommand(const QList > &l, int token) { const int count = l.size(); for (int i = 0; i < count; i++) @@ -307,9 +306,8 @@ void CdbEngine::init() m_wow64State = wow64Uninitialized; m_outputBuffer.clear(); - m_builtinCommandQueue.clear(); + m_commandQueue.clear(); m_currentBuiltinResponse.clear(); - m_extensionCommandQueue.clear(); m_extensionMessageBuffer.clear(); m_pendingBreakpointMap.clear(); m_insertSubBreakpointMap.clear(); @@ -782,7 +780,7 @@ void CdbEngine::runEngine() bool CdbEngine::commandsPending() const { - return !m_builtinCommandQueue.isEmpty() || !m_extensionCommandQueue.isEmpty(); + return !m_commandQueue.isEmpty(); } void CdbEngine::shutdownInferior() @@ -1197,7 +1195,7 @@ void CdbEngine::postBuiltinCommand(const QByteArray &cmd, const int token = m_nextCommandToken++; CdbCommandPtr pendingCommand(new CdbCommand(token, handler)); - m_builtinCommandQueue.push_back(pendingCommand); + m_commandQueue.push_back(pendingCommand); // Enclose command in echo-commands for token QByteArray fullCmd; ByteArrayInputStream str(fullCmd); @@ -1206,7 +1204,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_builtinCommandQueue.size()); + m_commandQueue.size()); if (debug > 1) qDebug("CdbEngine::postBuiltinCommand: resulting command '%s'\n", fullCmd.constData()); @@ -1237,12 +1235,12 @@ void CdbEngine::postExtensionCommand(const QByteArray &cmd, CdbCommandPtr pendingCommand(new CdbCommand(token, handler)); - m_extensionCommandQueue.push_back(pendingCommand); + m_commandQueue.push_back(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_extensionCommandQueue.size()); + m_commandQueue.size()); postCommand(fullCmd); } @@ -2256,13 +2254,13 @@ void CdbEngine::handleExtensionMessage(char t, int token, const QByteArray &what showMessage(QString::fromLatin1(message), LogMisc); return; } - const int index = indexOfCommand(m_extensionCommandQueue, token); + 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_extensionCommandQueue.takeAt(index); + const CdbCommandPtr command = m_commandQueue.takeAt(index); if (debug) qDebug("### Completed extension command for token=%d, pending=%d", - command->token, m_extensionCommandQueue.size()); + command->token, m_commandQueue.size()); if (!command->handler) return; @@ -2443,13 +2441,13 @@ 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_builtinCommandQueue.size() - 1); + m_commandQueue.size() - 1); QTC_ASSERT(token == m_currentBuiltinResponseToken, return); if (boolSetting(VerboseLog)) showMessage(QLatin1String(m_currentBuiltinResponse), LogMisc); - const int commandIndex = indexOfCommand(m_builtinCommandQueue, m_currentBuiltinResponseToken); - QTC_ASSERT(commandIndex >= 0 && commandIndex < m_builtinCommandQueue.size(), return); - const CdbCommandPtr ¤tCommand = m_builtinCommandQueue.at(commandIndex); + const int commandIndex = indexOfCommand(m_commandQueue, m_currentBuiltinResponseToken); + QTC_ASSERT(commandIndex >= 0 && commandIndex < m_commandQueue.size(), return); + const CdbCommandPtr ¤tCommand = m_commandQueue.at(commandIndex); DebuggerResponse response; response.token = token; response.data.m_name = "data"; @@ -2458,7 +2456,7 @@ void CdbEngine::parseOutputLine(QByteArray line) response.resultClass = ResultDone; if (currentCommand->handler) currentCommand->handler(response); - m_builtinCommandQueue.removeAt(commandIndex); + 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 7e3635051f2..01de8ec5215 100644 --- a/src/plugins/debugger/cdb/cdbengine.h +++ b/src/plugins/debugger/cdb/cdbengine.h @@ -245,10 +245,9 @@ private: SpecialStopMode m_specialStopMode; ProjectExplorer::DeviceProcessSignalOperation::Ptr m_signalOperation; int m_nextCommandToken; - QList m_builtinCommandQueue; + QList m_commandQueue; QByteArray m_currentBuiltinResponse; int m_currentBuiltinResponseToken; - QList m_extensionCommandQueue; QMap m_normalizedFileCache; const QByteArray m_extensionCommandPrefixBA; //!< Library name used as prefix bool m_operateByInstructionPending; //!< Creator operate by instruction action changed.