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>
This commit is contained in:
hjk
2019-03-20 17:49:26 +01:00
parent 90e828b890
commit 741950a3aa
10 changed files with 286 additions and 261 deletions

View File

@@ -106,13 +106,13 @@ const char CallgrindLocalActionId[] = "Callgrind.Local.Action";
const char CallgrindRemoteActionId[] = "Callgrind.Remote.Action"; const char CallgrindRemoteActionId[] = "Callgrind.Remote.Action";
const char CALLGRIND_RUN_MODE[] = "CallgrindTool.CallgrindRunMode"; const char CALLGRIND_RUN_MODE[] = "CallgrindTool.CallgrindRunMode";
class CallgrindTool : public QObject class CallgrindToolPrivate : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
CallgrindTool(); CallgrindToolPrivate();
~CallgrindTool() override; ~CallgrindToolPrivate() override;
void setupRunner(CallgrindToolRunner *runner); void setupRunner(CallgrindToolRunner *runner);
@@ -218,10 +218,10 @@ public:
QString m_toggleCollectFunction; QString m_toggleCollectFunction;
bool m_toolBusy = false; 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"); setObjectName("CallgrindTool");
@@ -235,22 +235,22 @@ CallgrindTool::CallgrindTool()
m_proxyModel.setFilterCaseSensitivity(Qt::CaseInsensitive); m_proxyModel.setFilterCaseSensitivity(Qt::CaseInsensitive);
connect(&m_stackBrowser, &StackBrowser::currentChanged, connect(&m_stackBrowser, &StackBrowser::currentChanged,
this, &CallgrindTool::stackBrowserChanged); this, &CallgrindToolPrivate::stackBrowserChanged);
connect(&m_updateTimer, &QTimer::timeout, connect(&m_updateTimer, &QTimer::timeout,
this, &CallgrindTool::updateFilterString); this, &CallgrindToolPrivate::updateFilterString);
connect(EditorManager::instance(), &EditorManager::editorOpened, connect(EditorManager::instance(), &EditorManager::editorOpened,
this, &CallgrindTool::editorOpened); this, &CallgrindToolPrivate::editorOpened);
m_startAction = Debugger::createStartAction(); m_startAction = Debugger::createStartAction();
m_stopAction = Debugger::createStopAction(); m_stopAction = Debugger::createStopAction();
ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); 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."); "Callgrind tool to record function calls when a program runs.");
if (!Utils::HostOsInfo::isWindowsHost()) { 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); action->setToolTip(toolTip);
menu->addAction(ActionManager::registerAction(action, CallgrindLocalActionId), menu->addAction(ActionManager::registerAction(action, CallgrindLocalActionId),
Debugger::Constants::G_ANALYZER_TOOLS); 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); action->setToolTip(toolTip);
menu->addAction(ActionManager::registerAction(action, CallgrindRemoteActionId), menu->addAction(ActionManager::registerAction(action, CallgrindRemoteActionId),
Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
@@ -295,10 +295,10 @@ CallgrindTool::CallgrindTool()
Context analyzerContext = Context(Debugger::Constants::C_DEBUGMODE); Context analyzerContext = Context(Debugger::Constants::C_DEBUGMODE);
editorContextMenu->addSeparator(analyzerContext); 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()); action->setIcon(ProjectExplorer::Icons::ANALYZER_START_SMALL.icon());
connect(action, &QAction::triggered, this, connect(action, &QAction::triggered, this,
&CallgrindTool::handleShowCostsOfFunction); &CallgrindToolPrivate::handleShowCostsOfFunction);
Command *cmd = ActionManager::registerAction(action, "Analyzer.Callgrind.ShowCostsOfFunction", Command *cmd = ActionManager::registerAction(action, "Analyzer.Callgrind.ShowCostsOfFunction",
analyzerContext); analyzerContext);
editorContextMenu->addAction(cmd); editorContextMenu->addAction(cmd);
@@ -314,14 +314,14 @@ CallgrindTool::CallgrindTool()
m_visualization = new Visualization; m_visualization = new Visualization;
m_visualization->setFrameStyle(QFrame::NoFrame); m_visualization->setFrameStyle(QFrame::NoFrame);
m_visualization->setObjectName("Valgrind.CallgrindTool.Visualisation"); m_visualization->setObjectName("Valgrind.CallgrindTool.Visualisation");
m_visualization->setWindowTitle(tr("Visualization")); m_visualization->setWindowTitle(CallgrindTool::tr("Visualization"));
m_visualization->setModel(&m_dataModel); m_visualization->setModel(&m_dataModel);
connect(m_visualization, &Visualization::functionActivated, connect(m_visualization, &Visualization::functionActivated,
this, &CallgrindTool::visualisationFunctionSelected); this, &CallgrindToolPrivate::visualisationFunctionSelected);
m_callersView = new CostView; m_callersView = new CostView;
m_callersView->setObjectName("Valgrind.CallgrindTool.CallersView"); 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->setSettings(coreSettings, "Valgrind.CallgrindTool.CallersView");
m_callersView->sortByColumn(CallModel::CostColumn, Qt::DescendingOrder); m_callersView->sortByColumn(CallModel::CostColumn, Qt::DescendingOrder);
m_callersView->setFrameStyle(QFrame::NoFrame); m_callersView->setFrameStyle(QFrame::NoFrame);
@@ -330,11 +330,11 @@ CallgrindTool::CallgrindTool()
m_callersView->setModel(&m_callersProxy); m_callersView->setModel(&m_callersProxy);
m_callersView->hideColumn(CallModel::CalleeColumn); m_callersView->hideColumn(CallModel::CalleeColumn);
connect(m_callersView, &QAbstractItemView::activated, connect(m_callersView, &QAbstractItemView::activated,
this, &CallgrindTool::callerFunctionSelected); this, &CallgrindToolPrivate::callerFunctionSelected);
m_calleesView = new CostView; m_calleesView = new CostView;
m_calleesView->setObjectName("Valgrind.CallgrindTool.CalleesView"); 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->setSettings(coreSettings, "Valgrind.CallgrindTool.CalleesView");
m_calleesView->sortByColumn(CallModel::CostColumn, Qt::DescendingOrder); m_calleesView->sortByColumn(CallModel::CostColumn, Qt::DescendingOrder);
m_calleesView->setFrameStyle(QFrame::NoFrame); m_calleesView->setFrameStyle(QFrame::NoFrame);
@@ -343,22 +343,22 @@ CallgrindTool::CallgrindTool()
m_calleesView->setModel(&m_calleesProxy); m_calleesView->setModel(&m_calleesProxy);
m_calleesView->hideColumn(CallModel::CallerColumn); m_calleesView->hideColumn(CallModel::CallerColumn);
connect(m_calleesView, &QAbstractItemView::activated, connect(m_calleesView, &QAbstractItemView::activated,
this, &CallgrindTool::calleeFunctionSelected); this, &CallgrindToolPrivate::calleeFunctionSelected);
m_flatView = new CostView; m_flatView = new CostView;
m_flatView->setObjectName("Valgrind.CallgrindTool.FlatView"); 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->setSettings(coreSettings, "Valgrind.CallgrindTool.FlatView");
m_flatView->sortByColumn(DataModel::SelfCostColumn, Qt::DescendingOrder); m_flatView->sortByColumn(DataModel::SelfCostColumn, Qt::DescendingOrder);
m_flatView->setFrameStyle(QFrame::NoFrame); m_flatView->setFrameStyle(QFrame::NoFrame);
m_flatView->setAttribute(Qt::WA_MacShowFocusRect, false); m_flatView->setAttribute(Qt::WA_MacShowFocusRect, false);
m_flatView->setModel(&m_proxyModel); m_flatView->setModel(&m_proxyModel);
connect(m_flatView, &QAbstractItemView::activated, connect(m_flatView, &QAbstractItemView::activated,
this, &CallgrindTool::dataFunctionSelected); this, &CallgrindToolPrivate::dataFunctionSelected);
updateCostFormat(); updateCostFormat();
ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings(); ValgrindGlobalSettings *settings = ValgrindGlobalSettings::instance();
// //
// Control Widget // Control Widget
@@ -367,15 +367,15 @@ CallgrindTool::CallgrindTool()
// load external log file // load external log file
action = m_loadExternalLogFile = new QAction(this); action = m_loadExternalLogFile = new QAction(this);
action->setIcon(Utils::Icons::OPENFILE_TOOLBAR.icon()); action->setIcon(Utils::Icons::OPENFILE_TOOLBAR.icon());
action->setToolTip(tr("Load External Log File")); action->setToolTip(CallgrindTool::tr("Load External Log File"));
connect(action, &QAction::triggered, this, &CallgrindTool::loadExternalLogFile); connect(action, &QAction::triggered, this, &CallgrindToolPrivate::loadExternalLogFile);
action = m_startKCachegrind = new QAction(this); action = m_startKCachegrind = new QAction(this);
action->setEnabled(false); action->setEnabled(false);
const Utils::Icon kCachegrindIcon({{":/valgrind/images/kcachegrind.png", const Utils::Icon kCachegrindIcon({{":/valgrind/images/kcachegrind.png",
Theme::IconsBaseColor}}); Theme::IconsBaseColor}});
action->setIcon(kCachegrindIcon.icon()); 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] { connect(action, &QAction::triggered, this, [this, settings] {
QProcess::startDetached(settings->kcachegrindExecutable(), { m_lastFileName }); QProcess::startDetached(settings->kcachegrindExecutable(), { m_lastFileName });
}); });
@@ -384,30 +384,30 @@ CallgrindTool::CallgrindTool()
m_dumpAction = action = new QAction(this); m_dumpAction = action = new QAction(this);
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Utils::Icons::REDO.icon()); action->setIcon(Utils::Icons::REDO.icon());
//action->setText(tr("Dump")); //action->setText(CallgrindTool::tr("Dump"));
action->setToolTip(tr("Request the dumping of profile information. This will update the Callgrind visualization.")); action->setToolTip(CallgrindTool::tr("Request the dumping of profile information. This will update the Callgrind visualization."));
connect(action, &QAction::triggered, this, &CallgrindTool::slotRequestDump); connect(action, &QAction::triggered, this, &CallgrindToolPrivate::slotRequestDump);
// reset action // reset action
m_resetAction = action = new QAction(this); m_resetAction = action = new QAction(this);
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Utils::Icons::RELOAD.icon()); action->setIcon(Utils::Icons::RELOAD.icon());
//action->setText(tr("Reset")); //action->setText(CallgrindTool::tr("Reset"));
action->setToolTip(tr("Reset all event counters.")); action->setToolTip(CallgrindTool::tr("Reset all event counters."));
connect(action, &QAction::triggered, this, &CallgrindTool::resetRequested); connect(action, &QAction::triggered, this, &CallgrindToolPrivate::resetRequested);
// pause action // pause action
m_pauseAction = action = new QAction(this); m_pauseAction = action = new QAction(this);
action->setCheckable(true); action->setCheckable(true);
action->setIcon(Utils::Icons::INTERRUPT_SMALL_TOOLBAR.icon()); action->setIcon(Utils::Icons::INTERRUPT_SMALL_TOOLBAR.icon());
//action->setText(tr("Ignore")); //action->setText(CallgrindTool::tr("Ignore"));
action->setToolTip(tr("Pause event logging. No events are counted which will speed up program execution during profiling.")); action->setToolTip(CallgrindTool::tr("Pause event logging. No events are counted which will speed up program execution during profiling."));
connect(action, &QAction::toggled, this, &CallgrindTool::pauseToggled); connect(action, &QAction::toggled, this, &CallgrindToolPrivate::pauseToggled);
// discard data action // discard data action
m_discardAction = action = new QAction(this); m_discardAction = action = new QAction(this);
action->setIcon(Utils::Icons::CLEAN_TOOLBAR.icon()); 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) { connect(action, &QAction::triggered, this, [this](bool) {
clearTextMarks(); clearTextMarks();
doClear(true); doClear(true);
@@ -418,21 +418,21 @@ CallgrindTool::CallgrindTool()
m_goBack = action = new QAction(this); m_goBack = action = new QAction(this);
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Utils::Icons::PREV_TOOLBAR.icon()); 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); connect(action, &QAction::triggered, &m_stackBrowser, &StackBrowser::goBack);
// go forward // go forward
m_goNext = action = new QAction(this); m_goNext = action = new QAction(this);
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Utils::Icons::NEXT_TOOLBAR.icon()); 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); connect(action, &QAction::triggered, &m_stackBrowser, &StackBrowser::goNext);
// event selection // event selection
m_eventCombo = new QComboBox; 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), connect(m_eventCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &CallgrindTool::setCostEvent); this, &CallgrindToolPrivate::setCostEvent);
updateEventCombo(); updateEventCombo();
m_perspective.addToolBarAction(m_startAction); m_perspective.addToolBarAction(m_startAction);
@@ -453,61 +453,61 @@ CallgrindTool::CallgrindTool()
auto group = new QActionGroup(this); auto group = new QActionGroup(this);
// Show costs as absolute numbers // Show costs as absolute numbers
m_costAbsolute = new QAction(tr("Absolute Costs"), this); m_costAbsolute = new QAction(CallgrindTool::tr("Absolute Costs"), this);
m_costAbsolute->setToolTip(tr("Show costs as absolute numbers.")); m_costAbsolute->setToolTip(CallgrindTool::tr("Show costs as absolute numbers."));
m_costAbsolute->setCheckable(true); m_costAbsolute->setCheckable(true);
m_costAbsolute->setChecked(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); group->addAction(m_costAbsolute);
// Show costs in percentages // Show costs in percentages
m_costRelative = new QAction(tr("Relative Costs"), this); m_costRelative = new QAction(CallgrindTool::tr("Relative Costs"), this);
m_costRelative->setToolTip(tr("Show costs relative to total inclusive cost.")); m_costRelative->setToolTip(CallgrindTool::tr("Show costs relative to total inclusive cost."));
m_costRelative->setCheckable(true); m_costRelative->setCheckable(true);
connect(m_costRelative, &QAction::toggled, this, &CallgrindTool::updateCostFormat); connect(m_costRelative, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat);
group->addAction(m_costRelative); group->addAction(m_costRelative);
// Show costs relative to parent // Show costs relative to parent
m_costRelativeToParent = new QAction(tr("Relative Costs to Parent"), this); m_costRelativeToParent = new QAction(CallgrindTool::tr("Relative Costs to Parent"), this);
m_costRelativeToParent->setToolTip(tr("Show costs relative to parent function's inclusive cost.")); m_costRelativeToParent->setToolTip(CallgrindTool::tr("Show costs relative to parent function's inclusive cost."));
m_costRelativeToParent->setCheckable(true); m_costRelativeToParent->setCheckable(true);
connect(m_costRelativeToParent, &QAction::toggled, this, &CallgrindTool::updateCostFormat); connect(m_costRelativeToParent, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat);
group->addAction(m_costRelativeToParent); group->addAction(m_costRelativeToParent);
auto button = new QToolButton; auto button = new QToolButton;
button->addActions(group->actions()); button->addActions(group->actions());
button->setPopupMode(QToolButton::InstantPopup); button->setPopupMode(QToolButton::InstantPopup);
button->setText("$"); button->setText("$");
button->setToolTip(tr("Cost Format")); button->setToolTip(CallgrindTool::tr("Cost Format"));
m_perspective.addToolBarWidget(button); m_perspective.addToolBarWidget(button);
} }
// Cycle detection // Cycle detection
//action = new QAction("Cycle Detection", this); ///FIXME: icon //action = new QAction("Cycle Detection", this); ///FIXME: icon
action = m_cycleDetection = new QAction("O", 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); action->setCheckable(true);
connect(action, &QAction::toggled, &m_dataModel, &DataModel::enableCycleDetection); connect(action, &QAction::toggled, &m_dataModel, &DataModel::enableCycleDetection);
connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setDetectCycles); connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setDetectCycles);
// Shorter template signature // Shorter template signature
action = m_shortenTemplates = new QAction("<>", this); 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); action->setCheckable(true);
connect(action, &QAction::toggled, &m_dataModel, &DataModel::setShortenTemplates); connect(action, &QAction::toggled, &m_dataModel, &DataModel::setShortenTemplates);
connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setShortenTemplates); connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setShortenTemplates);
// Filtering // 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->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); action->setCheckable(true);
connect(action, &QAction::toggled, this, &CallgrindTool::handleFilterProjectCosts); connect(action, &QAction::toggled, this, &CallgrindToolPrivate::handleFilterProjectCosts);
// Filter // Filter
///FIXME: find workaround for https://bugreports.qt.io/browse/QTCREATORBUG-3247 ///FIXME: find workaround for https://bugreports.qt.io/browse/QTCREATORBUG-3247
m_searchFilter = new QLineEdit; m_searchFilter = new QLineEdit;
m_searchFilter->setPlaceholderText(tr("Filter...")); m_searchFilter->setPlaceholderText(CallgrindTool::tr("Filter..."));
connect(m_searchFilter, &QLineEdit::textChanged, connect(m_searchFilter, &QLineEdit::textChanged,
&m_updateTimer, static_cast<void(QTimer::*)()>(&QTimer::start)); &m_updateTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
@@ -526,10 +526,10 @@ CallgrindTool::CallgrindTool()
false, Qt::RightDockWidgetArea); false, Qt::RightDockWidgetArea);
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions, connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
this, &CallgrindTool::updateRunActions); this, &CallgrindToolPrivate::updateRunActions);
} }
CallgrindTool::~CallgrindTool() CallgrindToolPrivate::~CallgrindToolPrivate()
{ {
qDeleteAll(m_textMarks); qDeleteAll(m_textMarks);
delete m_flatView; delete m_flatView;
@@ -538,7 +538,7 @@ CallgrindTool::~CallgrindTool()
delete m_visualization; delete m_visualization;
} }
void CallgrindTool::doClear(bool clearParseData) void CallgrindToolPrivate::doClear(bool clearParseData)
{ {
if (clearParseData) // Crashed when done from destructor. if (clearParseData) // Crashed when done from destructor.
setParseData(nullptr); setParseData(nullptr);
@@ -552,7 +552,7 @@ void CallgrindTool::doClear(bool clearParseData)
m_proxyModel.setFilterFixedString(QString()); m_proxyModel.setFilterFixedString(QString());
} }
void CallgrindTool::setBusyCursor(bool busy) void CallgrindToolPrivate::setBusyCursor(bool busy)
{ {
QCursor cursor(busy ? Qt::BusyCursor : Qt::ArrowCursor); QCursor cursor(busy ? Qt::BusyCursor : Qt::ArrowCursor);
m_flatView->setCursor(cursor); m_flatView->setCursor(cursor);
@@ -561,7 +561,7 @@ void CallgrindTool::setBusyCursor(bool busy)
m_visualization->setCursor(cursor); m_visualization->setCursor(cursor);
} }
void CallgrindTool::selectFunction(const Function *func) void CallgrindToolPrivate::selectFunction(const Function *func)
{ {
if (!func) { if (!func) {
m_flatView->clearSelection(); 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_goBack->setEnabled(m_stackBrowser.hasPrevious());
m_goNext->setEnabled(m_stackBrowser.hasNext()); m_goNext->setEnabled(m_stackBrowser.hasNext());
@@ -602,12 +602,12 @@ void CallgrindTool::stackBrowserChanged()
selectFunction(item); selectFunction(item);
} }
void CallgrindTool::updateFilterString() void CallgrindToolPrivate::updateFilterString()
{ {
m_proxyModel.setFilterFixedString(m_searchFilter->text()); m_proxyModel.setFilterFixedString(m_searchFilter->text());
} }
void CallgrindTool::setCostFormat(CostDelegate::CostFormat format) void CallgrindToolPrivate::setCostFormat(CostDelegate::CostFormat format)
{ {
switch (format) { switch (format) {
case CostDelegate::FormatAbsolute: 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 // prevent assert in model, don't try to set event to -1
// happens when we clear the eventcombo // happens when we clear the eventcombo
@@ -634,19 +634,19 @@ void CallgrindTool::setCostEvent(int index)
m_callersModel.setCostEvent(index); m_callersModel.setCostEvent(index);
} }
void CallgrindTool::enableCycleDetection(bool enabled) void CallgrindToolPrivate::enableCycleDetection(bool enabled)
{ {
m_cycleDetection->setChecked(enabled); m_cycleDetection->setChecked(enabled);
} }
void CallgrindTool::shortenTemplates(bool enabled) void CallgrindToolPrivate::shortenTemplates(bool enabled)
{ {
m_shortenTemplates->setChecked(enabled); m_shortenTemplates->setChecked(enabled);
} }
// Following functions can be called with actions=0 or widgets=0 // Following functions can be called with actions=0 or widgets=0
// depending on initialization sequence (whether callgrind was current). // depending on initialization sequence (whether callgrind was current).
CostDelegate::CostFormat CallgrindTool::costFormat() const CostDelegate::CostFormat CallgrindToolPrivate::costFormat() const
{ {
if (m_costRelativeToParent && m_costRelativeToParent->isChecked()) if (m_costRelativeToParent && m_costRelativeToParent->isChecked())
return CostDelegate::FormatRelativeToParent; return CostDelegate::FormatRelativeToParent;
@@ -655,7 +655,7 @@ CostDelegate::CostFormat CallgrindTool::costFormat() const
return CostDelegate::FormatAbsolute; return CostDelegate::FormatAbsolute;
} }
void CallgrindTool::updateCostFormat() void CallgrindToolPrivate::updateCostFormat()
{ {
const CostDelegate::CostFormat format = costFormat(); const CostDelegate::CostFormat format = costFormat();
if (m_flatView) if (m_flatView)
@@ -664,11 +664,11 @@ void CallgrindTool::updateCostFormat()
m_calleesView->setCostFormat(format); m_calleesView->setCostFormat(format);
m_callersView->setCostFormat(format); m_callersView->setCostFormat(format);
} }
if (ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings()) if (ValgrindGlobalSettings *settings = ValgrindGlobalSettings::instance())
settings->setCostFormat(format); settings->setCostFormat(format);
} }
void CallgrindTool::handleFilterProjectCosts() void CallgrindToolPrivate::handleFilterProjectCosts()
{ {
Project *pro = ProjectTree::currentProject(); 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 *>(); auto func = index.data(DataModel::FunctionRole).value<const Function *>();
QTC_ASSERT(func, return); QTC_ASSERT(func, return);
@@ -688,7 +688,7 @@ void CallgrindTool::dataFunctionSelected(const QModelIndex &index)
selectFunction(func); selectFunction(func);
} }
void CallgrindTool::calleeFunctionSelected(const QModelIndex &index) void CallgrindToolPrivate::calleeFunctionSelected(const QModelIndex &index)
{ {
auto call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>(); auto call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>();
QTC_ASSERT(call, return); QTC_ASSERT(call, return);
@@ -696,7 +696,7 @@ void CallgrindTool::calleeFunctionSelected(const QModelIndex &index)
selectFunction(call->callee()); selectFunction(call->callee());
} }
void CallgrindTool::callerFunctionSelected(const QModelIndex &index) void CallgrindToolPrivate::callerFunctionSelected(const QModelIndex &index)
{ {
auto call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>(); auto call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>();
QTC_ASSERT(call, return); QTC_ASSERT(call, return);
@@ -704,7 +704,7 @@ void CallgrindTool::callerFunctionSelected(const QModelIndex &index)
selectFunction(call->caller()); selectFunction(call->caller());
} }
void CallgrindTool::visualisationFunctionSelected(const Function *function) void CallgrindToolPrivate::visualisationFunctionSelected(const Function *function)
{ {
if (function && function == m_visualization->function()) if (function && function == m_visualization->function())
// up-navigation when the initial function was activated // up-navigation when the initial function was activated
@@ -713,7 +713,7 @@ void CallgrindTool::visualisationFunctionSelected(const Function *function)
selectFunction(function); selectFunction(function);
} }
void CallgrindTool::setParseData(ParseData *data) void CallgrindToolPrivate::setParseData(ParseData *data)
{ {
// we have new parse data, invalidate filters in the proxy model // we have new parse data, invalidate filters in the proxy model
m_visualization->setFunction(nullptr); m_visualization->setFunction(nullptr);
@@ -741,7 +741,7 @@ void CallgrindTool::setParseData(ParseData *data)
//setBusy(false); //setBusy(false);
} }
void CallgrindTool::updateEventCombo() void CallgrindToolPrivate::updateEventCombo()
{ {
QTC_ASSERT(m_eventCombo, return); QTC_ASSERT(m_eventCombo, return);
@@ -758,16 +758,16 @@ void CallgrindTool::updateEventCombo()
m_eventCombo->addItem(ParseData::prettyStringForEvent(event)); m_eventCombo->addItem(ParseData::prettyStringForEvent(event));
} }
void CallgrindTool::setupRunner(CallgrindToolRunner *toolRunner) void CallgrindToolPrivate::setupRunner(CallgrindToolRunner *toolRunner)
{ {
RunControl *runControl = toolRunner->runControl(); RunControl *runControl = toolRunner->runControl();
connect(toolRunner, &CallgrindToolRunner::parserDataReady, this, &CallgrindTool::takeParserDataFromRunControl); connect(toolRunner, &CallgrindToolRunner::parserDataReady, this, &CallgrindToolPrivate::takeParserDataFromRunControl);
connect(runControl, &RunControl::stopped, this, &CallgrindTool::engineFinished); connect(runControl, &RunControl::stopped, this, &CallgrindToolPrivate::engineFinished);
connect(this, &CallgrindTool::dumpRequested, toolRunner, &CallgrindToolRunner::dump); connect(this, &CallgrindToolPrivate::dumpRequested, toolRunner, &CallgrindToolRunner::dump);
connect(this, &CallgrindTool::resetRequested, toolRunner, &CallgrindToolRunner::reset); connect(this, &CallgrindToolPrivate::resetRequested, toolRunner, &CallgrindToolRunner::reset);
connect(this, &CallgrindTool::pauseToggled, toolRunner, &CallgrindToolRunner::setPaused); connect(this, &CallgrindToolPrivate::pauseToggled, toolRunner, &CallgrindToolRunner::setPaused);
connect(m_stopAction, &QAction::triggered, toolRunner, [runControl] { runControl->initiateStop(); }); connect(m_stopAction, &QAction::triggered, toolRunner, [runControl] { runControl->initiateStop(); });
@@ -800,28 +800,28 @@ void CallgrindTool::setupRunner(CallgrindToolRunner *toolRunner)
doClear(true); doClear(true);
} }
void CallgrindTool::updateRunActions() void CallgrindToolPrivate::updateRunActions()
{ {
if (m_toolBusy) { if (m_toolBusy) {
m_startAction->setEnabled(false); m_startAction->setEnabled(false);
m_startKCachegrind->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); m_stopAction->setEnabled(true);
} else { } 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); bool canRun = ProjectExplorerPlugin::canRunStartupProject(CALLGRIND_RUN_MODE, &whyNot);
m_startAction->setToolTip(whyNot); m_startAction->setToolTip(whyNot);
m_startAction->setEnabled(canRun); m_startAction->setEnabled(canRun);
m_stopAction->setEnabled(false); m_stopAction->setEnabled(false);
} }
} }
void CallgrindTool::clearTextMarks() void CallgrindToolPrivate::clearTextMarks()
{ {
qDeleteAll(m_textMarks); qDeleteAll(m_textMarks);
m_textMarks.clear(); m_textMarks.clear();
} }
void CallgrindTool::engineFinished() void CallgrindToolPrivate::engineFinished()
{ {
m_toolBusy = false; m_toolBusy = false;
updateRunActions(); updateRunActions();
@@ -835,51 +835,51 @@ void CallgrindTool::engineFinished()
if (data) if (data)
showParserResults(data); showParserResults(data);
else else
Debugger::showPermanentStatusMessage(tr("Profiling aborted.")); Debugger::showPermanentStatusMessage(CallgrindTool::tr("Profiling aborted."));
setBusyCursor(false); setBusyCursor(false);
} }
void CallgrindTool::showParserResults(const ParseData *data) void CallgrindToolPrivate::showParserResults(const ParseData *data)
{ {
QString msg; QString msg;
if (data) { if (data) {
// be careful, the list of events might be empty // be careful, the list of events might be empty
if (data->events().isEmpty()) { if (data->events().isEmpty()) {
msg = tr("Parsing finished, no data."); msg = CallgrindTool::tr("Parsing finished, no data.");
} else { } else {
const QString costStr = QString::fromLatin1("%1 %2") const QString costStr = QString::fromLatin1("%1 %2")
.arg(QString::number(data->totalCost(0)), data->events().constFirst()); .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 { } else {
msg = tr("Parsing failed."); msg = CallgrindTool::tr("Parsing failed.");
} }
Debugger::showPermanentStatusMessage(msg); Debugger::showPermanentStatusMessage(msg);
} }
void CallgrindTool::editorOpened(IEditor *editor) void CallgrindToolPrivate::editorOpened(IEditor *editor)
{ {
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) { if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
connect(widget, &TextEditorWidget::markContextMenuRequested, 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 // Find callgrind text mark that corresponds to this editor's file and line number
foreach (CallgrindTextMark *textMark, m_textMarks) { foreach (CallgrindTextMark *textMark, m_textMarks) {
if (textMark->fileName() == widget->textDocument()->filePath() && textMark->lineNumber() == line) { if (textMark->fileName() == widget->textDocument()->filePath() && textMark->lineNumber() == line) {
const Function *func = textMark->function(); 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); }); connect(action, &QAction::triggered, this, [this, func] { selectFunction(func); });
break; break;
} }
} }
} }
void CallgrindTool::handleShowCostsOfFunction() void CallgrindToolPrivate::handleShowCostsOfFunction()
{ {
CPlusPlus::Symbol *symbol = AnalyzerUtils::findSymbolUnderCursor(); CPlusPlus::Symbol *symbol = AnalyzerUtils::findSymbolUnderCursor();
if (!symbol) if (!symbol)
@@ -895,32 +895,32 @@ void CallgrindTool::handleShowCostsOfFunction()
m_startAction->trigger(); m_startAction->trigger();
} }
void CallgrindTool::slotRequestDump() void CallgrindToolPrivate::slotRequestDump()
{ {
//setBusy(true); //setBusy(true);
m_visualization->setText(tr("Populating...")); m_visualization->setText(CallgrindTool::tr("Populating..."));
emit dumpRequested(); emit dumpRequested();
} }
void CallgrindTool::loadExternalLogFile() void CallgrindToolPrivate::loadExternalLogFile()
{ {
const QString filePath = QFileDialog::getOpenFileName( const QString filePath = QFileDialog::getOpenFileName(
ICore::mainWindow(), ICore::mainWindow(),
tr("Open Callgrind Log File"), CallgrindTool::tr("Open Callgrind Log File"),
QString(), QString(),
tr("Callgrind Output (callgrind.out*);;All Files (*)")); CallgrindTool::tr("Callgrind Output (callgrind.out*);;All Files (*)"));
if (filePath.isEmpty()) if (filePath.isEmpty())
return; return;
QFile logFile(filePath); QFile logFile(filePath);
if (!logFile.open(QIODevice::ReadOnly | QIODevice::Text)) { 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::addTask(Task::Error, msg, Debugger::Constants::ANALYZERTASK_ID);
TaskHub::requestPopup(); TaskHub::requestPopup();
return; return;
} }
Debugger::showPermanentStatusMessage(tr("Parsing Profile Data...")); Debugger::showPermanentStatusMessage(CallgrindTool::tr("Parsing Profile Data..."));
QCoreApplication::processEvents(); QCoreApplication::processEvents();
Parser parser; Parser parser;
@@ -928,12 +928,12 @@ void CallgrindTool::loadExternalLogFile()
takeParserData(parser.takeData()); takeParserData(parser.takeData());
} }
void CallgrindTool::takeParserDataFromRunControl(CallgrindToolRunner *rc) void CallgrindToolPrivate::takeParserDataFromRunControl(CallgrindToolRunner *rc)
{ {
takeParserData(rc->takeParserData()); takeParserData(rc->takeParserData());
} }
void CallgrindTool::takeParserData(ParseData *data) void CallgrindToolPrivate::takeParserData(ParseData *data)
{ {
showParserResults(data); showParserResults(data);
@@ -945,14 +945,14 @@ void CallgrindTool::takeParserData(ParseData *data)
doClear(true); doClear(true);
setParseData(data); setParseData(data);
const QString kcachegrindExecutable = ValgrindPlugin::globalSettings()->kcachegrindExecutable(); const QString kcachegrindExecutable = ValgrindGlobalSettings::instance()->kcachegrindExecutable();
const bool kcachegrindExists = !Utils::Environment::systemEnvironment().searchInPath( const bool kcachegrindExists = !Utils::Environment::systemEnvironment().searchInPath(
kcachegrindExecutable).isEmpty(); kcachegrindExecutable).isEmpty();
m_startKCachegrind->setEnabled(kcachegrindExists && !m_lastFileName.isEmpty()); m_startKCachegrind->setEnabled(kcachegrindExists && !m_lastFileName.isEmpty());
createTextMarks(); createTextMarks();
} }
void CallgrindTool::createTextMarks() void CallgrindToolPrivate::createTextMarks()
{ {
QList<QString> locations; QList<QString> locations;
for (int row = 0; row < m_dataModel.rowCount(); ++row) { 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) 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, {}); RunControl::registerWorker<CallgrindToolRunner>(CALLGRIND_RUN_MODE, {});
} }
void destroyCallgrindTool() CallgrindTool::~CallgrindTool()
{ {
delete theCallgrindTool; delete dd;
theCallgrindTool = nullptr;
} }
} // namespace Internal } // namespace Internal

View File

@@ -25,11 +25,21 @@
#pragma once #pragma once
#include <QCoreApplication>
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
void initCallgrindTool(); class ValgrindGlobalSettings;
void destroyCallgrindTool();
class CallgrindTool : public QObject
{
Q_OBJECT
public:
CallgrindTool();
~CallgrindTool() final;
};
} // namespace Internal } // namespace Internal
} // namespace Valgrind } // namespace Valgrind

View File

@@ -90,7 +90,6 @@
#include <QToolButton> #include <QToolButton>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#ifdef Q_OS_WIN
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QLineEdit> #include <QLineEdit>
@@ -98,6 +97,8 @@
#include <QSpinBox> #include <QSpinBox>
#include <QStandardPaths> #include <QStandardPaths>
#include <QVBoxLayout> #include <QVBoxLayout>
#ifdef Q_OS_WIN
#include <QWinEventNotifier> #include <QWinEventNotifier>
#include <utils/winutils.h> #include <utils/winutils.h>
@@ -170,7 +171,7 @@ public:
QString MemcheckToolRunner::progressTitle() const QString MemcheckToolRunner::progressTitle() const
{ {
return tr("Analyzing Memory"); return MemcheckTool::tr("Analyzing Memory");
} }
void MemcheckToolRunner::start() void MemcheckToolRunner::start()
@@ -382,13 +383,11 @@ static void initKindFilterAction(QAction *action, const QVariantList &kinds)
action->setData(kinds); action->setData(kinds);
} }
class MemcheckTool : public QObject class MemcheckToolPrivate : public QObject
{ {
Q_DECLARE_TR_FUNCTIONS(Valgrind::Internal::MemcheckTool)
public: public:
MemcheckTool(); MemcheckToolPrivate();
~MemcheckTool() override; ~MemcheckToolPrivate() override;
void setupRunner(MemcheckToolRunner *runTool); void setupRunner(MemcheckToolRunner *runTool);
void loadShowXmlLogFile(const QString &filePath, const QString &exitMsg); void loadShowXmlLogFile(const QString &filePath, const QString &exitMsg);
@@ -437,10 +436,12 @@ private:
bool m_toolBusy = false; bool m_toolBusy = false;
QString m_exitMsg; 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 class HeobDialog : public QDialog
{ {
Q_DECLARE_TR_FUNCTIONS(HeobDialog) Q_DECLARE_TR_FUNCTIONS(HeobDialog)
@@ -473,12 +474,14 @@ private:
PathChooser *m_pathChooser = nullptr; PathChooser *m_pathChooser = nullptr;
}; };
#ifdef Q_OS_WIN
class HeobData : public QObject class HeobData : public QObject
{ {
Q_DECLARE_TR_FUNCTIONS(HeobData) Q_DECLARE_TR_FUNCTIONS(HeobData)
public: public:
HeobData(MemcheckTool *mcTool, const QString &xmlPath, Kit *kit, bool attach); HeobData(MemcheckToolPrivate *mcTool, const QString &xmlPath, Kit *kit, bool attach);
~HeobData() override; ~HeobData() override;
bool createErrorPipe(DWORD heobPid); bool createErrorPipe(DWORD heobPid);
@@ -496,7 +499,7 @@ private:
OVERLAPPED m_ov; OVERLAPPED m_ov;
unsigned m_data[2]; unsigned m_data[2];
QWinEventNotifier *m_processFinishedNotifier = nullptr; QWinEventNotifier *m_processFinishedNotifier = nullptr;
MemcheckTool *m_mcTool = nullptr; MemcheckToolPrivate *m_mcTool = nullptr;
QString m_xmlPath; QString m_xmlPath;
Kit *m_kit = nullptr; Kit *m_kit = nullptr;
bool m_attach = false; bool m_attach = false;
@@ -504,37 +507,37 @@ private:
}; };
#endif #endif
MemcheckTool::MemcheckTool() MemcheckToolPrivate::MemcheckToolPrivate()
{ {
m_settings = ValgrindPlugin::globalSettings(); m_settings = ValgrindGlobalSettings::instance();
setObjectName("MemcheckTool"); setObjectName("MemcheckTool");
m_filterProjectAction = new QAction(tr("External Errors"), this); m_filterProjectAction = new QAction(MemcheckTool::tr("External Errors"), this);
m_filterProjectAction->setToolTip( 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_filterProjectAction->setCheckable(true);
m_suppressionSeparator = new QAction(tr("Suppressions"), this); m_suppressionSeparator = new QAction(MemcheckTool::tr("Suppressions"), this);
m_suppressionSeparator->setSeparator(true); m_suppressionSeparator->setSeparator(true);
m_suppressionSeparator->setToolTip( 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}); initKindFilterAction(a, {Leak_DefinitelyLost, Leak_IndirectlyLost});
m_errorFilterActions.append(a); 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}); initKindFilterAction(a, {Leak_PossiblyLost, Leak_StillReachable});
m_errorFilterActions.append(a); 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, initKindFilterAction(a, {InvalidRead, InvalidWrite, InvalidJump, Overlap,
InvalidMemPool, UninitCondition, UninitValue, InvalidMemPool, UninitCondition, UninitValue,
SyscallParam, ClientCheck}); SyscallParam, ClientCheck});
m_errorFilterActions.append(a); 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 }); initKindFilterAction(a, { InvalidFree, MismatchedFree });
m_errorFilterActions.append(a); m_errorFilterActions.append(a);
@@ -552,12 +555,12 @@ MemcheckTool::MemcheckTool()
m_errorView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); m_errorView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_errorView->setAutoScroll(false); m_errorView->setAutoScroll(false);
m_errorView->setObjectName("Valgrind.MemcheckTool.ErrorView"); 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); m_perspective.addWindow(m_errorView, Perspective::SplitVertical, nullptr);
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions, connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
this, &MemcheckTool::maybeActiveRunConfigurationChanged); this, &MemcheckToolPrivate::maybeActiveRunConfigurationChanged);
// //
// The Control Widget. // The Control Widget.
@@ -570,15 +573,15 @@ MemcheckTool::MemcheckTool()
// Load external XML log file // Load external XML log file
auto action = new QAction(this); auto action = new QAction(this);
action->setIcon(Icons::OPENFILE_TOOLBAR.icon()); action->setIcon(Icons::OPENFILE_TOOLBAR.icon());
action->setToolTip(tr("Load External XML Log File")); action->setToolTip(MemcheckTool::tr("Load External XML Log File"));
connect(action, &QAction::triggered, this, &MemcheckTool::loadExternalXmlLogFile); connect(action, &QAction::triggered, this, &MemcheckToolPrivate::loadExternalXmlLogFile);
m_loadExternalLogFile = action; m_loadExternalLogFile = action;
// Go to previous leak. // Go to previous leak.
action = new QAction(this); action = new QAction(this);
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Icons::PREV_TOOLBAR.icon()); 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); connect(action, &QAction::triggered, m_errorView, &MemcheckErrorView::goBack);
m_goBack = action; m_goBack = action;
@@ -586,13 +589,13 @@ MemcheckTool::MemcheckTool()
action = new QAction(this); action = new QAction(this);
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Icons::NEXT_TOOLBAR.icon()); 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); connect(action, &QAction::triggered, m_errorView, &MemcheckErrorView::goNext);
m_goNext = action; m_goNext = action;
auto filterButton = new QToolButton; auto filterButton = new QToolButton;
filterButton->setIcon(Icons::FILTER.icon()); filterButton->setIcon(Icons::FILTER.icon());
filterButton->setText(tr("Error Filter")); filterButton->setText(MemcheckTool::tr("Error Filter"));
filterButton->setPopupMode(QToolButton::InstantPopup); filterButton->setPopupMode(QToolButton::InstantPopup);
filterButton->setProperty("noArrow", true); filterButton->setProperty("noArrow", true);
@@ -602,15 +605,15 @@ MemcheckTool::MemcheckTool()
m_filterMenu->addSeparator(); m_filterMenu->addSeparator();
m_filterMenu->addAction(m_filterProjectAction); m_filterMenu->addAction(m_filterProjectAction);
m_filterMenu->addAction(m_suppressionSeparator); 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); filterButton->setMenu(m_filterMenu);
ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); 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()) { if (!HostOsInfo::isWindowsHost()) {
action = new QAction(this); action = new QAction(this);
action->setText(tr("Valgrind Memory Analyzer")); action->setText(MemcheckTool::tr("Valgrind Memory Analyzer"));
action->setToolTip(toolTip); action->setToolTip(toolTip);
menu->addAction(ActionManager::registerAction(action, "Memcheck.Local"), menu->addAction(ActionManager::registerAction(action, "Memcheck.Local"),
Debugger::Constants::G_ANALYZER_TOOLS); Debugger::Constants::G_ANALYZER_TOOLS);
@@ -628,7 +631,7 @@ MemcheckTool::MemcheckTool()
action = new QAction(this); action = new QAction(this);
action->setText(tr("Valgrind Memory Analyzer with GDB")); 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, " "Memcheck tool to find memory leaks.\nWhen a problem is detected, "
"the application is interrupted and can be debugged.")); "the application is interrupted and can be debugged."));
menu->addAction(ActionManager::registerAction(action, "MemcheckWithGdb.Local"), menu->addAction(ActionManager::registerAction(action, "MemcheckWithGdb.Local"),
@@ -645,10 +648,10 @@ MemcheckTool::MemcheckTool()
action->setEnabled(m_startWithGdbAction->isEnabled()); action->setEnabled(m_startWithGdbAction->isEnabled());
}); });
} else { } else {
action = new QAction(tr("Heob"), this); action = new QAction(MemcheckTool::tr("Heob"), this);
Core::Command *cmd = Core::ActionManager::registerAction(action, "Memcheck.Local"); Core::Command *cmd = Core::ActionManager::registerAction(action, "Memcheck.Local");
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+H"))); 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); menu->addAction(cmd, Debugger::Constants::G_ANALYZER_TOOLS);
connect(m_startAction, &QAction::changed, action, [action, this] { connect(m_startAction, &QAction::changed, action, [action, this] {
action->setEnabled(m_startAction->isEnabled()); action->setEnabled(m_startAction->isEnabled());
@@ -692,14 +695,13 @@ MemcheckTool::MemcheckTool()
maybeActiveRunConfigurationChanged(); maybeActiveRunConfigurationChanged();
} }
MemcheckTool::~MemcheckTool() MemcheckToolPrivate::~MemcheckToolPrivate()
{ {
delete m_errorView; delete m_errorView;
} }
void MemcheckTool::heobAction() void MemcheckToolPrivate::heobAction()
{ {
#ifdef Q_OS_WIN
Runnable sr; Runnable sr;
Abi abi; Abi abi;
bool hasLocalRc = false; bool hasLocalRc = false;
@@ -808,6 +810,7 @@ void MemcheckTool::heobAction()
// process environment // process environment
QByteArray env; QByteArray env;
void *envPtr = nullptr; void *envPtr = nullptr;
Q_UNUSED(envPtr);
if (!envStrings.isEmpty()) { if (!envStrings.isEmpty()) {
uint pos = 0; uint pos = 0;
for (const QString &par : envStrings) { for (const QString &par : envStrings) {
@@ -823,6 +826,7 @@ void MemcheckTool::heobAction()
envPtr = env.data(); envPtr = env.data();
} }
#ifdef Q_OS_WIN
// heob process // heob process
STARTUPINFO si; STARTUPINFO si;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
@@ -855,20 +859,20 @@ void MemcheckTool::heobAction()
#endif #endif
} }
void MemcheckTool::updateRunActions() void MemcheckToolPrivate::updateRunActions()
{ {
if (m_toolBusy) { if (m_toolBusy) {
m_startAction->setEnabled(false); 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->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); m_stopAction->setEnabled(true);
} else { } 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); bool canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_RUN_MODE, &whyNot);
m_startAction->setToolTip(whyNot); m_startAction->setToolTip(whyNot);
m_startAction->setEnabled(canRun); 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); canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_WITH_GDB_RUN_MODE, &whyNot);
m_startWithGdbAction->setToolTip(whyNot); m_startWithGdbAction->setToolTip(whyNot);
m_startWithGdbAction->setEnabled(canRun); 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); 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) { foreach (QAction *action, m_errorFilterActions) {
bool contained = true; bool contained = true;
@@ -907,7 +911,7 @@ void MemcheckTool::updateFromSettings()
m_errorProxyModel.setFilterExternalIssues(m_settings->filterExternalIssues()); m_errorProxyModel.setFilterExternalIssues(m_settings->filterExternalIssues());
} }
void MemcheckTool::maybeActiveRunConfigurationChanged() void MemcheckToolPrivate::maybeActiveRunConfigurationChanged()
{ {
updateRunActions(); updateRunActions();
@@ -918,7 +922,7 @@ void MemcheckTool::maybeActiveRunConfigurationChanged()
settings = rc->currentSettings<ValgrindBaseSettings>(ANALYZER_VALGRIND_SETTINGS); settings = rc->currentSettings<ValgrindBaseSettings>(ANALYZER_VALGRIND_SETTINGS);
if (!settings) // fallback to global settings if (!settings) // fallback to global settings
settings = ValgrindPlugin::globalSettings(); settings = ValgrindGlobalSettings::instance();
if (m_settings == settings) if (m_settings == settings)
return; return;
@@ -932,20 +936,24 @@ void MemcheckTool::maybeActiveRunConfigurationChanged()
// now make the new settings current, update and connect input widgets // now make the new settings current, update and connect input widgets
m_settings = settings; m_settings = settings;
QTC_ASSERT(m_settings, return); QTC_ASSERT(m_settings, return);
connect(m_settings, &ValgrindBaseSettings::destroyed, this, &MemcheckTool::settingsDestroyed); connect(m_settings, &ValgrindBaseSettings::destroyed,
this, &MemcheckToolPrivate::settingsDestroyed);
updateFromSettings(); updateFromSettings();
} }
void MemcheckTool::setupRunner(MemcheckToolRunner *runTool) void MemcheckToolPrivate::setupRunner(MemcheckToolRunner *runTool)
{ {
RunControl *runControl = runTool->runControl(); RunControl *runControl = runTool->runControl();
m_errorModel.setRelevantFrameFinder(makeFrameFinder(transform(runControl->project()->files(Project::AllFiles), m_errorModel.setRelevantFrameFinder(makeFrameFinder(transform(runControl->project()->files(Project::AllFiles),
&FileName::toString))); &FileName::toString)));
connect(runTool, &MemcheckToolRunner::parserError, this, &MemcheckTool::parserError); connect(runTool, &MemcheckToolRunner::parserError,
connect(runTool, &MemcheckToolRunner::internalParserError, this, &MemcheckTool::internalParserError); this, &MemcheckToolPrivate::parserError);
connect(runTool, &MemcheckToolRunner::stopped, this, &MemcheckTool::engineFinished); connect(runTool, &MemcheckToolRunner::internalParserError,
this, &MemcheckToolPrivate::internalParserError);
connect(runTool, &MemcheckToolRunner::stopped,
this, &MemcheckToolPrivate::engineFinished);
m_stopAction->disconnect(); m_stopAction->disconnect();
connect(m_stopAction, &QAction::triggered, runControl, &RunControl::initiateStop); 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(); clearErrorView();
m_settings->setFilterExternalIssues(false); m_settings->setFilterExternalIssues(false);
@@ -984,13 +992,13 @@ void MemcheckTool::loadShowXmlLogFile(const QString &filePath, const QString &ex
loadXmlLogFile(filePath); loadXmlLogFile(filePath);
} }
void MemcheckTool::loadExternalXmlLogFile() void MemcheckToolPrivate::loadExternalXmlLogFile()
{ {
const QString filePath = QFileDialog::getOpenFileName( const QString filePath = QFileDialog::getOpenFileName(
ICore::mainWindow(), ICore::mainWindow(),
tr("Open Memcheck XML Log File"), MemcheckTool::tr("Open Memcheck XML Log File"),
QString(), QString(),
tr("XML Files (*.xml);;All Files (*)")); MemcheckTool::tr("XML Files (*.xml);;All Files (*)"));
if (filePath.isEmpty()) if (filePath.isEmpty())
return; return;
@@ -998,12 +1006,12 @@ void MemcheckTool::loadExternalXmlLogFile()
loadXmlLogFile(filePath); loadXmlLogFile(filePath);
} }
void MemcheckTool::loadXmlLogFile(const QString &filePath) void MemcheckToolPrivate::loadXmlLogFile(const QString &filePath)
{ {
auto logFile = new QFile(filePath); auto logFile = new QFile(filePath);
if (!logFile->open(QIODevice::ReadOnly | QIODevice::Text)) { if (!logFile->open(QIODevice::ReadOnly | QIODevice::Text)) {
delete logFile; 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::addTask(Task::Error, msg, Debugger::Constants::ANALYZERTASK_ID);
TaskHub::requestPopup(); TaskHub::requestPopup();
if (!m_exitMsg.isEmpty()) if (!m_exitMsg.isEmpty())
@@ -1015,34 +1023,38 @@ void MemcheckTool::loadXmlLogFile(const QString &filePath)
clearErrorView(); clearErrorView();
m_loadExternalLogFile->setDisabled(true); m_loadExternalLogFile->setDisabled(true);
if (!m_settings || m_settings != ValgrindPlugin::globalSettings()) { if (!m_settings || m_settings != ValgrindGlobalSettings::instance()) {
m_settings = ValgrindPlugin::globalSettings(); m_settings = ValgrindGlobalSettings::instance();
m_errorView->settingsChanged(m_settings); m_errorView->settingsChanged(m_settings);
updateFromSettings(); updateFromSettings();
} }
auto parser = new ThreadedParser; auto parser = new ThreadedParser;
connect(parser, &ThreadedParser::error, this, &MemcheckTool::parserError); connect(parser, &ThreadedParser::error,
connect(parser, &ThreadedParser::internalError, this, &MemcheckTool::internalParserError); this, &MemcheckToolPrivate::parserError);
connect(parser, &ThreadedParser::finished, this, &MemcheckTool::loadingExternalXmlLogFileFinished); connect(parser, &ThreadedParser::internalError,
connect(parser, &ThreadedParser::finished, parser, &ThreadedParser::deleteLater); this, &MemcheckToolPrivate::internalParserError);
connect(parser, &ThreadedParser::finished,
this, &MemcheckToolPrivate::loadingExternalXmlLogFileFinished);
connect(parser, &ThreadedParser::finished,
parser, &ThreadedParser::deleteLater);
parser->parse(logFile); // ThreadedParser owns the file parser->parse(logFile); // ThreadedParser owns the file
} }
void MemcheckTool::parserError(const Error &error) void MemcheckToolPrivate::parserError(const Error &error)
{ {
m_errorModel.addError(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::addTask(Task::Error, msg, Debugger::Constants::ANALYZERTASK_ID);
TaskHub::requestPopup(); TaskHub::requestPopup();
} }
void MemcheckTool::clearErrorView() void MemcheckToolPrivate::clearErrorView()
{ {
QTC_ASSERT(m_errorView, return); QTC_ASSERT(m_errorView, return);
m_errorModel.clear(); m_errorModel.clear();
@@ -1052,7 +1064,7 @@ void MemcheckTool::clearErrorView()
//QTC_ASSERT(filterMenu()->actions().last() == m_suppressionSeparator, qt_noop()); //QTC_ASSERT(filterMenu()->actions().last() == m_suppressionSeparator, qt_noop());
} }
void MemcheckTool::updateErrorFilter() void MemcheckToolPrivate::updateErrorFilter()
{ {
QTC_ASSERT(m_errorView, return); QTC_ASSERT(m_errorView, return);
QTC_ASSERT(m_settings, return); QTC_ASSERT(m_settings, return);
@@ -1073,7 +1085,7 @@ void MemcheckTool::updateErrorFilter()
m_settings->setVisibleErrorKinds(errorKinds); m_settings->setVisibleErrorKinds(errorKinds);
} }
int MemcheckTool::updateUiAfterFinishedHelper() int MemcheckToolPrivate::updateUiAfterFinishedHelper()
{ {
const int issuesFound = m_errorModel.rowCount(); const int issuesFound = m_errorModel.rowCount();
m_goBack->setEnabled(issuesFound > 1); m_goBack->setEnabled(issuesFound > 1);
@@ -1083,34 +1095,31 @@ int MemcheckTool::updateUiAfterFinishedHelper()
return issuesFound; return issuesFound;
} }
void MemcheckTool::engineFinished() void MemcheckToolPrivate::engineFinished()
{ {
m_toolBusy = false; m_toolBusy = false;
updateRunActions(); updateRunActions();
const int issuesFound = updateUiAfterFinishedHelper(); const int issuesFound = updateUiAfterFinishedHelper();
Debugger::showPermanentStatusMessage( 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(); 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()) if (!m_exitMsg.isEmpty())
statusMessage += ' ' + m_exitMsg; statusMessage += ' ' + m_exitMsg;
Debugger::showPermanentStatusMessage(statusMessage); Debugger::showPermanentStatusMessage(statusMessage);
} }
void MemcheckTool::setBusyCursor(bool busy) void MemcheckToolPrivate::setBusyCursor(bool busy)
{ {
QCursor cursor(busy ? Qt::BusyCursor : Qt::ArrowCursor); QCursor cursor(busy ? Qt::BusyCursor : Qt::ArrowCursor);
m_errorView->setCursor(cursor); m_errorView->setCursor(cursor);
} }
static MemcheckTool *theMemcheckTool;
MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl) MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl)
: ValgrindToolRunner(runControl), : ValgrindToolRunner(runControl),
m_withGdb(runControl->runMode() == MEMCHECK_WITH_GDB_RUN_MODE), 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) if (device()->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)
addStartDependency(new LocalAddressFinder(runControl, &m_localServerAddress)); addStartDependency(new LocalAddressFinder(runControl, &m_localServerAddress));
theMemcheckTool->setupRunner(this); dd->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;
} }
#ifdef Q_OS_WIN
const char heobXmlC[] = "heob/Xml"; const char heobXmlC[] = "heob/Xml";
const char heobHandleExceptionC[] = "heob/HandleException"; const char heobHandleExceptionC[] = "heob/HandleException";
const char heobPageProtectionC[] = "heob/PageProtection"; const char heobPageProtectionC[] = "heob/PageProtection";
@@ -1168,11 +1162,6 @@ const char heobAttachC[] = "heob/Attach";
const char heobExtraArgsC[] = "heob/ExtraArgs"; const char heobExtraArgsC[] = "heob/ExtraArgs";
const char heobPathC[] = "heob/Path"; const char heobPathC[] = "heob/Path";
static QString upperHexNum(unsigned num)
{
return QString("%1").arg(num, 8, 16, QChar('0')).toUpper();
}
HeobDialog::HeobDialog(QWidget *parent) : HeobDialog::HeobDialog(QWidget *parent) :
QDialog(parent) QDialog(parent)
{ {
@@ -1422,6 +1411,12 @@ void HeobDialog::saveOptions()
settings->setValue(heobPathC, m_pathChooser->path()); 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) 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) : m_ov(), m_data(), m_mcTool(mcTool), m_xmlPath(xmlPath), m_kit(kit), m_attach(attach)
{ {
@@ -1636,6 +1631,19 @@ void HeobData::debugStopped()
} }
#endif #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 Internal
} // namespace Valgrind } // namespace Valgrind

View File

@@ -26,11 +26,24 @@
#pragma once #pragma once
#include <QCoreApplication>
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
void initMemcheckTool(); class MemcheckToolRunner;
void destroyMemcheckTool();
class MemcheckTool : public QObject
{
Q_OBJECT
public:
MemcheckTool();
~MemcheckTool() final;
private:
class MemcheckToolPrivate *d = nullptr;
};
} // namespace Internal } // namespace Internal
} // namespace Valgrind } // namespace Valgrind

View File

@@ -191,7 +191,7 @@ void ValgrindConfigWidget::updateUi()
void ValgrindConfigWidget::slotAddSuppression() void ValgrindConfigWidget::slotAddSuppression()
{ {
ValgrindGlobalSettings *conf = ValgrindPlugin::globalSettings(); ValgrindGlobalSettings *conf = ValgrindGlobalSettings::instance();
QTC_ASSERT(conf, return); QTC_ASSERT(conf, return);
QStringList files = QFileDialog::getOpenFileNames(this, QStringList files = QFileDialog::getOpenFileNames(this,
tr("Valgrind Suppression Files"), tr("Valgrind Suppression Files"),

View File

@@ -62,7 +62,7 @@ ValgrindToolRunner::ValgrindToolRunner(RunControl *runControl)
qobject_cast<ValgrindBaseSettings *>(runControl->settings(ANALYZER_VALGRIND_SETTINGS)); qobject_cast<ValgrindBaseSettings *>(runControl->settings(ANALYZER_VALGRIND_SETTINGS));
if (!m_settings) if (!m_settings)
m_settings = ValgrindPlugin::globalSettings(); m_settings = ValgrindGlobalSettings::instance();
} }
void ValgrindToolRunner::start() void ValgrindToolRunner::start()

View File

@@ -53,8 +53,6 @@ using namespace ProjectExplorer;
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
static ValgrindGlobalSettings *theGlobalSettings = nullptr;
class ValgrindOptionsPage : public IOptionsPage class ValgrindOptionsPage : public IOptionsPage
{ {
public: public:
@@ -71,13 +69,13 @@ public:
QWidget *widget() override QWidget *widget() override
{ {
if (!m_widget) if (!m_widget)
m_widget = new ValgrindConfigWidget(theGlobalSettings, true); m_widget = new ValgrindConfigWidget(ValgrindGlobalSettings::instance(), true);
return m_widget; return m_widget;
} }
void apply() override void apply() override
{ {
theGlobalSettings->writeSettings(); ValgrindGlobalSettings::instance()->writeSettings();
} }
void finish() override void finish() override
@@ -95,7 +93,7 @@ public:
ValgrindRunConfigurationAspect(Target *) ValgrindRunConfigurationAspect(Target *)
{ {
setProjectSettings(new ValgrindProjectSettings); setProjectSettings(new ValgrindProjectSettings);
setGlobalSettings(ValgrindPlugin::globalSettings()); setGlobalSettings(ValgrindGlobalSettings::instance());
setId(ANALYZER_VALGRIND_SETTINGS); setId(ANALYZER_VALGRIND_SETTINGS);
setDisplayName(QCoreApplication::translate("Valgrind::Internal::ValgrindRunConfigurationAspect", setDisplayName(QCoreApplication::translate("Valgrind::Internal::ValgrindRunConfigurationAspect",
"Valgrind Settings")); "Valgrind Settings"));
@@ -105,16 +103,22 @@ public:
} }
}; };
class ValgrindPluginPrivate
{
public:
ValgrindGlobalSettings valgrindGlobalSettings; // Needs to come before the tools.
MemcheckTool memcheckTool;
CallgrindTool callgrindTool;
};
ValgrindPlugin::~ValgrindPlugin() ValgrindPlugin::~ValgrindPlugin()
{ {
delete theGlobalSettings; delete d;
theGlobalSettings = nullptr;
} }
bool ValgrindPlugin::initialize(const QStringList &, QString *) bool ValgrindPlugin::initialize(const QStringList &, QString *)
{ {
theGlobalSettings = new ValgrindGlobalSettings; d = new ValgrindPluginPrivate;
theGlobalSettings->readSettings();
new ValgrindOptionsPage(this); new ValgrindOptionsPage(this);
@@ -123,24 +127,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
return true; 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 *> ValgrindPlugin::createTestObjects() const
{ {
QList<QObject *> tests; QList<QObject *> tests;

View File

@@ -32,8 +32,6 @@
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
class ValgrindGlobalSettings;
class ValgrindPlugin : public ExtensionSystem::IPlugin class ValgrindPlugin : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
@@ -41,15 +39,15 @@ class ValgrindPlugin : public ExtensionSystem::IPlugin
public: public:
ValgrindPlugin() = default; ValgrindPlugin() = default;
~ValgrindPlugin() override; ~ValgrindPlugin() final;
bool initialize(const QStringList &arguments, QString *errorString) override; bool initialize(const QStringList &arguments, QString *errorString) final;
void extensionsInitialized() override; void extensionsInitialized() final {}
ShutdownFlag aboutToShutdown() override;
static ValgrindGlobalSettings *globalSettings();
private: private:
QList<QObject *> createTestObjects() const override; QList<QObject *> createTestObjects() const override;
class ValgrindPluginPrivate *d = nullptr;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -301,12 +301,20 @@ void ValgrindBaseSettings::setVisualisationMinimumInclusiveCostRatio(
// //
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
static ValgrindGlobalSettings *theGlobalSettings = nullptr;
ValgrindGlobalSettings::ValgrindGlobalSettings() ValgrindGlobalSettings::ValgrindGlobalSettings()
: ValgrindBaseSettings([this] { return new ValgrindConfigWidget(this, true); }) : ValgrindBaseSettings([this] { return new ValgrindConfigWidget(this, true); })
{ {
theGlobalSettings = this;
readSettings(); readSettings();
} }
ValgrindGlobalSettings *ValgrindGlobalSettings::instance()
{
return theGlobalSettings;
}
void ValgrindGlobalSettings::fromMap(const QVariantMap &map) void ValgrindGlobalSettings::fromMap(const QVariantMap &map)
{ {
ValgrindBaseSettings::fromMap(map); ValgrindBaseSettings::fromMap(map);
@@ -513,8 +521,8 @@ void ValgrindProjectSettings::toMap(QVariantMap &map) const
void ValgrindProjectSettings::addSuppressionFiles(const QStringList &suppressions) void ValgrindProjectSettings::addSuppressionFiles(const QStringList &suppressions)
{ {
QStringList globalSuppressions = ValgrindPlugin::globalSettings()->suppressionFiles(); const QStringList globalSuppressions = ValgrindGlobalSettings::instance()->suppressionFiles();
foreach (const QString &s, suppressions) { for (const QString &s : suppressions) {
if (m_addedSuppressionFiles.contains(s)) if (m_addedSuppressionFiles.contains(s))
continue; continue;
m_disabledGlobalSuppressionFiles.removeAll(s); m_disabledGlobalSuppressionFiles.removeAll(s);
@@ -525,8 +533,8 @@ void ValgrindProjectSettings::addSuppressionFiles(const QStringList &suppression
void ValgrindProjectSettings::removeSuppressionFiles(const QStringList &suppressions) void ValgrindProjectSettings::removeSuppressionFiles(const QStringList &suppressions)
{ {
QStringList globalSuppressions = ValgrindPlugin::globalSettings()->suppressionFiles(); const QStringList globalSuppressions = ValgrindGlobalSettings::instance()->suppressionFiles();
foreach (const QString &s, suppressions) { for (const QString &s : suppressions) {
m_addedSuppressionFiles.removeAll(s); m_addedSuppressionFiles.removeAll(s);
if (globalSuppressions.contains(s)) if (globalSuppressions.contains(s))
m_disabledGlobalSuppressionFiles.append(s); m_disabledGlobalSuppressionFiles.append(s);
@@ -535,8 +543,8 @@ void ValgrindProjectSettings::removeSuppressionFiles(const QStringList &suppress
QStringList ValgrindProjectSettings::suppressionFiles() const QStringList ValgrindProjectSettings::suppressionFiles() const
{ {
QStringList ret = ValgrindPlugin::globalSettings()->suppressionFiles(); QStringList ret = ValgrindGlobalSettings::instance()->suppressionFiles();
foreach (const QString &s, m_disabledGlobalSuppressionFiles) for (const QString &s : m_disabledGlobalSuppressionFiles)
ret.removeAll(s); ret.removeAll(s);
ret.append(m_addedSuppressionFiles); ret.append(m_addedSuppressionFiles);
return ret; return ret;

View File

@@ -187,6 +187,8 @@ class ValgrindGlobalSettings : public ValgrindBaseSettings
public: public:
ValgrindGlobalSettings(); ValgrindGlobalSettings();
static ValgrindGlobalSettings *instance();
void toMap(QVariantMap &map) const override; void toMap(QVariantMap &map) const override;
void fromMap(const QVariantMap &map) override; void fromMap(const QVariantMap &map) override;