DAP: Add CMake support to DAP engine

Added CMake support to the DAP engine in Qt Creator.
This feature can be enabled by setting the environment
variable QTC_USE_CMAKE_DEBUGGER. CMake debug session can
be started by clicking "Run CMake" or "Run".

Note:
Doesn't work with "Run debugging" in this patch.
Works only with cmake 3.27.0 and newer.

Change-Id: I756ea57f507aa4a6621ad62a8c0ef52c44a5185d
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Artem Sokolovskii
2023-06-27 16:57:51 +02:00
parent 52bc1578e5
commit 1fc0ca5277
8 changed files with 272 additions and 69 deletions

View File

@@ -13,8 +13,14 @@
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/taskhub.h>
#include <projectexplorer/kitchooser.h>
#include <projectexplorer/runcontrol.h>
#include <extensionsystem/invoker.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/process.h>
#include <utils/processinfo.h>
#include <utils/processinterface.h>
#include <utils/stringutils.h>
@@ -40,6 +46,11 @@ CMakeProcess::~CMakeProcess()
static const int failedToStartExitCode = 0xFF; // See ProcessPrivate::handleDone() impl
static QObject *debuggerPlugin()
{
return ExtensionSystem::PluginManager::getObjectByName("DebuggerPlugin");
}
void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &arguments)
{
QTC_ASSERT(!m_process, return);
@@ -128,6 +139,19 @@ void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &
commandLine.addArgs({"-S", sourceDirectory.path(), "-B", buildDirectory.path()});
commandLine.addArgs(arguments);
if (qEnvironmentVariableIsSet("QTC_USE_CMAKE_DEBUGGER")) {
FilePath file = FilePath::fromString("/tmp/cmake-dap.sock");
file.removeFile();
commandLine.addArgs({"--debugger", "--debugger-pipe=/tmp/cmake-dap.sock"});
connect(m_process.get(), &Process::started, this, [this, cmakeExecutable] {
QMetaObject::invokeMethod(debuggerPlugin(),
"attachToProcess",
Qt::QueuedConnection,
Q_ARG(qint64, m_process->processId()),
Q_ARG(const Utils::FilePath &, cmakeExecutable));
});
}
TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
BuildSystem::startNewBuildSystemOutput(::CMakeProjectManager::Tr::tr("Running %1 in %2.")