From eeea437743b38f7f8ea21813c7d2d6ba1e1788e2 Mon Sep 17 00:00:00 2001 From: Artem Sokolovskii Date: Thu, 13 Jul 2023 13:43:59 +0200 Subject: [PATCH] DAP: Add displaying nested variables Change-Id: I588dde7c0ef402fe8d6c9d43dc9f0183bfa2d733 Reviewed-by: hjk --- src/plugins/debugger/dap/dapengine.cpp | 39 ++++++++++++++++++++------ src/plugins/debugger/dap/dapengine.h | 6 ++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/plugins/debugger/dap/dapengine.cpp b/src/plugins/debugger/dap/dapengine.cpp index 16a314db000..65b5a731101 100644 --- a/src/plugins/debugger/dap/dapengine.cpp +++ b/src/plugins/debugger/dap/dapengine.cpp @@ -151,6 +151,8 @@ DapEngine::DapEngine() { setObjectName("DapEngine"); setDebuggerName("DAP"); + m_rootWatchItem = new WatchItem(); + m_currentWatchItem = m_rootWatchItem; } void DapEngine::executeDebuggerCommand(const QString &/*command*/) @@ -837,17 +839,20 @@ void DapEngine::handleOutput(const QJsonDocument &data) const QString name = scope.toObject().value("name").toString(); const int variablesReference = scope.toObject().value("variablesReference").toInt(); qCDebug(dapEngineLog) << "scoped success" << name << variablesReference; -// if (name == "Locals") -// dapVariables(variablesReference); + if (name == "Locals") { // Fix for several scopes + m_rootWatchItem = new WatchItem(); + m_currentWatchItem = m_rootWatchItem; + watchHandler()->removeAllData(); + watchHandler()->notifyUpdateStarted(); + dapVariables(variablesReference); + } } } } if (command == "variables") { - if (ob.value("success").toBool()) { - auto variables = ob.value("body").toObject().value("variables").toArray(); - refreshLocals(variables); - } + auto variables = ob.value("body").toObject().value("variables").toArray(); + refreshLocals(variables); } if (command == "stepIn" || command == "stepOut" || command == "next") { @@ -985,7 +990,6 @@ void DapEngine::handleOutput(const QJsonDocument &data) void DapEngine::refreshLocals(const QJsonArray &variables) { - watchHandler()->notifyUpdateStarted(); for (auto variable : variables) { WatchItem *item = new WatchItem; const QString name = variable.toObject().value("name").toString(); @@ -995,10 +999,27 @@ void DapEngine::refreshLocals(const QJsonArray &variables) item->value = variable.toObject().value("value").toString(); item->address = variable.toObject().value("address").toInt(); item->type = variable.toObject().value("type").toString(); + qCDebug(dapEngineLog) << "variable" << name << item->hexAddress(); - watchHandler()->insertItem(item); + m_currentWatchItem->appendChild(item); + + const int variablesReference = variable.toObject().value("variablesReference").toInt(); + if (variablesReference > 0) + m_variablesReferenceQueue.push({variablesReference, item}); } - watchHandler()->notifyUpdateFinished(); + + if (m_variablesReferenceQueue.empty()) { + for (auto item = m_rootWatchItem->begin(); item != m_rootWatchItem->end(); ++item) + watchHandler()->insertItem(*item); + watchHandler()->notifyUpdateFinished(); + return; + } + + const auto front = m_variablesReferenceQueue.front(); + m_variablesReferenceQueue.pop(); + + dapVariables(front.first); + m_currentWatchItem = front.second; } void DapEngine::refreshStack(const QJsonArray &stackFrames) diff --git a/src/plugins/debugger/dap/dapengine.h b/src/plugins/debugger/dap/dapengine.h index 16181b96669..5a0c34492f9 100644 --- a/src/plugins/debugger/dap/dapengine.h +++ b/src/plugins/debugger/dap/dapengine.h @@ -9,6 +9,8 @@ #include +#include + namespace Debugger::Internal { class DebuggerCommand; @@ -126,6 +128,10 @@ private: int m_nextBreakpointId = 1; int m_currentThreadId = -1; + + std::queue> m_variablesReferenceQueue; + WatchItem *m_currentWatchItem = nullptr; + WatchItem *m_rootWatchItem = nullptr; }; } // Debugger::Internal