DAP: Add CMake debug to the debug panel

This commit introduces the capability to initiate
CMake Debug sessions directly from the debug panel
in the QtCretor.

Change-Id: I00245e0e14aded378e881c4049cdc41dd1fbd00e
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Artem Sokolovskii
2023-07-04 16:32:37 +02:00
parent a5e773aeee
commit cd6e990de8
17 changed files with 140 additions and 49 deletions

View File

@@ -115,6 +115,7 @@ CMakeBuildSystem::CMakeBuildSystem(CMakeBuildConfiguration *bc)
&CMakeBuildSystem::handleParsingSucceeded);
connect(&m_reader, &FileApiReader::errorOccurred, this, &CMakeBuildSystem::handleParsingFailed);
connect(&m_reader, &FileApiReader::dirty, this, &CMakeBuildSystem::becameDirty);
connect(&m_reader, &FileApiReader::debuggingStarted, this, &BuildSystem::debuggingStarted);
wireUpConnections();
@@ -193,7 +194,15 @@ void CMakeBuildSystem::triggerParsing()
qCDebug(cmakeBuildSystemLog) << "Asking reader to parse";
m_reader.parse(reparseParameters & REPARSE_FORCE_CMAKE_RUN,
reparseParameters & REPARSE_FORCE_INITIAL_CONFIGURATION,
reparseParameters & REPARSE_FORCE_EXTRA_CONFIGURATION);
reparseParameters & REPARSE_FORCE_EXTRA_CONFIGURATION,
reparseParameters & REPARSE_DEBUG);
}
void CMakeBuildSystem::requestDebugging()
{
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to \"Rescan Project\" command";
reparse(REPARSE_FORCE_CMAKE_RUN | REPARSE_FORCE_EXTRA_CONFIGURATION | REPARSE_URGENT
| REPARSE_DEBUG);
}
bool CMakeBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const

View File

@@ -40,6 +40,7 @@ public:
~CMakeBuildSystem() final;
void triggerParsing() final;
void requestDebugging() final;
bool supportsAction(ProjectExplorer::Node *context,
ProjectExplorer::ProjectAction action,
@@ -143,6 +144,7 @@ private:
= (1 << 1), // Force initial configuration arguments to cmake
REPARSE_FORCE_EXTRA_CONFIGURATION = (1 << 2), // Force extra configuration arguments to cmake
REPARSE_URGENT = (1 << 3), // Do not delay the parser run by 1s
REPARSE_DEBUG = (1 << 4), // Start with debugging
};
void reparse(int reparseParameters);
QString reparseParametersString(int reparseFlags);

View File

@@ -122,8 +122,9 @@ void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &
m_process->setWorkingDirectory(buildDirectory);
m_process->setEnvironment(parameters.environment);
m_process->setStdOutLineCallback([](const QString &s) {
m_process->setStdOutLineCallback([this](const QString &s) {
BuildSystem::appendBuildSystemOutput(stripTrailingNewline(s));
emit stdOutReady(s);
});
m_process->setStdErrLineCallback([this](const QString &s) {
@@ -139,19 +140,6 @@ 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.")

View File

@@ -33,6 +33,7 @@ public:
signals:
void finished(int exitCode);
void stdOutReady(const QString &s);
private:
void handleProcessDone(const Utils::ProcessResultData &resultData);

View File

@@ -82,19 +82,26 @@ void FileApiReader::resetData()
void FileApiReader::parse(bool forceCMakeRun,
bool forceInitialConfiguration,
bool forceExtraConfiguration)
bool forceExtraConfiguration,
bool debugging)
{
qCDebug(cmakeFileApiMode) << "Parse called with arguments: ForceCMakeRun:" << forceCMakeRun
<< " - forceConfiguration:" << forceInitialConfiguration
<< " - forceExtraConfiguration:" << forceExtraConfiguration;
startState();
const QStringList args = (forceInitialConfiguration ? m_parameters.initialCMakeArguments
QStringList args = (forceInitialConfiguration ? m_parameters.initialCMakeArguments
: QStringList())
+ (forceExtraConfiguration
? (m_parameters.configurationChangesArguments
+ m_parameters.additionalCMakeArguments)
: QStringList());
if (debugging) {
FilePath file = FilePath::fromString("/tmp/cmake-dap.sock");
file.removeFile();
args << "--debugger" << "--debugger-pipe=/tmp/cmake-dap.sock";
}
qCDebug(cmakeFileApiMode) << "Parameters request these CMake arguments:" << args;
const FilePath replyFile = FileApiParser::scanForCMakeReplyFile(m_parameters.buildDirectory);
@@ -339,6 +346,10 @@ void FileApiReader::startCMakeState(const QStringList &configurationArguments)
m_cmakeProcess = std::make_unique<CMakeProcess>();
connect(m_cmakeProcess.get(), &CMakeProcess::finished, this, &FileApiReader::cmakeFinishedState);
connect(m_cmakeProcess.get(), &CMakeProcess::stdOutReady, this, [this](const QString &data) {
if (data.endsWith("Waiting for debugger client to connect...\n"))
emit debuggingStarted();
});
qCDebug(cmakeFileApiMode) << ">>>>>> Running cmake with arguments:" << configurationArguments;
// Reset watcher:

View File

@@ -38,7 +38,10 @@ public:
void setParameters(const BuildDirParameters &p);
void resetData();
void parse(bool forceCMakeRun, bool forceInitialConfiguration, bool forceExtraConfiguration);
void parse(bool forceCMakeRun,
bool forceInitialConfiguration,
bool forceExtraConfiguration,
bool debugging);
void stop();
void stopCMakeRun();
@@ -64,6 +67,7 @@ signals:
void dataAvailable(bool restoredFromBackup) const;
void dirty() const;
void errorOccurred(const QString &message) const;
void debuggingStarted() const;
private:
void startState();