Commit 7fd559bb authored by Anton Anikin's avatar Anton Anikin Committed by Gleb Popov

Fix bug 389060 (Heaptrack analysis keeps firing /usr/bin/plasmoidviewer)

Summary:
Old version has wrong logic - we should always use "kdevexecute" plugin instead any IExecutePlugin instance. New version also checks launch configuration type and starts analysis only for native applications.

BUG: 389060

Reviewers: #kdevelop, mwolff

Reviewed By: #kdevelop, mwolff

Subscribers: mwolff, arrowd, kfunk, kossebau, kdevelop-devel

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D15565
parent 1b0af1fc
......@@ -25,7 +25,6 @@
#include <execute/iexecuteplugin.h>
#include <interfaces/icore.h>
#include <interfaces/iplugincontroller.h>
#include <interfaces/iuicontroller.h>
#include <util/environmentprofilelist.h>
#include <util/path.h>
......@@ -38,16 +37,13 @@
namespace Heaptrack
{
Job::Job(KDevelop::ILaunchConfiguration* launchConfig)
Job::Job(KDevelop::ILaunchConfiguration* launchConfig, IExecutePlugin* executePlugin)
: m_pid(-1)
{
Q_ASSERT(launchConfig);
Q_ASSERT(executePlugin);
auto pluginController = KDevelop::ICore::self()->pluginController();
auto iface = pluginController->pluginForExtension(QStringLiteral("org.kdevelop.IExecutePlugin"))->extension<IExecutePlugin>();
Q_ASSERT(iface);
QString envProfile = iface->environmentProfileName(launchConfig);
QString envProfile = executePlugin->environmentProfileName(launchConfig);
if (envProfile.isEmpty()) {
envProfile = KDevelop::EnvironmentProfileList(KSharedConfig::openConfig()).defaultProfileName();
}
......@@ -55,19 +51,19 @@ Job::Job(KDevelop::ILaunchConfiguration* launchConfig)
QString errorString;
m_analyzedExecutable = iface->executable(launchConfig, errorString).toLocalFile();
m_analyzedExecutable = executePlugin->executable(launchConfig, errorString).toLocalFile();
if (!errorString.isEmpty()) {
setError(-1);
setErrorText(errorString);
}
QStringList analyzedExecutableArguments = iface->arguments(launchConfig, errorString);
QStringList analyzedExecutableArguments = executePlugin->arguments(launchConfig, errorString);
if (!errorString.isEmpty()) {
setError(-1);
setErrorText(errorString);
}
QUrl workDir = iface->workingDirectory(launchConfig);
QUrl workDir = executePlugin->workingDirectory(launchConfig);
if (workDir.isEmpty() || !workDir.isValid()) {
workDir = QUrl::fromLocalFile(QFileInfo(m_analyzedExecutable).absolutePath());
}
......
......@@ -22,10 +22,8 @@
#include <interfaces/istatus.h>
#include <outputview/outputexecutejob.h>
namespace KDevelop
{
class ILaunchConfiguration;
}
class IExecutePlugin;
namespace KDevelop { class ILaunchConfiguration; }
namespace Heaptrack
{
......@@ -36,7 +34,7 @@ class Job : public KDevelop::OutputExecuteJob, public KDevelop::IStatus
Q_INTERFACES(KDevelop::IStatus)
public:
explicit Job(KDevelop::ILaunchConfiguration* launchConfig);
Job(KDevelop::ILaunchConfiguration* launchConfig, IExecutePlugin* executePlugin);
explicit Job(long int pid);
~Job() override;
......
......@@ -78,7 +78,7 @@
},
"X-KDevelop-Category": "Global",
"X-KDevelop-IRequired": [
"org.kdevelop.IExecutePlugin"
"org.kdevelop.IExecutePlugin@kdevexecute"
],
"X-KDevelop-Mode": "GUI"
}
......@@ -33,15 +33,18 @@
#include <execute/iexecuteplugin.h>
#include <interfaces/iplugincontroller.h>
#include <interfaces/launchconfigurationtype.h>
#include <shell/core.h>
#include <shell/launchconfiguration.h>
#include <shell/runcontroller.h>
#include <util/executecompositejob.h>
#include <KActionCollection>
#include <KMessageBox>
#include <KPluginFactory>
#include <QAction>
#include <QApplication>
#include <QFile>
K_PLUGIN_FACTORY_WITH_JSON(HeaptrackFactory, "kdevheaptrack.json", registerPlugin<Heaptrack::Plugin>();)
......@@ -79,25 +82,43 @@ Plugin::~Plugin()
void Plugin::launchHeaptrack()
{
auto runController = KDevelop::Core::self()->runControllerInternal();
if (runController->launchConfigurations().isEmpty()) {
runController->showConfigurationDialog();
IExecutePlugin* executePlugin = nullptr;
// First we should check that our "kdevexecute" plugin is loaded. This is needed since
// current plugin controller logic allows us to unload this plugin with keeping dependent
// plugins like Heaptrack in "loaded" state. This seems to be wrong behaviour but now we have
// to do additional checks.
// TODO fix plugin controller to avoid such inconsistent states.
auto pluginController = core()->pluginController();
if (auto plugin = pluginController->pluginForExtension(
QStringLiteral("org.kdevelop.IExecutePlugin"), QStringLiteral("kdevexecute"))) {
executePlugin = plugin->extension<IExecutePlugin>();
} else {
auto pluginInfo = pluginController->infoForPluginId(QStringLiteral("kdevexecute"));
KMessageBox::error(
qApp->activeWindow(),
i18n("Unable to start Heaptrack analysis - \"%1\" plugin is not loaded.", pluginInfo.name()));
return;
}
auto runController = KDevelop::Core::self()->runControllerInternal();
auto defaultLaunch = runController->defaultLaunch();
if (!defaultLaunch) {
return;
runController->showConfigurationDialog();
}
auto pluginController = core()->self()->pluginController();
auto iface = pluginController->pluginForExtension(QStringLiteral("org.kdevelop.IExecutePlugin"))->extension<IExecutePlugin>();
Q_ASSERT(iface);
if (!defaultLaunch->type()->launcherForId(QStringLiteral("nativeAppLauncher"))) {
KMessageBox::error(
qApp->activeWindow(),
i18n("Heaptrack analysis can be started only for native applications."));
return;
}
auto heaptrackJob = new Job(defaultLaunch);
auto heaptrackJob = new Job(defaultLaunch, executePlugin);
connect(heaptrackJob, &Job::finished, this, &Plugin::jobFinished);
QList<KJob*> jobList;
if (KJob* depJob = iface->dependencyJob(defaultLaunch)) {
if (KJob* depJob = executePlugin->dependencyJob(defaultLaunch)) {
jobList += depJob;
}
jobList += heaptrackJob;
......
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