forked from qt-creator/qt-creator
Debugger: Decrease dependency of protocol structures on Qt
For potential re-use in qtcreatorcdbextension. Change-Id: Ia5742b61c71fcd04eeaa894ed62218151d528a53 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -233,7 +233,7 @@ void GdbMi::parseTuple_helper(const char *&from, const char *to)
|
|||||||
//qDebug() << "\n=======\n" << qPrintable(child.toString()) << "\n========\n";
|
//qDebug() << "\n=======\n" << qPrintable(child.toString()) << "\n========\n";
|
||||||
if (!child.isValid())
|
if (!child.isValid())
|
||||||
return;
|
return;
|
||||||
m_children += child;
|
m_children.push_back(child);
|
||||||
skipCommas(from, to);
|
skipCommas(from, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ void GdbMi::parseList(const char *&from, const char *to)
|
|||||||
GdbMi child;
|
GdbMi child;
|
||||||
child.parseResultOrValue(from, to);
|
child.parseResultOrValue(from, to);
|
||||||
if (child.isValid())
|
if (child.isValid())
|
||||||
m_children += child;
|
m_children.push_back(child);
|
||||||
skipCommas(from, to);
|
skipCommas(from, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ static QByteArray ind(int indent)
|
|||||||
|
|
||||||
void GdbMi::dumpChildren(QByteArray * str, bool multiline, int indent) const
|
void GdbMi::dumpChildren(QByteArray * str, bool multiline, int indent) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_children.size(); ++i) {
|
for (size_t i = 0; i < m_children.size(); ++i) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
*str += ',';
|
*str += ',';
|
||||||
if (multiline)
|
if (multiline)
|
||||||
@@ -743,30 +743,6 @@ void DebuggerCommand::argHelper(const char *name, const QByteArray &data)
|
|||||||
args.append(",");
|
args.append(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
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 + '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebuggerCommand::arg(const char *name, int value)
|
void DebuggerCommand::arg(const char *name, int value)
|
||||||
{
|
{
|
||||||
argHelper(name, QByteArray::number(value));
|
argHelper(name, QByteArray::number(value));
|
||||||
|
|||||||
@@ -31,9 +31,11 @@
|
|||||||
#ifndef DEBUGGER_PROTOCOL_H
|
#ifndef DEBUGGER_PROTOCOL_H
|
||||||
#define DEBUGGER_PROTOCOL_H
|
#define DEBUGGER_PROTOCOL_H
|
||||||
|
|
||||||
#include <QTime>
|
#include <QByteArray>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -67,13 +69,10 @@ public:
|
|||||||
void beginGroup(const char *name = 0);
|
void beginGroup(const char *name = 0);
|
||||||
void endGroup();
|
void endGroup();
|
||||||
|
|
||||||
static QByteArray toData(const QList<QByteArray> &value);
|
|
||||||
static QByteArray toData(const QHash<QByteArray, QByteArray> &value);
|
|
||||||
|
|
||||||
QByteArray function;
|
QByteArray function;
|
||||||
QByteArray args;
|
QByteArray args;
|
||||||
Callback callback;
|
Callback callback;
|
||||||
QTime postTime;
|
uint postTime; // msecsSinceStartOfDay
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -137,7 +136,7 @@ public:
|
|||||||
|
|
||||||
QByteArray m_name;
|
QByteArray m_name;
|
||||||
QByteArray m_data;
|
QByteArray m_data;
|
||||||
QList<GdbMi> m_children;
|
std::vector<GdbMi> m_children;
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -159,7 +158,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
inline QByteArray data() const { return m_data; }
|
inline QByteArray data() const { return m_data; }
|
||||||
inline const QList<GdbMi> &children() const { return m_children; }
|
inline const std::vector<GdbMi> &children() const { return m_children; }
|
||||||
inline int childCount() const { return m_children.size(); }
|
inline int childCount() const { return m_children.size(); }
|
||||||
|
|
||||||
const GdbMi &childAt(int index) const { return m_children[index]; }
|
const GdbMi &childAt(int index) const { return m_children[index]; }
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ void GdbEngine::handleResponse(const QByteArray &buff)
|
|||||||
data.parseResultOrValue(from, to);
|
data.parseResultOrValue(from, to);
|
||||||
if (data.isValid()) {
|
if (data.isValid()) {
|
||||||
//qDebug() << "parsed result:" << data.toString();
|
//qDebug() << "parsed result:" << data.toString();
|
||||||
result.m_children += data;
|
result.m_children.push_back(data);
|
||||||
result.m_type = GdbMi::Tuple;
|
result.m_type = GdbMi::Tuple;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -944,7 +944,7 @@ void GdbEngine::flushCommand(const DebuggerCommand &cmd0)
|
|||||||
const int token = ++currentToken();
|
const int token = ++currentToken();
|
||||||
|
|
||||||
DebuggerCommand cmd = cmd0;
|
DebuggerCommand cmd = cmd0;
|
||||||
cmd.postTime = QTime::currentTime();
|
cmd.postTime = QTime::currentTime().msecsSinceStartOfDay();
|
||||||
m_commandForToken[token] = cmd;
|
m_commandForToken[token] = cmd;
|
||||||
if (cmd.flags & ConsoleCommand)
|
if (cmd.flags & ConsoleCommand)
|
||||||
cmd.function = "-interpreter-exec console \"" + cmd.function + '"';
|
cmd.function = "-interpreter-exec console \"" + cmd.function + '"';
|
||||||
@@ -1119,7 +1119,7 @@ void GdbEngine::handleResultRecord(DebuggerResponse *response)
|
|||||||
if (boolSetting(LogTimeStamps)) {
|
if (boolSetting(LogTimeStamps)) {
|
||||||
showMessage(_("Response time: %1: %2 s")
|
showMessage(_("Response time: %1: %2 s")
|
||||||
.arg(_(cmd.function))
|
.arg(_(cmd.function))
|
||||||
.arg(cmd.postTime.msecsTo(QTime::currentTime()) / 1000.),
|
.arg(QTime::fromMSecsSinceStartOfDay(cmd.postTime).msecsTo(QTime::currentTime()) / 1000.),
|
||||||
LogTime);
|
LogTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3441,8 +3441,8 @@ void GdbEngine::handleThreadListIds(const DebuggerResponse &response)
|
|||||||
// "72^done,{thread-ids={thread-id="2",thread-id="1"},number-of-threads="2"}
|
// "72^done,{thread-ids={thread-id="2",thread-id="1"},number-of-threads="2"}
|
||||||
// In gdb 7.1+ additionally: current-thread-id="1"
|
// In gdb 7.1+ additionally: current-thread-id="1"
|
||||||
ThreadsHandler *handler = threadsHandler();
|
ThreadsHandler *handler = threadsHandler();
|
||||||
const QList<GdbMi> items = response.data["thread-ids"].children();
|
const std::vector<GdbMi> &items = response.data["thread-ids"].children();
|
||||||
for (int index = 0, n = items.size(); index != n; ++index) {
|
for (size_t index = 0, n = items.size(); index != n; ++index) {
|
||||||
ThreadData thread;
|
ThreadData thread;
|
||||||
thread.id = ThreadId(items.at(index).toInt());
|
thread.id = ThreadId(items.at(index).toInt());
|
||||||
handler->updateThread(thread);
|
handler->updateThread(thread);
|
||||||
@@ -3896,7 +3896,7 @@ void GdbEngine::handleFetchMemory(const DebuggerResponse &response, MemoryAgentC
|
|||||||
if (response.resultClass == ResultDone) {
|
if (response.resultClass == ResultDone) {
|
||||||
GdbMi memory = response.data["memory"];
|
GdbMi memory = response.data["memory"];
|
||||||
QTC_ASSERT(memory.children().size() <= 1, return);
|
QTC_ASSERT(memory.children().size() <= 1, return);
|
||||||
if (memory.children().isEmpty())
|
if (memory.children().empty())
|
||||||
return;
|
return;
|
||||||
GdbMi memory0 = memory.children().at(0); // we asked for only one 'row'
|
GdbMi memory0 = memory.children().at(0); // we asked for only one 'row'
|
||||||
GdbMi data = memory0["data"];
|
GdbMi data = memory0["data"];
|
||||||
|
|||||||
@@ -461,10 +461,10 @@ void ThreadsHandler::updateThreads(const GdbMi &data)
|
|||||||
// m_currentIndex = -1;
|
// m_currentIndex = -1;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const QList<GdbMi> items = data["threads"].children();
|
const std::vector<GdbMi> &items = data["threads"].children();
|
||||||
const int n = items.size();
|
const int n = items.size();
|
||||||
for (int index = 0; index != n; ++index) {
|
for (int index = 0; index != n; ++index) {
|
||||||
const GdbMi item = items.at(index);
|
const GdbMi item = items[index];
|
||||||
const GdbMi frame = item["frame"];
|
const GdbMi frame = item["frame"];
|
||||||
ThreadData thread;
|
ThreadData thread;
|
||||||
thread.id = ThreadId(item["id"].toInt());
|
thread.id = ThreadId(item["id"].toInt());
|
||||||
|
|||||||
Reference in New Issue
Block a user