2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2013-03-27 13:03:15 +01:00
|
|
|
|
|
|
|
|
#include "debuggerrunconfigurationaspect.h"
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
#include "debuggertr.h"
|
2013-03-27 13:03:15 +01:00
|
|
|
|
2023-04-19 08:23:17 +02:00
|
|
|
#include <cppeditor/cppmodelmanager.h>
|
|
|
|
|
|
2020-02-17 14:25:30 +01:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2013-03-27 13:03:15 +01:00
|
|
|
#include <coreplugin/icontext.h>
|
2013-03-27 17:17:24 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2022-07-05 15:37:08 +02:00
|
|
|
|
2020-02-17 14:25:30 +01:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
|
#include <projectexplorer/buildstep.h>
|
|
|
|
|
#include <projectexplorer/buildsteplist.h>
|
2023-08-11 09:18:56 +02:00
|
|
|
#include <projectexplorer/kitaspects.h>
|
2013-03-27 13:03:15 +01:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2013-03-27 17:17:24 +01:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
2013-03-27 13:03:15 +01:00
|
|
|
#include <projectexplorer/target.h>
|
2022-07-05 15:37:08 +02:00
|
|
|
|
2020-02-17 14:25:30 +01:00
|
|
|
#include <qtsupport/qtbuildaspects.h>
|
2013-03-27 13:03:15 +01:00
|
|
|
|
2023-03-31 14:02:36 +02:00
|
|
|
#include <utils/detailswidget.h>
|
2022-08-24 14:55:12 +02:00
|
|
|
#include <utils/environment.h>
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
|
|
|
|
|
2013-03-27 17:17:24 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
2014-03-26 11:23:04 +01:00
|
|
|
|
2013-03-27 13:03:15 +01:00
|
|
|
namespace Debugger {
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Debugger::DebuggerRunConfigurationAspect
|
|
|
|
|
*/
|
|
|
|
|
|
2023-11-29 15:08:48 +01:00
|
|
|
static bool isDisabled(TriStateAspect *aspect)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(aspect, return false);
|
|
|
|
|
return aspect->value() == TriState::Disabled;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 11:48:32 +02:00
|
|
|
DebuggerRunConfigurationAspect::DebuggerRunConfigurationAspect(Target *target)
|
|
|
|
|
: m_target(target)
|
2013-03-27 13:03:15 +01:00
|
|
|
{
|
2013-08-12 17:04:10 +02:00
|
|
|
setId("DebuggerAspect");
|
2022-07-05 15:37:08 +02:00
|
|
|
setDisplayName(Tr::tr("Debugger settings"));
|
2019-09-30 14:00:58 +02:00
|
|
|
|
|
|
|
|
setConfigWidgetCreator([this] {
|
2023-04-20 11:00:50 +02:00
|
|
|
Layouting::Grid builder;
|
2023-04-24 17:06:32 +02:00
|
|
|
builder.addRow({m_cppAspect});
|
2023-11-29 15:08:48 +01:00
|
|
|
builder.addRow({m_pythonAspect});
|
2023-04-20 11:00:50 +02:00
|
|
|
auto info = new QLabel(
|
|
|
|
|
Tr::tr("<a href=\""
|
|
|
|
|
"qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html"
|
|
|
|
|
"\">What are the prerequisites?</a>"));
|
|
|
|
|
builder.addRow({m_qmlAspect, info});
|
|
|
|
|
connect(info, &QLabel::linkActivated, [](const QString &link) {
|
|
|
|
|
Core::HelpManager::showHelpUrl(link);
|
|
|
|
|
});
|
2023-04-24 17:06:32 +02:00
|
|
|
builder.addRow({m_overrideStartupAspect});
|
2019-09-30 14:00:58 +02:00
|
|
|
|
2022-08-24 14:55:12 +02:00
|
|
|
static const QString env = qtcEnvironmentVariable("QTC_DEBUGGER_MULTIPROCESS");
|
2019-11-07 12:22:29 +01:00
|
|
|
if (env.toInt())
|
2023-04-24 17:06:32 +02:00
|
|
|
builder.addRow({m_multiProcessAspect});
|
2023-03-31 14:02:36 +02:00
|
|
|
|
|
|
|
|
auto details = new DetailsWidget;
|
|
|
|
|
details->setState(DetailsWidget::Expanded);
|
|
|
|
|
auto innerPane = new QWidget;
|
|
|
|
|
details->setWidget(innerPane);
|
2023-05-02 12:51:03 +02:00
|
|
|
builder.addItem(Layouting::noMargin);
|
|
|
|
|
builder.attachTo(innerPane);
|
2023-03-31 14:02:36 +02:00
|
|
|
|
|
|
|
|
const auto setSummaryText = [this, details] {
|
|
|
|
|
QStringList items;
|
2024-02-15 17:10:32 +01:00
|
|
|
if (m_cppAspect() == TriState::Enabled)
|
2023-06-13 15:32:09 +02:00
|
|
|
items.append(Tr::tr("Enable C++ debugger."));
|
2024-02-15 17:10:32 +01:00
|
|
|
else if (m_cppAspect() == TriState::Default)
|
2023-06-13 15:32:09 +02:00
|
|
|
items.append(Tr::tr("Try to determine need for C++ debugger."));
|
2023-04-20 11:00:50 +02:00
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
if (m_qmlAspect() == TriState::Enabled)
|
2023-06-13 15:32:09 +02:00
|
|
|
items.append(Tr::tr("Enable QML debugger."));
|
2024-02-15 17:10:32 +01:00
|
|
|
else if (m_qmlAspect() == TriState::Default)
|
2023-06-13 15:32:09 +02:00
|
|
|
items.append(Tr::tr("Try to determine need for QML debugger."));
|
2023-04-20 11:00:50 +02:00
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
items.append(m_overrideStartupAspect().isEmpty()
|
2023-06-13 15:32:09 +02:00
|
|
|
? Tr::tr("Without additional startup commands.")
|
|
|
|
|
: Tr::tr("With additional startup commands."));
|
|
|
|
|
details->setSummaryText(items.join(" "));
|
2023-03-31 14:02:36 +02:00
|
|
|
};
|
|
|
|
|
setSummaryText();
|
|
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
connect(&m_cppAspect, &BaseAspect::changed, this, setSummaryText);
|
|
|
|
|
connect(&m_qmlAspect, &BaseAspect::changed, this, setSummaryText);
|
|
|
|
|
connect(&m_overrideStartupAspect, &BaseAspect::changed, this, setSummaryText);
|
2023-03-31 14:02:36 +02:00
|
|
|
|
|
|
|
|
return details;
|
2019-09-30 14:00:58 +02:00
|
|
|
});
|
|
|
|
|
|
2022-04-08 11:35:54 +02:00
|
|
|
addDataExtractor(this, &DebuggerRunConfigurationAspect::useCppDebugger, &Data::useCppDebugger);
|
|
|
|
|
addDataExtractor(this, &DebuggerRunConfigurationAspect::useQmlDebugger, &Data::useQmlDebugger);
|
2023-11-29 15:08:48 +01:00
|
|
|
addDataExtractor(this, &DebuggerRunConfigurationAspect::usePythonDebugger, &Data::usePythonDebugger);
|
2022-04-08 11:35:54 +02:00
|
|
|
addDataExtractor(this, &DebuggerRunConfigurationAspect::useMultiProcess, &Data::useMultiProcess);
|
|
|
|
|
addDataExtractor(this, &DebuggerRunConfigurationAspect::overrideStartup, &Data::overrideStartup);
|
|
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
m_cppAspect.setSettingsKey("RunConfiguration.UseCppDebugger");
|
|
|
|
|
m_cppAspect.setLabelText(Tr::tr("C++ debugger:"));
|
|
|
|
|
m_cppAspect.setOptionTexts(Tr::tr("Enabled"), Tr::tr("Disabled"), Tr::tr("Automatic"));
|
2019-09-30 14:00:58 +02:00
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
m_qmlAspect.setSettingsKey("RunConfiguration.UseQmlDebugger");
|
|
|
|
|
m_qmlAspect.setLabelText(Tr::tr("QML debugger:"));
|
|
|
|
|
m_qmlAspect.setOptionTexts(Tr::tr("Enabled"), Tr::tr("Disabled"), Tr::tr("Automatic"));
|
2019-09-30 14:00:58 +02:00
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
m_pythonAspect.setSettingsKey("RunConfiguration.UsePythonDebugger");
|
|
|
|
|
m_pythonAspect.setLabelText(Tr::tr("Python debugger:"));
|
|
|
|
|
m_pythonAspect.setOptionTexts(Tr::tr("Enabled"), Tr::tr("Disabled"), Tr::tr("Automatic"));
|
2023-11-29 15:08:48 +01:00
|
|
|
|
2019-09-30 14:00:58 +02:00
|
|
|
// Make sure at least one of the debuggers is set to be active.
|
2024-02-15 17:10:32 +01:00
|
|
|
connect(&m_cppAspect, &TriStateAspect::changed, this, [this] {
|
|
|
|
|
if (Utils::allOf({&m_cppAspect, &m_qmlAspect, &m_pythonAspect}, &isDisabled))
|
|
|
|
|
m_qmlAspect.setValue(TriState::Default);
|
2019-09-30 14:00:58 +02:00
|
|
|
});
|
2024-02-15 17:10:32 +01:00
|
|
|
connect(&m_qmlAspect, &TriStateAspect::changed, this, [this] {
|
|
|
|
|
if (Utils::allOf({&m_cppAspect, &m_qmlAspect, &m_pythonAspect}, &isDisabled))
|
|
|
|
|
m_cppAspect.setValue(TriState::Default);
|
2023-11-29 15:08:48 +01:00
|
|
|
});
|
2024-02-15 17:10:32 +01:00
|
|
|
connect(&m_qmlAspect, &TriStateAspect::changed, this, [this] {
|
|
|
|
|
if (Utils::allOf({&m_cppAspect, &m_qmlAspect, &m_pythonAspect}, &isDisabled))
|
|
|
|
|
m_cppAspect.setValue(TriState::Default);
|
2019-09-30 14:00:58 +02:00
|
|
|
});
|
2023-04-20 11:00:50 +02:00
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
m_multiProcessAspect.setSettingsKey("RunConfiguration.UseMultiProcess");
|
|
|
|
|
m_multiProcessAspect.setLabel(Tr::tr("Enable Debugging of Subprocesses"),
|
2020-08-13 09:16:00 +02:00
|
|
|
BoolAspect::LabelPlacement::AtCheckBox);
|
2019-09-30 14:00:58 +02:00
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
m_overrideStartupAspect.setSettingsKey("RunConfiguration.OverrideDebuggerStartup");
|
|
|
|
|
m_overrideStartupAspect.setDisplayStyle(StringAspect::TextEditDisplay);
|
|
|
|
|
m_overrideStartupAspect.setLabelText(Tr::tr("Additional startup commands:"));
|
2013-03-27 13:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
DebuggerRunConfigurationAspect::~DebuggerRunConfigurationAspect() = default;
|
2019-10-17 17:58:22 +02:00
|
|
|
|
2013-03-27 13:03:15 +01:00
|
|
|
void DebuggerRunConfigurationAspect::setUseQmlDebugger(bool value)
|
|
|
|
|
{
|
2024-02-15 17:10:32 +01:00
|
|
|
m_qmlAspect.setValue(value ? TriState::Enabled : TriState::Disabled);
|
2013-03-27 13:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DebuggerRunConfigurationAspect::useCppDebugger() const
|
|
|
|
|
{
|
2024-02-15 17:10:32 +01:00
|
|
|
if (m_cppAspect() == TriState::Default)
|
2018-09-12 09:31:45 +02:00
|
|
|
return m_target->project()->projectLanguages().contains(
|
2017-01-30 14:59:10 +01:00
|
|
|
ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
2024-02-15 17:10:32 +01:00
|
|
|
return m_cppAspect() == TriState::Enabled;
|
2013-03-27 13:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
2023-04-19 08:23:17 +02:00
|
|
|
static bool projectHasQmlDefines(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
2023-07-12 09:47:29 +02:00
|
|
|
auto projectInfo = CppEditor::CppModelManager::projectInfo(project);
|
2023-07-06 10:55:40 +02:00
|
|
|
if (!projectInfo) // we may have e.g. a Python project
|
|
|
|
|
return false;
|
2023-04-19 08:23:17 +02:00
|
|
|
return Utils::anyOf(projectInfo->projectParts(),
|
|
|
|
|
[](const CppEditor::ProjectPart::ConstPtr &part){
|
|
|
|
|
return Utils::anyOf(part->projectMacros, [](const Macro ¯o){
|
|
|
|
|
return macro.key == "QT_DECLARATIVE_LIB"
|
|
|
|
|
|| macro.key == "QT_QUICK_LIB"
|
|
|
|
|
|| macro.key == "QT_QML_LIB";
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 13:03:15 +01:00
|
|
|
bool DebuggerRunConfigurationAspect::useQmlDebugger() const
|
|
|
|
|
{
|
2024-02-15 17:10:32 +01:00
|
|
|
if (m_qmlAspect() == TriState::Default) {
|
2018-09-12 09:31:45 +02:00
|
|
|
const Core::Context languages = m_target->project()->projectLanguages();
|
2017-01-30 14:59:10 +01:00
|
|
|
if (!languages.contains(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID))
|
2023-04-19 08:23:17 +02:00
|
|
|
return projectHasQmlDefines(m_target->project());
|
2015-12-11 10:43:47 +01:00
|
|
|
|
2014-03-26 11:23:04 +01:00
|
|
|
//
|
2019-11-28 16:58:42 +01:00
|
|
|
// Try to find a build configuration to check whether qml debugging is enabled there
|
2018-09-12 09:31:45 +02:00
|
|
|
if (BuildConfiguration *bc = m_target->activeBuildConfiguration()) {
|
2023-11-29 15:08:48 +01:00
|
|
|
if (const auto aspect = bc->aspect<QtSupport::QmlDebuggingAspect>())
|
|
|
|
|
return aspect->value() == TriState::Enabled;
|
2014-03-26 11:23:04 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-30 14:59:10 +01:00
|
|
|
return !languages.contains(ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
2014-02-07 11:54:18 +01:00
|
|
|
}
|
2024-02-15 17:10:32 +01:00
|
|
|
return m_qmlAspect() == TriState::Enabled;
|
2013-03-27 13:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-29 15:08:48 +01:00
|
|
|
bool DebuggerRunConfigurationAspect::usePythonDebugger() const
|
|
|
|
|
{
|
2024-02-15 17:10:32 +01:00
|
|
|
if (m_pythonAspect() == TriState::Default) {
|
2023-11-29 15:08:48 +01:00
|
|
|
const Core::Context languages = m_target->project()->projectLanguages();
|
|
|
|
|
return languages.contains(ProjectExplorer::Constants::PYTHON_LANGUAGE_ID);
|
|
|
|
|
}
|
2024-02-15 17:10:32 +01:00
|
|
|
return m_pythonAspect() == TriState::Enabled;
|
2023-11-29 15:08:48 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-27 13:03:15 +01:00
|
|
|
bool DebuggerRunConfigurationAspect::useMultiProcess() const
|
|
|
|
|
{
|
2024-02-15 17:10:32 +01:00
|
|
|
return m_multiProcessAspect();
|
2013-03-27 13:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerRunConfigurationAspect::setUseMultiProcess(bool value)
|
|
|
|
|
{
|
2024-02-15 17:10:32 +01:00
|
|
|
m_multiProcessAspect.setValue(value);
|
2013-03-27 13:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-30 11:26:32 +02:00
|
|
|
QString DebuggerRunConfigurationAspect::overrideStartup() const
|
|
|
|
|
{
|
2024-02-15 17:10:32 +01:00
|
|
|
return m_overrideStartupAspect();
|
2019-09-30 11:26:32 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-26 14:09:13 +01:00
|
|
|
int DebuggerRunConfigurationAspect::portsUsedByDebugger() const
|
|
|
|
|
{
|
|
|
|
|
int ports = 0;
|
|
|
|
|
if (useQmlDebugger())
|
|
|
|
|
++ports;
|
|
|
|
|
if (useCppDebugger())
|
|
|
|
|
++ports;
|
|
|
|
|
return ports;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-23 16:53:06 +02:00
|
|
|
void DebuggerRunConfigurationAspect::toMap(Store &map) const
|
2013-03-27 13:03:15 +01:00
|
|
|
{
|
2024-02-15 17:10:32 +01:00
|
|
|
m_cppAspect.toMap(map);
|
|
|
|
|
m_qmlAspect.toMap(map);
|
|
|
|
|
m_pythonAspect.toMap(map);
|
|
|
|
|
m_multiProcessAspect.toMap(map);
|
|
|
|
|
m_overrideStartupAspect.toMap(map);
|
2023-05-09 08:38:54 +02:00
|
|
|
|
|
|
|
|
// compatibility to old settings
|
2024-02-15 17:10:32 +01:00
|
|
|
map.insert("RunConfiguration.UseCppDebuggerAuto", m_cppAspect() == TriState::Default);
|
|
|
|
|
map.insert("RunConfiguration.UseQmlDebuggerAuto", m_qmlAspect() == TriState::Default);
|
2013-03-27 13:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-23 16:53:06 +02:00
|
|
|
void DebuggerRunConfigurationAspect::fromMap(const Store &map)
|
2013-03-27 13:03:15 +01:00
|
|
|
{
|
2024-02-15 17:10:32 +01:00
|
|
|
m_cppAspect.fromMap(map);
|
|
|
|
|
m_qmlAspect.fromMap(map);
|
|
|
|
|
m_pythonAspect.fromMap(map);
|
2023-04-20 11:00:50 +02:00
|
|
|
|
|
|
|
|
// respect old project settings
|
|
|
|
|
if (map.value("RunConfiguration.UseCppDebuggerAuto", false).toBool())
|
2024-02-15 17:10:32 +01:00
|
|
|
m_cppAspect.setValue(TriState::Default);
|
2023-04-20 11:00:50 +02:00
|
|
|
if (map.value("RunConfiguration.UseQmlDebuggerAuto", false).toBool())
|
2024-02-15 17:10:32 +01:00
|
|
|
m_qmlAspect.setValue(TriState::Default);
|
2023-04-20 11:00:50 +02:00
|
|
|
|
2024-02-15 17:10:32 +01:00
|
|
|
m_multiProcessAspect.fromMap(map);
|
|
|
|
|
m_overrideStartupAspect.fromMap(map);
|
2013-03-27 13:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Debugger
|