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):
d.putPlainChildren(value)
def qdump__Debugger__Internal__WatchItem(d, value):
d.putByteArrayValue(value["d"]["iname"])
d.putByteArrayValue(value["iname"])
d.putPlainChildren(value)
def qdump__Debugger__Internal__BreakpointModelId(d, value):
......
......@@ -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()
{
if (m_model) {
......
......@@ -88,6 +88,7 @@ public:
void appendChild(TreeItem *item);
void insertChild(int pos, TreeItem *item);
void removeChildren();
void sortChildren(const std::function<bool(const TreeItem *, const TreeItem *)> &cmp);
void update();
void updateColumn(int column);
void expand();
......
......@@ -974,46 +974,47 @@ static inline bool isWatchIName(const QByteArray &iname)
return iname.startsWith("watch");
}
void CdbEngine::updateWatchData(const WatchData &dataIn)
void CdbEngine::updateWatchItem(WatchItem *item)
{
if (debug || debugLocals || debugWatches)
qDebug("CdbEngine::updateWatchData() %dms accessible=%d %s: %s",
elapsedLogTime(), m_accessible, stateName(state()),
qPrintable(dataIn.toString()));
qPrintable(item->toString()));
if (!m_accessible) // Add watch data while running?
return;
// New watch item?
if (dataIn.isWatcher() && dataIn.isValueNeeded()) {
if (item->isWatcher() && item->isValueNeeded()) {
QByteArray 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,
[this, dataIn](const CdbResponse &r) { handleAddWatch(r, dataIn); });
[this, data](const CdbResponse &r) { handleAddWatch(r, data); });
return;
}
if (!dataIn.hasChildren && !dataIn.isValueNeeded()) {
WatchData data = dataIn;
data.setAllUnneeded();
watchHandler()->insertData(data);
return;
if (item->wantsChildren || item->isValueNeeded()) {
updateLocalVariable(item->iname);
} else {
item->setAllUnneeded();
item->update();
}
updateLocalVariable(dataIn.iname);
}
void CdbEngine::handleAddWatch(const CdbResponse &response, WatchData item)
void CdbEngine::handleAddWatch(const CdbResponse &response, WatchData data)
{
if (debugWatches)
qDebug() << "handleAddWatch ok=" << response.success << item.iname;
qDebug() << "handleAddWatch ok=" << response.success << data.iname;
if (response.success) {
updateLocalVariable(item.iname);
updateLocalVariable(data.iname);
} else {
item.setError(tr("Unable to add expression"));
watchHandler()->insertData(item);
auto item = new WatchItem(data);
item->setError(tr("Unable to add expression"));
watchHandler()->insertItem(item);
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);
}
}
......@@ -1269,7 +1270,7 @@ static inline bool isAsciiWord(const QString &s)
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)
qDebug() << "CdbEngine::assignValueInDebugger" << w->iname << expr << value;
......@@ -1871,13 +1872,13 @@ void CdbEngine::handleLocals(const CdbResponse &response, bool newFrame)
QSet<QByteArray> toDelete;
if (newFrame) {
foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2))
toDelete.insert(item->d.iname);
toDelete.insert(item->iname);
}
foreach (const GdbMi &child, all.children()) {
WatchItem *item = new WatchItem(child);
handler->insertItem(item);
toDelete.remove(item->d.iname);
toDelete.remove(item->iname);
}
handler->purgeOutdatedItems(toDelete);
......
......@@ -89,7 +89,7 @@ public:
virtual void shutdownEngine();
virtual void abortDebugger();
virtual void detachDebugger();
virtual void updateWatchData(const WatchData &data);
virtual void updateWatchItem(WatchItem *item);
virtual bool hasCapability(unsigned cap) const;
virtual void watchPoint(const QPoint &);
virtual void setRegisterValue(const QByteArray &name, const QString &value);
......@@ -106,7 +106,7 @@ public:
virtual void executeRunToLine(const ContextData &data);
virtual void executeRunToFunction(const QString &functionName);
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 activateFrame(int index);
......
......@@ -1439,10 +1439,6 @@ bool DebuggerEngine::setToolTipExpression(const DebuggerToolTipContext &)
return false;
}
void DebuggerEngine::updateWatchData(const WatchData &)
{
}
void DebuggerEngine::watchDataSelected(const QByteArray &)
{
}
......@@ -1635,7 +1631,7 @@ void DebuggerEngine::changeBreakpoint(Breakpoint bp)
QTC_CHECK(false);
}
void DebuggerEngine::assignValueInDebugger(const WatchData *,
void DebuggerEngine::assignValueInDebugger(WatchItem *,
const QString &, const QVariant &)
{
}
......
......@@ -62,6 +62,7 @@ class DebuggerPluginPrivate;
class DisassemblerAgent;
class MemoryAgent;
class WatchData;
class WatchItem;
class BreakHandler;
class ModulesHandler;
class RegisterHandler;
......@@ -139,7 +140,7 @@ public:
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 startDebugger(DebuggerRunControl *runControl);
......@@ -198,7 +199,7 @@ public:
virtual bool acceptsDebuggerCommands() const { return true; }
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);
virtual void selectThread(Internal::ThreadId threadId) = 0;
......
......@@ -218,9 +218,9 @@ ToolTipWatchItem::ToolTipWatchItem(WatchItem *item)
name = item->displayName();
value = item->displayValue();
type = item->displayType();
iname = item->d.iname;
iname = item->iname;
valueColor = item->valueColor();
expandable = item->d.hasChildren;
expandable = item->hasChildren();
expression = item->expression();
foreach (TreeItem *child, item->children())
appendChild(new ToolTipWatchItem(static_cast<WatchItem *>(child)));
......
......@@ -3724,11 +3724,11 @@ void GdbEngine::reloadLocals()
updateLocals();
}
void GdbEngine::updateWatchData(const WatchData &data)
void GdbEngine::updateWatchItem(WatchItem *item)
{
UpdateParameters params;
params.tryPartial = m_pendingBreakpointRequests == 0;
params.varList = data.iname;
params.varList = item->iname;
updateLocalsPython(params);
}
......@@ -3759,14 +3759,14 @@ void GdbEngine::updateLocals()
updateLocalsPython(UpdateParameters());
}
void GdbEngine::assignValueInDebugger(const WatchData *data,
void GdbEngine::assignValueInDebugger(WatchItem *item,
const QString &expression, const QVariant &value)
{
DebuggerCommand cmd("assignValue");
cmd.arg("type", data->type.toHex());
cmd.arg("type", item->type.toHex());
cmd.arg("expr", expression.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);
runCommand(cmd);
}
......@@ -4805,17 +4805,17 @@ void GdbEngine::handleStackFramePython(const DebuggerResponse &response, bool pa
QSet<QByteArray> toDelete;
if (!partial) {
foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2))
toDelete.insert(item->d.iname);
toDelete.insert(item->iname);
}
foreach (const GdbMi &child, data.children()) {
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)
item->d.size = ti.size;
item->size = ti.size;
handler->insertItem(item);
toDelete.remove(item->d.iname);
toDelete.remove(item->iname);
}
handler->purgeOutdatedItems(toDelete);
......
......@@ -59,7 +59,6 @@ class MemoryAgentCookie;
class BreakpointParameters;
class BreakpointResponse;
class WatchData;
class DisassemblerAgentCookie;
class DisassemblerLines;
......@@ -384,7 +383,7 @@ protected:
// Watch specific stuff
//
virtual bool setToolTipExpression(const DebuggerToolTipContext &);
virtual void assignValueInDebugger(const WatchData *data,
virtual void assignValueInDebugger(WatchItem *item,
const QString &expr, const QVariant &value);
virtual void fetchMemory(MemoryAgent *agent, QObject *token,
......@@ -398,8 +397,8 @@ protected:
virtual void watchPoint(const QPoint &);
void handleWatchPoint(const DebuggerResponse &response);
void updateWatchData(const WatchData &data);
void rebuildWatchModel();
void updateWatchItem(WatchItem *item);
void showToolTip();
void handleVarAssign(const DebuggerResponse &response);
......
......@@ -844,19 +844,17 @@ void LldbEngine::reloadFullStack()
//
//////////////////////////////////////////////////////////////////////
void LldbEngine::assignValueInDebugger(const Internal::WatchData *data,
void LldbEngine::assignValueInDebugger(WatchItem *,
const QString &expression, const QVariant &value)
{
Q_UNUSED(data);
DebuggerCommand cmd("assignValue");
cmd.arg("exp", expression.toLatin1().toHex());
cmd.arg("value", value.toString().toLatin1().toHex());
runCommand(cmd);
}
void LldbEngine::updateWatchData(const WatchData &data)
void LldbEngine::updateWatchItem(WatchItem *)
{
Q_UNUSED(data);
updateLocals();
}
......@@ -1001,12 +999,12 @@ void LldbEngine::refreshLocals(const GdbMi &vars)
QSet<QByteArray> toDelete;
foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2))
toDelete.insert(item->d.iname);
toDelete.insert(item->iname);
foreach (const GdbMi &child, vars.children()) {
WatchItem *item = new WatchItem(child);
handler->insertItem(item);
toDelete.remove(item->d.iname);
toDelete.remove(item->iname);
}
handler->purgeOutdatedItems(toDelete);
......
......@@ -105,8 +105,7 @@ private:
void removeBreakpoint(Breakpoint bp);
void changeBreakpoint(Breakpoint bp);
void assignValueInDebugger(const WatchData *data,
const QString &expr, const QVariant &value);
void assignValueInDebugger(WatchItem *item, const QString &expr, const QVariant &value);
void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
void loadSymbols(const QString &moduleName);
......@@ -122,7 +121,7 @@ private:
bool supportsThreads() 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 fetchMemory(Internal::MemoryAgent *, QObject *, quint64 addr, quint64 length);
......
......@@ -382,7 +382,7 @@ bool PdbEngine::setToolTipExpression(const DebuggerToolTipContext &ctx)
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");
//cmd.arg("expression", expression);
......@@ -393,9 +393,9 @@ void PdbEngine::assignValueInDebugger(const WatchData *, const QString &expressi
updateLocals();
}
void PdbEngine::updateWatchData(const WatchData &data)
void PdbEngine::updateWatchItem(WatchItem *item)
{
Q_UNUSED(data);
Q_UNUSED(item);
updateAll();
}
......@@ -573,12 +573,12 @@ void PdbEngine::refreshLocals(const GdbMi &vars)
QSet<QByteArray> toDelete;
foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2))
toDelete.insert(item->d.iname);
toDelete.insert(item->iname);
foreach (const GdbMi &child, vars.children()) {
WatchItem *item = new WatchItem(child);
handler->insertItem(item);
toDelete.remove(item->d.iname);
toDelete.remove(item->iname);
}
handler->purgeOutdatedItems(toDelete);
......
......@@ -82,7 +82,7 @@ private:
void insertBreakpoint(Breakpoint bp);
void removeBreakpoint(Breakpoint bp);
void assignValueInDebugger(const WatchData *data,
void assignValueInDebugger(WatchItem *item,
const QString &expr, const QVariant &value);
void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
......@@ -96,7 +96,7 @@ private:
bool supportsThreads() const { return true; }
bool isSynchronous() const { return true; }
void updateWatchData(const WatchData &data);
void updateWatchItem(WatchItem *item);
QString mainPythonFile() const;
void runCommand(const DebuggerCommand &cmd);
......
......@@ -38,6 +38,7 @@ namespace Debugger {
namespace Internal {
class WatchData;
class WatchItem;
class BreakHandler;
class BreakpointModelId;
class QmlEngine;
......
......@@ -112,18 +112,18 @@ bool QmlCppEngine::setToolTipExpression(const DebuggerToolTipContext &ctx)
return success;
}
void QmlCppEngine::updateWatchData(const WatchData &data)
void QmlCppEngine::updateWatchItem(WatchItem *item)
{
if (data.isInspect())
m_qmlEngine->updateWatchData(data);
if (item->isInspect())
m_qmlEngine->updateWatchItem(item);
else
m_activeEngine->updateWatchData(data);
m_activeEngine->updateWatchItem(item);
}
void QmlCppEngine::watchDataSelected(const QByteArray &iname)
{
const WatchData *wd = watchHandler()->findData(iname);
if (wd && wd->isInspect())
const WatchItem *item = watchHandler()->findItem(iname);
if (item && item->isInspect())
m_qmlEngine->watchDataSelected(iname);
}
......@@ -264,13 +264,13 @@ void QmlCppEngine::selectThread(ThreadId threadId)
m_activeEngine->selectThread(threadId);
}
void QmlCppEngine::assignValueInDebugger(const WatchData *data,
void QmlCppEngine::assignValueInDebugger(WatchItem *item,
const QString &expr, const QVariant &value)
{
if (data->isInspect())
m_qmlEngine->assignValueInDebugger(data, expr, value);
if (item->isInspect())
m_qmlEngine->assignValueInDebugger(item, expr, value);
else
m_activeEngine->assignValueInDebugger(data, expr, value);
m_activeEngine->assignValueInDebugger(item, expr, value);
}
void QmlCppEngine::notifyInferiorIll()
......
......@@ -48,7 +48,7 @@ public:
bool canDisplayTooltip() const;
bool setToolTipExpression(const DebuggerToolTipContext &);
void updateWatchData(const WatchData &data);
void updateWatchItem(WatchItem *item);
void watchDataSelected(const QByteArray &iname);
void watchPoint(const QPoint &);
......@@ -79,7 +79,7 @@ public:
bool acceptsBreakpoint(Breakpoint bp) const;
void selectThread(ThreadId threadId);
void assignValueInDebugger(const WatchData *data,
void assignValueInDebugger(WatchItem *item,
const QString &expr, const QVariant &value);
DebuggerEngine *cppEngine() { return m_cppEngine; }
......
......@@ -988,45 +988,41 @@ bool QmlEngine::setToolTipExpression(const DebuggerToolTipContext &context)
//
//////////////////////////////////////////////////////////////////////
void QmlEngine::assignValueInDebugger(const WatchData *data,
void QmlEngine::assignValueInDebugger(WatchItem *item,
const QString &expression, const QVariant &valueV)
{
if (!expression.isEmpty()) {
if (data->isInspect() && m_inspectorAdapter.agent())
m_inspectorAdapter.agent()->assignValue(data, expression, valueV);
if (item->isInspect() && m_inspectorAdapter.agent())
m_inspectorAdapter.agent()->assignValue(item, expression, valueV);
else if (m_adapter.activeDebuggerClient())
m_adapter.activeDebuggerClient()->assignValueInDebugger(data, expression, valueV);
m_adapter.activeDebuggerClient()->assignValueInDebugger(item, expression, valueV);
}
}
void QmlEngine::updateWatchData(const WatchData &data)
void QmlEngine::updateWatchItem(WatchItem *item)
{
// qDebug() << "UPDATE WATCH DATA" << data.toString();
//showStatusMessage(tr("Stopped."), 5000);
if (data.isInspect()) {
m_inspectorAdapter.agent()->updateWatchData(data);
if (item->isInspect()) {
m_inspectorAdapter.agent()->updateWatchData(*item);
} else {
if (!data.name.isEmpty() && m_adapter.activeDebuggerClient()) {
if (data.isValueNeeded())
m_adapter.activeDebuggerClient()->updateWatchData(data);
if (data.isChildrenNeeded()
&& watchHandler()->isExpandedIName(data.iname)) {
m_adapter.activeDebuggerClient()->expandObject(data.iname, data.id);
if (!item->name.isEmpty() && m_adapter.activeDebuggerClient()) {
if (item->isValueNeeded())
m_adapter.activeDebuggerClient()->updateWatchData(*item);
if (item->isChildrenNeeded() && watchHandler()->isExpandedIName(item->iname)) {
m_adapter.activeDebuggerClient()->expandObject(item->iname, item->id);
}
}
synchronizeWatchers();
}
if (!data.isSomethingNeeded())
watchHandler()->insertData(data);
}
void QmlEngine::watchDataSelected(const QByteArray &iname)
{
const WatchData *wd = watchHandler()->findData(iname);
if (wd && wd->isInspect())
m_inspectorAdapter.agent()->watchDataSelected(wd);
const WatchItem *item = watchHandler()->findItem(iname);
if (item && item->isInspect())
m_inspectorAdapter.agent()->watchDataSelected(item->id);
}
void QmlEngine::synchronizeWatchers()
......@@ -1153,11 +1149,11 @@ void QmlEngine::updateCurrentContext()
context = stackHandler()->currentFrame().function;
} else {
QModelIndex currentIndex = inspectorTreeView()->currentIndex();
const WatchData *currentData = watchHandler()->watchData(currentIndex);
const WatchData *currentData = watchHandler()->watchItem(currentIndex);
if (!currentData)
return;
const WatchData *parentData = watchHandler()->watchData(currentIndex.parent());
const WatchData *grandParentData = watchHandler()->watchData(
const WatchData *parentData = watchHandler()->watchItem(currentIndex.parent());
const WatchData *grandParentData = watchHandler()->watchItem(
currentIndex.parent().parent());
if (currentData->id != parentData->id)
context = currentData->name;
......@@ -1217,7 +1213,7 @@ bool QmlEngine::evaluateScript(const QString &expression)
if (state() != InferiorStopOk) {
QModelIndex currentIndex = inspectorTreeView()->currentIndex();
QmlInspectorAgent *agent = m_inspectorAdapter.agent();
quint32 queryId = agent->queryExpressionResult(watchHandler()->watchData(currentIndex)->id,
quint32 queryId = agent->queryExpressionResult(watchHandler()->watchItem(currentIndex)->id,
expression);
if (queryId) {
queryIds << queryId;
......
......@@ -145,10 +145,9 @@ private:
void changeBreakpoint(Breakpoint bp);
bool acceptsBreakpoint(Breakpoint bp) const;
void assignValueInDebugger(const WatchData *data,
void assignValueInDebugger(WatchItem *item,
const QString &expr, const QVariant &value);
void loadSymbols(const QString &moduleName);
void loadAllSymbols();
void requestModuleSymbols(const QString &moduleName);
......@@ -158,7 +157,7 @@ private:
void reloadFullStack() {}
bool supportsThreads() const { return false; }
void updateWatchData(const WatchData &data);
void updateWatchItem(WatchItem *item);
void watchDataSelected(const QByteArray &iname);
void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
bool evaluateScript(const QString &expression);
......
......@@ -125,13 +125,13 @@ void QmlInspectorAgent::updateWatchData(const WatchData &data)
}
}
void QmlInspectorAgent::watchDataSelected(const WatchData *data)
void QmlInspectorAgent::watchDataSelected(quint64 id)
{
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << data->id << ')';
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << id << ')';
if (data->id) {
QTC_ASSERT(m_debugIdLocations.keys().contains(data->id), return);
emit jumpToObjectDefinition(m_debugIdLocations.value(data->id), data->id);
if (id) {
QTC_ASSERT(m_debugIdLocations.keys().contains(id), return);
emit jumpToObjectDefinition(m_debugIdLocations.value(id), id);
}
}
......@@ -154,7 +154,7 @@ bool QmlInspectorAgent::selectObjectInTree(int debugId)
using namespace QmlDebug::Constants;
if (m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
// reset current Selection
QByteArray root = m_debuggerEngine->watchHandler()->watchData(QModelIndex())->iname;
QByteArray root = m_debuggerEngine->watchHandler()->watchItem(QModelIndex())->iname;
m_debuggerEngine->watchHandler()->setCurrentItem(root);
} else {
fetchObject(debugId);
......@@ -256,8 +256,8 @@ ObjectReference QmlInspectorAgent::objectForName(
const WatchHandler *watchHandler = m_debuggerEngine->watchHandler();
while (iter.hasNext()) {