diff --git a/debuggers/common/mi/micommand.h b/debuggers/common/mi/micommand.h index d1d060cc4f..ff5e22b5b4 100644 --- a/debuggers/common/mi/micommand.h +++ b/debuggers/common/mi/micommand.h @@ -1,377 +1,377 @@ /*************************************************************************** begin : Sun Aug 8 1999 copyright : (C) 1999 by John Birch email : jbb@kdevelop.org copyright : (C) 2016 by Aetf email : aetf@unlimitedcodeworks.xyz ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef _MICOMMAND_H_ #define _MICOMMAND_H_ #include "mi/mi.h" #include #include #include #include namespace KDevMI { class MIDebugSession; namespace MI { class VarItem; class ValueCallback; enum CommandFlag { /// The command handler also wishes to receive an error responses, overriding the default error handler CmdHandlesError = 1 << 0, /// The command is expected to cause the inferior to run. Controllers that display the /// program's state should refrain from sending commands while a command with this flag /// is currently pending; however, note that a command with this flag needn't be guaranteed /// to lead to a running state. CmdMaybeStartsRunning = 1 << 1, /// The command is a temporary-run type command, meaning that it typically causes the program /// to run, but only for a short time before it stops again (e.g. Step and StepInto-type /// commands). When the program is running due to this type of command, a CmdImmediately /// command will wait before forcing an interrupt of the debugger, and the program is _not_ /// automatically restarted if an interrupt was forced. /// /// TODO: this special handling has not actually been implemented yet CmdTemporaryRun = 1 << 2, /// This command should be executed immediately, even if the program is currently running /// (e.g. breakpoint setting and modification); however, if the program is interrupted, /// it should be resumed after this command has run. CmdImmediately = 1 << 3, /// This is a command that should interrupt a running program, without resuming. CmdInterrupt = 1 << 4, }; Q_DECLARE_FLAGS(CommandFlags, CommandFlag) //base class for handlers class MICommandHandler { public: virtual ~MICommandHandler() {} virtual void handle(const ResultRecord&) = 0; virtual bool handlesError() { return false; } /** * If the handler object should be deleted after the handle() call. */ virtual bool autoDelete() { return true; } }; class FunctionCommandHandler : public MICommandHandler { public: typedef std::function Function; - explicit FunctionCommandHandler(const Function& callback, CommandFlags flags = nullptr); + explicit FunctionCommandHandler(const Function& callback, CommandFlags flags = {}); void handle(const ResultRecord&) override; bool handlesError() override; private: CommandFlags _flags; Function _callback; }; /** * @author John Birch */ class MICommand { protected: - explicit MICommand(CommandType type, const QString& arguments = QString(), CommandFlags flags = nullptr); + explicit MICommand(CommandType type, const QString& arguments = QString(), CommandFlags flags = {}); friend class KDevMI::MIDebugSession; public: virtual ~MICommand(); CommandType type() const; virtual QString miCommand() const; CommandFlags flags() const {return flags_;} /** * Returns the MI token with which the command is sent, allowing the parser to match up * the result message with the command. */ uint32_t token() const {return token_;} /** * Set the MI token. This is done by \ref MICommandQueue. */ void setToken(uint32_t token) {token_ = token;} /** * Returns the thread that needs to be currently selected when this command is executed, * or -1 if there is no requirement. */ int thread() const; /** * Set the thread required to be currently selected when the command is executed. */ void setThread(int thread); /** * Returns the frame that needs to be currently selected when this command is executed, * or -1 if there is no requirement. */ int frame() const; /** * Set the frame required to be currently selected when the command is executed. */ void setFrame(int frame); /** * Sets the handler for results. * * 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 dynamically, possibly using results of the previous commands. If the empty string is returned, nothing is sent. */ virtual QString cmdToSend(); /* Returns the initial string that was specified in ctor invocation. The actual command will be determined by cmdToSend above and the return value of this method is only used in various diagnostic messages emitted before actually sending the command. */ QString initialString() const; /* Returns true if this is command entered by the user and so should be always shown in the gdb output window. */ virtual bool isUserCommand() const; // If there's a handler for this command, invokes it and returns true. // Otherwise, returns false. bool invokeHandler(const ResultRecord& r); // Returns 'true' if 'invokeHandler' should be invoked even // on MI errors. bool handlesError() const; // Called by debuggercontroller for each new output string // debugger emits for this command. In MI mode, this includes // all "stream" messages, but does not include MI responses. void newOutput(const QString&); const QStringList& allStreamOutput() const; QString command() const; void setStateReloading(bool f); bool stateReloading() const; /// Called when the command has been enqueued in the debug session /// and the command is wait for being submitted to GDB. void markAsEnqueued(); /// Called when the command has been submitted to GDB and the command /// waits for completion by GDB. void markAsSubmitted(); /// Called when the command has been completed and the response has arrived. void markAsCompleted(); /// returns the amount of time (in ms) passed between submission and completion. qint64 gdbProcessingTime() const; /// returns the amount of time (in ms) passed between enqueuing and submission. qint64 queueTime() const; /// returns the amount of time (in ms) passed between enqueuing and completion. qint64 totalProcessingTime() const; protected: CommandType type_; CommandFlags flags_; uint32_t token_ = 0; QString command_; MICommandHandler *commandHandler_; QStringList lines; bool stateReloading_; int m_thread; int m_frame; // remember the timestamps (in ms since start of the epoch) when this command // - was added to the command queue (enqueued) // - was submitted to GDB // - was completed; response from GDB arrived qint64 m_enqueueTimestamp; qint64 m_submitTimestamp; qint64 m_completeTimestamp; }; class UserCommand : public MICommand { public: UserCommand(CommandType type, const QString& s); bool isUserCommand() const override; }; /** This is a class for raw CLI commands. Instead of invoking user provided hook with MI response, it invokes the a hook with lists of strings. */ class CliCommand : public MICommand { public: template CliCommand(CommandType type, const QString& command, Handler* handler_this, void (Handler::* handler_method)(const QStringList&), - CommandFlags flags = nullptr); + CommandFlags flags = {}); }; /** Command that does nothing and can be just used to invoke a user provided handler when all preceding commands are executed. */ class SentinelCommand : public MICommand { public: typedef std::function Function; template SentinelCommand(Handler* handler_this, void (Handler::* handler_method)(), - CommandFlags flags = nullptr) + CommandFlags flags = {}) : MICommand(NonMI, QString(), flags) { QPointer guarded_this(handler_this); handler = [guarded_this, handler_method]() { if (guarded_this) { (guarded_this.data()->*handler_method)(); } }; } - explicit SentinelCommand(const Function& handler, CommandFlags flags = nullptr) + explicit SentinelCommand(const Function& handler, CommandFlags flags = {}) : MICommand(NonMI, QString(), flags) , handler(handler) { } using MICommand::invokeHandler; void invokeHandler() { handler(); } QString cmdToSend() override { return ""; } private: Function handler; }; class ExpressionValueCommand : public QObject, public MICommand { public: typedef void (QObject::*handler_method_t)(const QString&); template ExpressionValueCommand( const QString& expression, Handler* handler_this, void (Handler::* handler_method)(const QString&)) : MICommand(DataEvaluateExpression, expression), handler_this(handler_this), handler_method(static_cast(handler_method)) { setHandler(this, &ExpressionValueCommand::handleResponse); } void handleResponse(const ResultRecord& r) { (handler_this.data()->*handler_method)(r["value"].literal()); } private: QPointer handler_this; 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 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())); } template CliCommand::CliCommand( CommandType type, const QString& command, Handler* handler_this, void (Handler::* handler_method)(const QStringList&), CommandFlags flags) : MICommand(type, command) { QPointer guarded_this(handler_this); setHandler(new FunctionCommandHandler([this, guarded_this, handler_method](const ResultRecord&) { if (guarded_this) { (guarded_this.data()->*handler_method)(this->allStreamOutput()); } }, flags)); } } // end of namespace MI } // end of namespace KDevMI Q_DECLARE_OPERATORS_FOR_FLAGS(KDevMI::MI::CommandFlags) #endif diff --git a/debuggers/common/mibreakpointcontroller.h b/debuggers/common/mibreakpointcontroller.h index 161066e24b..cc5f148483 100644 --- a/debuggers/common/mibreakpointcontroller.h +++ b/debuggers/common/mibreakpointcontroller.h @@ -1,118 +1,118 @@ /* This file is part of the KDE project Copyright (C) 2002 Matthias Hoelzer-Kluepfel Copyright (C) 2002 John Firebaugh Copyright (C) 2007 Hamish Rodda Copyright (C) 2009 Niko Sams This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef MIBREAKPOINTCONTROLLER_H #define MIBREAKPOINTCONTROLLER_H #include "dbgglobal.h" #include #include namespace KDevMI { namespace MI { struct AsyncRecord; struct ResultRecord; struct Value; } struct BreakpointData { int debuggerId; KDevelop::BreakpointModel::ColumnFlags dirty; KDevelop::BreakpointModel::ColumnFlags sent; KDevelop::BreakpointModel::ColumnFlags errors; bool pending; BreakpointData() : debuggerId(-1) , pending(false) {} }; typedef QSharedPointer BreakpointDataPtr; class MIDebugSession; /** * Handles signals from the editor that relate to breakpoints and the execution * point of the debugger. * We may change, add or remove breakpoints in this class. */ class MIBreakpointController : public KDevelop::IBreakpointController { Q_OBJECT public: explicit MIBreakpointController(MIDebugSession* parent); using IBreakpointController::breakpointModel; /** * Controls whether when duplicate breakpoints are received via async notification from GDB, * one of the duplicates will be deleted. */ void setDeleteDuplicateBreakpoints(bool enable); void breakpointAdded(int row) override; void breakpointModelChanged(int row, KDevelop::BreakpointModel::ColumnFlags columns) override; void breakpointAboutToBeDeleted(int row) override; void debuggerStateChanged(KDevelop::IDebugSession::DebuggerState) override; void notifyBreakpointCreated(const MI::AsyncRecord& r); void notifyBreakpointModified(const MI::AsyncRecord& r); void notifyBreakpointDeleted(const MI::AsyncRecord& r); public Q_SLOTS: void initSendBreakpoints(); private Q_SLOTS: void programStopped(const MI::AsyncRecord &r); private: MIDebugSession* debugSession() const; int breakpointRow(const BreakpointDataPtr& breakpoint); void createBreakpoint(int row); void sendUpdates(int row); void recalculateState(int row); void sendMaybe(KDevelop::Breakpoint *breakpoint) override; void createFromDebugger(const MI::Value& miBkpt); void updateFromDebugger(int row, const MI::Value& miBkpt, - KDevelop::BreakpointModel::ColumnFlags lockedColumns = nullptr); + KDevelop::BreakpointModel::ColumnFlags lockedColumns = {}); int rowFromDebuggerId(int gdbId) const; struct Handler; struct InsertedHandler; struct UpdateHandler; struct DeleteHandler; struct IgnoreChanges; QList m_breakpoints; QList m_pendingDeleted; int m_ignoreChanges = 0; bool m_deleteDuplicateBreakpoints = false; }; } // end of namespace KDevMI #endif // MIBREAKPOINTCONTROLLER_H diff --git a/debuggers/lldb/lldbcommand.h b/debuggers/lldb/lldbcommand.h index 21ccbf1b3b..a57782e25d 100644 --- a/debuggers/lldb/lldbcommand.h +++ b/debuggers/lldb/lldbcommand.h @@ -1,54 +1,54 @@ /* * LLDB specific version of MI command * Copyright 2016 Aetf * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef LLDBCOMMAND_H #define LLDBCOMMAND_H #include "mi/micommand.h" namespace KDevMI { namespace LLDB { /** * LLDB specific version of MICommand, when LLDB-MI implements all * needed mi command, this class would be no longer needed. */ class DebugSession; class LldbCommand : public MI::MICommand { protected: explicit LldbCommand(MI::CommandType type, const QString& arguments = QString(), - MI::CommandFlags flags = nullptr); + MI::CommandFlags flags = {}); friend class KDevMI::LLDB::DebugSession; public: ~LldbCommand(); QString cmdToSend() override; QString miCommand() const override; private: QString overrideCmd; }; } // end of namespace LLDB } // end of namespace KDevMI #endif // LLDBCOMMAND_H