File indexing completed on 2024-05-12 04:37:36

0001 /*
0002     SPDX-FileCopyrightText: 2009 Vladimir Prus <ghost@cs.msu.su>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_IFRAMESTACKMODEL_H
0008 #define KDEVPLATFORM_IFRAMESTACKMODEL_H
0009 
0010 #include "idebugsession.h"
0011 
0012 #include <QUrl>
0013 
0014 #include <QAbstractItemModel>
0015 #include <QString>
0016 
0017 namespace KDevelop {
0018 class IFrameStackModelPrivate;
0019 
0020 class KDEVPLATFORMDEBUGGER_EXPORT IFrameStackModel : public QAbstractItemModel
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     /** Stack frame */
0026     struct FrameItem {
0027         int nr;
0028         QString name;
0029         QUrl file;
0030         /* If -1, it means that file is not necessary a source file,
0031            but possibly a solib name.  */
0032         int line;
0033     };
0034 
0035     explicit IFrameStackModel(IDebugSession *session);
0036     ~IFrameStackModel() override;
0037 
0038     IDebugSession* session() const;
0039 
0040     /** Sets the current thread to the specified number,
0041        and sets the current frame to 0.
0042        Note that nothing prevents us from introducing
0043        setCurrentThreadAndFrame, but for all the cases when we
0044        switch to a different thread we want frame 0.  */
0045     virtual void setCurrentThread(int threadNumber) = 0;
0046     virtual void setCurrentThread(const QModelIndex &index) = 0;
0047     virtual int currentThread() const = 0;
0048     virtual QModelIndex currentThreadIndex() const = 0;
0049 
0050     /** Return the frame we wish to operate on.  This is always
0051        in context of the current thread.  This may be -1 if
0052        no frame is selected. This should only the be the case
0053        if the thread has no stack as such -- e.g. because it's
0054        running, or because it's exited.  */
0055     virtual int currentFrame() const = 0;
0056     virtual QModelIndex currentFrameIndex() const = 0;
0057     virtual void setCurrentFrame(int frame) = 0;
0058 
0059     virtual FrameItem frame(const QModelIndex &index) = 0;
0060 
0061     virtual void fetchThreads() = 0;
0062     virtual void fetchFrames(int threadNumber, int from, int to) = 0;
0063     virtual void fetchMoreFrames() = 0;
0064 
0065 Q_SIGNALS:
0066     /* FIXME: It might make for a more concise interface if those
0067        two were removed, and the clients react to thread_or_frame_changed
0068        event and compare the current thread/frame in the framestack model
0069        with the one they are displaying.  */
0070     void currentThreadChanged(int thread);
0071     void currentFrameChanged(int frame);
0072 
0073 private:
0074     virtual void handleEvent(IDebugSession::event_t event) = 0;
0075 
0076 private:
0077     friend class IDebugSession;
0078     const QScopedPointer<class IFrameStackModelPrivate> d_ptr;
0079     Q_DECLARE_PRIVATE(IFrameStackModel)
0080 };
0081 
0082 }
0083 
0084 Q_DECLARE_TYPEINFO(KDevelop::IFrameStackModel::FrameItem, Q_MOVABLE_TYPE);
0085 
0086 #endif