1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// *************************************************************************
// gdbcommandqueue.cpp
// -------------------
// begin : Wed Dec 5, 2007
// copyright : (C) 2007 by Hamish Rodda
// email : rodda@kde.org
// **************************************************************************
//
// **************************************************************************
// * *
// * This program is free software; you can redistribute it and/or modify *
// * it under the terms of the GNU General Public License as published by *
// * the Free Software Foundation; either version 2 of the License, or *
// * (at your option) any later version. *
// * *
// **************************************************************************
#include "gdbcommandqueue.h"
#include "mi/gdbmi.h"
#include "gdbcommand.h"
using namespace GDBDebugger;
using namespace GDBMI;
CommandQueue::CommandQueue()
: m_tokenCounter(0)
{
}
CommandQueue::~CommandQueue()
{
qDeleteAll(m_commandList);
}
void CommandQueue::enqueue(GDBCommand* command)
{
++m_tokenCounter;
if (m_tokenCounter == 0)
m_tokenCounter = 1;
command->setToken(m_tokenCounter);
m_commandList.append(command);
if (command->flags() & (CmdImmediately | CmdInterrupt))
++m_immediatelyCounter;
rationalizeQueue(command);
}
void CommandQueue::rationalizeQueue(GDBCommand * command)
{
if (command->type() >= ExecAbort && command->type() <= ExecUntil)
// Changing execution location, abort any variable updates
removeVariableUpdates();
}
void CommandQueue::removeVariableUpdates()
{
QMutableListIterator<GDBCommand*> it = m_commandList;
while (it.hasNext()) {
GDBCommand* command = it.next();
CommandType type = command->type();
if ((type >= VarEvaluateExpression && type <= VarListChildren) || type == VarUpdate) {
if (command->flags() & (CmdImmediately | CmdInterrupt))
--m_immediatelyCounter;
it.remove();
delete command;
}
}
}
void CommandQueue::clear()
{
qDeleteAll(m_commandList);
m_commandList.clear();
m_immediatelyCounter = 0;
}
int CommandQueue::count() const
{
return m_commandList.count();
}
bool CommandQueue::isEmpty() const
{
return m_commandList.isEmpty();
}
bool CommandQueue::haveImmediateCommand() const
{
return m_immediatelyCounter > 0;
}
GDBCommand* CommandQueue::nextCommand()
{
if (m_commandList.isEmpty())
return nullptr;
GDBCommand* command = m_commandList.takeAt(0);
if (command->flags() & (CmdImmediately | CmdInterrupt))
--m_immediatelyCounter;
return command;
}
|