File indexing completed on 2024-05-05 04:39:53
0001 /* 0002 SPDX-FileCopyrightText: 1999 John Birch <jbb@kdevelop.org > 0003 SPDX-FileCopyrightText: 2007 Vladimir Prus <ghost@cs.msu.su> 0004 SPDX-FileCopyrightText: 2016 Aetf <aetf@unlimitedcodeworks.xyz> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "gdb.h" 0010 0011 #include "dbgglobal.h" 0012 #include "debuglog.h" 0013 0014 #include <interfaces/icore.h> 0015 #include <interfaces/iruntime.h> 0016 #include <interfaces/iruntimecontroller.h> 0017 #include <interfaces/iuicontroller.h> 0018 #include <sublime/message.h> 0019 0020 #include <KConfigGroup> 0021 #include <KLocalizedString> 0022 #include <KShell> 0023 0024 #include <QApplication> 0025 #include <QFileInfo> 0026 #include <QUrl> 0027 0028 using namespace KDevMI::GDB; 0029 using namespace KDevMI::MI; 0030 0031 GdbDebugger::GdbDebugger(QObject* parent) 0032 : MIDebugger(parent) 0033 { 0034 } 0035 0036 GdbDebugger::~GdbDebugger() 0037 { 0038 } 0039 0040 bool GdbDebugger::start(KConfigGroup& config, const QStringList& extraArguments) 0041 { 0042 // FIXME: verify that default value leads to something sensible 0043 QUrl gdbUrl = config.readEntry(Config::GdbPathEntry, QUrl()); 0044 if (gdbUrl.isEmpty()) { 0045 m_debuggerExecutable = QStringLiteral("gdb"); 0046 } else { 0047 // FIXME: verify its' a local path. 0048 m_debuggerExecutable = gdbUrl.url(QUrl::PreferLocalFile | QUrl::StripTrailingSlash); 0049 } 0050 0051 QStringList arguments = extraArguments; 0052 arguments << QStringLiteral("--interpreter=mi2") << QStringLiteral("-quiet"); 0053 0054 QString fullCommand; 0055 0056 QUrl shell = config.readEntry(Config::DebuggerShellEntry, QUrl()); 0057 if(!shell.isEmpty()) { 0058 qCDebug(DEBUGGERGDB) << "have shell" << shell; 0059 QString shell_without_args = shell.toLocalFile().split(QLatin1Char(' ')).first(); 0060 0061 QFileInfo info(shell_without_args); 0062 /*if( info.isRelative() ) 0063 { 0064 shell_without_args = build_dir + "/" + shell_without_args; 0065 info.setFile( shell_without_args ); 0066 }*/ 0067 if(!info.exists()) { 0068 const QString messageText = i18n("Could not locate the debugging shell '%1'.", shell_without_args); 0069 auto* message = new Sublime::Message(messageText, Sublime::Message::Error); 0070 KDevelop::ICore::self()->uiController()->postMessage(message); 0071 return false; 0072 } 0073 0074 arguments.insert(0, m_debuggerExecutable); 0075 arguments.insert(0, shell.toLocalFile()); 0076 m_process->setShellCommand(KShell::joinArgs(arguments)); 0077 } else { 0078 m_process->setProgram(m_debuggerExecutable, arguments); 0079 fullCommand = m_debuggerExecutable + QLatin1Char(' '); 0080 } 0081 fullCommand += arguments.join(QLatin1Char(' ')); 0082 0083 KDevelop::ICore::self()->runtimeController()->currentRuntime()->startProcess(m_process); 0084 0085 qCDebug(DEBUGGERGDB) << "Starting GDB with command" << fullCommand; 0086 qCDebug(DEBUGGERGDB) << "GDB process pid:" << m_process->processId(); 0087 emit userCommandOutput(fullCommand + QLatin1Char('\n')); 0088 return true; 0089 } 0090 0091 #include "moc_gdb.cpp"