From 0c3cadb7a80b6471854b3ad664cfe41430da9e88 Mon Sep 17 00:00:00 2001 From: ZhangTingan Date: Wed, 14 May 2025 14:15:13 +0800 Subject: [PATCH 1/2] fix: can`t handle terminated event from debugpy Log: cppdap does not process event which body is empty, but 'body'is an optional filed, it should handle such cases. Bug: --- 3rdparty/cppdap/src/session.cpp | 5 ++++- src/plugins/debugger/dap/dapdebugger.cpp | 13 ------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/3rdparty/cppdap/src/session.cpp b/3rdparty/cppdap/src/session.cpp index 20a72d318..934d60ef1 100644 --- a/3rdparty/cppdap/src/session.cpp +++ b/3rdparty/cppdap/src/session.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef ENABLE_LOG #define Log(message) printf("%s", message); @@ -418,7 +419,9 @@ class Impl : public dap::Session { // "body" is an optional field for some events, such as "Terminated Event". bool body_ok = true; d->field("body", [&](dap::Deserializer* d) { - if (!typeinfo->deserialize(d, data)) { + // todo: to completed + std::set bodyCanBeEmpty { "terminated" }; + if (!typeinfo->deserialize(d, data) && bodyCanBeEmpty.find(event) == bodyCanBeEmpty.end()) { body_ok = false; } return true; diff --git a/src/plugins/debugger/dap/dapdebugger.cpp b/src/plugins/debugger/dap/dapdebugger.cpp index ba2dbb548..b527705ee 100644 --- a/src/plugins/debugger/dap/dapdebugger.cpp +++ b/src/plugins/debugger/dap/dapdebugger.cpp @@ -89,7 +89,6 @@ class DebuggerPrivate DEBUG::DebugSession *currentSession { nullptr }; dap::integer threadId = 0; - QList threads; StackFrameData currentValidFrame; /** @@ -736,17 +735,6 @@ void DAPDebugger::registerDapHandlers() Q_UNUSED(event) qInfo() << "\n--> recv : " << "ThreadEvent"; - - if (event.reason == "started") - d->threads.append(event.threadId); - - if (event.reason == "exited") { - d->threads.removeOne(event.threadId); - if (d->threads.isEmpty()) { - printOutput(tr("\nThe debugee has Terminated.\n"), OutputPane::OutputFormat::NormalMessage); - updateRunState(kNoRun); - } - } }); // The event indicates that the target has produced some output. @@ -1361,7 +1349,6 @@ void DAPDebugger::exitDebug() d->threadId = 0; - d->threads.clear(); d->threadSelector->clear(); } From ef4b62eefdcd657db174b287bcc144d83b7d0057 Mon Sep 17 00:00:00 2001 From: ZhangTingan Date: Thu, 15 May 2025 15:12:16 +0800 Subject: [PATCH 2/2] fix: The logs are not displayed in the same window before and after debugging starts. Log: as title Bug: --- src/common/widget/appoutputpane.cpp | 9 +++++++++ src/common/widget/appoutputpane.h | 1 + src/plugins/debugger/dap/dapdebugger.cpp | 24 ++++++++++++++---------- src/plugins/debugger/dap/dapdebugger.h | 2 +- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/common/widget/appoutputpane.cpp b/src/common/widget/appoutputpane.cpp index 7a61b3c17..60ed366da 100644 --- a/src/common/widget/appoutputpane.cpp +++ b/src/common/widget/appoutputpane.cpp @@ -267,6 +267,15 @@ void AppOutputPane::createApplicationPane(const QString &id, const QString &prog emit paneCreated(id); } +void AppOutputPane::setProcessStarted(const QString &id) +{ + if (!d->appIsRunning.contains(id)) + return; + d->appIsRunning[id] = true; + if (d->stackWidget->currentWidget() == d->appPane[id]) + d->closeProcessBtn->setEnabled(true); +} + void AppOutputPane::setProcessFinished(const QString &id) { if (!d->appIsRunning.contains(id)) diff --git a/src/common/widget/appoutputpane.h b/src/common/widget/appoutputpane.h index bb8be63b2..f052a001c 100644 --- a/src/common/widget/appoutputpane.h +++ b/src/common/widget/appoutputpane.h @@ -32,6 +32,7 @@ class AppOutputPane : public DTK_WIDGET_NAMESPACE::DFrame OutputPane::OutputFormat format, OutputPane::AppendMode mode); + void setProcessStarted(const QString &id); void setProcessFinished(const QString &id); using StopHandler = std::function; diff --git a/src/plugins/debugger/dap/dapdebugger.cpp b/src/plugins/debugger/dap/dapdebugger.cpp index b527705ee..ae1309379 100644 --- a/src/plugins/debugger/dap/dapdebugger.cpp +++ b/src/plugins/debugger/dap/dapdebugger.cpp @@ -213,6 +213,19 @@ void DAPDebugger::startDebug() if (d->currentSession == d->remoteSession) d->currentSession = d->localSession; + QMetaObject::invokeMethod(this, [=](){ + auto appOutPutPane = AppOutputPane::instance(); + appOutPutPane->createApplicationPane("debugPane", "debugTarget"); + appOutPutPane->setStopHandler("debugPane", [=]() { + abortDebug(); + d->outputPane = appOutPutPane->defaultPane(); + }); + d->outputPane = appOutPutPane->getOutputPaneById("debugPane"); + + appOutPutPane->bindToolBarToPane(debugToolBarName, d->outputPane); + AppOutputPane::instance()->setProcessFinished("debugPane"); // only show log untill debuggee launching + }); + auto &ctx = dpfInstance.serviceContext(); LanguageService *service = ctx.service(LanguageService::name()); if (service) { @@ -1600,16 +1613,7 @@ void DAPDebugger::launchSession(int port, const QMap ¶m, } else { debugService->getModel()->clear(); debugService->getModel()->addSession(d->currentSession); - - auto appOutPutPane = AppOutputPane::instance(); - appOutPutPane->createApplicationPane("debugPane", "debugTarget"); - appOutPutPane->setStopHandler("debugPane", [=]() { - abortDebug(); - d->outputPane = appOutPutPane->defaultPane(); - }); - d->outputPane = appOutPutPane->getOutputPaneById("debugPane"); - - appOutPutPane->bindToolBarToPane(debugToolBarName, d->outputPane); + AppOutputPane::instance()->setProcessStarted("debugPane"); } } diff --git a/src/plugins/debugger/dap/dapdebugger.h b/src/plugins/debugger/dap/dapdebugger.h index 4df9150c5..bf54cc93d 100644 --- a/src/plugins/debugger/dap/dapdebugger.h +++ b/src/plugins/debugger/dap/dapdebugger.h @@ -132,7 +132,7 @@ public slots: void launchSession(int port, const QMap ¶m, const QString &kitName); void disassemble(const QString &address); void handleAssemble(const QString &content); - + QString transformRemotePath(const QString &remotePath); dpfservice::ProjectInfo getActiveProjectInfo() const;