Commit 6b784626 authored by Ral Snchez Siles's avatar Ral Snchez Siles Committed by Sven Brauch

Inject environment profile variables into debug process environment.

Summary:
Extends DebugJob and DebugSession classes including launch configuration environment variables.

The approach taken is getting the environment profile name within the debug process, storing it in the debug job and injecting the environment variables in the debuggee just before it is launched

BUG: 322477

Reviewers: #kdevelop, brauch

Reviewed By: #kdevelop, brauch

Subscribers: brauch, kdevelop-devel, apol, vkorneev

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D14870
parent 8e54ef73
......@@ -39,7 +39,8 @@ void DebugJob::start()
QStringList program;
QString debuggerUrl = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kdevpythonsupport/debugger", QStandardPaths::LocateDirectory) + "/kdevpdb.py";
program << m_interpreter << "-u" << debuggerUrl << m_scriptUrl.toLocalFile() << m_args;
m_session = new DebugSession(program, m_workingDirectory);
// Inject environment
m_session = new DebugSession(program, m_workingDirectory, m_envProfileName);
setStandardToolView(KDevelop::IOutputView::DebugView);
setBehaviours(KDevelop::IOutputView::Behaviours(KDevelop::IOutputView::AllowUserClose) | KDevelop::IOutputView::AutoScroll);
......
......@@ -43,6 +43,7 @@ public:
QString m_interpreter;
QStringList m_args;
QUrl m_workingDirectory;
QString m_envProfileName;
private slots:
void standardOutputReceived(QStringList lines);
......
......@@ -26,6 +26,7 @@
#include <debugger/framestack/framestackmodel.h>
#include <interfaces/icore.h>
#include <interfaces/idocumentcontroller.h>
#include <util/environmentprofilelist.h>
#include "debugsession.h"
#include "pdbframestackmodel.h"
......@@ -52,12 +53,14 @@ static QByteArray debuggerOutputEnd = "<<<__KDEVPYTHON_END___DEBUGGER_OUTPUT";
namespace Python {
DebugSession::DebugSession(QStringList program, const QUrl &workingDirectory) :
DebugSession::DebugSession(QStringList program, const QUrl &workingDirectory,
const QString& envProfileName) :
IDebugSession()
, m_breakpointController(nullptr)
, m_variableController(nullptr)
, m_frameStackModel(nullptr)
, m_workingDirectory(workingDirectory)
, m_envProfileName(envProfileName)
, m_nextNotifyMethod(nullptr)
, m_inDebuggerData(0)
{
......@@ -91,6 +94,17 @@ void DebugSession::start()
m_debuggerProcess->setOutputChannelMode(KProcess::SeparateChannels);
m_debuggerProcess->blockSignals(true);
m_debuggerProcess->setWorkingDirectory(m_workingDirectory.path());
const KDevelop::EnvironmentProfileList environmentProfiles(KSharedConfig::openConfig());
const auto environment = environmentProfiles.variables(m_envProfileName);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
for(auto i = environment.cbegin(); i != environment.cend(); i++ )
{
env.insert(i.key(), i.value());
}
m_debuggerProcess->setProcessEnvironment(env);
connect(m_debuggerProcess, &QProcess::readyReadStandardOutput, this, &DebugSession::dataAvailable);
connect(m_debuggerProcess, SIGNAL(finished(int)), this, SLOT(debuggerQuit(int)));
connect(this, &DebugSession::debuggerReady, this, &DebugSession::checkCommandQueue);
......
......@@ -42,7 +42,8 @@ class DebugSession : public KDevelop::IDebugSession
{
Q_OBJECT
public:
DebugSession(QStringList program, const QUrl& workingDirectory);
DebugSession(QStringList program, const QUrl& workingDirectory,
const QString& envProfileName);
~DebugSession() override;
IBreakpointController* breakpointController() const override;
......@@ -220,6 +221,7 @@ private:
QStringList m_program;
QList<PdbCommand*> m_commandQueue;
const QUrl& m_workingDirectory;
const QString m_envProfileName;
private:
/// objects to notify next
QPointer<QObject> m_nextNotifyObject;
......
......@@ -38,6 +38,7 @@
#include <QDebug>
#include "debuggerdebug.h"
#include <util/environmentprofilelist.h>
namespace Python {
......@@ -115,6 +116,18 @@ KJob* PdbLauncher::start(const QString& launchMode, KDevelop::ILaunchConfigurati
job->m_interpreter = interpreter;
job->m_args = iface->arguments(cfg, err);
job->m_workingDirectory = wd;
const KDevelop::EnvironmentProfileList environmentProfiles(KSharedConfig::openConfig());
QString envProfileName = iface->environmentProfileName(cfg);
if (envProfileName.isEmpty()) {
qCWarning(KDEV_PYTHON_DEBUGGER) << "No environment profile specified, looks like a broken "
"configuration, please check run configuration " << cfg->name() <<
". Using default environment profile.";
envProfileName = environmentProfiles.defaultProfileName();
}
job->m_envProfileName = envProfileName;
QList<KJob*> l;
l << job;
return new KDevelop::ExecuteCompositeJob( KDevelop::ICore::self()->runController(), l );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment