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