File indexing completed on 2024-04-28 04:38:34

0001 /*
0002     SPDX-FileCopyrightText: 2002 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
0003     SPDX-FileCopyrightText: 2002 John Firebaugh <jfirebaugh@kde.org>
0004     SPDX-FileCopyrightText: 2007 Hamish Rodda <rodda@kde.org>
0005     SPDX-FileCopyrightText: 2009 Niko Sams <niko.sams@gmail.com>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef MIBREAKPOINTCONTROLLER_H
0011 #define MIBREAKPOINTCONTROLLER_H
0012 
0013 #include "dbgglobal.h"
0014 
0015 #include <debugger/interfaces/ibreakpointcontroller.h>
0016 #include <debugger/interfaces/idebugsession.h>
0017 
0018 namespace KDevMI {
0019 
0020 namespace MI {
0021 struct AsyncRecord;
0022 struct ResultRecord;
0023 struct Value;
0024 }
0025 
0026 struct BreakpointData {
0027     int debuggerId = -1;
0028     KDevelop::BreakpointModel::ColumnFlags dirty;
0029     KDevelop::BreakpointModel::ColumnFlags sent;
0030     KDevelop::BreakpointModel::ColumnFlags errors;
0031     bool pending = false;
0032 
0033     BreakpointData()
0034     {}
0035 };
0036 
0037 using BreakpointDataPtr = QSharedPointer<BreakpointData>;
0038 
0039 class MIDebugSession;
0040 /**
0041 * Handles signals from the editor that relate to breakpoints and the execution
0042 * point of the debugger.
0043 * We may change, add or remove breakpoints in this class.
0044 */
0045 class MIBreakpointController : public KDevelop::IBreakpointController
0046 {
0047     Q_OBJECT
0048 public:
0049     explicit MIBreakpointController(MIDebugSession* parent);
0050 
0051     using IBreakpointController::breakpointModel;
0052 
0053     /**
0054      * Controls whether when duplicate breakpoints are received via async notification from GDB,
0055      * one of the duplicates will be deleted.
0056      */
0057     void setDeleteDuplicateBreakpoints(bool enable);
0058 
0059     void breakpointAdded(int row) override;
0060     void breakpointModelChanged(int row, KDevelop::BreakpointModel::ColumnFlags columns) override;
0061     void breakpointAboutToBeDeleted(int row) override;
0062     void debuggerStateChanged(KDevelop::IDebugSession::DebuggerState) override;
0063 
0064     void notifyBreakpointCreated(const MI::AsyncRecord& r);
0065     void notifyBreakpointModified(const MI::AsyncRecord& r);
0066     void notifyBreakpointDeleted(const MI::AsyncRecord& r);
0067 
0068 public Q_SLOTS:
0069     void initSendBreakpoints();
0070 
0071 private Q_SLOTS:
0072     void programStopped(const MI::AsyncRecord &r);
0073 
0074 private:
0075     MIDebugSession* debugSession() const;
0076 
0077     int breakpointRow(const BreakpointDataPtr& breakpoint);
0078     void createBreakpoint(int row);
0079     void sendUpdates(int row);
0080     void recalculateState(int row);
0081 
0082     void sendMaybe(KDevelop::Breakpoint *breakpoint) override;
0083 
0084     void createFromDebugger(const MI::Value& miBkpt);
0085     void updateFromDebugger(int row, const MI::Value& miBkpt,
0086                             KDevelop::BreakpointModel::ColumnFlags lockedColumns = {});
0087 
0088     int rowFromDebuggerId(int gdbId) const;
0089 
0090     struct Handler;
0091     struct InsertedHandler;
0092     struct UpdateHandler;
0093     struct DeleteHandler;
0094     struct IgnoreChanges;
0095 
0096     QList<BreakpointDataPtr> m_breakpoints;
0097     QList<BreakpointDataPtr> m_pendingDeleted;
0098     int m_ignoreChanges = 0;
0099     bool m_deleteDuplicateBreakpoints = false;
0100 };
0101 
0102 } // end of namespace KDevMI
0103 
0104 #endif // MIBREAKPOINTCONTROLLER_H