DAP: Add different log category for different dap engines

Change-Id: Ia21926b860f8fee7399c40ad382ff31f360f73ce
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Artem Sokolovskii
2023-09-12 10:44:57 +02:00
parent 578e4c13fd
commit 7605f5c934
10 changed files with 109 additions and 56 deletions

View File

@@ -22,7 +22,6 @@
using namespace Core; using namespace Core;
using namespace Utils; using namespace Utils;
static Q_LOGGING_CATEGORY(dapEngineLog, "qtc.dbg.dapengine", QtWarningMsg)
namespace Debugger::Internal { namespace Debugger::Internal {
@@ -83,7 +82,7 @@ public:
: DapClient(provider, parent) : DapClient(provider, parent)
{} {}
void sendInitialize() void sendInitialize() override
{ {
postRequest("initialize", postRequest("initialize",
QJsonObject{{"clientID", "QtCreator"}, QJsonObject{{"clientID", "QtCreator"},
@@ -91,6 +90,13 @@ public:
{"adapterID", "cmake"}, {"adapterID", "cmake"},
{"pathFormat", "path"}}); {"pathFormat", "path"}});
} }
private:
const QLoggingCategory &logCategory() override {
static const QLoggingCategory logCategory = QLoggingCategory("qtc.dbg.dapengine.cmake",
QtWarningMsg);
return logCategory;
}
}; };
CMakeDapEngine::CMakeDapEngine() CMakeDapEngine::CMakeDapEngine()
@@ -103,9 +109,9 @@ CMakeDapEngine::CMakeDapEngine()
void CMakeDapEngine::setupEngine() void CMakeDapEngine::setupEngine()
{ {
QTC_ASSERT(state() == EngineSetupRequested, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == EngineSetupRequested, qCDebug(logCategory()) << state());
qCDebug(dapEngineLog) << "build system name" qCDebug(logCategory()) << "build system name"
<< ProjectExplorer::ProjectTree::currentBuildSystem()->name(); << ProjectExplorer::ProjectTree::currentBuildSystem()->name();
IDataProvider *dataProvider; IDataProvider *dataProvider;

View File

@@ -22,6 +22,13 @@ private:
/* Needed for CMake support issue:25176 */ /* Needed for CMake support issue:25176 */
bool hasCapability(unsigned cap) const override; bool hasCapability(unsigned cap) const override;
const QLoggingCategory &logCategory() override
{
static const QLoggingCategory logCategory = QLoggingCategory("qtc.dbg.dapengine.cmake",
QtWarningMsg);
return logCategory;
}
}; };
} // Debugger::Internal } // Debugger::Internal

View File

@@ -13,8 +13,6 @@
using namespace Core; using namespace Core;
using namespace Utils; using namespace Utils;
static Q_LOGGING_CATEGORY(dapEngineLog, "qtc.dbg.dapengine", QtWarningMsg);
namespace Debugger::Internal { namespace Debugger::Internal {
DapClient::DapClient(IDataProvider *dataProvider, QObject *parent) DapClient::DapClient(IDataProvider *dataProvider, QObject *parent)
@@ -51,7 +49,7 @@ void DapClient::postRequest(const QString &command, const QJsonObject &arguments
const QByteArray data = QJsonDocument(obseq).toJson(QJsonDocument::Compact); const QByteArray data = QJsonDocument(obseq).toJson(QJsonDocument::Compact);
const QByteArray msg = "Content-Length: " + QByteArray::number(data.size()) + "\r\n\r\n" + data; const QByteArray msg = "Content-Length: " + QByteArray::number(data.size()) + "\r\n\r\n" + data;
qCDebug(dapEngineLog) << msg; qCDebug(logCategory()) << msg;
m_dataProvider->writeRaw(msg); m_dataProvider->writeRaw(msg);
} }
@@ -150,7 +148,7 @@ void DapClient::readOutput()
{ {
m_inbuffer.append(m_dataProvider->readAllStandardOutput()); m_inbuffer.append(m_dataProvider->readAllStandardOutput());
qCDebug(dapEngineLog) << m_inbuffer; qCDebug(logCategory()) << m_inbuffer;
while (true) { while (true) {
// Something like // Something like
@@ -190,7 +188,7 @@ void DapClient::emitSignals(const QJsonDocument &doc)
const QJsonValue t = ob.value("type"); const QJsonValue t = ob.value("type");
const QString type = t.toString(); const QString type = t.toString();
qCDebug(dapEngineLog) << "dap response" << ob; qCDebug(logCategory()) << "dap response" << ob;
if (type == "response") { if (type == "response") {
DapResponseType type = DapResponseType::Unknown; DapResponseType type = DapResponseType::Unknown;

View File

@@ -7,6 +7,8 @@
#include <utils/process.h> #include <utils/process.h>
#include <QLoggingCategory>
namespace Debugger::Internal { namespace Debugger::Internal {
class IDataProvider : public QObject class IDataProvider : public QObject
@@ -109,9 +111,14 @@ signals:
private: private:
void readOutput(); void readOutput();
private: virtual const QLoggingCategory &logCategory()
IDataProvider *m_dataProvider = nullptr; {
static const QLoggingCategory logCategory = QLoggingCategory("qtc.dbg.dapengine",
QtWarningMsg);
return logCategory;
}
IDataProvider *m_dataProvider = nullptr;
QByteArray m_inbuffer; QByteArray m_inbuffer;
}; };

View File

@@ -61,13 +61,11 @@
using namespace Core; using namespace Core;
using namespace Utils; using namespace Utils;
static Q_LOGGING_CATEGORY(dapEngineLog, "qtc.dbg.dapengine", QtWarningMsg)
namespace Debugger::Internal { namespace Debugger::Internal {
void DapEngine::executeDebuggerCommand(const QString &/*command*/) void DapEngine::executeDebuggerCommand(const QString &/*command*/)
{ {
QTC_ASSERT(state() == InferiorStopOk, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == InferiorStopOk, qCDebug(logCategory()) << state());
// if (state() == DebuggerNotReady) { // if (state() == DebuggerNotReady) {
// showMessage("DAP PROCESS NOT RUNNING, PLAIN CMD IGNORED: " + command); // showMessage("DAP PROCESS NOT RUNNING, PLAIN CMD IGNORED: " + command);
// return; // return;
@@ -92,50 +90,50 @@ void DapEngine::runCommand(const DebuggerCommand &cmd)
void DapEngine::shutdownInferior() void DapEngine::shutdownInferior()
{ {
QTC_ASSERT(state() == InferiorShutdownRequested, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == InferiorShutdownRequested, qCDebug(logCategory()) << state());
m_dapClient->sendDisconnect(); m_dapClient->sendDisconnect();
qCDebug(dapEngineLog) << "DapEngine::shutdownInferior()"; qCDebug(logCategory()) << "DapEngine::shutdownInferior()";
notifyInferiorShutdownFinished(); notifyInferiorShutdownFinished();
} }
void DapEngine::shutdownEngine() void DapEngine::shutdownEngine()
{ {
QTC_ASSERT(state() == EngineShutdownRequested, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == EngineShutdownRequested, qCDebug(logCategory()) << state());
m_dapClient->sendTerminate(); m_dapClient->sendTerminate();
qCDebug(dapEngineLog) << "DapEngine::shutdownEngine()"; qCDebug(logCategory()) << "DapEngine::shutdownEngine()";
m_dapClient->dataProvider()->kill(); m_dapClient->dataProvider()->kill();
} }
void DapEngine::handleDapStarted() void DapEngine::handleDapStarted()
{ {
notifyEngineSetupOk(); notifyEngineSetupOk();
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
m_dapClient->sendInitialize(); m_dapClient->sendInitialize();
qCDebug(dapEngineLog) << "handleDapStarted"; qCDebug(logCategory()) << "handleDapStarted";
} }
void DapEngine::handleDapInitialize() void DapEngine::handleDapInitialize()
{ {
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
m_dapClient->sendLaunch(runParameters().inferior.command.executable()); m_dapClient->sendLaunch(runParameters().inferior.command.executable());
qCDebug(dapEngineLog) << "handleDapLaunch"; qCDebug(logCategory()) << "handleDapLaunch";
} }
void DapEngine::handleDapEventInitialized() void DapEngine::handleDapEventInitialized()
{ {
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
m_dapClient->sendConfigurationDone(); m_dapClient->sendConfigurationDone();
qCDebug(dapEngineLog) << "handleDapConfigurationDone"; qCDebug(logCategory()) << "handleDapConfigurationDone";
} }
void DapEngine::handleDapConfigurationDone() void DapEngine::handleDapConfigurationDone()
@@ -271,7 +269,7 @@ void DapEngine::dapInsertBreakpoint(const Breakpoint &bp)
m_dapClient->setBreakpoints(breakpoints, params.fileName); m_dapClient->setBreakpoints(breakpoints, params.fileName);
qCDebug(dapEngineLog) << "insertBreakpoint" << bp->modelId() << bp->responseId(); qCDebug(logCategory()) << "insertBreakpoint" << bp->modelId() << bp->responseId();
} }
void DapEngine::updateBreakpoint(const Breakpoint &bp) void DapEngine::updateBreakpoint(const Breakpoint &bp)
@@ -312,7 +310,7 @@ void DapEngine::dapRemoveBreakpoint(const Breakpoint &bp)
m_dapClient->setBreakpoints(breakpoints, params.fileName); m_dapClient->setBreakpoints(breakpoints, params.fileName);
qCDebug(dapEngineLog) << "removeBreakpoint" << bp->modelId() << bp->responseId(); qCDebug(logCategory()) << "removeBreakpoint" << bp->modelId() << bp->responseId();
} }
void DapEngine::loadSymbols(const Utils::FilePath &/*moduleName*/) void DapEngine::loadSymbols(const Utils::FilePath &/*moduleName*/)
@@ -474,7 +472,7 @@ void DapEngine::handleDapDone()
void DapEngine::readDapStandardError() void DapEngine::readDapStandardError()
{ {
QString err = m_dapClient->dataProvider()->readAllStandardError(); QString err = m_dapClient->dataProvider()->readAllStandardError();
qCDebug(dapEngineLog) << "DAP STDERR:" << err; qCDebug(logCategory()) << "DAP STDERR:" << err;
//qWarning() << "Unexpected DAP stderr:" << err; //qWarning() << "Unexpected DAP stderr:" << err;
showMessage("Unexpected DAP stderr: " + err); showMessage("Unexpected DAP stderr: " + err);
//handleOutput(err); //handleOutput(err);
@@ -486,23 +484,23 @@ void DapEngine::handleResponse(DapResponseType type, const QJsonObject &response
if (response.contains("success") && !response.value("success").toBool()) { if (response.contains("success") && !response.value("success").toBool()) {
showMessage(QString("DAP COMMAND FAILED: %1").arg(command)); showMessage(QString("DAP COMMAND FAILED: %1").arg(command));
qCDebug(dapEngineLog) << "DAP COMMAND FAILED:" << command; qCDebug(logCategory()) << "DAP COMMAND FAILED:" << command;
return; return;
} }
switch (type) { switch (type) {
case DapResponseType::Initialize: case DapResponseType::Initialize:
qCDebug(dapEngineLog) << "initialize success"; qCDebug(logCategory()) << "initialize success";
handleDapInitialize(); handleDapInitialize();
break; break;
case DapResponseType::ConfigurationDone: case DapResponseType::ConfigurationDone:
showMessage("configurationDone", LogDebug); showMessage("configurationDone", LogDebug);
qCDebug(dapEngineLog) << "configurationDone success"; qCDebug(logCategory()) << "configurationDone success";
handleDapConfigurationDone(); handleDapConfigurationDone();
break; break;
case DapResponseType::Continue: case DapResponseType::Continue:
showMessage("continue", LogDebug); showMessage("continue", LogDebug);
qCDebug(dapEngineLog) << "continue success"; qCDebug(logCategory()) << "continue success";
notifyInferiorRunOk(); notifyInferiorRunOk();
break; break;
case DapResponseType::StackTrace: case DapResponseType::StackTrace:
@@ -544,7 +542,7 @@ void DapEngine::handleStackTraceResponse(const QJsonObject &response)
const FilePath file = FilePath::fromString( const FilePath file = FilePath::fromString(
stackFrame.value("source").toObject().value("path").toString()); stackFrame.value("source").toObject().value("path").toString());
const int line = stackFrame.value("line").toInt(); const int line = stackFrame.value("line").toInt();
qCDebug(dapEngineLog) << "stackTrace success" << file << line; qCDebug(logCategory()) << "stackTrace success" << file << line;
gotoLocation(Location(file, line)); gotoLocation(Location(file, line));
refreshStack(stackFrames); refreshStack(stackFrames);
@@ -605,7 +603,7 @@ void DapEngine::handleEvent(DapEventType type, const QJsonObject &event)
switch (type) { switch (type) {
case DapEventType::Initialized: case DapEventType::Initialized:
qCDebug(dapEngineLog) << "initialize success"; qCDebug(logCategory()) << "initialize success";
claimInitialBreakpoints(); claimInitialBreakpoints();
handleDapEventInitialized(); handleDapEventInitialized();
break; break;
@@ -672,7 +670,7 @@ void DapEngine::handleBreakpointEvent(const QJsonObject &event)
Breakpoint bp = breakHandler()->findBreakpointByResponseId( Breakpoint bp = breakHandler()->findBreakpointByResponseId(
QString::number(breakpoint.value("id").toInt())); QString::number(breakpoint.value("id").toInt()));
qCDebug(dapEngineLog) << "breakpoint id :" << breakpoint.value("id").toInt(); qCDebug(logCategory()) << "breakpoint id :" << breakpoint.value("id").toInt();
if (bp) { if (bp) {
BreakpointParameters parameters = bp->requestedParameters(); BreakpointParameters parameters = bp->requestedParameters();
@@ -690,10 +688,10 @@ void DapEngine::handleBreakpointEvent(const QJsonObject &event)
const BreakpointParameters &params = bp->requestedParameters(); const BreakpointParameters &params = bp->requestedParameters();
if (params.oneShot) if (params.oneShot)
continueInferior(); continueInferior();
qCDebug(dapEngineLog) << "breakpoint inserted"; qCDebug(logCategory()) << "breakpoint inserted";
} else { } else {
notifyBreakpointInsertFailed(bp); notifyBreakpointInsertFailed(bp);
qCDebug(dapEngineLog) << "breakpoint insertion failed"; qCDebug(logCategory()) << "breakpoint insertion failed";
} }
return; return;
} }
@@ -701,10 +699,10 @@ void DapEngine::handleBreakpointEvent(const QJsonObject &event)
if (body.value("reason").toString() == "removed") { if (body.value("reason").toString() == "removed") {
if (breakpoint.value("verified").toBool()) { if (breakpoint.value("verified").toBool()) {
notifyBreakpointRemoveOk(bp); notifyBreakpointRemoveOk(bp);
qCDebug(dapEngineLog) << "breakpoint removed"; qCDebug(logCategory()) << "breakpoint removed";
} else { } else {
notifyBreakpointRemoveFailed(bp); notifyBreakpointRemoveFailed(bp);
qCDebug(dapEngineLog) << "breakpoint remove failed"; qCDebug(logCategory()) << "breakpoint remove failed";
} }
return; return;
} }
@@ -727,7 +725,7 @@ void DapEngine::refreshLocals(const QJsonArray &variables)
if (variablesReference > 0) if (variablesReference > 0)
item->wantsChildren = true; item->wantsChildren = true;
qCDebug(dapEngineLog) << "variable" << name << variablesReference; qCDebug(logCategory()) << "variable" << name << variablesReference;
if (m_isFirstLayer) if (m_isFirstLayer)
m_watchItems.append(item); m_watchItems.append(item);
else else
@@ -800,7 +798,7 @@ bool DapEngine::hasCapability(unsigned cap) const
void DapEngine::claimInitialBreakpoints() void DapEngine::claimInitialBreakpoints()
{ {
BreakpointManager::claimBreakpointsForEngine(this); BreakpointManager::claimBreakpointsForEngine(this);
qCDebug(dapEngineLog) << "claimInitialBreakpoints"; qCDebug(logCategory()) << "claimInitialBreakpoints";
} }
void DapEngine::connectDataGeneratorSignals() void DapEngine::connectDataGeneratorSignals()

View File

@@ -7,6 +7,7 @@
#include <utils/process.h> #include <utils/process.h>
#include <QLoggingCategory>
#include <QVariant> #include <QVariant>
#include <queue> #include <queue>
@@ -118,6 +119,13 @@ protected:
std::queue<int> m_variablesReferenceQueue; std::queue<int> m_variablesReferenceQueue;
WatchItem *m_currentWatchItem = nullptr; WatchItem *m_currentWatchItem = nullptr;
QList<WatchItem *> m_watchItems; QList<WatchItem *> m_watchItems;
virtual const QLoggingCategory &logCategory()
{
static const QLoggingCategory logCategory = QLoggingCategory("qtc.dbg.dapengine",
QtWarningMsg);
return logCategory;
}
}; };
} // Debugger::Internal } // Debugger::Internal

View File

@@ -17,12 +17,10 @@
#include <QDebug> #include <QDebug>
#include <QLocalSocket> #include <QLocalSocket>
#include <QLoggingCategory>
#include <QVersionNumber> #include <QVersionNumber>
using namespace Core; using namespace Core;
using namespace Utils; using namespace Utils;
static Q_LOGGING_CATEGORY(dapEngineLog, "qtc.dbg.dapengine", QtWarningMsg)
namespace Debugger::Internal { namespace Debugger::Internal {
@@ -85,6 +83,22 @@ private:
const CommandLine m_cmd; const CommandLine m_cmd;
}; };
class GdbDapClient : public DapClient
{
public:
GdbDapClient(IDataProvider *provider, QObject *parent = nullptr)
: DapClient(provider, parent)
{}
private:
const QLoggingCategory &logCategory() override
{
static const QLoggingCategory logCategory = QLoggingCategory("qtc.dbg.dapengine.gdb",
QtWarningMsg);
return logCategory;
}
};
GdbDapEngine::GdbDapEngine() GdbDapEngine::GdbDapEngine()
: DapEngine() : DapEngine()
{ {
@@ -100,12 +114,11 @@ void GdbDapEngine::handleDapInitialize()
return; return;
} }
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
m_dapClient->postRequest("attach", QJsonObject{{"__restart", ""}}); m_dapClient->postRequest("attach", QJsonObject{{"__restart", ""}});
qCDebug(dapEngineLog) << "handleDapAttach"; qCDebug(logCategory()) << "handleDapAttach";
} }
bool GdbDapEngine::isLocalAttachEngine() const bool GdbDapEngine::isLocalAttachEngine() const
{ {
return runParameters().startMode == AttachToLocalProcess; return runParameters().startMode == AttachToLocalProcess;
@@ -123,7 +136,7 @@ void GdbDapEngine::handleDapConfigurationDone()
void GdbDapEngine::setupEngine() void GdbDapEngine::setupEngine()
{ {
QTC_ASSERT(state() == EngineSetupRequested, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == EngineSetupRequested, qCDebug(logCategory()) << state());
const DebuggerRunParameters &rp = runParameters(); const DebuggerRunParameters &rp = runParameters();
CommandLine cmd{rp.debugger.command.executable(), {"-i", "dap"}}; CommandLine cmd{rp.debugger.command.executable(), {"-i", "dap"}};
@@ -142,7 +155,7 @@ void GdbDapEngine::setupEngine()
} }
IDataProvider *dataProvider = new ProcessDataProvider(rp, cmd, this); IDataProvider *dataProvider = new ProcessDataProvider(rp, cmd, this);
m_dapClient = new DapClient(dataProvider, this); m_dapClient = new GdbDapClient(dataProvider, this);
connectDataGeneratorSignals(); connectDataGeneratorSignals();
m_dapClient->dataProvider()->start(); m_dapClient->dataProvider()->start();

View File

@@ -19,6 +19,13 @@ private:
void handleDapConfigurationDone() override; void handleDapConfigurationDone() override;
bool isLocalAttachEngine() const; bool isLocalAttachEngine() const;
const QLoggingCategory &logCategory() override
{
static const QLoggingCategory logCategory = QLoggingCategory("qtc.dbg.dapengine.gdb",
QtWarningMsg);
return logCategory;
}
}; };
} // Debugger::Internal } // Debugger::Internal

View File

@@ -20,7 +20,6 @@
#include <projectexplorer/projecttree.h> #include <projectexplorer/projecttree.h>
#include <QDebug> #include <QDebug>
#include <QLoggingCategory>
#include <QTcpSocket> #include <QTcpSocket>
#include <QTimer> #include <QTimer>
#include <QVersionNumber> #include <QVersionNumber>
@@ -28,11 +27,8 @@
using namespace Core; using namespace Core;
using namespace Utils; using namespace Utils;
static Q_LOGGING_CATEGORY(dapEngineLog, "qtc.dbg.dapengine", QtWarningMsg)
namespace Debugger::Internal { namespace Debugger::Internal {
const char installDebugPyInfoBarId[] = "Python::InstallDebugPy"; const char installDebugPyInfoBarId[] = "Python::InstallDebugPy";
static bool missingPySideInstallation(const FilePath &pythonPath, const QString &packageName) static bool missingPySideInstallation(const FilePath &pythonPath, const QString &packageName)
@@ -88,7 +84,6 @@ public:
connect(m_timer, &QTimer::timeout, this, [this]() { connect(m_timer, &QTimer::timeout, this, [this]() {
m_socket.connectToHost(m_hostName, m_port); m_socket.connectToHost(m_hostName, m_port);
m_socket.waitForConnected(); m_socket.waitForConnected();
qCDebug(dapEngineLog) << "proc id" << m_proc.processId();
if (m_socket.state() == QTcpSocket::ConnectedState) if (m_socket.state() == QTcpSocket::ConnectedState)
m_timer->stop(); m_timer->stop();
@@ -152,7 +147,7 @@ public:
: DapClient(provider, parent) : DapClient(provider, parent)
{} {}
void sendInitialize() void sendInitialize() override
{ {
postRequest("initialize", postRequest("initialize",
QJsonObject{{"clientID", "QtCreator"}, QJsonObject{{"clientID", "QtCreator"},
@@ -160,6 +155,13 @@ public:
{"adapterID", "python"}, {"adapterID", "python"},
{"pathFormat", "path"}}); {"pathFormat", "path"}});
} }
private:
const QLoggingCategory &logCategory() override
{
static const QLoggingCategory dapEngineLog = QLoggingCategory("qtc.dbg.dapengine.python",
QtWarningMsg);
return dapEngineLog;
}
}; };
PyDapEngine::PyDapEngine() PyDapEngine::PyDapEngine()
@@ -172,11 +174,11 @@ PyDapEngine::PyDapEngine()
void PyDapEngine::handleDapInitialize() void PyDapEngine::handleDapInitialize()
{ {
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state()); QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
m_dapClient->sendAttach(); m_dapClient->sendAttach();
qCDebug(dapEngineLog) << "handleDapAttach"; qCDebug(logCategory()) << "handleDapAttach";
} }
void PyDapEngine::quitDebugger() void PyDapEngine::quitDebugger()

View File

@@ -18,6 +18,13 @@ private:
void setupEngine() override; void setupEngine() override;
Utils::Process m_proc; Utils::Process m_proc;
const QLoggingCategory &logCategory() override
{
static const QLoggingCategory logCategory = QLoggingCategory("qtc.dbg.dapengine.python",
QtWarningMsg);
return logCategory;
}
}; };
} // Debugger::Internal } // Debugger::Internal