Commit 9ba17acc authored by hjk's avatar hjk

Debugger: Replace debuggerCore() by equivalent free functions

One indirection less on the user code side, and easier to export
if needed (partially addressing QTCREATORBUG-13187)

Change-Id: I13ab9f471a3a34da7a6331aefc83f6d02413bfab
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 6b4c254b
......@@ -297,7 +297,6 @@ void BreakHandler::saveBreakpoints()
{
const QString one = _("1");
//qDebug() << "SAVING BREAKPOINTS...";
QTC_ASSERT(debuggerCore(), return);
QList<QVariant> list;
ConstIterator it = m_storage.constBegin(), et = m_storage.constEnd();
for ( ; it != et; ++it) {
......@@ -1210,7 +1209,7 @@ void BreakHandler::timerEvent(QTimerEvent *event)
killTimer(m_syncTimerId);
m_syncTimerId = -1;
saveBreakpoints(); // FIXME: remove?
debuggerCore()->synchronizeBreakpoints();
Internal::synchronizeBreakpoints();
}
void BreakHandler::gotoLocation(BreakpointModelId id) const
......
......@@ -789,7 +789,7 @@ void BreakTreeView::contextMenuEvent(QContextMenuEvent *ev)
QAction *synchronizeAction =
new QAction(tr("Synchronize Breakpoints"), &menu);
synchronizeAction->setEnabled(debuggerCore()->hasSnapshots());
synchronizeAction->setEnabled(Internal::hasSnapshots());
bool enabled = selectedIds.isEmpty() || handler->isEnabled(selectedIds.at(0));
......
......@@ -387,7 +387,7 @@ void CdbEngine::init()
// Create local list of mappings in native separators
m_sourcePathMappings.clear();
const QSharedPointer<GlobalDebuggerOptions> globalOptions = debuggerCore()->globalDebuggerOptions();
const QSharedPointer<GlobalDebuggerOptions> globalOptions = Internal::globalDebuggerOptions();
SourcePathMap sourcePathMap = globalOptions->sourcePathMap;
if (!sourcePathMap.isEmpty()) {
m_sourcePathMappings.reserve(sourcePathMap.size());
......@@ -583,7 +583,7 @@ void CdbEngine::createFullBacktrace()
void CdbEngine::handleCreateFullBackTrace(const CdbEngine::CdbBuiltinCommandPtr &cmd)
{
debuggerCore()->openTextEditor(QLatin1String("Backtrace $"), QLatin1String(cmd->joinedReply()));
Internal::openTextEditor(QLatin1String("Backtrace $"), QLatin1String(cmd->joinedReply()));
}
void CdbEngine::setupEngine()
......@@ -1529,7 +1529,7 @@ void CdbEngine::updateLocals(bool forNewStackFrame)
// variables in case of errors in uninitializedVariables().
if (boolSetting(UseCodeModel)) {
QStringList uninitializedVariables;
getUninitializedVariables(debuggerCore()->cppCodeModelSnapshot(),
getUninitializedVariables(Internal::cppCodeModelSnapshot(),
frame.function, frame.file, frame.line, &uninitializedVariables);
if (!uninitializedVariables.isEmpty()) {
str << blankSeparator << "-u \"";
......@@ -2296,9 +2296,9 @@ void CdbEngine::processStop(const GdbMi &stopReason, bool conditionalBreakPointT
// Fire off remaining commands asynchronously
if (!m_pendingBreakpointMap.isEmpty() && !m_pendingSubBreakpointMap.isEmpty())
postCommandSequence(CommandListBreakPoints);
if (debuggerCore()->isDockVisible(QLatin1String(DOCKWIDGET_REGISTER)))
if (Internal::isDockVisible(QLatin1String(DOCKWIDGET_REGISTER)))
postCommandSequence(CommandListRegisters);
if (debuggerCore()->isDockVisible(QLatin1String(DOCKWIDGET_MODULES)))
if (Internal::isDockVisible(QLatin1String(DOCKWIDGET_MODULES)))
postCommandSequence(CommandListModules);
}
// After the sequence has been sent off and CDB is pondering the commands,
......@@ -2920,7 +2920,7 @@ void CdbEngine::attemptBreakpointSynchronization()
&& parameters.type == BreakpointByFileAndLine
&& boolSetting(CdbBreakPointCorrection)) {
if (lineCorrection.isNull())
lineCorrection.reset(new BreakpointCorrectionContext(debuggerCore()->cppCodeModelSnapshot(),
lineCorrection.reset(new BreakpointCorrectionContext(Internal::cppCodeModelSnapshot(),
CppTools::CppModelManager::instance()->workingCopy()));
response.lineNumber = lineCorrection->fixLineNumber(parameters.fileName, parameters.lineNumber);
postBuiltinCommand(
......
......@@ -49,8 +49,6 @@ namespace CPlusPlus { class Snapshot; }
namespace Utils { class SavedAction; }
namespace ProjectExplorer { class RunControl; }
namespace Debugger {
class DebuggerEngine;
......@@ -68,52 +66,36 @@ enum TestCases
TestNoBoundsOfCurrentFunction = 1
};
class DebuggerCore : public QObject
{
Q_OBJECT
public:
DebuggerCore() {}
virtual void updateState(DebuggerEngine *engine) = 0;
virtual void updateWatchersWindow(bool showWatch, bool showReturn) = 0;
virtual QIcon locationMarkIcon() const = 0;
virtual const CPlusPlus::Snapshot &cppCodeModelSnapshot() const = 0;
virtual bool hasSnapshots() const = 0;
virtual void openTextEditor(const QString &titlePattern, const QString &contents) = 0;
virtual bool isActiveDebugLanguage(int language) const = 0;
// void runTest(const QString &fileName);
virtual void showMessage(const QString &msg, int channel, int timeout = -1) = 0;
virtual bool isReverseDebugging() const = 0;
virtual void runControlStarted(DebuggerEngine *engine) = 0;
virtual void runControlFinished(DebuggerEngine *engine) = 0;
virtual void displayDebugger(DebuggerEngine *engine, bool updateEngine) = 0;
virtual DebuggerLanguages activeLanguages() const = 0;
virtual void synchronizeBreakpoints() = 0;
virtual bool initialize(const QStringList &arguments, QString *errorMessage) = 0;
virtual QWidget *mainWindow() const = 0;
virtual bool isDockVisible(const QString &objectName) const = 0;
virtual void showModuleSymbols(const QString &moduleName,
const QVector<Symbol> &symbols) = 0;
virtual void showModuleSections(const QString &moduleName,
const QVector<Section> &sections) = 0;
virtual void openMemoryEditor() = 0;
virtual void languagesChanged() = 0;
virtual void setThreads(const QStringList &list, int index) = 0;
virtual QSharedPointer<GlobalDebuggerOptions> globalDebuggerOptions() const = 0;
static QTreeView *inspectorView();
public slots:
virtual void attachExternalApplication(ProjectExplorer::RunControl *rc) = 0;
};
// Some convenience.
void updateState(DebuggerEngine *engine);
void updateWatchersWindow(bool showWatch, bool showReturn);
QIcon locationMarkIcon();
const CPlusPlus::Snapshot &cppCodeModelSnapshot();
bool hasSnapshots();
void openTextEditor(const QString &titlePattern, const QString &contents);
bool isActiveDebugLanguage(int language);
// void runTest(const QString &fileName);
void showMessage(const QString &msg, int channel, int timeout = -1);
bool isReverseDebugging();
void runControlStarted(DebuggerEngine *engine);
void runControlFinished(DebuggerEngine *engine);
void displayDebugger(DebuggerEngine *engine, bool updateEngine);
DebuggerLanguages activeLanguages();
void synchronizeBreakpoints();
QWidget *mainWindow();
bool isDockVisible(const QString &objectName);
void showModuleSymbols(const QString &moduleName, const QVector<Internal::Symbol> &symbols);
void showModuleSections(const QString &moduleName, const QVector<Internal::Section> &sections);
void openMemoryEditor();
void setThreads(const QStringList &list, int index);
QSharedPointer<Internal::GlobalDebuggerOptions> globalDebuggerOptions();
QTreeView *inspectorView();
QVariant sessionValue(const QByteArray &name);
void setSessionValue(const QByteArray &name, const QVariant &value);
QVariant configValue(const QByteArray &name);
......@@ -127,9 +109,6 @@ QStringList stringListSetting(int code);
BreakHandler *breakHandler();
DebuggerEngine *currentEngine();
// This is the only way to access the global object.
DebuggerCore *debuggerCore();
QMessageBox *showMessageBox(int icon, const QString &title,
const QString &text, int buttons = 0);
......
......@@ -493,7 +493,7 @@ void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) c
if (channel == ConsoleOutput && consoleManager)
consoleManager->printToConsolePane(QmlJS::ConsoleItem::UndefinedType, msg);
debuggerCore()->showMessage(msg, channel, timeout);
Internal::showMessage(msg, channel, timeout);
if (d->m_runControl) {
switch (channel) {
case AppOutput:
......@@ -577,7 +577,7 @@ void DebuggerEngine::gotoLocation(const Location &loc)
if (loc.needsMarker()) {
d->m_locationMark.reset(new TextEditor::TextMark(file, line));
d->m_locationMark->setIcon(debuggerCore()->locationMarkIcon());
d->m_locationMark->setIcon(Internal::locationMarkIcon());
d->m_locationMark->setPriority(TextEditor::TextMark::HighPriority);
}
......@@ -971,7 +971,7 @@ void DebuggerEngine::notifyInferiorSpontaneousStop()
showStatusMessage(tr("Stopped."));
setState(InferiorStopOk);
if (boolSetting(RaiseOnInterrupt))
ICore::raiseWindow(debuggerCore()->mainWindow());
ICore::raiseWindow(Internal::mainWindow());
}
void DebuggerEngine::notifyInferiorStopFailed()
......@@ -1219,7 +1219,7 @@ void DebuggerEngine::updateViews()
// The slave engines are not entitled to change the view. Their wishes
// should be coordinated by their master engine.
if (isMasterEngine())
debuggerCore()->updateState(this);
Internal::updateState(this);
}
bool DebuggerEngine::isSlaveEngine() const
......@@ -1312,7 +1312,7 @@ qint64 DebuggerEngine::inferiorPid() const
bool DebuggerEngine::isReverseDebugging() const
{
return debuggerCore()->isReverseDebugging();
return Internal::isReverseDebugging();
}
// Called by DebuggerRunControl.
......@@ -1799,7 +1799,7 @@ void DebuggerEngine::validateExecutable(DebuggerStartParameters *sp)
Utils::ElfData elfData = reader.readHeaders();
QString error = reader.errorString();
debuggerCore()->showMessage(_("EXAMINING ") + binary, LogDebug);
Internal::showMessage(_("EXAMINING ") + binary, LogDebug);
QByteArray msg = "ELF SECTIONS: ";
static QList<QByteArray> interesting;
......@@ -1823,16 +1823,16 @@ void DebuggerEngine::validateExecutable(DebuggerStartParameters *sp)
if (interesting.contains(header.name))
seen.insert(header.name);
}
debuggerCore()->showMessage(_(msg), LogDebug);
Internal::showMessage(_(msg), LogDebug);
if (!error.isEmpty()) {
debuggerCore()->showMessage(_("ERROR WHILE READING ELF SECTIONS: ") + error,
Internal::showMessage(_("ERROR WHILE READING ELF SECTIONS: ") + error,
LogDebug);
return;
}
if (elfData.sectionHeaders.isEmpty()) {
debuggerCore()->showMessage(_("NO SECTION HEADERS FOUND. IS THIS AN EXECUTABLE?"),
Internal::showMessage(_("NO SECTION HEADERS FOUND. IS THIS AN EXECUTABLE?"),
LogDebug);
return;
}
......@@ -1842,7 +1842,7 @@ void DebuggerEngine::validateExecutable(DebuggerStartParameters *sp)
bool hasEmbeddedInfo = elfData.indexOf(".debug_info") >= 0;
bool hasLink = elfData.indexOf(".gnu_debuglink") >= 0;
if (hasEmbeddedInfo) {
QSharedPointer<GlobalDebuggerOptions> options = debuggerCore()->globalDebuggerOptions();
QSharedPointer<GlobalDebuggerOptions> options = Internal::globalDebuggerOptions();
SourcePathRegExpMap globalRegExpSourceMap;
globalRegExpSourceMap.reserve(options->sourcePathRegExpMap.size());
foreach (auto entry, options->sourcePathRegExpMap) {
......
......@@ -102,7 +102,7 @@ public slots:
void updateUiForCurrentRunConfiguration();
void updateActiveLanguages();
void updateDockWidgetSettings();
void openMemoryEditor() { debuggerCore()->openMemoryEditor(); }
void openMemoryEditor() { Internal::openMemoryEditor(); }
public:
DebuggerMainWindow *q;
......@@ -231,10 +231,8 @@ void DebuggerMainWindowPrivate::updateActiveLanguages()
newLanguages |= QmlLanguage;
}
if (newLanguages != m_activeDebugLanguages) {
if (newLanguages != m_activeDebugLanguages)
m_activeDebugLanguages = newLanguages;
debuggerCore()->languagesChanged();
}
if (m_changingUI || !m_inDebugMode)
return;
......
This diff is collapsed.
......@@ -34,6 +34,8 @@
#include "debugger_global.h"
#include <extensionsystem/iplugin.h>
namespace ProjectExplorer { class RunControl; }
namespace Debugger {
namespace Internal {
......@@ -52,6 +54,7 @@ private:
QObject *remoteCommand(const QStringList &options, const QStringList &arguments);
ShutdownFlag aboutToShutdown();
void extensionsInitialized();
Q_SLOT void attachExternalApplication(ProjectExplorer::RunControl *rc);
#ifdef WITH_TESTS
private slots:
......
......@@ -153,7 +153,7 @@ void DebuggerRunControl::start()
"Affected are breakpoints %1")
.arg(unhandledIds.join(QLatin1String(", ")));
debuggerCore()->showMessage(warningMessage, LogWarning);
Internal::showMessage(warningMessage, LogWarning);
static bool checked = true;
if (checked)
......@@ -165,7 +165,7 @@ void DebuggerRunControl::start()
}
}
debuggerCore()->runControlStarted(m_engine);
Internal::runControlStarted(m_engine);
// We might get a synchronous startFailed() notification on Windows,
// when launching the process fails. Emit a proper finished() sequence.
......@@ -191,7 +191,7 @@ void DebuggerRunControl::handleFinished()
appendMessage(tr("Debugging has finished") + QLatin1Char('\n'), NormalMessageFormat);
if (m_engine)
m_engine->handleFinished();
debuggerCore()->runControlFinished(m_engine);
Internal::runControlFinished(m_engine);
}
bool DebuggerRunControl::promptToStop(bool *optionalPrompt) const
......@@ -422,7 +422,7 @@ DebuggerRunControl *DebuggerRunControlFactory::createAndScheduleRun(const Debugg
ProjectExplorerPlugin::showRunErrorMessage(errorMessage);
return 0;
}
debuggerCore()->showMessage(sp.startMessage, 0);
Internal::showMessage(sp.startMessage, 0);
ProjectExplorerPlugin::startRunControl(rc, DebugRunMode);
return rc;
}
......
......@@ -1115,7 +1115,7 @@ void DebuggerToolTipManager::showToolTip
tw->acquireEngine();
const Utils::WidgetContent widgetContent(tw, true);
Utils::ToolTip::show(context.mousePosition, widgetContent, debuggerCore()->mainWindow());
Utils::ToolTip::show(context.mousePosition, widgetContent, Internal::mainWindow());
}
bool DebuggerToolTipManager::eventFilter(QObject *o, QEvent *e)
......@@ -1320,7 +1320,7 @@ void DebuggerToolTipManager::slotTooltipOverrideRequested
if (context.expression.isEmpty()) {
const Utils::WidgetContent widgetContent(new QLabel(tr("No valid expression")), true);
Utils::ToolTip::show(context.mousePosition, widgetContent, debuggerCore()->mainWindow());
Utils::ToolTip::show(context.mousePosition, widgetContent, Internal::mainWindow());
*handled = true;
return;
}
......
......@@ -117,7 +117,7 @@ DisassemblerAgentPrivate::DisassemblerAgentPrivate()
mimeType(_("text/x-qtcreator-generic-asm")),
resetLocationScheduled(false)
{
locationMark.setIcon(debuggerCore()->locationMarkIcon());
locationMark.setIcon(Internal::locationMarkIcon());
locationMark.setPriority(TextMark::HighPriority);
}
......
......@@ -3049,7 +3049,7 @@ void GdbEngine::handleShowModuleSymbols(const GdbResponse &response)
}
file.close();
file.remove();
debuggerCore()->showModuleSymbols(modulePath, symbols);
Internal::showModuleSymbols(modulePath, symbols);
} else {
showMessageBox(QMessageBox::Critical, tr("Cannot Read Symbols"),
tr("Cannot read symbols for module \"%1\".").arg(fileName));
......@@ -3097,7 +3097,7 @@ void GdbEngine::handleShowModuleSections(const GdbResponse &response)
}
}
if (!sections.isEmpty())
debuggerCore()->showModuleSections(moduleName, sections);
Internal::showModuleSections(moduleName, sections);
}
}
......@@ -3555,7 +3555,7 @@ void GdbEngine::handleMakeSnapshot(const GdbResponse &response)
void GdbEngine::reloadRegisters()
{
if (!debuggerCore()->isDockVisible(_(DOCKWIDGET_REGISTER)))
if (!Internal::isDockVisible(_(DOCKWIDGET_REGISTER)))
return;
if (state() != InferiorStopOk && state() != InferiorUnrunnable)
......@@ -4250,7 +4250,7 @@ void GdbEngine::startGdb(const QStringList &args)
//showMessage(_("Assuming Qt is installed at %1").arg(qtInstallPath));
const SourcePathMap sourcePathMap =
DebuggerSourcePathMappingWidget::mergePlatformQtPath(sp,
debuggerCore()->globalDebuggerOptions()->sourcePathMap);
Internal::globalDebuggerOptions()->sourcePathMap);
const SourcePathMap completeSourcePathMap =
mergeStartParametersSourcePathMap(sp, sourcePathMap);
for (auto it = completeSourcePathMap.constBegin(), cend = completeSourcePathMap.constEnd();
......@@ -4586,7 +4586,7 @@ void GdbEngine::createFullBacktrace()
void GdbEngine::handleCreateFullBacktrace(const GdbResponse &response)
{
if (response.resultClass == GdbResultDone) {
debuggerCore()->openTextEditor(_("Backtrace $"),
Internal::openTextEditor(_("Backtrace $"),
_(response.consoleStreamOutput + response.logStreamOutput));
}
}
......
......@@ -466,7 +466,7 @@ void LldbEngine::handleResponse(const QByteArray &response)
void LldbEngine::showFullBacktrace(const GdbMi &data)
{
debuggerCore()->openTextEditor(_("Backtrace $"),
Internal::openTextEditor(_("Backtrace $"),
QString::fromUtf8(QByteArray::fromHex(data.data())));
}
......@@ -805,7 +805,7 @@ void LldbEngine::refreshSymbols(const GdbMi &symbols)
symbol.demangled = item["demangled"].toUtf8();
syms.append(symbol);
}
debuggerCore()->showModuleSymbols(moduleName, syms);
Internal::showModuleSymbols(moduleName, syms);
}
......@@ -1232,7 +1232,7 @@ void LldbEngine::refreshLocation(const GdbMi &reportedLocation)
void LldbEngine::reloadRegisters()
{
if (debuggerCore()->isDockVisible(QLatin1String(DOCKWIDGET_REGISTER)))
if (Internal::isDockVisible(QLatin1String(DOCKWIDGET_REGISTER)))
runCommand("reportRegisters");
}
......
......@@ -439,7 +439,7 @@ void PdbEngine::handleListSymbols(const PdbResponse &response)
symbol.name = _(item["name"].data());
symbols.append(symbol);
}
debuggerCore()->showModuleSymbols(moduleName, symbols);
Internal::showModuleSymbols(moduleName, symbols);
}
//////////////////////////////////////////////////////////////////////
......
......@@ -83,7 +83,7 @@ namespace Internal {
static QTreeView *inspectorTreeView()
{
return DebuggerCore::inspectorView();
return Internal::inspectorView();
}
class ASTWalker : public Visitor
......
......@@ -214,7 +214,7 @@ void SnapshotHandler::activateSnapshot(int index)
beginResetModel();
m_currentIndex = index;
//qDebug() << "ACTIVATING INDEX: " << m_currentIndex << " OF " << size();
debuggerCore()->displayDebugger(at(index), true);
Internal::displayDebugger(at(index), true);
endResetModel();
}
......
......@@ -144,7 +144,7 @@ void SourceAgent::updateLocationMarker()
if (d->engine->stackHandler()->currentFrame().file == d->path) {
int lineNumber = d->engine->stackHandler()->currentFrame().line;
d->locationMark = new TextEditor::TextMark(QString(), lineNumber);
d->locationMark->setIcon(debuggerCore()->locationMarkIcon());
d->locationMark->setIcon(Internal::locationMarkIcon());
d->locationMark->setPriority(TextEditor::TextMark::HighPriority);
d->editor->textDocument()->addMark(d->locationMark);
QTextCursor tc = d->editor->textCursor();
......
......@@ -356,7 +356,7 @@ void ThreadsHandler::updateThreadBox()
QStringList list;
foreach (const ThreadData &thread, m_threads)
list.append(QString::fromLatin1("#%1 %2").arg(thread.id.raw()).arg(thread.name));
debuggerCore()->setThreads(list, indexOf(m_currentId));
Internal::setThreads(list, indexOf(m_currentId));
}
void ThreadsHandler::threadDataChanged(ThreadId id)
......
......@@ -150,7 +150,7 @@ class SeparatedView : public QTabWidget
Q_OBJECT
public:
SeparatedView() : QTabWidget(debuggerCore()->mainWindow())
SeparatedView() : QTabWidget(Internal::mainWindow())
{
setTabsClosable(true);
connect(this, SIGNAL(tabCloseRequested(int)), SLOT(closeTab(int)));
......@@ -1902,7 +1902,7 @@ void WatchHandler::updateWatchersWindow()
return;
previousShowWatch = showWatch;
previousShowReturn = showReturn;
debuggerCore()->updateWatchersWindow(showWatch, showReturn);
Internal::updateWatchersWindow(showWatch, showReturn);
}
QStringList WatchHandler::watchedExpressions()
......
......@@ -956,7 +956,7 @@ void WatchTreeView::contextMenuEvent(QContextMenuEvent *ev)
copyToClipboard(mi1.data().toString());
} else if (act == &actShowInEditor) {
QString contents = handler->editorContents();
debuggerCore()->openTextEditor(tr("Locals & Expressions"), contents);
Internal::openTextEditor(tr("Locals & Expressions"), contents);
} else if (act == &actCloseEditorToolTips) {
DebuggerToolTipManager::closeAllToolTips();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment