diff --git a/debuggers/common/mi/micommand.h b/debuggers/common/mi/micommand.h --- a/debuggers/common/mi/micommand.h +++ b/debuggers/common/mi/micommand.h @@ -26,7 +26,11 @@ #include -namespace KDevMI { namespace MI { +namespace KDevMI { + +class MIDebugSession; + +namespace MI { class VarItem; class ValueCallback; @@ -94,26 +98,15 @@ class MICommand { -public: +protected: MICommand(CommandType type, const QString& arguments = QString(), CommandFlags flags = 0); - - template - MICommand(CommandType type, const QString& arguments, - Handler* handler_this, - void (Handler::* handler_method)(const ResultRecord&), - CommandFlags flags = 0); - - MICommand(CommandType type, const QString& arguments, MICommandHandler* handler, - CommandFlags flags = 0); - - MICommand(CommandType type, const QString& arguments, - const FunctionCommandHandler::Function& callback, - CommandFlags flags = 0); + friend class KDevMI::MIDebugSession; +public: virtual ~MICommand(); CommandType type() const; - QString miCommand() const; + virtual QString miCommand() const; CommandFlags flags() const {return flags_;} @@ -156,6 +149,10 @@ * The command object assumes ownership of @p handler. */ void setHandler(MICommandHandler* handler); + void setHandler(const FunctionCommandHandler::Function &callback); + + template + void setHandler(Handler* handler_this, void (Handler::* handler_method)(const ResultRecord&)); /* The command that should be sent to debugger. This method is virtual so the command can compute this @@ -287,11 +284,12 @@ const QString& expression, Handler* handler_this, void (Handler::* handler_method)(const QString&)) - : MICommand(DataEvaluateExpression, expression, this, - &ExpressionValueCommand::handleResponse), + : MICommand(DataEvaluateExpression, expression), handler_this(handler_this), handler_method(static_cast(handler_method)) - {} + { + setHandler(this, &ExpressionValueCommand::handleResponse); + } void handleResponse(const ResultRecord& r) { @@ -303,28 +301,28 @@ handler_method_t handler_method; }; +template +FunctionCommandHandler::Function guarded_callback(Handler *handler_this, + void (Handler::* handler_method)(const ResultRecord&)) +{ + QPointer guarded_this(handler_this); + return [guarded_this, handler_method](const ResultRecord& r) { + if (guarded_this) { + (guarded_this.data()->*handler_method)(r); + } + }; +} template -MICommand::MICommand( - CommandType type, - const QString& command, - Handler* handler_this, - void (Handler::* handler_method)(const ResultRecord&), - CommandFlags flags) -: type_(type), - flags_(flags & ~CmdHandlesError), - command_(command), - commandHandler_(nullptr), - stateReloading_(false), - m_thread(-1), - m_frame(-1) +void MICommand::setHandler(Handler* handler_this, + void (Handler::* handler_method)(const ResultRecord&)) { QPointer guarded_this(handler_this); setHandler(new FunctionCommandHandler([guarded_this, handler_method](const ResultRecord& r) { if (guarded_this) { (guarded_this.data()->*handler_method)(r); } - }, flags)); + }, flags())); } template diff --git a/debuggers/common/mi/micommand.cpp b/debuggers/common/mi/micommand.cpp --- a/debuggers/common/mi/micommand.cpp +++ b/debuggers/common/mi/micommand.cpp @@ -36,33 +36,9 @@ MICommand::MICommand(CommandType type, const QString& command, CommandFlags flags) : type_(type) - , flags_(flags & ~CmdHandlesError) - , command_(command) - , commandHandler_(0) - , stateReloading_(false) - , m_thread(-1) - , m_frame(-1) -{ -} - -MICommand::MICommand(CommandType type, const QString& arguments, MICommandHandler* handler, - CommandFlags flags) - : type_(type) , flags_(flags) - , command_(arguments) - , commandHandler_(handler) - , stateReloading_(false) - , m_thread(-1) - , m_frame(-1) -{ -} - -MICommand::MICommand(CommandType type, const QString& arguments, - const FunctionCommandHandler::Function& callback, CommandFlags flags) - : type_(type) - , flags_(flags & ~CmdHandlesError) - , command_(arguments) - , commandHandler_(new FunctionCommandHandler(callback, flags)) + , command_(command) + , commandHandler_(nullptr) , stateReloading_(false) , m_thread(-1) , m_frame(-1) @@ -114,6 +90,15 @@ if (commandHandler_ && commandHandler_->autoDelete()) delete commandHandler_; commandHandler_ = handler; + + if (!commandHandler_) { + flags_ = flags_ & ~CmdHandlesError; + } +} + +void MICommand::setHandler(const FunctionCommandHandler::Function& callback) +{ + setHandler(new FunctionCommandHandler(callback, flags())); } bool MICommand::invokeHandler(const ResultRecord& r) @@ -169,7 +154,7 @@ case BreakAfter: command = "break-after";//"ignore" break; - case BreakCatch: + case BreakCatch: // FIXME: non-exist command command = "break-catch"; break; case BreakCommands: diff --git a/debuggers/common/mibreakpointcontroller.h b/debuggers/common/mibreakpointcontroller.h --- a/debuggers/common/mibreakpointcontroller.h +++ b/debuggers/common/mibreakpointcontroller.h @@ -64,7 +64,7 @@ { Q_OBJECT public: - MIBreakpointController( MIDebugSession* parent); + MIBreakpointController(MIDebugSession* parent); using IBreakpointController::breakpointModel; @@ -99,7 +99,6 @@ void sendMaybe(KDevelop::Breakpoint *breakpoint) override; - // TODO: what's this void createFromDebugger(const MI::Value& miBkpt); void updateFromDebugger(int row, const MI::Value& miBkpt, KDevelop::BreakpointModel::ColumnFlags lockedColumns = 0); diff --git a/debuggers/common/mibreakpointcontroller.cpp b/debuggers/common/mibreakpointcontroller.cpp --- a/debuggers/common/mibreakpointcontroller.cpp +++ b/debuggers/common/mibreakpointcontroller.cpp @@ -144,9 +144,9 @@ controller->sendUpdates(row); } else { // breakpoint was deleted while insertion was in flight - controller->debugSession()->addCommand( - new MICommand(BreakDelete, QString::number(breakpoint->debuggerId), - CmdImmediately)); + controller->debugSession()->addCommand(BreakDelete, + QString::number(breakpoint->debuggerId), + CmdImmediately); } } @@ -285,9 +285,8 @@ return; debugSession()->addCommand( - new MICommand( BreakDelete, QString::number(breakpoint->debuggerId), - new DeleteHandler(this, breakpoint), CmdImmediately)); + new DeleteHandler(this, breakpoint), CmdImmediately); m_pendingDeleted << breakpoint; } @@ -349,23 +348,21 @@ BreakpointModel::ConditionColumnFlag | BreakpointModel::IgnoreHitsColumnFlag | BreakpointModel::LocationColumnFlag; - debugSession()->addCommand( - new MICommand(BreakInsert, arguments, - new InsertedHandler(this, breakpoint, sent), - CmdImmediately)); + debugSession()->addCommand(BreakInsert, arguments, + new InsertedHandler(this, breakpoint, sent), + CmdImmediately); } else { QString opt; if (modelBreakpoint->kind() == Breakpoint::ReadBreakpoint) opt = "-r "; else if (modelBreakpoint->kind() == Breakpoint::AccessBreakpoint) opt = "-a "; - debugSession()->addCommand( - new MICommand( - BreakWatch, - opt + Utils::quoteExpression(modelBreakpoint->location()), - new InsertedHandler(this, breakpoint, BreakpointModel::LocationColumnFlag), - CmdImmediately)); + debugSession()->addCommand(BreakWatch, + opt + Utils::quoteExpression(modelBreakpoint->location()), + new InsertedHandler(this, breakpoint, + BreakpointModel::LocationColumnFlag), + CmdImmediately); } recalculateState(row); @@ -383,33 +380,35 @@ if (breakpoint->dirty & BreakpointModel::LocationColumnFlag) { // Gdb considers locations as fixed, so delete and re-create the breakpoint - debugSession()->addCommand( - new MICommand(BreakDelete, QString::number(breakpoint->debuggerId), CmdImmediately)); + debugSession()->addCommand(BreakDelete, + QString::number(breakpoint->debuggerId), CmdImmediately); breakpoint->debuggerId = -1; createBreakpoint(row); return; } if (breakpoint->dirty & BreakpointModel::EnableColumnFlag) { - debugSession()->addCommand( - new MICommand(modelBreakpoint->enabled() ? BreakEnable : BreakDisable, - QString::number(breakpoint->debuggerId), - new UpdateHandler(this, breakpoint, BreakpointModel::EnableColumnFlag), - CmdImmediately)); + debugSession()->addCommand(modelBreakpoint->enabled() ? BreakEnable : BreakDisable, + QString::number(breakpoint->debuggerId), + new UpdateHandler(this, breakpoint, + BreakpointModel::EnableColumnFlag), + CmdImmediately); } if (breakpoint->dirty & BreakpointModel::IgnoreHitsColumnFlag) { - debugSession()->addCommand( - new MICommand(BreakAfter, - QString("%0 %1").arg(breakpoint->debuggerId).arg(modelBreakpoint->ignoreHits()), - new UpdateHandler(this, breakpoint, BreakpointModel::IgnoreHitsColumnFlag), - CmdImmediately)); + debugSession()->addCommand(BreakAfter, + QString("%0 %1").arg(breakpoint->debuggerId) + .arg(modelBreakpoint->ignoreHits()), + new UpdateHandler(this, breakpoint, + BreakpointModel::IgnoreHitsColumnFlag), + CmdImmediately); } if (breakpoint->dirty & BreakpointModel::ConditionColumnFlag) { - debugSession()->addCommand( - new MICommand(BreakCondition, - QString("%0 %1").arg(breakpoint->debuggerId).arg(modelBreakpoint->condition()), - new UpdateHandler(this, breakpoint, BreakpointModel::ConditionColumnFlag), - CmdImmediately)); + debugSession()->addCommand(BreakCondition, + QString("%0 %1").arg(breakpoint->debuggerId) + .arg(modelBreakpoint->condition()), + new UpdateHandler(this, breakpoint, + BreakpointModel::ConditionColumnFlag), + CmdImmediately); } recalculateState(row); diff --git a/debuggers/common/midebugger.cpp b/debuggers/common/midebugger.cpp --- a/debuggers/common/midebugger.cpp +++ b/debuggers/common/midebugger.cpp @@ -137,7 +137,7 @@ void MIDebugger::readyReadStandardError() { - process_->setReadChannel(QProcess::StandardOutput); + process_->setReadChannel(QProcess::StandardError); emit internalCommandOutput(QString::fromUtf8(process_->readAll())); } diff --git a/debuggers/common/midebugsession.h b/debuggers/common/midebugsession.h --- a/debuggers/common/midebugsession.h +++ b/debuggers/common/midebugsession.h @@ -33,6 +33,7 @@ #include "dbgglobal.h" #include "mibreakpointcontroller.h" #include "mi/mi.h" +#include "mi/micommand.h" #include @@ -46,7 +47,6 @@ namespace MI { class CommandQueue; -class MICommand; } class MIDebugger; @@ -177,6 +177,9 @@ */ bool attachToProcess(int pid); +public: + virtual MI::MICommand *createCommand(MI::CommandType type, const QString& arguments, + MI::CommandFlags flags = 0) const; /** Adds a command to the end of queue of commands to be executed by gdb. The command will be actually sent to gdb only when replies from all previous commands are received and full processed. @@ -186,13 +189,27 @@ command, so it's possible to use results of prior commands when computing the exact command to send. */ + void addUserCommand(const QString &cmd); + void addCommand(MI::MICommand* cmd); - /** Same as above, but internally constructs new MI::MICommand - instance from the string. */ - void addCommand(MI::CommandType type, const QString& cmd = QString()); + /** Same as above, but internally constructs MICommand using createCommand() */ + void addCommand(MI::CommandType type, const QString& arguments = QString(), + MI::CommandFlags flags = 0); - void addUserCommand(const QString &cmd); + void addCommand(MI::CommandType type, const QString& arguments, + MI::MICommandHandler* handler, + MI::CommandFlags flags = 0); + + void addCommand(MI::CommandType type, const QString& arguments, + const MI::FunctionCommandHandler::Function& callback, + MI::CommandFlags flags = 0); + + template + void addCommand(MI::CommandType type, const QString& arguments, + Handler* handler_this, + void (Handler::* handler_method)(const MI::ResultRecord&), + MI::CommandFlags flags = 0); protected Q_SLOTS: virtual void slotDebuggerReady(); @@ -312,6 +329,17 @@ bool m_sourceInitFile; }; +template +void MIDebugSession::addCommand(MI::CommandType type, const QString& arguments, + Handler* handler_this, + void (Handler::* handler_method)(const MI::ResultRecord&), + MI::CommandFlags flags) +{ + auto cmd = createCommand(type, arguments, flags); + cmd->setHandler(handler_this, handler_method); + queueCmd(cmd); +} + } // end of namespace KDevMI #endif // MIDEBUGSESSION_H diff --git a/debuggers/common/midebugsession.cpp b/debuggers/common/midebugsession.cpp --- a/debuggers/common/midebugsession.cpp +++ b/debuggers/common/midebugsession.cpp @@ -221,7 +221,7 @@ m_tty.reset(nullptr); return false; } - queueCmd(new MICommand(InferiorTtySet, tty)); + addCommand(InferiorTtySet, tty); // Only dummy err here, actual erros have been checked already in the job and we don't get here if there were any QString err; @@ -232,7 +232,7 @@ if (dir.isEmpty()) { dir = QFileInfo(executable).absolutePath(); } - queueCmd(new MICommand(MI::EnvironmentCd, '"' + dir + '"')); + addCommand(EnvironmentCd, '"' + dir + '"'); // Set the environment variables EnvironmentGroupList l(KSharedConfig::openConfig()); @@ -244,12 +244,12 @@ envgrp = l.defaultGroup(); } for (const auto &envvar : l.createEnvironment(envgrp, {})) { - queueCmd(new MICommand(MI::GdbSet, "environment " + envvar)); + addCommand(GdbSet, "environment " + envvar); } // Set the run arguments if (!arguments.isEmpty()) - queueCmd(new MICommand(MI::ExecArguments, KShell::joinArgs(arguments))); + addCommand(ExecArguments, KShell::joinArgs(arguments)); // Do other debugger specific config options and actually start the inferior program if (!execInferior(cfg, executable)) { @@ -291,14 +291,14 @@ // We can't omit application name from gdb invocation // because for libtool binaries, we have no way to guess // real binary name. - queueCmd(new MICommand(MI::FileExecAndSymbols)); + addCommand(MI::FileExecAndSymbols); - queueCmd(new MICommand(MI::TargetAttach, QString::number(pid), - this, &MIDebugSession::handleTargetAttach, - CmdHandlesError)); + addCommand(TargetAttach, QString::number(pid), + this, &MIDebugSession::handleTargetAttach, + CmdHandlesError); - queueCmd(new SentinelCommand(breakpointController(), - &MIBreakpointController::initSendBreakpoints)); + addCommand(new SentinelCommand(breakpointController(), + &MIBreakpointController::initSendBreakpoints)); raiseEvent(connected_to_program); @@ -329,9 +329,10 @@ } // FIXME: support non-local URLs - queueCmd(new MICommand(MI::FileExecAndSymbols, debugee.toLocalFile())); - queueCmd(new MICommand(MI::NonMI, "core " + coreFile.toLocalFile(), - this, &MIDebugSession::handleCoreFile, CmdHandlesError)); + addCommand(FileExecAndSymbols, debugee.toLocalFile()); + addCommand(NonMI, "core " + coreFile.toLocalFile(), + this, &MIDebugSession::handleCoreFile, + CmdHandlesError); raiseEvent(connected_to_program); raiseEvent(program_state_changed); @@ -517,8 +518,8 @@ interruptDebugger(); } // The -exec-abort is not implemented in gdb - // queueCmd(new MICommand(MI::ExecAbort)); - queueCmd(new MICommand(MI::NonMI, "kill")); + // addCommand(ExecAbort); + addCommand(NonMI, "kill"); } run(); } @@ -544,12 +545,12 @@ // If the app is attached then we release it here. This doesn't stop // the app running. if (debuggerStateIsOn(s_attached)) { - queueCmd(new MICommand(MI::TargetDetach)); + addCommand(TargetDetach); emit debuggerUserCommandOutput("(gdb) detach\n"); } // Now try to stop debugger running. - queueCmd(new MICommand(MI::GdbExit)); + addCommand(GdbExit); emit debuggerUserCommandOutput("(gdb) quit"); // We cannot wait forever, kill gdb after 5 seconds if it's not yet quit @@ -576,15 +577,15 @@ // Explicitly send the interrupt in case something went wrong with the usual // ensureGdbListening logic. m_debugger->interrupt(); - queueCmd(new MICommand(MI::ExecInterrupt, QString(), CmdInterrupt)); + addCommand(ExecInterrupt, QString(), CmdInterrupt); } void MIDebugSession::run() { if (debuggerStateIsOn(s_appNotStarted|s_dbgNotStarted|s_shuttingDown)) return; - queueCmd(new MICommand(MI::ExecContinue, QString(), CmdMaybeStartsRunning)); + addCommand(MI::ExecContinue, QString(), CmdMaybeStartsRunning); } void MIDebugSession::runToCursor() @@ -610,55 +611,55 @@ if (debuggerStateIsOn(s_appNotStarted|s_shuttingDown)) return; - queueCmd(new MICommand(MI::ExecNext, QString(), CmdMaybeStartsRunning | CmdTemporaryRun)); + addCommand(ExecNext, QString(), CmdMaybeStartsRunning | CmdTemporaryRun); } void MIDebugSession::stepIntoInstruction() { if (debuggerStateIsOn(s_appNotStarted|s_shuttingDown)) return; - queueCmd(new MICommand(MI::ExecStepInstruction, QString(), - CmdMaybeStartsRunning | CmdTemporaryRun)); + addCommand(ExecStepInstruction, QString(), + CmdMaybeStartsRunning | CmdTemporaryRun); } void MIDebugSession::stepInto() { if (debuggerStateIsOn(s_appNotStarted|s_shuttingDown)) return; - queueCmd(new MICommand(MI::ExecStep, QString(), CmdMaybeStartsRunning | CmdTemporaryRun)); + addCommand(ExecStep, QString(), CmdMaybeStartsRunning | CmdTemporaryRun); } void MIDebugSession::stepOverInstruction() { if (debuggerStateIsOn(s_appNotStarted|s_shuttingDown)) return; - queueCmd(new MICommand(MI::ExecNextInstruction, QString(), - CmdMaybeStartsRunning | CmdTemporaryRun)); + addCommand(ExecNextInstruction, QString(), + CmdMaybeStartsRunning | CmdTemporaryRun); } void MIDebugSession::stepOut() { if (debuggerStateIsOn(s_appNotStarted|s_shuttingDown)) return; - queueCmd(new MICommand(MI::ExecFinish, QString(), CmdMaybeStartsRunning | CmdTemporaryRun)); + addCommand(ExecFinish, QString(), CmdMaybeStartsRunning | CmdTemporaryRun); } void MIDebugSession::runUntil(const QUrl& url, int line) { if (debuggerStateIsOn(s_dbgNotStarted|s_shuttingDown)) return; if (!url.isValid()) { - queueCmd(new MICommand(MI::ExecUntil, QString::number(line), - CmdMaybeStartsRunning | CmdTemporaryRun)); + addCommand(ExecUntil, QString::number(line), + CmdMaybeStartsRunning | CmdTemporaryRun); } else { - queueCmd(new MICommand(MI::ExecUntil, - QString("%1:%2").arg(url.toLocalFile()).arg(line), - CmdMaybeStartsRunning | CmdTemporaryRun)); + addCommand(ExecUntil, + QString("%1:%2").arg(url.toLocalFile()).arg(line), + CmdMaybeStartsRunning | CmdTemporaryRun); } } @@ -668,8 +669,8 @@ return; if (!address.isEmpty()) { - queueCmd(new MICommand(MI::ExecUntil, QString("*%1").arg(address), - CmdMaybeStartsRunning | CmdTemporaryRun)); + addCommand(ExecUntil, QString("*%1").arg(address), + CmdMaybeStartsRunning | CmdTemporaryRun); } } @@ -679,10 +680,8 @@ return; if (url.isValid()) { - queueCmd(new MICommand(MI::NonMI, - QString("tbreak %1:%2").arg(url.toLocalFile()).arg(line))); - queueCmd(new MICommand(MI::NonMI, - QString("jump %1:%2").arg(url.toLocalFile()).arg(line))); + addCommand(NonMI, QString("tbreak %1:%2").arg(url.toLocalFile()).arg(line)); + addCommand(NonMI, QString("jump %1:%2").arg(url.toLocalFile()).arg(line)); } } @@ -692,8 +691,8 @@ return; if (!address.isEmpty()) { - queueCmd(new MICommand(MI::NonMI, QString("tbreak *%1").arg(address))); - queueCmd(new MICommand(MI::NonMI, QString("jump *%1").arg(address))); + addCommand(NonMI, QString("tbreak *%1").arg(address)); + addCommand(NonMI, QString("jump *%1").arg(address)); } } @@ -711,14 +710,38 @@ raiseEvent(program_state_changed); } +MICommand *MIDebugSession::createCommand(CommandType type, const QString& arguments, + CommandFlags flags) const +{ + return new MICommand(type, arguments, flags); +} + void MIDebugSession::addCommand(MICommand* cmd) { queueCmd(cmd); } -void MIDebugSession::addCommand(MI::CommandType type, const QString& str) +void MIDebugSession::addCommand(MI::CommandType type, const QString& arguments, MI::CommandFlags flags) +{ + queueCmd(createCommand(type, arguments, flags)); +} + +void MIDebugSession::addCommand(MI::CommandType type, const QString& arguments, + MI::MICommandHandler *handler, + MI::CommandFlags flags) { - queueCmd(new MICommand(type, str)); + auto cmd = createCommand(type, arguments, flags); + cmd->setHandler(handler); + queueCmd(cmd); +} + +void MIDebugSession::addCommand(MI::CommandType type, const QString& arguments, + const MI::FunctionCommandHandler::Function& callback, + MI::CommandFlags flags) +{ + auto cmd = createCommand(type, arguments, flags); + cmd->setHandler(callback); + queueCmd(cmd); } // Fairly obvious that we'll add whatever command you give me to a queue @@ -912,7 +935,7 @@ if (debuggerStateIsOn(s_automaticContinue)) { if (!debuggerStateIsOn(s_appRunning)) { qCDebug(DEBUGGERCOMMON) << "Posting automatic continue"; - queueCmd(new MICommand(MI::ExecContinue, QString(), CmdMaybeStartsRunning)); + addCommand(ExecContinue, QString(), CmdMaybeStartsRunning); } setDebuggerStateOff(s_automaticContinue); return; @@ -1003,7 +1026,7 @@ // watchpoinst on program exit is the right thing to // do. - queueCmd(new MICommand(MI::ExecContinue, QString(), CmdMaybeStartsRunning)); + addCommand(ExecContinue, QString(), CmdMaybeStartsRunning); m_stateReloadNeeded = false; return; diff --git a/debuggers/common/miframestackmodel.cpp b/debuggers/common/miframestackmodel.cpp --- a/debuggers/common/miframestackmodel.cpp +++ b/debuggers/common/miframestackmodel.cpp @@ -67,9 +67,7 @@ // that's causing std::logic_error when executing -thread-info with // more than one threads. Find a workaround for this (and report bug // if it truely is). - session()->addCommand( - new MICommand(ThreadInfo, "", - this, &MIFrameStackModel::handleThreadInfo)); + session()->addCommand(ThreadInfo, "", this, &MIFrameStackModel::handleThreadInfo); } void MIFrameStackModel::handleThreadInfo(const ResultRecord& r) @@ -151,8 +149,8 @@ { //to+1 so we know if there are more QString arg = QString("%1 %2").arg(from).arg(to+1); - MICommand *c = new MICommand(StackListFrames, arg, - new FrameListHandler(this, threadNumber, to)); + MICommand *c = session()->createCommand(StackListFrames, arg); + c->setHandler(new FrameListHandler(this, threadNumber, to)); c->setThread(threadNumber); session()->addCommand(c); } diff --git a/debuggers/common/mivariable.cpp b/debuggers/common/mivariable.cpp --- a/debuggers/common/mivariable.cpp +++ b/debuggers/common/mivariable.cpp @@ -61,8 +61,7 @@ if (hasStartedSession()) { IDebugSession* is = ICore::self()->debugController()->currentSession(); MIDebugSession * s = static_cast(is); - s->addCommand(new MICommand(VarDelete, - QString("\"%1\"").arg(varobj_))); + s->addCommand(VarDelete, QString("\"%1\"").arg(varobj_)); } } allVariables_.remove(varobj_); @@ -157,11 +156,9 @@ if (hasStartedSession()) { IDebugSession* is = ICore::self()->debugController()->currentSession(); MIDebugSession * s = static_cast(is); - s->addCommand( - new MICommand( - VarCreate, - QString("var%1 @ %2").arg(nextId++).arg(enquotedExpression()), - new CreateVarobjHandler(this, callback, callbackMethod))); + s->addCommand(VarCreate, + QString("var%1 @ %2").arg(nextId++).arg(enquotedExpression()), + new CreateVarobjHandler(this, callback, callbackMethod)); } } @@ -197,11 +194,9 @@ const QString& exp = child["exp"].literal(); if (exp == "public" || exp == "protected" || exp == "private") { ++m_activeCommands; - m_session->addCommand( - new MICommand(VarListChildren, - QString("--all-values \"%1\"") - .arg(child["name"].literal()), - this/*use again as handler*/)); + m_session->addCommand(VarListChildren, + QString("--all-values \"%1\"").arg(child["name"].literal()), + this/*use again as handler*/); } else { KDevelop::Variable* xvar = m_session->variableController()-> createVariable(variable->model(), variable, @@ -255,11 +250,10 @@ if (hasStartedSession()) { IDebugSession* is = ICore::self()->debugController()->currentSession(); MIDebugSession * s = static_cast(is); - s->addCommand( - new MICommand(VarListChildren, - QString("--all-values \"%1\" %2 %3").arg(varobj_) - .arg( c ).arg( c + fetchStep ), // fetch from .. to .. - new FetchMoreChildrenHandler(this, s))); + s->addCommand(VarListChildren, + QString("--all-values \"%1\" %2 %3") + .arg(varobj_).arg( c ).arg( c + fetchStep ), // fetch from .. to .. + new FetchMoreChildrenHandler(this, s)); } } @@ -374,12 +368,9 @@ if (hasStartedSession()) { IDebugSession* is = ICore::self()->debugController()->currentSession(); MIDebugSession * s = static_cast(is); - s->addCommand( - new MICommand(VarSetFormat, - QString(" \"%1\" %2 ").arg(varobj_).arg(format2str(format())), - new SetFormatHandler(this) - ) - ); + s->addCommand(VarSetFormat, + QString(" \"%1\" %2 ").arg(varobj_).arg(format2str(format())), + new SetFormatHandler(this)); } } } diff --git a/debuggers/common/mivariablecontroller.cpp b/debuggers/common/mivariablecontroller.cpp --- a/debuggers/common/mivariablecontroller.cpp +++ b/debuggers/common/mivariablecontroller.cpp @@ -87,9 +87,8 @@ if ((autoUpdate() & UpdateLocals) || ((autoUpdate() & UpdateWatches) && variableCollection()->watches()->childCount() > 0)) { - debugSession()->addCommand( - new MICommand(VarUpdate, "--all-values *", this, - &MIVariableController::handleVarUpdate)); + debugSession()->addCommand(VarUpdate, "--all-values *", this, + &MIVariableController::handleVarUpdate); } } @@ -155,20 +154,20 @@ localsName << var["name"].literal(); } int frame = m_session->frameStackModel()->currentFrame(); - m_session->addCommand( //dont'show value, low-frame, high-frame - new MICommand(StackListArguments, QString("0 %1 %2").arg(frame).arg(frame), - new StackListArgumentsHandler(localsName))); + m_session->addCommand(StackListArguments, + //dont'show value, low-frame, high-frame + QString("0 %1 %2").arg(frame).arg(frame), + new StackListArgumentsHandler(localsName)); } private: MIDebugSession *m_session; }; void MIVariableController::updateLocals() { - debugSession()->addCommand( - new MICommand(StackListLocals, "--simple-values", - new StackListLocalsHandler(debugSession()))); + debugSession()->addCommand(StackListLocals, "--simple-values", + new StackListLocalsHandler(debugSession())); } Range MIVariableController::expressionRangeUnderCursor(Document* doc, const Cursor& cursor) @@ -202,11 +201,9 @@ // gdb-specific one. if (MIVariable *gv = dynamic_cast(variable)) { - debugSession()->addCommand( - new MICommand(VarInfoPathExpression, - gv->varobj(), - this, - &MIVariableController::addWatch)); + debugSession()->addCommand(VarInfoPathExpression, + gv->varobj(), + this, &MIVariableController::addWatch); } } @@ -218,11 +215,9 @@ // gdb-specific one. if (MIVariable *gv = dynamic_cast(variable)) { - debugSession()->addCommand( - new MICommand(VarInfoPathExpression, - gv->varobj(), - this, - &MIVariableController::addWatchpoint)); + debugSession()->addCommand(VarInfoPathExpression, + gv->varobj(), + this, &MIVariableController::addWatchpoint); } } diff --git a/debuggers/gdb/debugsession.cpp b/debuggers/gdb/debugsession.cpp --- a/debuggers/gdb/debugsession.cpp +++ b/debuggers/gdb/debugsession.cpp @@ -96,34 +96,34 @@ void DebugSession::initializeDebugger() { - //queueCmd(new GDBCommand(GDBMI::EnableTimings, "yes")); + //addCommand(new GDBCommand(GDBMI::EnableTimings, "yes")); - queueCmd(new CliCommand(MI::GdbShow, "version", this, &DebugSession::handleVersion)); + addCommand(new CliCommand(MI::GdbShow, "version", this, &DebugSession::handleVersion)); // This makes gdb pump a variable out on one line. - queueCmd(new MICommand(MI::GdbSet, "width 0")); - queueCmd(new MICommand(MI::GdbSet, "height 0")); + addCommand(MI::GdbSet, "width 0"); + addCommand(MI::GdbSet, "height 0"); - queueCmd(new MICommand(MI::SignalHandle, "SIG32 pass nostop noprint")); - queueCmd(new MICommand(MI::SignalHandle, "SIG41 pass nostop noprint")); - queueCmd(new MICommand(MI::SignalHandle, "SIG42 pass nostop noprint")); - queueCmd(new MICommand(MI::SignalHandle, "SIG43 pass nostop noprint")); + addCommand(MI::SignalHandle, "SIG32 pass nostop noprint"); + addCommand(MI::SignalHandle, "SIG41 pass nostop noprint"); + addCommand(MI::SignalHandle, "SIG42 pass nostop noprint"); + addCommand(MI::SignalHandle, "SIG43 pass nostop noprint"); - queueCmd(new MICommand(MI::EnablePrettyPrinting)); + addCommand(MI::EnablePrettyPrinting); - queueCmd(new MICommand(MI::GdbSet, "charset UTF-8")); - queueCmd(new MICommand(MI::GdbSet, "print sevenbit-strings off")); + addCommand(MI::GdbSet, "charset UTF-8"); + addCommand(MI::GdbSet, "print sevenbit-strings off"); QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kdevgdb/printers/gdbinit"); if (!fileName.isEmpty()) { QFileInfo fileInfo(fileName); QString quotedPrintersPath = fileInfo.dir().path() .replace('\\', "\\\\") .replace('"', "\\\""); - queueCmd(new MICommand(MI::NonMI, - QString("python sys.path.insert(0, \"%0\")").arg(quotedPrintersPath))); - queueCmd(new MICommand(MI::NonMI, "source " + fileName)); + addCommand(MI::NonMI, + QString("python sys.path.insert(0, \"%0\")").arg(quotedPrintersPath)); + addCommand(MI::NonMI, "source " + fileName); } qCDebug(DEBUGGERGDB) << "Initialized GDB"; @@ -156,15 +156,15 @@ raiseEvent(debugger_ready); if (displayStaticMembers) { - queueCmd(new MICommand(MI::GdbSet, "print static-members on")); + addCommand(MI::GdbSet, "print static-members on"); } else { - queueCmd(new MICommand(MI::GdbSet, "print static-members off")); + addCommand(MI::GdbSet, "print static-members off"); } if (asmDemangle) { - queueCmd(new MICommand(MI::GdbSet, "print asm-demangle on")); + addCommand(MI::GdbSet, "print asm-demangle on"); } else { - queueCmd(new MICommand(MI::GdbSet, "print asm-demangle off")); + addCommand(MI::GdbSet, "print asm-demangle off"); } qCDebug(DEBUGGERGDB) << "Per inferior configuration done"; @@ -184,7 +184,7 @@ // handle remote debug if (configGdbScript.isValid()) { - queueCmd(new MICommand(MI::NonMI, "source " + KShell::quoteArg(configGdbScript.toLocalFile()))); + addCommand(MI::NonMI, "source " + KShell::quoteArg(configGdbScript.toLocalFile())); } // FIXME: have a check box option that controls remote debugging @@ -215,29 +215,29 @@ // Future: the shell script should be able to pass info (like pid) // to the gdb script... - queueCmd(new SentinelCommand([this, runGdbScript]() { + addCommand(new SentinelCommand([this, runGdbScript]() { breakpointController()->initSendBreakpoints(); breakpointController()->setDeleteDuplicateBreakpoints(true); qCDebug(DEBUGGERGDB) << "Running gdb script " << KShell::quoteArg(runGdbScript.toLocalFile()); - queueCmd(new MICommand(MI::NonMI, "source " + KShell::quoteArg(runGdbScript.toLocalFile()), - [this](const MI::ResultRecord&) { - breakpointController()->setDeleteDuplicateBreakpoints(false); - }, - CmdMaybeStartsRunning)); + addCommand(MI::NonMI, "source " + KShell::quoteArg(runGdbScript.toLocalFile()), + [this](const MI::ResultRecord&) { + breakpointController()->setDeleteDuplicateBreakpoints(false); + }, + CmdMaybeStartsRunning); raiseEvent(connected_to_program); }, CmdMaybeStartsRunning)); } else { // normal local debugging - queueCmd(new MICommand(MI::FileExecAndSymbols, KShell::quoteArg(executable), - this, &DebugSession::handleFileExecAndSymbols, - CmdHandlesError)); + addCommand(MI::FileExecAndSymbols, KShell::quoteArg(executable), + this, &DebugSession::handleFileExecAndSymbols, + CmdHandlesError); raiseEvent(connected_to_program); - queueCmd(new SentinelCommand([this]() { + addCommand(new SentinelCommand([this]() { breakpointController()->initSendBreakpoints(); - queueCmd(new MICommand(MI::ExecRun, QString(), CmdMaybeStartsRunning)); + addCommand(MI::ExecRun, QString(), CmdMaybeStartsRunning); }, CmdMaybeStartsRunning)); } return true; diff --git a/debuggers/gdb/disassemblewidget.cpp b/debuggers/gdb/disassemblewidget.cpp --- a/debuggers/gdb/disassemblewidget.cpp +++ b/debuggers/gdb/disassemblewidget.cpp @@ -319,16 +319,16 @@ //only get $pc if (from.isEmpty()){ - s->addCommand( - new MICommand(DataDisassemble, "-s \"$pc\" -e \"$pc+1\" -- 0", this, &DisassembleWidget::updateExecutionAddressHandler ) ); + s->addCommand(DataDisassemble, "-s \"$pc\" -e \"$pc+1\" -- 0", + this, &DisassembleWidget::updateExecutionAddressHandler); }else{ QString cmd = (to.isEmpty())? QString("-s %1 -e \"%1 + 256\" -- 0").arg(from ): QString("-s %1 -e %2+1 -- 0").arg(from).arg(to); // if both addr set - s->addCommand( - new MICommand(DataDisassemble, cmd, this, &DisassembleWidget::disassembleMemoryHandler ) ); + s->addCommand(DataDisassemble, cmd, + this, &DisassembleWidget::disassembleMemoryHandler); } } diff --git a/debuggers/gdb/registers/registercontroller.cpp b/debuggers/gdb/registers/registercontroller.cpp --- a/debuggers/gdb/registers/registercontroller.cpp +++ b/debuggers/gdb/registers/registercontroller.cpp @@ -112,7 +112,7 @@ handler = &IRegisterController::generalRegistersHandler; } - m_debugSession->addCommand(new MICommand(DataListRegisterValues, registers, this, handler)); + m_debugSession->addCommand(DataListRegisterValues, registers, this, handler); } void IRegisterController::registerNamesHandler(const ResultRecord& r) @@ -185,8 +185,7 @@ return false; } - m_debugSession->addCommand( - new MICommand(DataListRegisterNames, "", this, &IRegisterController::registerNamesHandler)); + m_debugSession->addCommand(DataListRegisterNames, "", this, &IRegisterController::registerNamesHandler); return true; } @@ -241,7 +240,7 @@ const QString command = QString("set var $%1=%2").arg(reg.name).arg(reg.value); qCDebug(DEBUGGERGDB) << "Setting register: " << command; - m_debugSession->addCommand(new MICommand(NonMI, command)); + m_debugSession->addCommand(NonMI, command); updateRegisters(group); } diff --git a/debuggers/gdb/registers/registersmanager.cpp b/debuggers/gdb/registers/registersmanager.cpp --- a/debuggers/gdb/registers/registersmanager.cpp +++ b/debuggers/gdb/registers/registersmanager.cpp @@ -73,8 +73,7 @@ return; } - debugSession->addCommand( - new MICommand(DataListRegisterNames, "", this, &ArchitectureParser::registerNamesHandler)); + debugSession->addCommand(DataListRegisterNames, "", this, &ArchitectureParser::registerNamesHandler); } RegistersManager::RegistersManager(QWidget* parent) diff --git a/debuggers/gdb/unittests/test_gdb.cpp b/debuggers/gdb/unittests/test_gdb.cpp --- a/debuggers/gdb/unittests/test_gdb.cpp +++ b/debuggers/gdb/unittests/test_gdb.cpp @@ -1751,7 +1751,7 @@ QCOMPARE(fsModel->currentFrame(), 0); QCOMPARE(session->line(), 29); - session->addCommand(new MI::MICommand(MI::NonMI, "catch throw")); + session->addCommand(MI::NonMI, "catch throw"); session->run(); WAIT_FOR_STATE(session, DebugSession::PausedState); QTest::qWait(1000); @@ -1910,13 +1910,13 @@ breakpoints()->addCodeBreakpoint("main"); session->startDebugging(&c, m_iface); WAIT_FOR_STATE(session, DebugSession::PausedState); - session->addCommand(new MI::MICommand(MI::NonMI, "rbreak .*aPl.*B")); + session->addCommand(MI::NonMI, "rbreak .*aPl.*B"); QTest::qWait(100); session->run(); WAIT_FOR_STATE(session, DebugSession::PausedState); QCOMPARE(breakpoints()->breakpoints().count(), 3); - session->addCommand(new MI::MICommand(MI::BreakDelete, "")); + session->addCommand(MI::BreakDelete, ""); session->run(); WAIT_FOR_STATE(session, DebugSession::EndedState); }