forked from qt-creator/qt-creator
Cdb: Store pending commands in an Hash.
Use the command token as the key. Simplifies the CdbCommand, because the command token doesn't need to be stored in the class. Change-Id: Ic43ba16529db6e11ce00db1db49b384a627a4941 Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
This commit is contained in:
@@ -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<QSharedPointer<CdbCommand> > &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);
|
||||
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 {
|
||||
|
||||
@@ -245,7 +245,7 @@ private:
|
||||
SpecialStopMode m_specialStopMode;
|
||||
ProjectExplorer::DeviceProcessSignalOperation::Ptr m_signalOperation;
|
||||
int m_nextCommandToken;
|
||||
QList<CdbCommandPtr> m_commandQueue;
|
||||
QHash<int, CdbCommandPtr> m_commandForToken;
|
||||
QByteArray m_currentBuiltinResponse;
|
||||
int m_currentBuiltinResponseToken;
|
||||
QMap<QString, NormalizedSourceFileName> m_normalizedFileCache;
|
||||
|
||||
Reference in New Issue
Block a user