File indexing completed on 2024-05-05 04:39:53

0001 /*
0002     SPDX-FileCopyrightText: 2006 Vladimir Prus <ghost@cs.msu.su>
0003     SPDX-FileCopyrightText: 2007 Hamish Rodda <rodda@kde.org>
0004     SPDX-FileCopyrightText: 2009 Andreas Pakulat <apaku@gmx.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #include "gdbconfigpage.h"
0010 
0011 #include <interfaces/idebugcontroller.h>
0012 #include <interfaces/ilaunchconfiguration.h>
0013 #include <interfaces/iproject.h>
0014 #include <util/executecompositejob.h>
0015 #include <execute/iexecuteplugin.h>
0016 
0017 #include "dbgglobal.h"
0018 #include "debuggerplugin.h"
0019 #include "debuglog.h"
0020 #include "midebugjobs.h"
0021 
0022 #include "ui_gdbconfigpage.h"
0023 #include <interfaces/iruncontroller.h>
0024 #include <interfaces/icore.h>
0025 
0026 #include <KConfigGroup>
0027 #include <KLocalizedString>
0028 #include <KMessageBox>
0029 #include <KMessageBox_KDevCompat>
0030 
0031 using namespace KDevelop;
0032 namespace Config = KDevMI::GDB::Config;
0033 
0034 GdbConfigPage::GdbConfigPage( QWidget* parent )
0035     : LaunchConfigurationPage(parent), ui( new Ui::GdbConfigPage )
0036 {
0037     ui->setupUi( this );
0038     ui->kcfg_gdbPath->setMode(KFile::File|KFile::ExistingOnly|KFile::LocalOnly);
0039     connect(ui->kcfg_asmDemangle, &QCheckBox::toggled, this, &GdbConfigPage::changed);
0040     connect(ui->kcfg_configGdbScript, &KUrlRequester::textChanged, this, &GdbConfigPage::changed);
0041     //connect(ui->kcfg_dbgTerminal, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
0042     connect(ui->kcfg_debuggingShell, &KUrlRequester::textChanged, this, &GdbConfigPage::changed);
0043     connect(ui->kcfg_displayStaticMembers, &QCheckBox::toggled, this, &GdbConfigPage::changed);
0044     connect(ui->kcfg_gdbPath, &KUrlRequester::textChanged, this, &GdbConfigPage::changed);
0045     connect(ui->kcfg_runGdbScript, &KUrlRequester::textChanged, this, &GdbConfigPage::changed);
0046     connect(ui->kcfg_runShellScript, &KUrlRequester::textChanged, this, &GdbConfigPage::changed);
0047     connect(ui->kcfg_startWith, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &GdbConfigPage::changed);
0048 
0049     //Setup data info for combobox
0050     ui->kcfg_startWith->setItemData(0, QStringLiteral("ApplicationOutput"));
0051     ui->kcfg_startWith->setItemData(1, QStringLiteral("GdbConsole"));
0052     ui->kcfg_startWith->setItemData(2, QStringLiteral("FrameStack"));
0053 }
0054 
0055 GdbConfigPage::~GdbConfigPage()
0056 {
0057     delete ui;
0058 }
0059 
0060 QIcon GdbConfigPage::icon() const
0061 {
0062     return QIcon();
0063 }
0064 
0065 void GdbConfigPage::loadFromConfiguration( const KConfigGroup& cfg, KDevelop::IProject*  )
0066 {
0067     bool block = blockSignals( true );
0068     ui->kcfg_gdbPath->setUrl( cfg.readEntry( Config::GdbPathEntry, QUrl() ) );
0069     ui->kcfg_debuggingShell->setUrl( cfg.readEntry( Config::DebuggerShellEntry, QUrl() ) );
0070     ui->kcfg_configGdbScript->setUrl( cfg.readEntry( Config::RemoteGdbConfigEntry, QUrl() ) );
0071     ui->kcfg_runShellScript->setUrl( cfg.readEntry( Config::RemoteGdbShellEntry, QUrl() ) );
0072     ui->kcfg_runGdbScript->setUrl( cfg.readEntry( Config::RemoteGdbRunEntry, QUrl() ) );
0073     ui->kcfg_displayStaticMembers->setChecked( cfg.readEntry( Config::StaticMembersEntry, false ) );
0074     ui->kcfg_asmDemangle->setChecked( cfg.readEntry( Config::DemangleNamesEntry, true) );
0075     ui->kcfg_startWith->setCurrentIndex( ui->kcfg_startWith->findData( cfg.readEntry( KDevMI::Config::StartWithEntry, "ApplicationOutput" ) ) );
0076     blockSignals( block );
0077 }
0078 
0079 void GdbConfigPage::saveToConfiguration( KConfigGroup cfg, KDevelop::IProject* ) const
0080 {
0081     cfg.writeEntry(Config::GdbPathEntry, ui->kcfg_gdbPath->url() );
0082     cfg.writeEntry(Config::DebuggerShellEntry, ui->kcfg_debuggingShell->url() );
0083     cfg.writeEntry(Config::RemoteGdbConfigEntry, ui->kcfg_configGdbScript->url() );
0084     cfg.writeEntry(Config::RemoteGdbShellEntry, ui->kcfg_runShellScript->url() );
0085     cfg.writeEntry(Config::RemoteGdbRunEntry, ui->kcfg_runGdbScript->url() );
0086     cfg.writeEntry(Config::StaticMembersEntry, ui->kcfg_displayStaticMembers->isChecked() );
0087     cfg.writeEntry(Config::DemangleNamesEntry, ui->kcfg_asmDemangle->isChecked() );
0088     cfg.writeEntry(KDevMI::Config::StartWithEntry, ui->kcfg_startWith->itemData( ui->kcfg_startWith->currentIndex() ).toString() );
0089 }
0090 
0091 QString GdbConfigPage::title() const
0092 {
0093     return i18nc("@title:tab", "GDB Configuration");
0094 }
0095 
0096 
0097 GdbLauncher::GdbLauncher( KDevMI::GDB::CppDebuggerPlugin* p, IExecutePlugin* execute )
0098     : m_plugin( p )
0099     , m_execute( execute )
0100 {
0101     factoryList << new GdbConfigPageFactory();
0102 }
0103 
0104 QList< KDevelop::LaunchConfigurationPageFactory* > GdbLauncher::configPages() const
0105 {
0106     return factoryList;
0107 }
0108 
0109 QString GdbLauncher::id()
0110 {
0111     return QStringLiteral("gdb");
0112 }
0113 
0114 QString GdbLauncher::name() const
0115 {
0116     return i18n("GDB");
0117 }
0118 
0119 KJob* GdbLauncher::start(const QString& launchMode, KDevelop::ILaunchConfiguration* cfg)
0120 {
0121     Q_ASSERT(cfg);
0122     if( !cfg )
0123     {
0124         return nullptr;
0125     }
0126     if( launchMode == QLatin1String("debug") )
0127     {
0128         Q_ASSERT(m_execute);
0129         Q_ASSERT(m_plugin);
0130 
0131         if (KDevelop::ICore::self()->debugController()->currentSession() != nullptr) {
0132             KMessageBox::ButtonCode answer = KMessageBox::warningTwoActions(
0133                 nullptr,
0134                 i18n("A program is already being debugged. Do you want to abort the "
0135                      "currently running debug session and continue with the launch?"),
0136                 {}, KGuiItem(i18nc("@action:button", "Abort Current Session"), QStringLiteral("application-exit")),
0137                 KStandardGuiItem::cancel());
0138             if (answer == KMessageBox::SecondaryAction)
0139                 return nullptr;
0140         }
0141 
0142         QList<KJob*> l;
0143         KJob* depjob = m_execute->dependencyJob(cfg);
0144         if( depjob )
0145         {
0146             l << depjob;
0147         }
0148         l << new KDevMI::MIDebugJob( m_plugin, cfg, m_execute );
0149         return new KDevelop::ExecuteCompositeJob( KDevelop::ICore::self()->runController(), l );
0150     }
0151     qCWarning(DEBUGGERGDB) << "Unknown launch mode" << launchMode << "for config:" << cfg->name();
0152     return nullptr;
0153 }
0154 
0155 QStringList GdbLauncher::supportedModes() const
0156 {
0157     return QStringList() << QStringLiteral("debug");
0158 }
0159 
0160 QString GdbLauncher::description() const
0161 {
0162     return i18n("Executes a native application in GDB");
0163 }
0164 
0165 KDevelop::LaunchConfigurationPage* GdbConfigPageFactory::createWidget( QWidget* parent )
0166 {
0167     return new GdbConfigPage( parent );
0168 }
0169 
0170 #include "moc_gdbconfigpage.cpp"