diff options
author | hjk <hjk@qt.io> | 2019-03-20 17:49:26 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2019-03-25 15:00:01 +0000 |
commit | 741950a3aadc199ca2f4491d66b04438001b6f59 (patch) | |
tree | 4dd98d4feca810a48070160fed40fa04ad8a6ec4 /src/plugins/valgrind | |
parent | 90e828b890e3ddb4db0eb90c4cf3627e74ccbf5c (diff) |
Valgrind: Restructure plugin setup
Bring it more in line with the standard pattern.
Plus some cosmetics.
Change-Id: I2297c4e72892db386c50ece7dc64bdc89f0d9010
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/valgrind')
-rw-r--r-- | src/plugins/valgrind/callgrindtool.cpp | 232 | ||||
-rw-r--r-- | src/plugins/valgrind/callgrindtool.h | 14 | ||||
-rw-r--r-- | src/plugins/valgrind/memchecktool.cpp | 206 | ||||
-rw-r--r-- | src/plugins/valgrind/memchecktool.h | 17 | ||||
-rw-r--r-- | src/plugins/valgrind/valgrindconfigwidget.cpp | 2 | ||||
-rw-r--r-- | src/plugins/valgrind/valgrindengine.cpp | 2 | ||||
-rw-r--r-- | src/plugins/valgrind/valgrindplugin.cpp | 40 | ||||
-rw-r--r-- | src/plugins/valgrind/valgrindplugin.h | 12 | ||||
-rw-r--r-- | src/plugins/valgrind/valgrindsettings.cpp | 20 | ||||
-rw-r--r-- | src/plugins/valgrind/valgrindsettings.h | 2 |
10 files changed, 286 insertions, 261 deletions
diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp index decc989781..4f14ed86c0 100644 --- a/src/plugins/valgrind/callgrindtool.cpp +++ b/src/plugins/valgrind/callgrindtool.cpp @@ -106,13 +106,13 @@ const char CallgrindLocalActionId[] = "Callgrind.Local.Action"; const char CallgrindRemoteActionId[] = "Callgrind.Remote.Action"; const char CALLGRIND_RUN_MODE[] = "CallgrindTool.CallgrindRunMode"; -class CallgrindTool : public QObject +class CallgrindToolPrivate : public QObject { Q_OBJECT public: - CallgrindTool(); - ~CallgrindTool() override; + CallgrindToolPrivate(); + ~CallgrindToolPrivate() override; void setupRunner(CallgrindToolRunner *runner); @@ -218,10 +218,10 @@ public: QString m_toggleCollectFunction; bool m_toolBusy = false; - Perspective m_perspective{"Callgrind.Perspective", tr("Callgrind")}; + Perspective m_perspective{"Callgrind.Perspective", CallgrindTool::tr("Callgrind")}; }; -CallgrindTool::CallgrindTool() +CallgrindToolPrivate::CallgrindToolPrivate() { setObjectName("CallgrindTool"); @@ -235,22 +235,22 @@ CallgrindTool::CallgrindTool() m_proxyModel.setFilterCaseSensitivity(Qt::CaseInsensitive); connect(&m_stackBrowser, &StackBrowser::currentChanged, - this, &CallgrindTool::stackBrowserChanged); + this, &CallgrindToolPrivate::stackBrowserChanged); connect(&m_updateTimer, &QTimer::timeout, - this, &CallgrindTool::updateFilterString); + this, &CallgrindToolPrivate::updateFilterString); connect(EditorManager::instance(), &EditorManager::editorOpened, - this, &CallgrindTool::editorOpened); + this, &CallgrindToolPrivate::editorOpened); m_startAction = Debugger::createStartAction(); m_stopAction = Debugger::createStopAction(); ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); - QString toolTip = tr("Valgrind Function Profiler uses the " + QString toolTip = CallgrindTool::tr("Valgrind Function Profiler uses the " "Callgrind tool to record function calls when a program runs."); if (!Utils::HostOsInfo::isWindowsHost()) { - auto action = new QAction(tr("Valgrind Function Profiler"), this); + auto action = new QAction(CallgrindTool::tr("Valgrind Function Profiler"), this); action->setToolTip(toolTip); menu->addAction(ActionManager::registerAction(action, CallgrindLocalActionId), Debugger::Constants::G_ANALYZER_TOOLS); @@ -266,7 +266,7 @@ CallgrindTool::CallgrindTool() }); } - auto action = new QAction(tr("Valgrind Function Profiler (External Application)"), this); + auto action = new QAction(CallgrindTool::tr("Valgrind Function Profiler (External Application)"), this); action->setToolTip(toolTip); menu->addAction(ActionManager::registerAction(action, CallgrindRemoteActionId), Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); @@ -295,10 +295,10 @@ CallgrindTool::CallgrindTool() Context analyzerContext = Context(Debugger::Constants::C_DEBUGMODE); editorContextMenu->addSeparator(analyzerContext); - auto action = new QAction(tr("Profile Costs of This Function and Its Callees"), this); + auto action = new QAction(CallgrindTool::tr("Profile Costs of This Function and Its Callees"), this); action->setIcon(ProjectExplorer::Icons::ANALYZER_START_SMALL.icon()); connect(action, &QAction::triggered, this, - &CallgrindTool::handleShowCostsOfFunction); + &CallgrindToolPrivate::handleShowCostsOfFunction); Command *cmd = ActionManager::registerAction(action, "Analyzer.Callgrind.ShowCostsOfFunction", analyzerContext); editorContextMenu->addAction(cmd); @@ -314,14 +314,14 @@ CallgrindTool::CallgrindTool() m_visualization = new Visualization; m_visualization->setFrameStyle(QFrame::NoFrame); m_visualization->setObjectName("Valgrind.CallgrindTool.Visualisation"); - m_visualization->setWindowTitle(tr("Visualization")); + m_visualization->setWindowTitle(CallgrindTool::tr("Visualization")); m_visualization->setModel(&m_dataModel); connect(m_visualization, &Visualization::functionActivated, - this, &CallgrindTool::visualisationFunctionSelected); + this, &CallgrindToolPrivate::visualisationFunctionSelected); m_callersView = new CostView; m_callersView->setObjectName("Valgrind.CallgrindTool.CallersView"); - m_callersView->setWindowTitle(tr("Callers")); + m_callersView->setWindowTitle(CallgrindTool::tr("Callers")); m_callersView->setSettings(coreSettings, "Valgrind.CallgrindTool.CallersView"); m_callersView->sortByColumn(CallModel::CostColumn, Qt::DescendingOrder); m_callersView->setFrameStyle(QFrame::NoFrame); @@ -330,11 +330,11 @@ CallgrindTool::CallgrindTool() m_callersView->setModel(&m_callersProxy); m_callersView->hideColumn(CallModel::CalleeColumn); connect(m_callersView, &QAbstractItemView::activated, - this, &CallgrindTool::callerFunctionSelected); + this, &CallgrindToolPrivate::callerFunctionSelected); m_calleesView = new CostView; m_calleesView->setObjectName("Valgrind.CallgrindTool.CalleesView"); - m_calleesView->setWindowTitle(tr("Callees")); + m_calleesView->setWindowTitle(CallgrindTool::tr("Callees")); m_calleesView->setSettings(coreSettings, "Valgrind.CallgrindTool.CalleesView"); m_calleesView->sortByColumn(CallModel::CostColumn, Qt::DescendingOrder); m_calleesView->setFrameStyle(QFrame::NoFrame); @@ -343,22 +343,22 @@ CallgrindTool::CallgrindTool() m_calleesView->setModel(&m_calleesProxy); m_calleesView->hideColumn(CallModel::CallerColumn); connect(m_calleesView, &QAbstractItemView::activated, - this, &CallgrindTool::calleeFunctionSelected); + this, &CallgrindToolPrivate::calleeFunctionSelected); m_flatView = new CostView; m_flatView->setObjectName("Valgrind.CallgrindTool.FlatView"); - m_flatView->setWindowTitle(tr("Functions")); + m_flatView->setWindowTitle(CallgrindTool::tr("Functions")); m_flatView->setSettings(coreSettings, "Valgrind.CallgrindTool.FlatView"); m_flatView->sortByColumn(DataModel::SelfCostColumn, Qt::DescendingOrder); m_flatView->setFrameStyle(QFrame::NoFrame); m_flatView->setAttribute(Qt::WA_MacShowFocusRect, false); m_flatView->setModel(&m_proxyModel); connect(m_flatView, &QAbstractItemView::activated, - this, &CallgrindTool::dataFunctionSelected); + this, &CallgrindToolPrivate::dataFunctionSelected); updateCostFormat(); - ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings(); + ValgrindGlobalSettings *settings = ValgrindGlobalSettings::instance(); // // Control Widget @@ -367,15 +367,15 @@ CallgrindTool::CallgrindTool() // load external log file action = m_loadExternalLogFile = new QAction(this); action->setIcon(Utils::Icons::OPENFILE_TOOLBAR.icon()); - action->setToolTip(tr("Load External Log File")); - connect(action, &QAction::triggered, this, &CallgrindTool::loadExternalLogFile); + action->setToolTip(CallgrindTool::tr("Load External Log File")); + connect(action, &QAction::triggered, this, &CallgrindToolPrivate::loadExternalLogFile); action = m_startKCachegrind = new QAction(this); action->setEnabled(false); const Utils::Icon kCachegrindIcon({{":/valgrind/images/kcachegrind.png", Theme::IconsBaseColor}}); action->setIcon(kCachegrindIcon.icon()); - action->setToolTip(tr("Open results in KCachegrind.")); + action->setToolTip(CallgrindTool::tr("Open results in KCachegrind.")); connect(action, &QAction::triggered, this, [this, settings] { QProcess::startDetached(settings->kcachegrindExecutable(), { m_lastFileName }); }); @@ -384,30 +384,30 @@ CallgrindTool::CallgrindTool() m_dumpAction = action = new QAction(this); action->setDisabled(true); action->setIcon(Utils::Icons::REDO.icon()); - //action->setText(tr("Dump")); - action->setToolTip(tr("Request the dumping of profile information. This will update the Callgrind visualization.")); - connect(action, &QAction::triggered, this, &CallgrindTool::slotRequestDump); + //action->setText(CallgrindTool::tr("Dump")); + action->setToolTip(CallgrindTool::tr("Request the dumping of profile information. This will update the Callgrind visualization.")); + connect(action, &QAction::triggered, this, &CallgrindToolPrivate::slotRequestDump); // reset action m_resetAction = action = new QAction(this); action->setDisabled(true); action->setIcon(Utils::Icons::RELOAD.icon()); - //action->setText(tr("Reset")); - action->setToolTip(tr("Reset all event counters.")); - connect(action, &QAction::triggered, this, &CallgrindTool::resetRequested); + //action->setText(CallgrindTool::tr("Reset")); + action->setToolTip(CallgrindTool::tr("Reset all event counters.")); + connect(action, &QAction::triggered, this, &CallgrindToolPrivate::resetRequested); // pause action m_pauseAction = action = new QAction(this); action->setCheckable(true); action->setIcon(Utils::Icons::INTERRUPT_SMALL_TOOLBAR.icon()); - //action->setText(tr("Ignore")); - action->setToolTip(tr("Pause event logging. No events are counted which will speed up program execution during profiling.")); - connect(action, &QAction::toggled, this, &CallgrindTool::pauseToggled); + //action->setText(CallgrindTool::tr("Ignore")); + action->setToolTip(CallgrindTool::tr("Pause event logging. No events are counted which will speed up program execution during profiling.")); + connect(action, &QAction::toggled, this, &CallgrindToolPrivate::pauseToggled); // discard data action m_discardAction = action = new QAction(this); action->setIcon(Utils::Icons::CLEAN_TOOLBAR.icon()); - action->setToolTip(tr("Discard Data")); + action->setToolTip(CallgrindTool::tr("Discard Data")); connect(action, &QAction::triggered, this, [this](bool) { clearTextMarks(); doClear(true); @@ -418,21 +418,21 @@ CallgrindTool::CallgrindTool() m_goBack = action = new QAction(this); action->setDisabled(true); action->setIcon(Utils::Icons::PREV_TOOLBAR.icon()); - action->setToolTip(tr("Go back one step in history. This will select the previously selected item.")); + action->setToolTip(CallgrindTool::tr("Go back one step in history. This will select the previously selected item.")); connect(action, &QAction::triggered, &m_stackBrowser, &StackBrowser::goBack); // go forward m_goNext = action = new QAction(this); action->setDisabled(true); action->setIcon(Utils::Icons::NEXT_TOOLBAR.icon()); - action->setToolTip(tr("Go forward one step in history.")); + action->setToolTip(CallgrindTool::tr("Go forward one step in history.")); connect(action, &QAction::triggered, &m_stackBrowser, &StackBrowser::goNext); // event selection m_eventCombo = new QComboBox; - m_eventCombo->setToolTip(tr("Selects which events from the profiling data are shown and visualized.")); + m_eventCombo->setToolTip(CallgrindTool::tr("Selects which events from the profiling data are shown and visualized.")); connect(m_eventCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), - this, &CallgrindTool::setCostEvent); + this, &CallgrindToolPrivate::setCostEvent); updateEventCombo(); m_perspective.addToolBarAction(m_startAction); @@ -453,61 +453,61 @@ CallgrindTool::CallgrindTool() auto group = new QActionGroup(this); // Show costs as absolute numbers - m_costAbsolute = new QAction(tr("Absolute Costs"), this); - m_costAbsolute->setToolTip(tr("Show costs as absolute numbers.")); + m_costAbsolute = new QAction(CallgrindTool::tr("Absolute Costs"), this); + m_costAbsolute->setToolTip(CallgrindTool::tr("Show costs as absolute numbers.")); m_costAbsolute->setCheckable(true); m_costAbsolute->setChecked(true); - connect(m_costAbsolute, &QAction::toggled, this, &CallgrindTool::updateCostFormat); + connect(m_costAbsolute, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat); group->addAction(m_costAbsolute); // Show costs in percentages - m_costRelative = new QAction(tr("Relative Costs"), this); - m_costRelative->setToolTip(tr("Show costs relative to total inclusive cost.")); + m_costRelative = new QAction(CallgrindTool::tr("Relative Costs"), this); + m_costRelative->setToolTip(CallgrindTool::tr("Show costs relative to total inclusive cost.")); m_costRelative->setCheckable(true); - connect(m_costRelative, &QAction::toggled, this, &CallgrindTool::updateCostFormat); + connect(m_costRelative, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat); group->addAction(m_costRelative); // Show costs relative to parent - m_costRelativeToParent = new QAction(tr("Relative Costs to Parent"), this); - m_costRelativeToParent->setToolTip(tr("Show costs relative to parent function's inclusive cost.")); + m_costRelativeToParent = new QAction(CallgrindTool::tr("Relative Costs to Parent"), this); + m_costRelativeToParent->setToolTip(CallgrindTool::tr("Show costs relative to parent function's inclusive cost.")); m_costRelativeToParent->setCheckable(true); - connect(m_costRelativeToParent, &QAction::toggled, this, &CallgrindTool::updateCostFormat); + connect(m_costRelativeToParent, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat); group->addAction(m_costRelativeToParent); auto button = new QToolButton; button->addActions(group->actions()); button->setPopupMode(QToolButton::InstantPopup); button->setText("$"); - button->setToolTip(tr("Cost Format")); + button->setToolTip(CallgrindTool::tr("Cost Format")); m_perspective.addToolBarWidget(button); } // Cycle detection //action = new QAction("Cycle Detection", this); ///FIXME: icon action = m_cycleDetection = new QAction("O", this); ///FIXME: icon - action->setToolTip(tr("Enable cycle detection to properly handle recursive or circular function calls.")); + action->setToolTip(CallgrindTool::tr("Enable cycle detection to properly handle recursive or circular function calls.")); action->setCheckable(true); connect(action, &QAction::toggled, &m_dataModel, &DataModel::enableCycleDetection); connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setDetectCycles); // Shorter template signature action = m_shortenTemplates = new QAction("<>", this); - action->setToolTip(tr("Remove template parameter lists when displaying function names.")); + action->setToolTip(CallgrindTool::tr("Remove template parameter lists when displaying function names.")); action->setCheckable(true); connect(action, &QAction::toggled, &m_dataModel, &DataModel::setShortenTemplates); connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setShortenTemplates); // Filtering - action = m_filterProjectCosts = new QAction(tr("Show Project Costs Only"), this); + action = m_filterProjectCosts = new QAction(CallgrindTool::tr("Show Project Costs Only"), this); action->setIcon(Utils::Icons::FILTER.icon()); - action->setToolTip(tr("Show only profiling info that originated from this project source.")); + action->setToolTip(CallgrindTool::tr("Show only profiling info that originated from this project source.")); action->setCheckable(true); - connect(action, &QAction::toggled, this, &CallgrindTool::handleFilterProjectCosts); + connect(action, &QAction::toggled, this, &CallgrindToolPrivate::handleFilterProjectCosts); // Filter ///FIXME: find workaround for https://bugreports.qt.io/browse/QTCREATORBUG-3247 m_searchFilter = new QLineEdit; - m_searchFilter->setPlaceholderText(tr("Filter...")); + m_searchFilter->setPlaceholderText(CallgrindTool::tr("Filter...")); connect(m_searchFilter, &QLineEdit::textChanged, &m_updateTimer, static_cast<void(QTimer::*)()>(&QTimer::start)); @@ -526,10 +526,10 @@ CallgrindTool::CallgrindTool() false, Qt::RightDockWidgetArea); connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions, - this, &CallgrindTool::updateRunActions); + this, &CallgrindToolPrivate::updateRunActions); } -CallgrindTool::~CallgrindTool() +CallgrindToolPrivate::~CallgrindToolPrivate() { qDeleteAll(m_textMarks); delete m_flatView; @@ -538,7 +538,7 @@ CallgrindTool::~CallgrindTool() delete m_visualization; } -void CallgrindTool::doClear(bool clearParseData) +void CallgrindToolPrivate::doClear(bool clearParseData) { if (clearParseData) // Crashed when done from destructor. setParseData(nullptr); @@ -552,7 +552,7 @@ void CallgrindTool::doClear(bool clearParseData) m_proxyModel.setFilterFixedString(QString()); } -void CallgrindTool::setBusyCursor(bool busy) +void CallgrindToolPrivate::setBusyCursor(bool busy) { QCursor cursor(busy ? Qt::BusyCursor : Qt::ArrowCursor); m_flatView->setCursor(cursor); @@ -561,7 +561,7 @@ void CallgrindTool::setBusyCursor(bool busy) m_visualization->setCursor(cursor); } -void CallgrindTool::selectFunction(const Function *func) +void CallgrindToolPrivate::selectFunction(const Function *func) { if (!func) { m_flatView->clearSelection(); @@ -594,7 +594,7 @@ void CallgrindTool::selectFunction(const Function *func) } } -void CallgrindTool::stackBrowserChanged() +void CallgrindToolPrivate::stackBrowserChanged() { m_goBack->setEnabled(m_stackBrowser.hasPrevious()); m_goNext->setEnabled(m_stackBrowser.hasNext()); @@ -602,12 +602,12 @@ void CallgrindTool::stackBrowserChanged() selectFunction(item); } -void CallgrindTool::updateFilterString() +void CallgrindToolPrivate::updateFilterString() { m_proxyModel.setFilterFixedString(m_searchFilter->text()); } -void CallgrindTool::setCostFormat(CostDelegate::CostFormat format) +void CallgrindToolPrivate::setCostFormat(CostDelegate::CostFormat format) { switch (format) { case CostDelegate::FormatAbsolute: @@ -622,7 +622,7 @@ void CallgrindTool::setCostFormat(CostDelegate::CostFormat format) } } -void CallgrindTool::setCostEvent(int index) +void CallgrindToolPrivate::setCostEvent(int index) { // prevent assert in model, don't try to set event to -1 // happens when we clear the eventcombo @@ -634,19 +634,19 @@ void CallgrindTool::setCostEvent(int index) m_callersModel.setCostEvent(index); } -void CallgrindTool::enableCycleDetection(bool enabled) +void CallgrindToolPrivate::enableCycleDetection(bool enabled) { m_cycleDetection->setChecked(enabled); } -void CallgrindTool::shortenTemplates(bool enabled) +void CallgrindToolPrivate::shortenTemplates(bool enabled) { m_shortenTemplates->setChecked(enabled); } // Following functions can be called with actions=0 or widgets=0 // depending on initialization sequence (whether callgrind was current). -CostDelegate::CostFormat CallgrindTool::costFormat() const +CostDelegate::CostFormat CallgrindToolPrivate::costFormat() const { if (m_costRelativeToParent && m_costRelativeToParent->isChecked()) return CostDelegate::FormatRelativeToParent; @@ -655,7 +655,7 @@ CostDelegate::CostFormat CallgrindTool::costFormat() const return CostDelegate::FormatAbsolute; } -void CallgrindTool::updateCostFormat() +void CallgrindToolPrivate::updateCostFormat() { const CostDelegate::CostFormat format = costFormat(); if (m_flatView) @@ -664,11 +664,11 @@ void CallgrindTool::updateCostFormat() m_calleesView->setCostFormat(format); m_callersView->setCostFormat(format); } - if (ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings()) + if (ValgrindGlobalSettings *settings = ValgrindGlobalSettings::instance()) settings->setCostFormat(format); } -void CallgrindTool::handleFilterProjectCosts() +void CallgrindToolPrivate::handleFilterProjectCosts() { Project *pro = ProjectTree::currentProject(); @@ -680,7 +680,7 @@ void CallgrindTool::handleFilterProjectCosts() } } -void CallgrindTool::dataFunctionSelected(const QModelIndex &index) +void CallgrindToolPrivate::dataFunctionSelected(const QModelIndex &index) { auto func = index.data(DataModel::FunctionRole).value<const Function *>(); QTC_ASSERT(func, return); @@ -688,7 +688,7 @@ void CallgrindTool::dataFunctionSelected(const QModelIndex &index) selectFunction(func); } -void CallgrindTool::calleeFunctionSelected(const QModelIndex &index) +void CallgrindToolPrivate::calleeFunctionSelected(const QModelIndex &index) { auto call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>(); QTC_ASSERT(call, return); @@ -696,7 +696,7 @@ void CallgrindTool::calleeFunctionSelected(const QModelIndex &index) selectFunction(call->callee()); } -void CallgrindTool::callerFunctionSelected(const QModelIndex &index) +void CallgrindToolPrivate::callerFunctionSelected(const QModelIndex &index) { auto call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>(); QTC_ASSERT(call, return); @@ -704,7 +704,7 @@ void CallgrindTool::callerFunctionSelected(const QModelIndex &index) selectFunction(call->caller()); } -void CallgrindTool::visualisationFunctionSelected(const Function *function) +void CallgrindToolPrivate::visualisationFunctionSelected(const Function *function) { if (function && function == m_visualization->function()) // up-navigation when the initial function was activated @@ -713,7 +713,7 @@ void CallgrindTool::visualisationFunctionSelected(const Function *function) selectFunction(function); } -void CallgrindTool::setParseData(ParseData *data) +void CallgrindToolPrivate::setParseData(ParseData *data) { // we have new parse data, invalidate filters in the proxy model m_visualization->setFunction(nullptr); @@ -741,7 +741,7 @@ void CallgrindTool::setParseData(ParseData *data) //setBusy(false); } -void CallgrindTool::updateEventCombo() +void CallgrindToolPrivate::updateEventCombo() { QTC_ASSERT(m_eventCombo, return); @@ -758,16 +758,16 @@ void CallgrindTool::updateEventCombo() m_eventCombo->addItem(ParseData::prettyStringForEvent(event)); } -void CallgrindTool::setupRunner(CallgrindToolRunner *toolRunner) +void CallgrindToolPrivate::setupRunner(CallgrindToolRunner *toolRunner) { RunControl *runControl = toolRunner->runControl(); - connect(toolRunner, &CallgrindToolRunner::parserDataReady, this, &CallgrindTool::takeParserDataFromRunControl); - connect(runControl, &RunControl::stopped, this, &CallgrindTool::engineFinished); + connect(toolRunner, &CallgrindToolRunner::parserDataReady, this, &CallgrindToolPrivate::takeParserDataFromRunControl); + connect(runControl, &RunControl::stopped, this, &CallgrindToolPrivate::engineFinished); - connect(this, &CallgrindTool::dumpRequested, toolRunner, &CallgrindToolRunner::dump); - connect(this, &CallgrindTool::resetRequested, toolRunner, &CallgrindToolRunner::reset); - connect(this, &CallgrindTool::pauseToggled, toolRunner, &CallgrindToolRunner::setPaused); + connect(this, &CallgrindToolPrivate::dumpRequested, toolRunner, &CallgrindToolRunner::dump); + connect(this, &CallgrindToolPrivate::resetRequested, toolRunner, &CallgrindToolRunner::reset); + connect(this, &CallgrindToolPrivate::pauseToggled, toolRunner, &CallgrindToolRunner::setPaused); connect(m_stopAction, &QAction::triggered, toolRunner, [runControl] { runControl->initiateStop(); }); @@ -800,28 +800,28 @@ void CallgrindTool::setupRunner(CallgrindToolRunner *toolRunner) doClear(true); } -void CallgrindTool::updateRunActions() +void CallgrindToolPrivate::updateRunActions() { if (m_toolBusy) { m_startAction->setEnabled(false); m_startKCachegrind->setEnabled(false); - m_startAction->setToolTip(tr("A Valgrind Callgrind analysis is still in progress.")); + m_startAction->setToolTip(CallgrindTool::tr("A Valgrind Callgrind analysis is still in progress.")); m_stopAction->setEnabled(true); } else { - QString whyNot = tr("Start a Valgrind Callgrind analysis."); + QString whyNot = CallgrindTool::tr("Start a Valgrind Callgrind analysis."); bool canRun = ProjectExplorerPlugin::canRunStartupProject(CALLGRIND_RUN_MODE, &whyNot); m_startAction->setToolTip(whyNot); m_startAction->setEnabled(canRun); m_stopAction->setEnabled(false); } } -void CallgrindTool::clearTextMarks() +void CallgrindToolPrivate::clearTextMarks() { qDeleteAll(m_textMarks); m_textMarks.clear(); } -void CallgrindTool::engineFinished() +void CallgrindToolPrivate::engineFinished() { m_toolBusy = false; updateRunActions(); @@ -835,51 +835,51 @@ void CallgrindTool::engineFinished() if (data) showParserResults(data); else - Debugger::showPermanentStatusMessage(tr("Profiling aborted.")); + Debugger::showPermanentStatusMessage(CallgrindTool::tr("Profiling aborted.")); setBusyCursor(false); } -void CallgrindTool::showParserResults(const ParseData *data) +void CallgrindToolPrivate::showParserResults(const ParseData *data) { QString msg; if (data) { // be careful, the list of events might be empty if (data->events().isEmpty()) { - msg = tr("Parsing finished, no data."); + msg = CallgrindTool::tr("Parsing finished, no data."); } else { const QString costStr = QString::fromLatin1("%1 %2") .arg(QString::number(data->totalCost(0)), data->events().constFirst()); - msg = tr("Parsing finished, total cost of %1 reported.").arg(costStr); + msg = CallgrindTool::tr("Parsing finished, total cost of %1 reported.").arg(costStr); } } else { - msg = tr("Parsing failed."); + msg = CallgrindTool::tr("Parsing failed."); } Debugger::showPermanentStatusMessage(msg); } -void CallgrindTool::editorOpened(IEditor *editor) +void CallgrindToolPrivate::editorOpened(IEditor *editor) { if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) { connect(widget, &TextEditorWidget::markContextMenuRequested, - this, &CallgrindTool::requestContextMenu); + this, &CallgrindToolPrivate::requestContextMenu); } } -void CallgrindTool::requestContextMenu(TextEditorWidget *widget, int line, QMenu *menu) +void CallgrindToolPrivate::requestContextMenu(TextEditorWidget *widget, int line, QMenu *menu) { // Find callgrind text mark that corresponds to this editor's file and line number foreach (CallgrindTextMark *textMark, m_textMarks) { if (textMark->fileName() == widget->textDocument()->filePath() && textMark->lineNumber() == line) { const Function *func = textMark->function(); - QAction *action = menu->addAction(tr("Select This Function in the Analyzer Output")); + QAction *action = menu->addAction(CallgrindTool::tr("Select This Function in the Analyzer Output")); connect(action, &QAction::triggered, this, [this, func] { selectFunction(func); }); break; } } } -void CallgrindTool::handleShowCostsOfFunction() +void CallgrindToolPrivate::handleShowCostsOfFunction() { CPlusPlus::Symbol *symbol = AnalyzerUtils::findSymbolUnderCursor(); if (!symbol) @@ -895,32 +895,32 @@ void CallgrindTool::handleShowCostsOfFunction() m_startAction->trigger(); } -void CallgrindTool::slotRequestDump() +void CallgrindToolPrivate::slotRequestDump() { //setBusy(true); - m_visualization->setText(tr("Populating...")); + m_visualization->setText(CallgrindTool::tr("Populating...")); emit dumpRequested(); } -void CallgrindTool::loadExternalLogFile() +void CallgrindToolPrivate::loadExternalLogFile() { const QString filePath = QFileDialog::getOpenFileName( ICore::mainWindow(), - tr("Open Callgrind Log File"), + CallgrindTool::tr("Open Callgrind Log File"), QString(), - tr("Callgrind Output (callgrind.out*);;All Files (*)")); + CallgrindTool::tr("Callgrind Output (callgrind.out*);;All Files (*)")); if (filePath.isEmpty()) return; QFile logFile(filePath); if (!logFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - QString msg = tr("Callgrind: Failed to open file for reading: %1").arg(filePath); + QString msg = CallgrindTool::tr("Callgrind: Failed to open file for reading: %1").arg(filePath); TaskHub::addTask(Task::Error, msg, Debugger::Constants::ANALYZERTASK_ID); TaskHub::requestPopup(); return; } - Debugger::showPermanentStatusMessage(tr("Parsing Profile Data...")); + Debugger::showPermanentStatusMessage(CallgrindTool::tr("Parsing Profile Data...")); QCoreApplication::processEvents(); Parser parser; @@ -928,12 +928,12 @@ void CallgrindTool::loadExternalLogFile() takeParserData(parser.takeData()); } -void CallgrindTool::takeParserDataFromRunControl(CallgrindToolRunner *rc) +void CallgrindToolPrivate::takeParserDataFromRunControl(CallgrindToolRunner *rc) { takeParserData(rc->takeParserData()); } -void CallgrindTool::takeParserData(ParseData *data) +void CallgrindToolPrivate::takeParserData(ParseData *data) { showParserResults(data); @@ -945,14 +945,14 @@ void CallgrindTool::takeParserData(ParseData *data) doClear(true); setParseData(data); - const QString kcachegrindExecutable = ValgrindPlugin::globalSettings()->kcachegrindExecutable(); + const QString kcachegrindExecutable = ValgrindGlobalSettings::instance()->kcachegrindExecutable(); const bool kcachegrindExists = !Utils::Environment::systemEnvironment().searchInPath( kcachegrindExecutable).isEmpty(); m_startKCachegrind->setEnabled(kcachegrindExists && !m_lastFileName.isEmpty()); createTextMarks(); } -void CallgrindTool::createTextMarks() +void CallgrindToolPrivate::createTextMarks() { QList<QString> locations; for (int row = 0; row < m_dataModel.rowCount(); ++row) { @@ -987,24 +987,24 @@ void CallgrindTool::createTextMarks() } -static CallgrindTool *theCallgrindTool; +// CallgrindTool + +static CallgrindToolPrivate *dd = nullptr; void setupCallgrindRunner(CallgrindToolRunner *toolRunner) { - theCallgrindTool->setupRunner(toolRunner); + dd->setupRunner(toolRunner); } -void initCallgrindTool() +CallgrindTool::CallgrindTool() { - theCallgrindTool = new CallgrindTool; - + dd = new CallgrindToolPrivate; RunControl::registerWorker<CallgrindToolRunner>(CALLGRIND_RUN_MODE, {}); } -void destroyCallgrindTool() +CallgrindTool::~CallgrindTool() { - delete theCallgrindTool; - theCallgrindTool = nullptr; + delete dd; } } // namespace Internal diff --git a/src/plugins/valgrind/callgrindtool.h b/src/plugins/valgrind/callgrindtool.h index 79af72ad28..4c4f6bbe86 100644 --- a/src/plugins/valgrind/callgrindtool.h +++ b/src/plugins/valgrind/callgrindtool.h @@ -25,11 +25,21 @@ #pragma once +#include <QCoreApplication> + namespace Valgrind { namespace Internal { -void initCallgrindTool(); -void destroyCallgrindTool(); +class ValgrindGlobalSettings; + +class CallgrindTool : public QObject +{ + Q_OBJECT + +public: + CallgrindTool(); + ~CallgrindTool() final; +}; } // namespace Internal } // namespace Valgrind diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index 221d297277..0fa8c8b0f9 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -90,7 +90,6 @@ #include <QToolButton> #include <QSortFilterProxyModel> -#ifdef Q_OS_WIN #include <QCheckBox> #include <QComboBox> #include <QLineEdit> @@ -98,6 +97,8 @@ #include <QSpinBox> #include <QStandardPaths> #include <QVBoxLayout> + +#ifdef Q_OS_WIN #include <QWinEventNotifier> #include <utils/winutils.h> @@ -170,7 +171,7 @@ public: QString MemcheckToolRunner::progressTitle() const { - return tr("Analyzing Memory"); + return MemcheckTool::tr("Analyzing Memory"); } void MemcheckToolRunner::start() @@ -382,13 +383,11 @@ static void initKindFilterAction(QAction *action, const QVariantList &kinds) action->setData(kinds); } -class MemcheckTool : public QObject +class MemcheckToolPrivate : public QObject { - Q_DECLARE_TR_FUNCTIONS(Valgrind::Internal::MemcheckTool) - public: - MemcheckTool(); - ~MemcheckTool() override; + MemcheckToolPrivate(); + ~MemcheckToolPrivate() override; void setupRunner(MemcheckToolRunner *runTool); void loadShowXmlLogFile(const QString &filePath, const QString &exitMsg); @@ -437,10 +436,12 @@ private: bool m_toolBusy = false; QString m_exitMsg; - Perspective m_perspective{"Memcheck.Perspective", tr("Memcheck")}; + Perspective m_perspective{"Memcheck.Perspective", MemcheckTool::tr("Memcheck")}; }; -#ifdef Q_OS_WIN +static MemcheckToolPrivate *dd = nullptr; + + class HeobDialog : public QDialog { Q_DECLARE_TR_FUNCTIONS(HeobDialog) @@ -473,12 +474,14 @@ private: PathChooser *m_pathChooser = nullptr; }; +#ifdef Q_OS_WIN + class HeobData : public QObject { Q_DECLARE_TR_FUNCTIONS(HeobData) public: - HeobData(MemcheckTool *mcTool, const QString &xmlPath, Kit *kit, bool attach); + HeobData(MemcheckToolPrivate *mcTool, const QString &xmlPath, Kit *kit, bool attach); ~HeobData() override; bool createErrorPipe(DWORD heobPid); @@ -496,7 +499,7 @@ private: OVERLAPPED m_ov; unsigned m_data[2]; QWinEventNotifier *m_processFinishedNotifier = nullptr; - MemcheckTool *m_mcTool = nullptr; + MemcheckToolPrivate *m_mcTool = nullptr; QString m_xmlPath; Kit *m_kit = nullptr; bool m_attach = false; @@ -504,37 +507,37 @@ private: }; #endif -MemcheckTool::MemcheckTool() +MemcheckToolPrivate::MemcheckToolPrivate() { - m_settings = ValgrindPlugin::globalSettings(); + m_settings = ValgrindGlobalSettings::instance(); setObjectName("MemcheckTool"); - m_filterProjectAction = new QAction(tr("External Errors"), this); + m_filterProjectAction = new QAction(MemcheckTool::tr("External Errors"), this); m_filterProjectAction->setToolTip( - tr("Show issues originating outside currently opened projects.")); + MemcheckTool::tr("Show issues originating outside currently opened projects.")); m_filterProjectAction->setCheckable(true); - m_suppressionSeparator = new QAction(tr("Suppressions"), this); + m_suppressionSeparator = new QAction(MemcheckTool::tr("Suppressions"), this); m_suppressionSeparator->setSeparator(true); m_suppressionSeparator->setToolTip( - tr("These suppression files were used in the last memory analyzer run.")); + MemcheckTool::tr("These suppression files were used in the last memory analyzer run.")); - QAction *a = new QAction(tr("Definite Memory Leaks"), this); + QAction *a = new QAction(MemcheckTool::tr("Definite Memory Leaks"), this); initKindFilterAction(a, {Leak_DefinitelyLost, Leak_IndirectlyLost}); m_errorFilterActions.append(a); - a = new QAction(tr("Possible Memory Leaks"), this); + a = new QAction(MemcheckTool::tr("Possible Memory Leaks"), this); initKindFilterAction(a, {Leak_PossiblyLost, Leak_StillReachable}); m_errorFilterActions.append(a); - a = new QAction(tr("Use of Uninitialized Memory"), this); + a = new QAction(MemcheckTool::tr("Use of Uninitialized Memory"), this); initKindFilterAction(a, {InvalidRead, InvalidWrite, InvalidJump, Overlap, InvalidMemPool, UninitCondition, UninitValue, SyscallParam, ClientCheck}); m_errorFilterActions.append(a); - a = new QAction(tr("Invalid Calls to \"free()\""), this); + a = new QAction(MemcheckTool::tr("Invalid Calls to \"free()\""), this); initKindFilterAction(a, { InvalidFree, MismatchedFree }); m_errorFilterActions.append(a); @@ -552,12 +555,12 @@ MemcheckTool::MemcheckTool() m_errorView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); m_errorView->setAutoScroll(false); m_errorView->setObjectName("Valgrind.MemcheckTool.ErrorView"); - m_errorView->setWindowTitle(tr("Memory Issues")); + m_errorView->setWindowTitle(MemcheckTool::tr("Memory Issues")); m_perspective.addWindow(m_errorView, Perspective::SplitVertical, nullptr); connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions, - this, &MemcheckTool::maybeActiveRunConfigurationChanged); + this, &MemcheckToolPrivate::maybeActiveRunConfigurationChanged); // // The Control Widget. @@ -570,15 +573,15 @@ MemcheckTool::MemcheckTool() // Load external XML log file auto action = new QAction(this); action->setIcon(Icons::OPENFILE_TOOLBAR.icon()); - action->setToolTip(tr("Load External XML Log File")); - connect(action, &QAction::triggered, this, &MemcheckTool::loadExternalXmlLogFile); + action->setToolTip(MemcheckTool::tr("Load External XML Log File")); + connect(action, &QAction::triggered, this, &MemcheckToolPrivate::loadExternalXmlLogFile); m_loadExternalLogFile = action; // Go to previous leak. action = new QAction(this); action->setDisabled(true); action->setIcon(Icons::PREV_TOOLBAR.icon()); - action->setToolTip(tr("Go to previous leak.")); + action->setToolTip(MemcheckTool::tr("Go to previous leak.")); connect(action, &QAction::triggered, m_errorView, &MemcheckErrorView::goBack); m_goBack = action; @@ -586,13 +589,13 @@ MemcheckTool::MemcheckTool() action = new QAction(this); action->setDisabled(true); action->setIcon(Icons::NEXT_TOOLBAR.icon()); - action->setToolTip(tr("Go to next leak.")); + action->setToolTip(MemcheckTool::tr("Go to next leak.")); connect(action, &QAction::triggered, m_errorView, &MemcheckErrorView::goNext); m_goNext = action; auto filterButton = new QToolButton; filterButton->setIcon(Icons::FILTER.icon()); - filterButton->setText(tr("Error Filter")); + filterButton->setText(MemcheckTool::tr("Error Filter")); filterButton->setPopupMode(QToolButton::InstantPopup); filterButton->setProperty("noArrow", true); @@ -602,15 +605,15 @@ MemcheckTool::MemcheckTool() m_filterMenu->addSeparator(); m_filterMenu->addAction(m_filterProjectAction); m_filterMenu->addAction(m_suppressionSeparator); - connect(m_filterMenu, &QMenu::triggered, this, &MemcheckTool::updateErrorFilter); + connect(m_filterMenu, &QMenu::triggered, this, &MemcheckToolPrivate::updateErrorFilter); filterButton->setMenu(m_filterMenu); ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); - QString toolTip = tr("Valgrind Analyze Memory uses the Memcheck tool to find memory leaks."); + QString toolTip = MemcheckTool::tr("Valgrind Analyze Memory uses the Memcheck tool to find memory leaks."); if (!HostOsInfo::isWindowsHost()) { action = new QAction(this); - action->setText(tr("Valgrind Memory Analyzer")); + action->setText(MemcheckTool::tr("Valgrind Memory Analyzer")); action->setToolTip(toolTip); menu->addAction(ActionManager::registerAction(action, "Memcheck.Local"), Debugger::Constants::G_ANALYZER_TOOLS); @@ -628,7 +631,7 @@ MemcheckTool::MemcheckTool() action = new QAction(this); action->setText(tr("Valgrind Memory Analyzer with GDB")); - action->setToolTip(tr("Valgrind Analyze Memory with GDB uses the " + action->setToolTip(MemcheckTool::tr("Valgrind Analyze Memory with GDB uses the " "Memcheck tool to find memory leaks.\nWhen a problem is detected, " "the application is interrupted and can be debugged.")); menu->addAction(ActionManager::registerAction(action, "MemcheckWithGdb.Local"), @@ -645,10 +648,10 @@ MemcheckTool::MemcheckTool() action->setEnabled(m_startWithGdbAction->isEnabled()); }); } else { - action = new QAction(tr("Heob"), this); + action = new QAction(MemcheckTool::tr("Heob"), this); Core::Command *cmd = Core::ActionManager::registerAction(action, "Memcheck.Local"); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+H"))); - connect(action, &QAction::triggered, this, &MemcheckTool::heobAction); + connect(action, &QAction::triggered, this, &MemcheckToolPrivate::heobAction); menu->addAction(cmd, Debugger::Constants::G_ANALYZER_TOOLS); connect(m_startAction, &QAction::changed, action, [action, this] { action->setEnabled(m_startAction->isEnabled()); @@ -692,14 +695,13 @@ MemcheckTool::MemcheckTool() maybeActiveRunConfigurationChanged(); } -MemcheckTool::~MemcheckTool() +MemcheckToolPrivate::~MemcheckToolPrivate() { delete m_errorView; } -void MemcheckTool::heobAction() +void MemcheckToolPrivate::heobAction() { -#ifdef Q_OS_WIN Runnable sr; Abi abi; bool hasLocalRc = false; @@ -808,6 +810,7 @@ void MemcheckTool::heobAction() // process environment QByteArray env; void *envPtr = nullptr; + Q_UNUSED(envPtr); if (!envStrings.isEmpty()) { uint pos = 0; for (const QString &par : envStrings) { @@ -823,6 +826,7 @@ void MemcheckTool::heobAction() envPtr = env.data(); } +#ifdef Q_OS_WIN // heob process STARTUPINFO si; PROCESS_INFORMATION pi; @@ -855,20 +859,20 @@ void MemcheckTool::heobAction() #endif } -void MemcheckTool::updateRunActions() +void MemcheckToolPrivate::updateRunActions() { if (m_toolBusy) { m_startAction->setEnabled(false); - m_startAction->setToolTip(tr("A Valgrind Memcheck analysis is still in progress.")); + m_startAction->setToolTip(MemcheckTool::tr("A Valgrind Memcheck analysis is still in progress.")); m_startWithGdbAction->setEnabled(false); - m_startWithGdbAction->setToolTip(tr("A Valgrind Memcheck analysis is still in progress.")); + m_startWithGdbAction->setToolTip(MemcheckTool::tr("A Valgrind Memcheck analysis is still in progress.")); m_stopAction->setEnabled(true); } else { - QString whyNot = tr("Start a Valgrind Memcheck analysis."); + QString whyNot = MemcheckTool::tr("Start a Valgrind Memcheck analysis."); bool canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_RUN_MODE, &whyNot); m_startAction->setToolTip(whyNot); m_startAction->setEnabled(canRun); - whyNot = tr("Start a Valgrind Memcheck with GDB analysis."); + whyNot = MemcheckTool::tr("Start a Valgrind Memcheck with GDB analysis."); canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_WITH_GDB_RUN_MODE, &whyNot); m_startWithGdbAction->setToolTip(whyNot); m_startWithGdbAction->setEnabled(canRun); @@ -876,13 +880,13 @@ void MemcheckTool::updateRunActions() } } -void MemcheckTool::settingsDestroyed(QObject *settings) +void MemcheckToolPrivate::settingsDestroyed(QObject *settings) { QTC_ASSERT(m_settings == settings, return); - m_settings = ValgrindPlugin::globalSettings(); + m_settings = ValgrindGlobalSettings::instance(); } -void MemcheckTool::updateFromSettings() +void MemcheckToolPrivate::updateFromSettings() { foreach (QAction *action, m_errorFilterActions) { bool contained = true; @@ -907,7 +911,7 @@ void MemcheckTool::updateFromSettings() m_errorProxyModel.setFilterExternalIssues(m_settings->filterExternalIssues()); } -void MemcheckTool::maybeActiveRunConfigurationChanged() +void MemcheckToolPrivate::maybeActiveRunConfigurationChanged() { updateRunActions(); @@ -918,7 +922,7 @@ void MemcheckTool::maybeActiveRunConfigurationChanged() settings = rc->currentSettings<ValgrindBaseSettings>(ANALYZER_VALGRIND_SETTINGS); if (!settings) // fallback to global settings - settings = ValgrindPlugin::globalSettings(); + settings = ValgrindGlobalSettings::instance(); if (m_settings == settings) return; @@ -932,20 +936,24 @@ void MemcheckTool::maybeActiveRunConfigurationChanged() // now make the new settings current, update and connect input widgets m_settings = settings; QTC_ASSERT(m_settings, return); - connect(m_settings, &ValgrindBaseSettings::destroyed, this, &MemcheckTool::settingsDestroyed); + connect(m_settings, &ValgrindBaseSettings::destroyed, + this, &MemcheckToolPrivate::settingsDestroyed); updateFromSettings(); } -void MemcheckTool::setupRunner(MemcheckToolRunner *runTool) +void MemcheckToolPrivate::setupRunner(MemcheckToolRunner *runTool) { RunControl *runControl = runTool->runControl(); m_errorModel.setRelevantFrameFinder(makeFrameFinder(transform(runControl->project()->files(Project::AllFiles), &FileName::toString))); - connect(runTool, &MemcheckToolRunner::parserError, this, &MemcheckTool::parserError); - connect(runTool, &MemcheckToolRunner::internalParserError, this, &MemcheckTool::internalParserError); - connect(runTool, &MemcheckToolRunner::stopped, this, &MemcheckTool::engineFinished); + connect(runTool, &MemcheckToolRunner::parserError, + this, &MemcheckToolPrivate::parserError); + connect(runTool, &MemcheckToolRunner::internalParserError, + this, &MemcheckToolPrivate::internalParserError); + connect(runTool, &MemcheckToolRunner::stopped, + this, &MemcheckToolPrivate::engineFinished); m_stopAction->disconnect(); connect(m_stopAction, &QAction::triggered, runControl, &RunControl::initiateStop); @@ -972,7 +980,7 @@ void MemcheckTool::setupRunner(MemcheckToolRunner *runTool) } } -void MemcheckTool::loadShowXmlLogFile(const QString &filePath, const QString &exitMsg) +void MemcheckToolPrivate::loadShowXmlLogFile(const QString &filePath, const QString &exitMsg) { clearErrorView(); m_settings->setFilterExternalIssues(false); @@ -984,13 +992,13 @@ void MemcheckTool::loadShowXmlLogFile(const QString &filePath, const QString &ex loadXmlLogFile(filePath); } -void MemcheckTool::loadExternalXmlLogFile() +void MemcheckToolPrivate::loadExternalXmlLogFile() { const QString filePath = QFileDialog::getOpenFileName( ICore::mainWindow(), - tr("Open Memcheck XML Log File"), + MemcheckTool::tr("Open Memcheck XML Log File"), QString(), - tr("XML Files (*.xml);;All Files (*)")); + MemcheckTool::tr("XML Files (*.xml);;All Files (*)")); if (filePath.isEmpty()) return; @@ -998,12 +1006,12 @@ void MemcheckTool::loadExternalXmlLogFile() loadXmlLogFile(filePath); } -void MemcheckTool::loadXmlLogFile(const QString &filePath) +void MemcheckToolPrivate::loadXmlLogFile(const QString &filePath) { auto logFile = new QFile(filePath); if (!logFile->open(QIODevice::ReadOnly | QIODevice::Text)) { delete logFile; - QString msg = tr("Memcheck: Failed to open file for reading: %1").arg(filePath); + QString msg = MemcheckTool::tr("Memcheck: Failed to open file for reading: %1").arg(filePath); TaskHub::addTask(Task::Error, msg, Debugger::Constants::ANALYZERTASK_ID); TaskHub::requestPopup(); if (!m_exitMsg.isEmpty()) @@ -1015,34 +1023,38 @@ void MemcheckTool::loadXmlLogFile(const QString &filePath) clearErrorView(); m_loadExternalLogFile->setDisabled(true); - if (!m_settings || m_settings != ValgrindPlugin::globalSettings()) { - m_settings = ValgrindPlugin::globalSettings(); + if (!m_settings || m_settings != ValgrindGlobalSettings::instance()) { + m_settings = ValgrindGlobalSettings::instance(); m_errorView->settingsChanged(m_settings); updateFromSettings(); } auto parser = new ThreadedParser; - connect(parser, &ThreadedParser::error, this, &MemcheckTool::parserError); - connect(parser, &ThreadedParser::internalError, this, &MemcheckTool::internalParserError); - connect(parser, &ThreadedParser::finished, this, &MemcheckTool::loadingExternalXmlLogFileFinished); - connect(parser, &ThreadedParser::finished, parser, &ThreadedParser::deleteLater); + connect(parser, &ThreadedParser::error, + this, &MemcheckToolPrivate::parserError); + connect(parser, &ThreadedParser::internalError, + this, &MemcheckToolPrivate::internalParserError); + connect(parser, &ThreadedParser::finished, + this, &MemcheckToolPrivate::loadingExternalXmlLogFileFinished); + connect(parser, &ThreadedParser::finished, + parser, &ThreadedParser::deleteLater); parser->parse(logFile); // ThreadedParser owns the file } -void MemcheckTool::parserError(const Error &error) +void MemcheckToolPrivate::parserError(const Error &error) { m_errorModel.addError(error); } -void MemcheckTool::internalParserError(const QString &errorString) +void MemcheckToolPrivate::internalParserError(const QString &errorString) { - QString msg = tr("Memcheck: Error occurred parsing Valgrind output: %1").arg(errorString); + QString msg = MemcheckTool::tr("Memcheck: Error occurred parsing Valgrind output: %1").arg(errorString); TaskHub::addTask(Task::Error, msg, Debugger::Constants::ANALYZERTASK_ID); TaskHub::requestPopup(); } -void MemcheckTool::clearErrorView() +void MemcheckToolPrivate::clearErrorView() { QTC_ASSERT(m_errorView, return); m_errorModel.clear(); @@ -1052,7 +1064,7 @@ void MemcheckTool::clearErrorView() //QTC_ASSERT(filterMenu()->actions().last() == m_suppressionSeparator, qt_noop()); } -void MemcheckTool::updateErrorFilter() +void MemcheckToolPrivate::updateErrorFilter() { QTC_ASSERT(m_errorView, return); QTC_ASSERT(m_settings, return); @@ -1073,7 +1085,7 @@ void MemcheckTool::updateErrorFilter() m_settings->setVisibleErrorKinds(errorKinds); } -int MemcheckTool::updateUiAfterFinishedHelper() +int MemcheckToolPrivate::updateUiAfterFinishedHelper() { const int issuesFound = m_errorModel.rowCount(); m_goBack->setEnabled(issuesFound > 1); @@ -1083,34 +1095,31 @@ int MemcheckTool::updateUiAfterFinishedHelper() return issuesFound; } -void MemcheckTool::engineFinished() +void MemcheckToolPrivate::engineFinished() { m_toolBusy = false; updateRunActions(); const int issuesFound = updateUiAfterFinishedHelper(); Debugger::showPermanentStatusMessage( - tr("Memory Analyzer Tool finished. %n issues were found.", nullptr, issuesFound)); + MemcheckTool::tr("Memory Analyzer Tool finished. %n issues were found.", nullptr, issuesFound)); } -void MemcheckTool::loadingExternalXmlLogFileFinished() +void MemcheckToolPrivate::loadingExternalXmlLogFileFinished() { const int issuesFound = updateUiAfterFinishedHelper(); - QString statusMessage = tr("Log file processed. %n issues were found.", nullptr, issuesFound); + QString statusMessage = MemcheckTool::tr("Log file processed. %n issues were found.", nullptr, issuesFound); if (!m_exitMsg.isEmpty()) statusMessage += ' ' + m_exitMsg; Debugger::showPermanentStatusMessage(statusMessage); } -void MemcheckTool::setBusyCursor(bool busy) +void MemcheckToolPrivate::setBusyCursor(bool busy) { QCursor cursor(busy ? Qt::BusyCursor : Qt::ArrowCursor); m_errorView->setCursor(cursor); } - -static MemcheckTool *theMemcheckTool; - MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl) : ValgrindToolRunner(runControl), m_withGdb(runControl->runMode() == MEMCHECK_WITH_GDB_RUN_MODE), @@ -1137,25 +1146,10 @@ MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl) if (device()->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) addStartDependency(new LocalAddressFinder(runControl, &m_localServerAddress)); - theMemcheckTool->setupRunner(this); -} - -void initMemcheckTool() -{ - theMemcheckTool = new MemcheckTool; - - RunControl::registerWorker<MemcheckToolRunner>(MEMCHECK_RUN_MODE, {}); - RunControl::registerWorker<MemcheckToolRunner>(MEMCHECK_WITH_GDB_RUN_MODE, {}); -} - -void destroyMemcheckTool() -{ - delete theMemcheckTool; - theMemcheckTool = nullptr; + dd->setupRunner(this); } -#ifdef Q_OS_WIN const char heobXmlC[] = "heob/Xml"; const char heobHandleExceptionC[] = "heob/HandleException"; const char heobPageProtectionC[] = "heob/PageProtection"; @@ -1168,11 +1162,6 @@ const char heobAttachC[] = "heob/Attach"; const char heobExtraArgsC[] = "heob/ExtraArgs"; const char heobPathC[] = "heob/Path"; -static QString upperHexNum(unsigned num) -{ - return QString("%1").arg(num, 8, 16, QChar('0')).toUpper(); -} - HeobDialog::HeobDialog(QWidget *parent) : QDialog(parent) { @@ -1422,6 +1411,12 @@ void HeobDialog::saveOptions() settings->setValue(heobPathC, m_pathChooser->path()); } +#ifdef Q_OS_WIN +static QString upperHexNum(unsigned num) +{ + return QString("%1").arg(num, 8, 16, QChar('0')).toUpper(); +} + HeobData::HeobData(MemcheckTool *mcTool, const QString &xmlPath, Kit *kit, bool attach) : m_ov(), m_data(), m_mcTool(mcTool), m_xmlPath(xmlPath), m_kit(kit), m_attach(attach) { @@ -1636,6 +1631,19 @@ void HeobData::debugStopped() } #endif +MemcheckTool::MemcheckTool() +{ + dd = new MemcheckToolPrivate; + + RunControl::registerWorker<MemcheckToolRunner>(MEMCHECK_RUN_MODE, {}); + RunControl::registerWorker<MemcheckToolRunner>(MEMCHECK_WITH_GDB_RUN_MODE, {}); +} + +MemcheckTool::~MemcheckTool() +{ + delete dd; +} + } // namespace Internal } // namespace Valgrind diff --git a/src/plugins/valgrind/memchecktool.h b/src/plugins/valgrind/memchecktool.h index 7fcef04d1e..e75bf9a1d6 100644 --- a/src/plugins/valgrind/memchecktool.h +++ b/src/plugins/valgrind/memchecktool.h @@ -26,11 +26,24 @@ #pragma once +#include <QCoreApplication> + namespace Valgrind { namespace Internal { -void initMemcheckTool(); -void destroyMemcheckTool(); +class MemcheckToolRunner; + +class MemcheckTool : public QObject +{ + Q_OBJECT + +public: + MemcheckTool(); + ~MemcheckTool() final; + +private: + class MemcheckToolPrivate *d = nullptr; +}; } // namespace Internal } // namespace Valgrind diff --git a/src/plugins/valgrind/valgrindconfigwidget.cpp b/src/plugins/valgrind/valgrindconfigwidget.cpp index 85bcba7590..69a1560dfb 100644 --- a/src/plugins/valgrind/valgrindconfigwidget.cpp +++ b/src/plugins/valgrind/valgrindconfigwidget.cpp @@ -191,7 +191,7 @@ void ValgrindConfigWidget::updateUi() void ValgrindConfigWidget::slotAddSuppression() { - ValgrindGlobalSettings *conf = ValgrindPlugin::globalSettings(); + ValgrindGlobalSettings *conf = ValgrindGlobalSettings::instance(); QTC_ASSERT(conf, return); QStringList files = QFileDialog::getOpenFileNames(this, tr("Valgrind Suppression Files"), diff --git a/src/plugins/valgrind/valgrindengine.cpp b/src/plugins/valgrind/valgrindengine.cpp index 3d0c23813f..547fa4a946 100644 --- a/src/plugins/valgrind/valgrindengine.cpp +++ b/src/plugins/valgrind/valgrindengine.cpp @@ -62,7 +62,7 @@ ValgrindToolRunner::ValgrindToolRunner(RunControl *runControl) qobject_cast<ValgrindBaseSettings *>(runControl->settings(ANALYZER_VALGRIND_SETTINGS)); if (!m_settings) - m_settings = ValgrindPlugin::globalSettings(); + m_settings = ValgrindGlobalSettings::instance(); } void ValgrindToolRunner::start() diff --git a/src/plugins/valgrind/valgrindplugin.cpp b/src/plugins/valgrind/valgrindplugin.cpp index 9512054b4a..0d5aa51828 100644 --- a/src/plugins/valgrind/valgrindplugin.cpp +++ b/src/plugins/valgrind/valgrindplugin.cpp @@ -53,8 +53,6 @@ using namespace ProjectExplorer; namespace Valgrind { namespace Internal { -static ValgrindGlobalSettings *theGlobalSettings = nullptr; - class ValgrindOptionsPage : public IOptionsPage { public: @@ -71,13 +69,13 @@ public: QWidget *widget() override { if (!m_widget) - m_widget = new ValgrindConfigWidget(theGlobalSettings, true); + m_widget = new ValgrindConfigWidget(ValgrindGlobalSettings::instance(), true); return m_widget; } void apply() override { - theGlobalSettings->writeSettings(); + ValgrindGlobalSettings::instance()->writeSettings(); } void finish() override @@ -95,7 +93,7 @@ public: ValgrindRunConfigurationAspect(Target *) { setProjectSettings(new ValgrindProjectSettings); - setGlobalSettings(ValgrindPlugin::globalSettings()); + setGlobalSettings(ValgrindGlobalSettings::instance()); setId(ANALYZER_VALGRIND_SETTINGS); setDisplayName(QCoreApplication::translate("Valgrind::Internal::ValgrindRunConfigurationAspect", "Valgrind Settings")); @@ -105,16 +103,22 @@ public: } }; +class ValgrindPluginPrivate +{ +public: + ValgrindGlobalSettings valgrindGlobalSettings; // Needs to come before the tools. + MemcheckTool memcheckTool; + CallgrindTool callgrindTool; +}; + ValgrindPlugin::~ValgrindPlugin() { - delete theGlobalSettings; - theGlobalSettings = nullptr; + delete d; } bool ValgrindPlugin::initialize(const QStringList &, QString *) { - theGlobalSettings = new ValgrindGlobalSettings; - theGlobalSettings->readSettings(); + d = new ValgrindPluginPrivate; new ValgrindOptionsPage(this); @@ -123,24 +127,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *) return true; } -void ValgrindPlugin::extensionsInitialized() -{ - initMemcheckTool(); - initCallgrindTool(); -} - -ExtensionSystem::IPlugin::ShutdownFlag ValgrindPlugin::aboutToShutdown() -{ - destroyCallgrindTool(); - destroyMemcheckTool(); - return SynchronousShutdown; -} - -ValgrindGlobalSettings *ValgrindPlugin::globalSettings() -{ - return theGlobalSettings; -} - QList<QObject *> ValgrindPlugin::createTestObjects() const { QList<QObject *> tests; diff --git a/src/plugins/valgrind/valgrindplugin.h b/src/plugins/valgrind/valgrindplugin.h index 5de834d58f..ddf1f3e2a8 100644 --- a/src/plugins/valgrind/valgrindplugin.h +++ b/src/plugins/valgrind/valgrindplugin.h @@ -32,8 +32,6 @@ namespace Valgrind { namespace Internal { -class ValgrindGlobalSettings; - class ValgrindPlugin : public ExtensionSystem::IPlugin { Q_OBJECT @@ -41,15 +39,15 @@ class ValgrindPlugin : public ExtensionSystem::IPlugin public: ValgrindPlugin() = default; - ~ValgrindPlugin() override; + ~ValgrindPlugin() final; - bool initialize(const QStringList &arguments, QString *errorString) override; - void extensionsInitialized() override; - ShutdownFlag aboutToShutdown() override; + bool initialize(const QStringList &arguments, QString *errorString) final; + void extensionsInitialized() final {} - static ValgrindGlobalSettings *globalSettings(); private: QList<QObject *> createTestObjects() const override; + + class ValgrindPluginPrivate *d = nullptr; }; } // namespace Internal diff --git a/src/plugins/valgrind/valgrindsettings.cpp b/src/plugins/valgrind/valgrindsettings.cpp index 0b854bc651..0d63b23ea8 100644 --- a/src/plugins/valgrind/valgrindsettings.cpp +++ b/src/plugins/valgrind/valgrindsettings.cpp @@ -301,12 +301,20 @@ void ValgrindBaseSettings::setVisualisationMinimumInclusiveCostRatio( // ////////////////////////////////////////////////////////////////// +static ValgrindGlobalSettings *theGlobalSettings = nullptr; + ValgrindGlobalSettings::ValgrindGlobalSettings() : ValgrindBaseSettings([this] { return new ValgrindConfigWidget(this, true); }) { + theGlobalSettings = this; readSettings(); } +ValgrindGlobalSettings *ValgrindGlobalSettings::instance() +{ + return theGlobalSettings; +} + void ValgrindGlobalSettings::fromMap(const QVariantMap &map) { ValgrindBaseSettings::fromMap(map); @@ -513,8 +521,8 @@ void ValgrindProjectSettings::toMap(QVariantMap &map) const void ValgrindProjectSettings::addSuppressionFiles(const QStringList &suppressions) { - QStringList globalSuppressions = ValgrindPlugin::globalSettings()->suppressionFiles(); - foreach (const QString &s, suppressions) { + const QStringList globalSuppressions = ValgrindGlobalSettings::instance()->suppressionFiles(); + for (const QString &s : suppressions) { if (m_addedSuppressionFiles.contains(s)) continue; m_disabledGlobalSuppressionFiles.removeAll(s); @@ -525,8 +533,8 @@ void ValgrindProjectSettings::addSuppressionFiles(const QStringList &suppression void ValgrindProjectSettings::removeSuppressionFiles(const QStringList &suppressions) { - QStringList globalSuppressions = ValgrindPlugin::globalSettings()->suppressionFiles(); - foreach (const QString &s, suppressions) { + const QStringList globalSuppressions = ValgrindGlobalSettings::instance()->suppressionFiles(); + for (const QString &s : suppressions) { m_addedSuppressionFiles.removeAll(s); if (globalSuppressions.contains(s)) m_disabledGlobalSuppressionFiles.append(s); @@ -535,8 +543,8 @@ void ValgrindProjectSettings::removeSuppressionFiles(const QStringList &suppress QStringList ValgrindProjectSettings::suppressionFiles() const { - QStringList ret = ValgrindPlugin::globalSettings()->suppressionFiles(); - foreach (const QString &s, m_disabledGlobalSuppressionFiles) + QStringList ret = ValgrindGlobalSettings::instance()->suppressionFiles(); + for (const QString &s : m_disabledGlobalSuppressionFiles) ret.removeAll(s); ret.append(m_addedSuppressionFiles); return ret; diff --git a/src/plugins/valgrind/valgrindsettings.h b/src/plugins/valgrind/valgrindsettings.h index 0437b50733..eaeda4190f 100644 --- a/src/plugins/valgrind/valgrindsettings.h +++ b/src/plugins/valgrind/valgrindsettings.h @@ -187,6 +187,8 @@ class ValgrindGlobalSettings : public ValgrindBaseSettings public: ValgrindGlobalSettings(); + static ValgrindGlobalSettings *instance(); + void toMap(QVariantMap &map) const override; void fromMap(const QVariantMap &map) override; |