diff --git a/debugger/pdblauncher.cpp b/debugger/pdblauncher.cpp index c4ae9282..7536b9a9 100644 --- a/debugger/pdblauncher.cpp +++ b/debugger/pdblauncher.cpp @@ -1,124 +1,131 @@ /* This file is part of kdev-python, the python language plugin for KDevelop Copyright (C) 2012 Sven Brauch This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "pdblauncher.h" #include #include "debugjob.h" #include #include #include #include #include #include #include #include #include #include #include #include +#include #include #include "debuggerdebug.h" namespace Python { PdbLauncher::PdbLauncher() { } QList< KDevelop::LaunchConfigurationPageFactory* > PdbLauncher::configPages() const { return QList(); } QString PdbLauncher::description() const { return i18n("A plugin to debug Python applications with pdb."); } QString PdbLauncher::id() { return "pdbdebugger"; } QString PdbLauncher::name() const { return "pdbdebugger"; } KJob* PdbLauncher::start(const QString& launchMode, KDevelop::ILaunchConfiguration* cfg) { qCDebug(KDEV_PYTHON_DEBUGGER) << "start of debugger process requested"; if ( launchMode == "debug" ) { IExecuteScriptPlugin* iface = KDevelop::ICore::self()->pluginController() ->pluginForExtension("org.kdevelop.IExecuteScriptPlugin")->extension(); Q_ASSERT(iface); QString err; QString interpreter = iface->interpreter(cfg, err); // check the interpreter QProcess p; p.setReadChannelMode(QProcess::MergedChannels); p.start(interpreter, QStringList() << "--version"); p.waitForFinished(500); QByteArray version = p.readAll(); qCDebug(KDEV_PYTHON_DEBUGGER) << "interpreter version:" << version; if ( ! version.startsWith("Python 3.") ) { KMessageBox::error(ICore::self()->uiController()->activeMainWindow(), i18n("Sorry, debugging is only supported for Python 3.x applications."), i18n("Unsupported interpreter")); return nullptr; } QUrl scriptUrl; if ( iface->runCurrentFile(cfg) ) { auto document = KDevelop::ICore::self()->documentController()->activeDocument(); if ( ! document ) { qCDebug(KDEV_PYTHON_DEBUGGER) << "no current document"; return nullptr; } scriptUrl = document->url(); } else { scriptUrl = iface->script(cfg, err); } + auto wd = iface->workingDirectory(cfg); + if( !wd.isValid() || wd.isEmpty() ) + { + wd = QUrl::fromLocalFile( QFileInfo( scriptUrl.toLocalFile() ).absolutePath() ); + } + DebugJob* job = new DebugJob(); job->m_scriptUrl = scriptUrl; job->m_interpreter = interpreter; job->m_args = iface->arguments(cfg, err); - job->m_workingDirectory = iface->workingDirectory(cfg); + job->m_workingDirectory = wd; QList l; l << job; return new KDevelop::ExecuteCompositeJob( KDevelop::ICore::self()->runController(), l ); } qCDebug(KDEV_PYTHON_DEBUGGER) << "unknown launch mode"; return nullptr; } QStringList PdbLauncher::supportedModes() const { return QStringList() << "debug"; } }