OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / breakhandler.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef DEBUGGER_BREAKHANDLER_H
35 #define DEBUGGER_BREAKHANDLER_H
36
37 #include "breakpoint.h"
38
39 #include <QtCore/QObject>
40 #include <QtCore/QAbstractTableModel>
41
42 #include <QtGui/QIcon>
43
44 //////////////////////////////////////////////////////////////////
45 //
46 // BreakHandler
47 //
48 //////////////////////////////////////////////////////////////////
49
50 namespace Debugger {
51
52 class DebuggerEngine;
53
54 namespace Internal {
55
56 class BreakpointMarker;
57
58 class BreakHandler : public QAbstractTableModel
59 {
60     Q_OBJECT
61
62 public:
63     BreakHandler();
64     ~BreakHandler();
65
66     void loadSessionData();
67     void saveSessionData();
68     void removeSessionData();
69
70     QAbstractItemModel *model() { return this; }
71
72     // The only way to add a new breakpoint.
73     void appendBreakpoint(const BreakpointParameters &data);
74
75     BreakpointIds allBreakpointIds() const;
76     BreakpointIds engineBreakpointIds(DebuggerEngine *engine) const;
77     BreakpointIds unclaimedBreakpointIds() const;
78     int size() const { return m_storage.size(); }
79
80     // Find a breakpoint matching approximately the data in needle.
81     BreakpointId findSimilarBreakpoint(const BreakpointResponse &needle) const;
82     BreakpointId findBreakpointByNumber(int bpNumber) const;
83     BreakpointId findWatchpointByAddress(quint64 address) const;
84     BreakpointId findBreakpointByFunction(const QString &functionName) const;
85     BreakpointId findBreakpointByIndex(const QModelIndex &index) const;
86     BreakpointIds findBreakpointsByIndex(const QList<QModelIndex> &list) const;
87     void setWatchpointByAddress(quint64 address);
88     bool hasWatchpointAt(quint64 address) const;
89     void updateMarkers();
90
91     static QIcon breakpointIcon();
92     static QIcon disabledBreakpointIcon();
93     static QIcon pendingBreakpointIcon();
94     static QIcon emptyIcon();
95     static QIcon watchpointIcon();
96     static QIcon tracepointIcon();
97
98     BreakpointId findBreakpointByFileAndLine(const QString &fileName,
99         int lineNumber, bool useMarkerPosition = true);
100     BreakpointId findBreakpointByAddress(quint64 address) const;
101
102     void breakByFunction(const QString &functionName);
103     void removeBreakpoint(BreakpointId id);
104     QIcon icon(BreakpointId id) const;
105     void gotoLocation(BreakpointId id) const;
106
107     // Getter retrieves property value.
108     // Setter sets property value and triggers update if changed.
109     bool useFullPath(BreakpointId id) const;
110     void setUseFullPath(BreakpointId, const bool &on);
111     QByteArray condition(BreakpointId id) const;
112     void setCondition(BreakpointId, const QByteArray &condition);
113     int ignoreCount(BreakpointId id) const;
114     void setIgnoreCount(BreakpointId, const int &count);
115     int threadSpec(BreakpointId id) const;
116     void setThreadSpec(BreakpointId, const int&spec);
117     QString fileName(BreakpointId id) const;
118     void setFileName(BreakpointId, const QString &fileName);
119     QString functionName(BreakpointId id) const;
120     void setFunctionName(BreakpointId, const QString &functionName);
121     BreakpointType type(BreakpointId id) const;
122     void setType(BreakpointId id, const BreakpointType &type);
123     quint64 address(BreakpointId id) const;
124     void setAddress(BreakpointId id, const quint64 &address);
125     int lineNumber(BreakpointId id) const;
126     void setBreakpointData(BreakpointId id, const BreakpointParameters &data);
127     const BreakpointParameters &breakpointData(BreakpointId id) const;
128     BreakpointState state(BreakpointId id) const;
129     bool isEnabled(BreakpointId id) const;
130     void setEnabled(BreakpointId id, bool on);
131     void updateLineNumberFromMarker(BreakpointId id, int lineNumber);
132     void setMarkerFileAndLine(BreakpointId id,
133         const QString &fileName, int lineNumber);
134     bool isTracepoint(BreakpointId id) const;
135     void setTracepoint(BreakpointId, bool on);
136     DebuggerEngine *engine(BreakpointId id) const;
137     void setEngine(BreakpointId id, DebuggerEngine *engine);
138     const BreakpointResponse &response(BreakpointId id) const;
139     void setResponse(BreakpointId id, const BreakpointResponse &data);
140     bool needsChange(BreakpointId id) const;
141
142     // State transitions.
143     void notifyBreakpointChangeAfterInsertNeeded(BreakpointId id);
144     void notifyBreakpointInsertProceeding(BreakpointId id);
145     void notifyBreakpointInsertOk(BreakpointId id);
146     void notifyBreakpointInsertFailed(BreakpointId id);
147     void notifyBreakpointChangeOk(BreakpointId id);
148     void notifyBreakpointChangeProceeding(BreakpointId id);
149     void notifyBreakpointChangeFailed(BreakpointId id);
150     void notifyBreakpointPending(BreakpointId id);
151     void notifyBreakpointRemoveProceeding(BreakpointId id);
152     void notifyBreakpointRemoveOk(BreakpointId id);
153     void notifyBreakpointRemoveFailed(BreakpointId id);
154     void notifyBreakpointReleased(BreakpointId id);
155     void notifyBreakpointNeedsReinsertion(BreakpointId id);
156     void notifyBreakpointAdjusted(BreakpointId id,
157             const BreakpointParameters &data);
158
159     static QString displayFromThreadSpec(int spec);
160     static int threadSpecFromDisplay(const QString &str);
161
162 private:
163     // QAbstractItemModel implementation.
164     int columnCount(const QModelIndex &parent) const;
165     int rowCount(const QModelIndex &parent) const;
166     QVariant data(const QModelIndex &index, int role) const;
167     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
168     Qt::ItemFlags flags(const QModelIndex &index) const;
169
170     void setState(BreakpointId id, BreakpointState state);
171     void loadBreakpoints();
172     void saveBreakpoints();
173     void updateMarker(BreakpointId id);
174     void cleanupBreakpoint(BreakpointId id);
175
176     struct BreakpointItem
177     {
178         BreakpointItem();
179
180         void destroyMarker();
181         bool needsChange() const;
182         bool isLocatedAt(const QString &fileName, int lineNumber,
183             bool useMarkerPosition) const;
184         QString toToolTip() const;
185         QString markerFileName() const;
186         int markerLineNumber() const;
187         QIcon icon() const;
188
189         BreakpointParameters data;
190         BreakpointState state;   // Current state of breakpoint.
191         DebuggerEngine *engine;  // Engine currently handling the breakpoint.
192         BreakpointResponse response;
193         BreakpointMarker *marker;
194     };
195     typedef QHash<BreakpointId, BreakpointItem> BreakpointStorage;
196     typedef BreakpointStorage::ConstIterator ConstIterator;
197     typedef BreakpointStorage::Iterator Iterator;
198     BreakpointStorage m_storage;
199
200     void scheduleSynchronization();
201     void timerEvent(QTimerEvent *event);
202     int m_syncTimerId;
203 };
204
205 } // namespace Internal
206 } // namespace Debugger
207
208 #endif // DEBUGGER_BREAKHANDLER_H