From ccffed93854d506a4fb57c933415872c1424e81c Mon Sep 17 00:00:00 2001 From: hjk <qtc-committer@nokia.com> Date: Mon, 2 May 2011 18:22:32 +0200 Subject: [PATCH] debugger: make F10/F11 start the app if not running and break on main --- src/plugins/debugger/debuggerconstants.h | 1 + src/plugins/debugger/debuggerplugin.cpp | 50 ++++++++++++------- src/plugins/debugger/debuggerrunner.cpp | 6 ++- .../debugger/debuggerstartparameters.h | 2 + src/plugins/debugger/gdb/gdbengine.cpp | 6 +++ 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/plugins/debugger/debuggerconstants.h b/src/plugins/debugger/debuggerconstants.h index 085f65e5090..888015ac34c 100644 --- a/src/plugins/debugger/debuggerconstants.h +++ b/src/plugins/debugger/debuggerconstants.h @@ -48,6 +48,7 @@ const char * const C_QMLDEBUGGER = "Qml/JavaScript Debugger"; // Project Explorer run mode (RUN/DEBUG) const char * const DEBUGMODE = "Debugger.DebugMode"; +const char * const DEBUGMODE2 = "Debugger.DebugMode2"; // Common actions (accessed by QML inspector) const char * const INTERRUPT = "Debugger.Interrupt"; diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index af877aa16e1..08b0ef7a0d2 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -682,6 +682,7 @@ public slots: void showSettingsDialog(); void debugProject(); + void debugProjectBreakMain(); void startExternalApplication(); void startRemoteCdbSession(); void startRemoteApplication(); @@ -779,20 +780,28 @@ public slots: void handleExecStep() { - currentEngine()->resetLocation(); - if (boolSetting(OperateByInstruction)) - currentEngine()->executeStepI(); - else - currentEngine()->executeStep(); + if (currentEngine()->state() == DebuggerNotReady) { + debugProjectBreakMain(); + } else { + currentEngine()->resetLocation(); + if (boolSetting(OperateByInstruction)) + currentEngine()->executeStepI(); + else + currentEngine()->executeStep(); + } } void handleExecNext() { - currentEngine()->resetLocation(); - if (boolSetting(OperateByInstruction)) - currentEngine()->executeNextI(); - else - currentEngine()->executeNext(); + if (currentEngine()->state() == DebuggerNotReady) { + debugProjectBreakMain(); + } else { + currentEngine()->resetLocation(); + if (boolSetting(OperateByInstruction)) + currentEngine()->executeNextI(); + else + currentEngine()->executeNext(); + } } void handleExecStepOut() @@ -1338,6 +1347,13 @@ void DebuggerPluginPrivate::debugProject() pe->runProject(pro, Constants::DEBUGMODE); } +void DebuggerPluginPrivate::debugProjectBreakMain() +{ + ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance(); + if (Project *pro = pe->startupProject()) + pe->runProject(pro, Constants::DEBUGMODE2); +} + void DebuggerPluginPrivate::startExternalApplication() { DebuggerStartParameters sp; @@ -1920,13 +1936,13 @@ void DebuggerPluginPrivate::setInitialState() m_interruptAction->setEnabled(false); m_continueAction->setEnabled(false); - m_stepAction->setEnabled(false); + m_stepAction->setEnabled(true); m_stepOutAction->setEnabled(false); m_runToLineAction->setEnabled(false); m_runToSelectedFunctionAction->setEnabled(true); m_returnFromFunctionAction->setEnabled(false); m_jumpToLineAction->setEnabled(false); - m_nextAction->setEnabled(false); + m_nextAction->setEnabled(true); action(AutoDerefPointers)->setEnabled(true); action(ExpandStack)->setEnabled(false); @@ -2041,7 +2057,9 @@ void DebuggerPluginPrivate::updateState(DebuggerEngine *engine) m_resetAction->setEnabled(state != DebuggerNotReady && state != DebuggerFinished); - m_stepAction->setEnabled(stopped); + m_stepAction->setEnabled(stopped || state == DebuggerNotReady); + m_nextAction->setEnabled(stopped || state == DebuggerNotReady); + m_stepOutAction->setEnabled(stopped); m_runToLineAction->setEnabled(stopped); m_runToSelectedFunctionAction->setEnabled(stopped); @@ -2051,8 +2069,6 @@ void DebuggerPluginPrivate::updateState(DebuggerEngine *engine) const bool canJump = stopped && (caps & JumpToLineCapability); m_jumpToLineAction->setEnabled(canJump); - m_nextAction->setEnabled(stopped); - const bool canDeref = actionsEnabled && (caps & AutoDerefPointersCapability); action(AutoDerefPointers)->setEnabled(canDeref); action(AutoDerefPointers)->setEnabled(true); @@ -2828,13 +2844,13 @@ void DebuggerPluginPrivate::extensionsInitialized() debugMenu->addAction(cmd); cmd = am->registerAction(m_nextAction, - Constants::NEXT, cppDebuggercontext); + Constants::NEXT, globalcontext); cmd->setDefaultKeySequence(QKeySequence(Constants::NEXT_KEY)); cmd->setAttribute(Command::CA_Hide); debugMenu->addAction(cmd); cmd = am->registerAction(m_stepAction, - Constants::STEP, cppDebuggercontext); + Constants::STEP, globalcontext); cmd->setDefaultKeySequence(QKeySequence(Constants::STEP_KEY)); cmd->setAttribute(Command::CA_Hide); debugMenu->addAction(cmd); diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp index 846f64803c6..535490f3d7c 100644 --- a/src/plugins/debugger/debuggerrunner.cpp +++ b/src/plugins/debugger/debuggerrunner.cpp @@ -654,7 +654,7 @@ DebuggerRunControlFactory::DebuggerRunControlFactory(QObject *parent, bool DebuggerRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const { // return mode == ProjectExplorer::Constants::DEBUGMODE; - return mode == Constants::DEBUGMODE + return (mode == Constants::DEBUGMODE || mode == Constants::DEBUGMODE2) && qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration); } @@ -761,8 +761,10 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu RunControl *DebuggerRunControlFactory::create (RunConfiguration *runConfiguration, const QString &mode) { - QTC_ASSERT(mode == Constants::DEBUGMODE, return 0); + QTC_ASSERT(mode == Constants::DEBUGMODE || mode == Constants::DEBUGMODE2, return 0); DebuggerStartParameters sp = localStartParameters(runConfiguration); + if (mode == Constants::DEBUGMODE2) + sp.breakOnMain = true; return create(sp, runConfiguration); } diff --git a/src/plugins/debugger/debuggerstartparameters.h b/src/plugins/debugger/debuggerstartparameters.h index 7ef6a486479..6cf48f56704 100644 --- a/src/plugins/debugger/debuggerstartparameters.h +++ b/src/plugins/debugger/debuggerstartparameters.h @@ -64,6 +64,7 @@ public: : isSnapshot(false), attachPID(-1), useTerminal(false), + breakOnMain(false), qmlServerAddress(QLatin1String("127.0.0.1")), qmlServerPort(0), useServerStartScript(false), @@ -85,6 +86,7 @@ public: QString workingDirectory; qint64 attachPID; bool useTerminal; + bool breakOnMain; // Used by AttachCrashedExternal. QString crashParameter; diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 64b9d8553ab..8016523961f 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -4448,6 +4448,12 @@ bool GdbEngine::startGdb(const QStringList &args, const QString &settingsIdHint) postCommand("disassemble 0 0", ConsoleCommand, CB(handleDisassemblerCheck)); + if (sp.breakOnMain) { + QByteArray cmd = "tbreak "; + cmd += sp.toolChainAbi.os() == Abi::WindowsOS ? "qMain" : "main"; + postCommand(cmd); + } + loadPythonDumpers(); QString scriptFileName = debuggerCore()->stringSetting(GdbScriptFile); -- GitLab