Commit ba05edc6 authored by hjk's avatar hjk

Debugger: Move LldbEngine::Command to debuggerprotocol

Better re-usable over there.

Change-Id: I75b70054d691771efaf5b19680d8a93d2943b5ba
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 7005d791
......@@ -33,6 +33,7 @@
#include "debugger_global.h"
#include "debuggerconstants.h"
#include "debuggerprotocol.h"
#include "debuggerstartparameters.h"
#include "threaddata.h" // For ThreadId.
......
......@@ -733,5 +733,124 @@ QString decodeData(const QByteArray &ba, int encoding)
return QCoreApplication::translate("Debugger", "<Encoding error>");
}
//////////////////////////////////////////////////////////////////////////////////
//
// DebuggerCommand
//
//////////////////////////////////////////////////////////////////////////////////
const DebuggerCommand &DebuggerCommand::argHelper(const char *name, const QByteArray &data) const
{
args.append('"');
args.append(name);
args.append("\":");
args.append(data);
args.append(",");
return *this;
}
QByteArray DebuggerCommand::toData(const QList<QByteArray> &value)
{
QByteArray res;
foreach (const QByteArray &item, value) {
if (!res.isEmpty())
res.append(',');
res += item;
}
return '[' + res + ']';
}
QByteArray DebuggerCommand::toData(const QHash<QByteArray, QByteArray> &value)
{
QByteArray res;
QHashIterator<QByteArray, QByteArray> it(value);
while (it.hasNext()) {
it.next();
if (!res.isEmpty())
res.append(',');
res += '"' + it.key() + "\":" + it.value();
}
return '{' + res + '}';
}
const DebuggerCommand &DebuggerCommand::arg(const char *name, int value) const
{
return argHelper(name, QByteArray::number(value));
}
const DebuggerCommand &DebuggerCommand::arg(const char *name, qlonglong value) const
{
return argHelper(name, QByteArray::number(value));
}
const DebuggerCommand &DebuggerCommand::arg(const char *name, qulonglong value) const
{
return argHelper(name, QByteArray::number(value));
}
const DebuggerCommand &DebuggerCommand::arg(const char *name, const QString &value) const
{
return arg(name, value.toUtf8().data());
}
const DebuggerCommand &DebuggerCommand::arg(const char *name, const QByteArray &value) const
{
return arg(name, value.data());
}
const DebuggerCommand &DebuggerCommand::arg(const char *name, const char *value) const
{
args.append('"');
args.append(name);
args.append("\":\"");
args.append(value);
args.append("\",");
return *this;
}
const DebuggerCommand &DebuggerCommand::arg(const char *value) const
{
args.append("\"");
args.append(value);
args.append("\",");
return *this;
}
const DebuggerCommand &DebuggerCommand::beginList(const char *name) const
{
if (name) {
args += '"';
args += name;
args += "\":";
}
args += '[';
return *this;
}
void DebuggerCommand::endList() const
{
if (args.endsWith(','))
args.chop(1);
args += "],";
}
const DebuggerCommand &DebuggerCommand::beginGroup(const char *name) const
{
if (name) {
args += '"';
args += name;
args += "\":";
}
args += '{';
return *this;
}
void DebuggerCommand::endGroup() const
{
if (args.endsWith(','))
args.chop(1);
args += "},";
}
} // namespace Internal
} // namespace Debugger
......@@ -36,6 +36,34 @@
namespace Debugger {
namespace Internal {
// Convenience structure to build up backend commands.
class DebuggerCommand
{
public:
DebuggerCommand() {}
DebuggerCommand(const char *f) : function(f) {}
const DebuggerCommand &arg(const char *name) const;
const DebuggerCommand &arg(const char *name, int value) const;
const DebuggerCommand &arg(const char *name, qlonglong value) const;
const DebuggerCommand &arg(const char *name, qulonglong value) const;
const DebuggerCommand &arg(const char *name, const QString &value) const;
const DebuggerCommand &arg(const char *name, const QByteArray &value) const;
const DebuggerCommand &arg(const char *name, const char *value) const;
const DebuggerCommand &beginList(const char *name = 0) const;
void endList() const;
const DebuggerCommand &beginGroup(const char *name = 0) const;
void endGroup() const;
static QByteArray toData(const QList<QByteArray> &value);
static QByteArray toData(const QHash<QByteArray, QByteArray> &value);
QByteArray function;
mutable QByteArray args;
private:
const DebuggerCommand &argHelper(const char *name, const QByteArray &value) const;
};
/*
output ==>
......
This diff is collapsed.
......@@ -66,33 +66,6 @@ public:
~LldbEngine();
private:
// Convenience struct to build up backend commands.
struct Command
{
Command() {}
Command(const char *f) : function(f) {}
const Command &arg(const char *name) const;
const Command &arg(const char *name, int value) const;
const Command &arg(const char *name, qlonglong value) const;
const Command &arg(const char *name, qulonglong value) const;
const Command &arg(const char *name, const QString &value) const;
const Command &arg(const char *name, const QByteArray &value) const;
const Command &arg(const char *name, const char *value) const;
const Command &beginList(const char *name = 0) const;
void endList() const;
const Command &beginGroup(const char *name = 0) const;
void endGroup() const;
static QByteArray toData(const QList<QByteArray> &value);
static QByteArray toData(const QHash<QByteArray, QByteArray> &value);
QByteArray function;
mutable QByteArray args;
private:
const Command &argHelper(const char *name, const QByteArray &value) const;
};
// DebuggerEngine implementation
void executeStep();
void executeStepOut();
......@@ -124,7 +97,7 @@ private:
bool acceptsBreakpoint(Breakpoint bp) const;
void attemptBreakpointSynchronization();
bool attemptBreakpointSynchronizationHelper(Command *command);
bool attemptBreakpointSynchronizationHelper(DebuggerCommand *command);
void assignValueInDebugger(const WatchData *data,
const QString &expr, const QVariant &value);
......@@ -200,9 +173,9 @@ private:
void handleChildren(const WatchData &data0, const GdbMi &item,
QList<WatchData> *list);
void runCommand(const Command &cmd);
void runCommand(const DebuggerCommand &cmd);
void debugLastCommand();
Command m_lastDebuggableCommand;
DebuggerCommand m_lastDebuggableCommand;
QByteArray m_inbuffer;
QString m_scriptFileName;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment