Commit b3f88df4 authored by hjk's avatar hjk

Debugger: Remove most remaining occurrences of WatchData

... in WatchHandler and DebuggerEngine interface.
Adjust using code.

Change-Id: I6371f3e96ba46a783e23a5767cdde24a10d3fce7
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent b08e5a9b
...@@ -67,7 +67,7 @@ def qdump__Debugger__Internal__WatchData(d, value): ...@@ -67,7 +67,7 @@ def qdump__Debugger__Internal__WatchData(d, value):
d.putPlainChildren(value) d.putPlainChildren(value)
def qdump__Debugger__Internal__WatchItem(d, value): def qdump__Debugger__Internal__WatchItem(d, value):
d.putByteArrayValue(value["d"]["iname"]) d.putByteArrayValue(value["iname"])
d.putPlainChildren(value) d.putPlainChildren(value)
def qdump__Debugger__Internal__BreakpointModelId(d, value): def qdump__Debugger__Internal__BreakpointModelId(d, value):
......
...@@ -725,6 +725,17 @@ void TreeItem::removeChildren() ...@@ -725,6 +725,17 @@ void TreeItem::removeChildren()
} }
} }
void TreeItem::sortChildren(const std::function<bool(const TreeItem *, const TreeItem *)> &cmp)
{
if (m_model) {
m_model->layoutAboutToBeChanged();
std::sort(m_children.begin(), m_children.end(), cmp);
m_model->layoutChanged();
} else {
std::sort(m_children.begin(), m_children.end(), cmp);
}
}
void TreeItem::update() void TreeItem::update()
{ {
if (m_model) { if (m_model) {
......
...@@ -88,6 +88,7 @@ public: ...@@ -88,6 +88,7 @@ public:
void appendChild(TreeItem *item); void appendChild(TreeItem *item);
void insertChild(int pos, TreeItem *item); void insertChild(int pos, TreeItem *item);
void removeChildren(); void removeChildren();
void sortChildren(const std::function<bool(const TreeItem *, const TreeItem *)> &cmp);
void update(); void update();
void updateColumn(int column); void updateColumn(int column);
void expand(); void expand();
......
...@@ -974,46 +974,47 @@ static inline bool isWatchIName(const QByteArray &iname) ...@@ -974,46 +974,47 @@ static inline bool isWatchIName(const QByteArray &iname)
return iname.startsWith("watch"); return iname.startsWith("watch");
} }
void CdbEngine::updateWatchData(const WatchData &dataIn) void CdbEngine::updateWatchItem(WatchItem *item)
{ {
if (debug || debugLocals || debugWatches) if (debug || debugLocals || debugWatches)
qDebug("CdbEngine::updateWatchData() %dms accessible=%d %s: %s", qDebug("CdbEngine::updateWatchData() %dms accessible=%d %s: %s",
elapsedLogTime(), m_accessible, stateName(state()), elapsedLogTime(), m_accessible, stateName(state()),
qPrintable(dataIn.toString())); qPrintable(item->toString()));
if (!m_accessible) // Add watch data while running? if (!m_accessible) // Add watch data while running?
return; return;
// New watch item? // New watch item?
if (dataIn.isWatcher() && dataIn.isValueNeeded()) { if (item->isWatcher() && item->isValueNeeded()) {
QByteArray args; QByteArray args;
ByteArrayInputStream str(args); ByteArrayInputStream str(args);
str << dataIn.iname << " \"" << dataIn.exp << '"'; WatchData data = *item; // Don't pass pointers to async functions.
str << data.iname << " \"" << data.exp << '"';
postExtensionCommand("addwatch", args, 0, postExtensionCommand("addwatch", args, 0,
[this, dataIn](const CdbResponse &r) { handleAddWatch(r, dataIn); }); [this, data](const CdbResponse &r) { handleAddWatch(r, data); });
return; return;
} }
if (!dataIn.hasChildren && !dataIn.isValueNeeded()) { if (item->wantsChildren || item->isValueNeeded()) {
WatchData data = dataIn; updateLocalVariable(item->iname);
data.setAllUnneeded(); } else {
watchHandler()->insertData(data); item->setAllUnneeded();
return; item->update();
} }
updateLocalVariable(dataIn.iname);
} }
void CdbEngine::handleAddWatch(const CdbResponse &response, WatchData item) void CdbEngine::handleAddWatch(const CdbResponse &response, WatchData data)
{ {
if (debugWatches) if (debugWatches)
qDebug() << "handleAddWatch ok=" << response.success << item.iname; qDebug() << "handleAddWatch ok=" << response.success << data.iname;
if (response.success) { if (response.success) {
updateLocalVariable(item.iname); updateLocalVariable(data.iname);
} else { } else {
item.setError(tr("Unable to add expression")); auto item = new WatchItem(data);
watchHandler()->insertData(item); item->setError(tr("Unable to add expression"));
watchHandler()->insertItem(item);
showMessage(QString::fromLatin1("Unable to add watch item \"%1\"/\"%2\": %3"). showMessage(QString::fromLatin1("Unable to add watch item \"%1\"/\"%2\": %3").
arg(QString::fromLatin1(item.iname), QString::fromLatin1(item.exp), arg(QString::fromLatin1(data.iname), QString::fromLatin1(data.exp),
QString::fromLocal8Bit(response.errorMessage)), LogError); QString::fromLocal8Bit(response.errorMessage)), LogError);
} }
} }
...@@ -1269,7 +1270,7 @@ static inline bool isAsciiWord(const QString &s) ...@@ -1269,7 +1270,7 @@ static inline bool isAsciiWord(const QString &s)
return true; return true;
} }
void CdbEngine::assignValueInDebugger(const WatchData *w, const QString &expr, const QVariant &value) void CdbEngine::assignValueInDebugger(WatchItem *w, const QString &expr, const QVariant &value)
{ {
if (debug) if (debug)
qDebug() << "CdbEngine::assignValueInDebugger" << w->iname << expr << value; qDebug() << "CdbEngine::assignValueInDebugger" << w->iname << expr << value;
...@@ -1871,13 +1872,13 @@ void CdbEngine::handleLocals(const CdbResponse &response, bool newFrame) ...@@ -1871,13 +1872,13 @@ void CdbEngine::handleLocals(const CdbResponse &response, bool newFrame)
QSet<QByteArray> toDelete; QSet<QByteArray> toDelete;
if (newFrame) { if (newFrame) {
foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2)) foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2))
toDelete.insert(item->d.iname); toDelete.insert(item->iname);
} }
foreach (const GdbMi &child, all.children()) { foreach (const GdbMi &child, all.children()) {
WatchItem *item = new WatchItem(child); WatchItem *item = new WatchItem(child);
handler->insertItem(item); handler->insertItem(item);
toDelete.remove(item->d.iname); toDelete.remove(item->iname);
} }
handler->purgeOutdatedItems(toDelete); handler->purgeOutdatedItems(toDelete);
......
...@@ -89,7 +89,7 @@ public: ...@@ -89,7 +89,7 @@ public:
virtual void shutdownEngine(); virtual void shutdownEngine();
virtual void abortDebugger(); virtual void abortDebugger();
virtual void detachDebugger(); virtual void detachDebugger();
virtual void updateWatchData(const WatchData &data); virtual void updateWatchItem(WatchItem *item);
virtual bool hasCapability(unsigned cap) const; virtual bool hasCapability(unsigned cap) const;
virtual void watchPoint(const QPoint &); virtual void watchPoint(const QPoint &);
virtual void setRegisterValue(const QByteArray &name, const QString &value); virtual void setRegisterValue(const QByteArray &name, const QString &value);
...@@ -106,7 +106,7 @@ public: ...@@ -106,7 +106,7 @@ public:
virtual void executeRunToLine(const ContextData &data); virtual void executeRunToLine(const ContextData &data);
virtual void executeRunToFunction(const QString &functionName); virtual void executeRunToFunction(const QString &functionName);
virtual void executeJumpToLine(const ContextData &data); virtual void executeJumpToLine(const ContextData &data);
virtual void assignValueInDebugger(const WatchData *w, const QString &expr, const QVariant &value); virtual void assignValueInDebugger(WatchItem *w, const QString &expr, const QVariant &value);
virtual void executeDebuggerCommand(const QString &command, DebuggerLanguages languages); virtual void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
virtual void activateFrame(int index); virtual void activateFrame(int index);
......
...@@ -1439,10 +1439,6 @@ bool DebuggerEngine::setToolTipExpression(const DebuggerToolTipContext &) ...@@ -1439,10 +1439,6 @@ bool DebuggerEngine::setToolTipExpression(const DebuggerToolTipContext &)
return false; return false;
} }
void DebuggerEngine::updateWatchData(const WatchData &)
{
}
void DebuggerEngine::watchDataSelected(const QByteArray &) void DebuggerEngine::watchDataSelected(const QByteArray &)
{ {
} }
...@@ -1635,7 +1631,7 @@ void DebuggerEngine::changeBreakpoint(Breakpoint bp) ...@@ -1635,7 +1631,7 @@ void DebuggerEngine::changeBreakpoint(Breakpoint bp)
QTC_CHECK(false); QTC_CHECK(false);
} }
void DebuggerEngine::assignValueInDebugger(const WatchData *, void DebuggerEngine::assignValueInDebugger(WatchItem *,
const QString &, const QVariant &) const QString &, const QVariant &)
{ {
} }
......
...@@ -62,6 +62,7 @@ class DebuggerPluginPrivate; ...@@ -62,6 +62,7 @@ class DebuggerPluginPrivate;
class DisassemblerAgent; class DisassemblerAgent;
class MemoryAgent; class MemoryAgent;
class WatchData; class WatchData;
class WatchItem;
class BreakHandler; class BreakHandler;
class ModulesHandler; class ModulesHandler;
class RegisterHandler; class RegisterHandler;
...@@ -139,7 +140,7 @@ public: ...@@ -139,7 +140,7 @@ public:
virtual bool setToolTipExpression(const Internal::DebuggerToolTipContext &); virtual bool setToolTipExpression(const Internal::DebuggerToolTipContext &);
virtual void updateWatchData(const Internal::WatchData &data); virtual void updateWatchItem(WatchItem *) {}
virtual void watchDataSelected(const QByteArray &iname); virtual void watchDataSelected(const QByteArray &iname);
virtual void startDebugger(DebuggerRunControl *runControl); virtual void startDebugger(DebuggerRunControl *runControl);
...@@ -198,7 +199,7 @@ public: ...@@ -198,7 +199,7 @@ public:
virtual bool acceptsDebuggerCommands() const { return true; } virtual bool acceptsDebuggerCommands() const { return true; }
virtual void executeDebuggerCommand(const QString &command, DebuggerLanguages languages); virtual void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
virtual void assignValueInDebugger(const Internal::WatchData *data, virtual void assignValueInDebugger(WatchItem *item,
const QString &expr, const QVariant &value); const QString &expr, const QVariant &value);
virtual void selectThread(Internal::ThreadId threadId) = 0; virtual void selectThread(Internal::ThreadId threadId) = 0;
......
...@@ -218,9 +218,9 @@ ToolTipWatchItem::ToolTipWatchItem(WatchItem *item) ...@@ -218,9 +218,9 @@ ToolTipWatchItem::ToolTipWatchItem(WatchItem *item)
name = item->displayName(); name = item->displayName();
value = item->displayValue(); value = item->displayValue();
type = item->displayType(); type = item->displayType();
iname = item->d.iname; iname = item->iname;
valueColor = item->valueColor(); valueColor = item->valueColor();
expandable = item->d.hasChildren; expandable = item->hasChildren();
expression = item->expression(); expression = item->expression();
foreach (TreeItem *child, item->children()) foreach (TreeItem *child, item->children())
appendChild(new ToolTipWatchItem(static_cast<WatchItem *>(child))); appendChild(new ToolTipWatchItem(static_cast<WatchItem *>(child)));
......
...@@ -3724,11 +3724,11 @@ void GdbEngine::reloadLocals() ...@@ -3724,11 +3724,11 @@ void GdbEngine::reloadLocals()
updateLocals(); updateLocals();
} }
void GdbEngine::updateWatchData(const WatchData &data) void GdbEngine::updateWatchItem(WatchItem *item)
{ {
UpdateParameters params; UpdateParameters params;
params.tryPartial = m_pendingBreakpointRequests == 0; params.tryPartial = m_pendingBreakpointRequests == 0;
params.varList = data.iname; params.varList = item->iname;
updateLocalsPython(params); updateLocalsPython(params);
} }
...@@ -3759,14 +3759,14 @@ void GdbEngine::updateLocals() ...@@ -3759,14 +3759,14 @@ void GdbEngine::updateLocals()
updateLocalsPython(UpdateParameters()); updateLocalsPython(UpdateParameters());
} }
void GdbEngine::assignValueInDebugger(const WatchData *data, void GdbEngine::assignValueInDebugger(WatchItem *item,
const QString &expression, const QVariant &value) const QString &expression, const QVariant &value)
{ {
DebuggerCommand cmd("assignValue"); DebuggerCommand cmd("assignValue");
cmd.arg("type", data->type.toHex()); cmd.arg("type", item->type.toHex());
cmd.arg("expr", expression.toLatin1().toHex()); cmd.arg("expr", expression.toLatin1().toHex());
cmd.arg("value", value.toString().toLatin1().toHex()); cmd.arg("value", value.toString().toLatin1().toHex());
cmd.arg("simpleType", isIntOrFloatType(data->type)); cmd.arg("simpleType", isIntOrFloatType(item->type));
cmd.callback = CB(handleVarAssign); cmd.callback = CB(handleVarAssign);
runCommand(cmd); runCommand(cmd);
} }
...@@ -4805,17 +4805,17 @@ void GdbEngine::handleStackFramePython(const DebuggerResponse &response, bool pa ...@@ -4805,17 +4805,17 @@ void GdbEngine::handleStackFramePython(const DebuggerResponse &response, bool pa
QSet<QByteArray> toDelete; QSet<QByteArray> toDelete;
if (!partial) { if (!partial) {
foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2)) foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2))
toDelete.insert(item->d.iname); toDelete.insert(item->iname);
} }
foreach (const GdbMi &child, data.children()) { foreach (const GdbMi &child, data.children()) {
WatchItem *item = new WatchItem(child); WatchItem *item = new WatchItem(child);
const TypeInfo ti = m_typeInfoCache.value(item->d.type); const TypeInfo ti = m_typeInfoCache.value(item->type);
if (ti.size) if (ti.size)
item->d.size = ti.size; item->size = ti.size;
handler->insertItem(item); handler->insertItem(item);
toDelete.remove(item->d.iname); toDelete.remove(item->iname);
} }
handler->purgeOutdatedItems(toDelete); handler->purgeOutdatedItems(toDelete);
......
...@@ -59,7 +59,6 @@ class MemoryAgentCookie; ...@@ -59,7 +59,6 @@ class MemoryAgentCookie;
class BreakpointParameters; class BreakpointParameters;
class BreakpointResponse; class BreakpointResponse;
class WatchData;
class DisassemblerAgentCookie; class DisassemblerAgentCookie;
class DisassemblerLines; class DisassemblerLines;
...@@ -384,7 +383,7 @@ protected: ...@@ -384,7 +383,7 @@ protected:
// Watch specific stuff // Watch specific stuff
// //
virtual bool setToolTipExpression(const DebuggerToolTipContext &); virtual bool setToolTipExpression(const DebuggerToolTipContext &);
virtual void assignValueInDebugger(const WatchData *data, virtual void assignValueInDebugger(WatchItem *item,
const QString &expr, const QVariant &value); const QString &expr, const QVariant &value);
virtual void fetchMemory(MemoryAgent *agent, QObject *token, virtual void fetchMemory(MemoryAgent *agent, QObject *token,
...@@ -398,8 +397,8 @@ protected: ...@@ -398,8 +397,8 @@ protected:
virtual void watchPoint(const QPoint &); virtual void watchPoint(const QPoint &);
void handleWatchPoint(const DebuggerResponse &response); void handleWatchPoint(const DebuggerResponse &response);
void updateWatchData(const WatchData &data);
void rebuildWatchModel(); void rebuildWatchModel();
void updateWatchItem(WatchItem *item);
void showToolTip(); void showToolTip();
void handleVarAssign(const DebuggerResponse &response); void handleVarAssign(const DebuggerResponse &response);
......
...@@ -844,19 +844,17 @@ void LldbEngine::reloadFullStack() ...@@ -844,19 +844,17 @@ void LldbEngine::reloadFullStack()
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
void LldbEngine::assignValueInDebugger(const Internal::WatchData *data, void LldbEngine::assignValueInDebugger(WatchItem *,
const QString &expression, const QVariant &value) const QString &expression, const QVariant &value)
{ {
Q_UNUSED(data);
DebuggerCommand cmd("assignValue"); DebuggerCommand cmd("assignValue");
cmd.arg("exp", expression.toLatin1().toHex()); cmd.arg("exp", expression.toLatin1().toHex());
cmd.arg("value", value.toString().toLatin1().toHex()); cmd.arg("value", value.toString().toLatin1().toHex());
runCommand(cmd); runCommand(cmd);
} }
void LldbEngine::updateWatchData(const WatchData &data) void LldbEngine::updateWatchItem(WatchItem *)
{ {
Q_UNUSED(data);
updateLocals(); updateLocals();
} }
...@@ -1001,12 +999,12 @@ void LldbEngine::refreshLocals(const GdbMi &vars) ...@@ -1001,12 +999,12 @@ void LldbEngine::refreshLocals(const GdbMi &vars)
QSet<QByteArray> toDelete; QSet<QByteArray> toDelete;
foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2)) foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2))
toDelete.insert(item->d.iname); toDelete.insert(item->iname);
foreach (const GdbMi &child, vars.children()) { foreach (const GdbMi &child, vars.children()) {
WatchItem *item = new WatchItem(child); WatchItem *item = new WatchItem(child);
handler->insertItem(item); handler->insertItem(item);
toDelete.remove(item->d.iname); toDelete.remove(item->iname);
} }
handler->purgeOutdatedItems(toDelete); handler->purgeOutdatedItems(toDelete);
......
...@@ -105,8 +105,7 @@ private: ...@@ -105,8 +105,7 @@ private:
void removeBreakpoint(Breakpoint bp); void removeBreakpoint(Breakpoint bp);
void changeBreakpoint(Breakpoint bp); void changeBreakpoint(Breakpoint bp);
void assignValueInDebugger(const WatchData *data, void assignValueInDebugger(WatchItem *item, const QString &expr, const QVariant &value);
const QString &expr, const QVariant &value);
void executeDebuggerCommand(const QString &command, DebuggerLanguages languages); void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
void loadSymbols(const QString &moduleName); void loadSymbols(const QString &moduleName);
...@@ -122,7 +121,7 @@ private: ...@@ -122,7 +121,7 @@ private:
bool supportsThreads() const { return true; } bool supportsThreads() const { return true; }
bool isSynchronous() const { return true; } bool isSynchronous() const { return true; }
void updateWatchData(const WatchData &data); void updateWatchItem(WatchItem *item);
void setRegisterValue(const QByteArray &name, const QString &value); void setRegisterValue(const QByteArray &name, const QString &value);
void fetchMemory(Internal::MemoryAgent *, QObject *, quint64 addr, quint64 length); void fetchMemory(Internal::MemoryAgent *, QObject *, quint64 addr, quint64 length);
......
...@@ -382,7 +382,7 @@ bool PdbEngine::setToolTipExpression(const DebuggerToolTipContext &ctx) ...@@ -382,7 +382,7 @@ bool PdbEngine::setToolTipExpression(const DebuggerToolTipContext &ctx)
return true; return true;
} }
void PdbEngine::assignValueInDebugger(const WatchData *, const QString &expression, const QVariant &value) void PdbEngine::assignValueInDebugger(WatchItem *, const QString &expression, const QVariant &value)
{ {
//DebuggerCommand cmd("assignValue"); //DebuggerCommand cmd("assignValue");
//cmd.arg("expression", expression); //cmd.arg("expression", expression);
...@@ -393,9 +393,9 @@ void PdbEngine::assignValueInDebugger(const WatchData *, const QString &expressi ...@@ -393,9 +393,9 @@ void PdbEngine::assignValueInDebugger(const WatchData *, const QString &expressi
updateLocals(); updateLocals();
} }
void PdbEngine::updateWatchData(const WatchData &data) void PdbEngine::updateWatchItem(WatchItem *item)
{ {
Q_UNUSED(data); Q_UNUSED(item);
updateAll(); updateAll();
} }
...@@ -573,12 +573,12 @@ void PdbEngine::refreshLocals(const GdbMi &vars) ...@@ -573,12 +573,12 @@ void PdbEngine::refreshLocals(const GdbMi &vars)
QSet<QByteArray> toDelete; QSet<QByteArray> toDelete;
foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2)) foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2))
toDelete.insert(item->d.iname); toDelete.insert(item->iname);
foreach (const GdbMi &child, vars.children()) { foreach (const GdbMi &child, vars.children()) {
WatchItem *item = new WatchItem(child); WatchItem *item = new WatchItem(child);
handler->insertItem(item); handler->insertItem(item);
toDelete.remove(item->d.iname); toDelete.remove(item->iname);
} }
handler->purgeOutdatedItems(toDelete); handler->purgeOutdatedItems(toDelete);
......
...@@ -82,7 +82,7 @@ private: ...@@ -82,7 +82,7 @@ private:
void insertBreakpoint(Breakpoint bp); void insertBreakpoint(Breakpoint bp);
void removeBreakpoint(Breakpoint bp); void removeBreakpoint(Breakpoint bp);
void assignValueInDebugger(const WatchData *data, void assignValueInDebugger(WatchItem *item,
const QString &expr, const QVariant &value); const QString &expr, const QVariant &value);
void executeDebuggerCommand(const QString &command, DebuggerLanguages languages); void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
...@@ -96,7 +96,7 @@ private: ...@@ -96,7 +96,7 @@ private:
bool supportsThreads() const { return true; } bool supportsThreads() const { return true; }
bool isSynchronous() const { return true; } bool isSynchronous() const { return true; }
void updateWatchData(const WatchData &data); void updateWatchItem(WatchItem *item);
QString mainPythonFile() const; QString mainPythonFile() const;
void runCommand(const DebuggerCommand &cmd); void runCommand(const DebuggerCommand &cmd);
......
...@@ -38,6 +38,7 @@ namespace Debugger { ...@@ -38,6 +38,7 @@ namespace Debugger {
namespace Internal { namespace Internal {
class WatchData; class WatchData;
class WatchItem;
class BreakHandler; class BreakHandler;
class BreakpointModelId; class BreakpointModelId;
class QmlEngine; class QmlEngine;
......
...@@ -112,18 +112,18 @@ bool QmlCppEngine::setToolTipExpression(const DebuggerToolTipContext &ctx) ...@@ -112,18 +112,18 @@ bool QmlCppEngine::setToolTipExpression(const DebuggerToolTipContext &ctx)
return success; return success;
} }
void QmlCppEngine::updateWatchData(const WatchData &data) void QmlCppEngine::updateWatchItem(WatchItem *item)
{ {
if (data.isInspect())