From 36b654567d639c313d7c1c39e360bcd8915f0ed5 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 5 Oct 2018 12:03:19 +0200 Subject: [PATCH] Debugger: Finalize moving Operate by Instruction to engines Fixes: QTCREATORBUG-21211 Fixes: QTCREATORBUG-21212 Change-Id: I6c0259052336f2141462157c319abeaec9a1e483 Reviewed-by: Christian Stenger --- src/plugins/debugger/cdb/cdbengine.cpp | 5 +-- src/plugins/debugger/cdb/cdbengine.h | 2 +- src/plugins/debugger/debuggeractions.cpp | 12 ------ src/plugins/debugger/debuggeractions.h | 1 - src/plugins/debugger/debuggerengine.cpp | 51 ++++++++++++++---------- src/plugins/debugger/debuggerengine.h | 3 ++ src/plugins/debugger/debuggerplugin.cpp | 13 +++--- src/plugins/debugger/gdb/gdbengine.cpp | 2 +- src/plugins/debugger/lldb/lldbengine.cpp | 2 +- src/plugins/debugger/stackhandler.cpp | 8 ++-- src/plugins/debugger/stackhandler.h | 2 +- 11 files changed, 47 insertions(+), 54 deletions(-) diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index 255712aa67e..a047ac1d7c5 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -201,8 +201,6 @@ CdbEngine::CdbEngine() : wh->addTypeFormats("QImage", imageFormats); wh->addTypeFormats("QImage *", imageFormats); - connect(action(OperateByInstruction), &QAction::triggered, - this, &CdbEngine::operateByInstructionTriggered); connect(action(CreateFullBacktrace), &QAction::triggered, this, &CdbEngine::createFullBacktrace); connect(&m_process, static_cast(&QProcess::finished), @@ -270,6 +268,7 @@ CdbEngine::~CdbEngine() = default; void CdbEngine::operateByInstructionTriggered(bool operateByInstruction) { + DebuggerEngine::operateByInstructionTriggered(operateByInstruction); if (m_operateByInstruction == operateByInstruction) return; m_operateByInstruction = operateByInstruction; @@ -522,7 +521,7 @@ void CdbEngine::handleInitialSessionIdle() const DebuggerRunParameters &rp = runParameters(); if (!rp.commandsAfterConnect.isEmpty()) runCommand({rp.commandsAfterConnect, NoFlags}); - operateByInstructionTriggered(action(OperateByInstruction)->isChecked()); + operateByInstructionTriggered(operatesByInstruction()); // QmlCppEngine expects the QML engine to be connected before any breakpoints are hit // (attemptBreakpointSynchronization() will be directly called then) if (rp.breakOnMain) { diff --git a/src/plugins/debugger/cdb/cdbengine.h b/src/plugins/debugger/cdb/cdbengine.h index e5b617eb437..c367925fd3a 100644 --- a/src/plugins/debugger/cdb/cdbengine.h +++ b/src/plugins/debugger/cdb/cdbengine.h @@ -113,7 +113,7 @@ private: void processError(); void processFinished(); void runCommand(const DebuggerCommand &cmd) override; - void operateByInstructionTriggered(bool); + void operateByInstructionTriggered(bool) override; void createFullBacktrace(); diff --git a/src/plugins/debugger/debuggeractions.cpp b/src/plugins/debugger/debuggeractions.cpp index cfb35146834..6d44afdadcd 100644 --- a/src/plugins/debugger/debuggeractions.cpp +++ b/src/plugins/debugger/debuggeractions.cpp @@ -165,18 +165,6 @@ DebuggerSettings::DebuggerSettings() item->setDefaultValue(false); insertItem(LogTimeStamps, item); - item = new SavedAction(this); - item->setText(tr("Operate by Instruction")); - item->setCheckable(true); - item->setDefaultValue(false); - item->setIcon(Debugger::Icons::SINGLE_INSTRUCTION_MODE.icon()); - item->setToolTip(tr("

This switches the debugger to instruction-wise " - "operation mode. In this mode, stepping operates on single " - "instructions and the source location view also shows the " - "disassembled instructions.")); - item->setIconVisibleInMenu(false); - insertItem(OperateByInstruction, item); - item = new SavedAction(this); item->setText(tr("Dereference Pointers Automatically")); item->setCheckable(true); diff --git a/src/plugins/debugger/debuggeractions.h b/src/plugins/debugger/debuggeractions.h index 39d3571d45e..6a91a0fc43e 100644 --- a/src/plugins/debugger/debuggeractions.h +++ b/src/plugins/debugger/debuggeractions.h @@ -82,7 +82,6 @@ enum DebuggerActionCode AutoQuit, LockView, LogTimeStamps, - OperateByInstruction, CloseSourceBuffersOnExit, CloseMemoryBuffersOnExit, SwitchModeOnExit, diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp index 67a01d026c1..cbc1be8b779 100644 --- a/src/plugins/debugger/debuggerengine.cpp +++ b/src/plugins/debugger/debuggerengine.cpp @@ -393,23 +393,6 @@ public: m_toolTipManager.resetLocation(); } - void handleOperateByInstructionTriggered(bool on) - { - // Go to source only if we have the file. - // if (DebuggerEngine *cppEngine = m_engine->cppEngine()) { - if (m_stackHandler.currentIndex() >= 0) { - const StackFrame frame = m_stackHandler.currentFrame(); - if (on || frame.isUsable()) - m_engine->gotoLocation(Location(frame, true)); - } - // } - } - - bool operatesByInstruction() const - { - return m_operateByInstructionAction.isChecked(); - } - public: void setInitialActionStates(); void setBusyCursor(bool on); @@ -542,9 +525,15 @@ void DebuggerEnginePrivate::setupViews() m_operateByInstructionAction.setVisible(m_engine->hasCapability(DisassemblerCapability)); m_operateByInstructionAction.setIcon(Debugger::Icons::SINGLE_INSTRUCTION_MODE.icon()); m_operateByInstructionAction.setCheckable(true); - m_operateByInstructionAction.setChecked(boolSetting(OperateByInstruction)); + m_operateByInstructionAction.setChecked(false); + m_operateByInstructionAction.setToolTip("

" + tr("This switches the debugger to instruction-wise " + "operation mode. In this mode, stepping operates on single " + "instructions and the source location view also shows the " + "disassembled instructions.")); + m_operateByInstructionAction.setIconVisibleInMenu(false); + connect(&m_operateByInstructionAction, &QAction::triggered, - this, &DebuggerEnginePrivate::handleOperateByInstructionTriggered); + m_engine, &DebuggerEngine::operateByInstructionTriggered); QTC_ASSERT(m_state == DebuggerNotReady || m_state == DebuggerFinished, qDebug() << m_state); m_progress.setProgressValue(200); @@ -977,7 +966,7 @@ void DebuggerEngine::gotoLocation(const Location &loc) d->resetLocation(); if (loc.canBeDisassembled() - && ((hasCapability(OperateByInstructionCapability) && d->operatesByInstruction()) + && ((hasCapability(OperateByInstructionCapability) && operatesByInstruction()) || !loc.hasDebugInfo()) ) { d->m_disassemblerAgent.setLocation(loc); @@ -1803,6 +1792,24 @@ bool DebuggerEngine::debuggerActionsEnabled() const return debuggerActionsEnabledHelper(d->m_state); } +bool DebuggerEngine::operatesByInstruction() const +{ + return d->m_operateByInstructionAction.isChecked(); +} + +void DebuggerEngine::operateByInstructionTriggered(bool on) +{ + // Go to source only if we have the file. + // if (DebuggerEngine *cppEngine = m_engine->cppEngine()) { + d->m_stackHandler.resetModel(); + if (d->m_stackHandler.currentIndex() >= 0) { + const StackFrame frame = d->m_stackHandler.currentFrame(); + if (on || frame.isUsable()) + gotoLocation(Location(frame, true)); + } + // } +} + bool DebuggerEngine::companionPreventsActions() const { return false; @@ -2291,7 +2298,7 @@ void DebuggerEngine::handleExecStep() ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE); } else { resetLocation(); - if (d->operatesByInstruction()) + if (operatesByInstruction()) executeStepI(); else executeStep(); @@ -2305,7 +2312,7 @@ void DebuggerEngine::handleExecNext() ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE); } else { resetLocation(); - if (d->operatesByInstruction()) + if (operatesByInstruction()) executeNextI(); else executeNext(); diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h index b9a31caf512..05c30078d4f 100644 --- a/src/plugins/debugger/debuggerengine.h +++ b/src/plugins/debugger/debuggerengine.h @@ -338,6 +338,9 @@ public: bool debuggerActionsEnabled() const; virtual bool companionPreventsActions() const; + bool operatesByInstruction() const; + virtual void operateByInstructionTriggered(bool on); // FIXME: Remove. + DebuggerState state() const; bool isDying() const; diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 81c657345bc..eb194281d9e 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1233,7 +1233,7 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, m_nextAction.setIcon(Icons::STEP_OVER.icon()); connect(&m_nextAction, &QAction::triggered, this, [] { if (DebuggerEngine *engine = EngineManager::currentEngine()) { - engine->executeNext(); + engine->handleExecNext(); } else { DebuggerRunTool::setBreakOnMainNextTime(); ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, false); @@ -1248,7 +1248,7 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, m_stepAction.setIcon(Icons::STEP_OVER.icon()); connect(&m_stepAction, &QAction::triggered, this, [] { if (DebuggerEngine *engine = EngineManager::currentEngine()) { - engine->executeStep(); + engine->handleExecStep(); } else { DebuggerRunTool::setBreakOnMainNextTime(); ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, false); @@ -1298,10 +1298,10 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, ActionManager::registerAction(&m_frameUpAction, "Debugger.FrameUp", cppDebuggercontext); - cmd = ActionManager::registerAction(action(OperateByInstruction), - Constants::OPERATE_BY_INSTRUCTION, cppDebuggercontext); - cmd->setAttribute(Command::CA_Hide); - debugMenu->addAction(cmd); +// cmd = ActionManager::registerAction(action(OperateByInstruction), +// Constants::OPERATE_BY_INSTRUCTION, cppDebuggercontext); +// cmd->setAttribute(Command::CA_Hide); +// debugMenu->addAction(cmd); cmd = ActionManager::registerAction(&m_breakAction, "Debugger.ToggleBreak"); cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("F8") : tr("F9"))); @@ -2056,7 +2056,6 @@ void DebuggerPluginPrivate::setInitialState() m_watchAction.setEnabled(false); m_breakAction.setEnabled(false); //m_snapshotAction.setEnabled(false); - action(OperateByInstruction)->setChecked(false); m_exitAction.setEnabled(false); m_abortAction.setEnabled(false); diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 940909ab41a..d367b548c2a 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -1233,7 +1233,7 @@ void GdbEngine::handleStopResponse(const GdbMi &data) //qDebug() << "BP " << rid << data.toString(); // Quickly set the location marker. - if (lineNumber && !boolSetting(OperateByInstruction) + if (lineNumber && !operatesByInstruction() && QFileInfo::exists(fullName) && function != "qt_v4TriggeredBreakpointHook" && function != "qt_qmlDebugMessageAvailable" diff --git a/src/plugins/debugger/lldb/lldbengine.cpp b/src/plugins/debugger/lldb/lldbengine.cpp index 17338305100..b8d414ad76c 100644 --- a/src/plugins/debugger/lldb/lldbengine.cpp +++ b/src/plugins/debugger/lldb/lldbengine.cpp @@ -891,7 +891,7 @@ void LldbEngine::handleLocationNotification(const GdbMi &reportedLocation) QString function = reportedLocation["function"].data(); int lineNumber = reportedLocation["line"].toInt(); Location loc = Location(fileName, lineNumber); - if (boolSetting(OperateByInstruction) || !QFileInfo::exists(fileName) || lineNumber <= 0) { + if (operatesByInstruction() || !QFileInfo::exists(fileName) || lineNumber <= 0) { loc = Location(address); loc.setNeedsMarker(true); loc.setUseAssembler(true); diff --git a/src/plugins/debugger/stackhandler.cpp b/src/plugins/debugger/stackhandler.cpp index c4bb6630b0b..e96f457ae6f 100644 --- a/src/plugins/debugger/stackhandler.cpp +++ b/src/plugins/debugger/stackhandler.cpp @@ -69,8 +69,6 @@ StackHandler::StackHandler(DebuggerEngine *engine) { setObjectName("StackModel"); - connect(action(OperateByInstruction), &QAction::triggered, - this, &StackHandler::resetModel); connect(action(ExpandStack), &QAction::triggered, this, &StackHandler::reloadFullStack); connect(action(MaximalStackDepth), &QAction::triggered, @@ -159,7 +157,7 @@ Qt::ItemFlags StackHandler::flags(const QModelIndex &index) const if (index.row() == m_stackFrames.size()) return QAbstractTableModel::flags(index); const StackFrame &frame = m_stackFrames.at(index.row()); - const bool isValid = frame.isUsable() || boolSetting(OperateByInstruction); + const bool isValid = frame.isUsable() || m_engine->operatesByInstruction(); return isValid && m_contentsValid ? QAbstractTableModel::flags(index) : Qt::ItemFlags(); } @@ -258,7 +256,7 @@ void StackHandler::setFramesAndCurrentIndex(const GdbMi &frames, bool isFull) // a few exceptions: // Always jump to frame #0 when stepping by instruction. - if (boolSetting(OperateByInstruction)) + if (m_engine->operatesByInstruction()) targetFrame = 0; // If there is no frame with source, jump to frame #0. @@ -284,7 +282,7 @@ void StackHandler::prependFrames(const StackFrames &frames) int StackHandler::firstUsableIndex() const { - if (!boolSetting(OperateByInstruction)) { + if (!m_engine->operatesByInstruction()) { for (int i = 0, n = m_stackFrames.size(); i != n; ++i) if (m_stackFrames.at(i).isUsable()) return i; diff --git a/src/plugins/debugger/stackhandler.h b/src/plugins/debugger/stackhandler.h index 0f06b77c755..02268e400af 100644 --- a/src/plugins/debugger/stackhandler.h +++ b/src/plugins/debugger/stackhandler.h @@ -73,6 +73,7 @@ public: bool isContentsValid() const { return m_contentsValid; } void scheduleResetLocation(); void resetLocation(); + void resetModel() { beginResetModel(); endResetModel(); } signals: void stackChanged(); @@ -87,7 +88,6 @@ private: bool setData(const QModelIndex &idx, const QVariant &data, int role) override; bool contextMenuEvent(const Utils::ItemViewEvent &event); - void resetModel() { beginResetModel(); endResetModel(); } void reloadFullStack(); void copyContentsToClipboard(); void saveTaskFile();