OSDN Git Service

f61fdeba4fbb949fcc27546a51f70b8df57897af
[qt-creator-jp/qt-creator-jp.git] / src / shared / symbianutils / codamessage.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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at info@qt.nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef CODAMESSAGE_H
34 #define CODAMESSAGE_H
35
36 #include "symbianutils_global.h"
37
38 #include <QtCore/QStringList>
39 #include <QtCore/QVector>
40
41 QT_BEGIN_NAMESPACE
42 class QTextStream;
43 QT_END_NAMESPACE
44
45 namespace Coda {
46
47 class JsonValue;
48 class JsonInputStream;
49
50 enum Services {
51     LocatorService,
52     RunControlService,
53     ProcessesService,
54     MemoryService,
55     SettingsService,  // non-standard, CODA specific
56     BreakpointsService,
57     RegistersService,
58     LoggingService,    // non-standard, CODA specific
59     FileSystemService,
60     SymbianInstallService,    // non-standard, CODA specific
61     SymbianOSData,    // non-standard, CODA specific
62     DebugSessionControl,    // non-standard, CODA specific
63     UnknownService
64 }; // Note: Check string array 'serviceNamesC' of same size when modifying this.
65
66 // Modes of RunControl/'Resume' (see EDF documentation).
67 // As of 24.6.2010, RM_RESUME, RM_STEP_OVER, RM_STEP_INTO,
68 // RM_STEP_OVER_RANGE, RM_STEP_INTO_RANGE are supported with
69 // RANG_START/RANGE_END parameters.
70 enum RunControlResumeMode {
71     RM_RESUME = 0,
72     RM_STEP_OVER = 1, RM_STEP_INTO = 2,
73     RM_STEP_OVER_LINE = 3, RM_STEP_INTO_LINE = 4,
74     RM_STEP_OUT = 5, RM_REVERSE_RESUME = 6,
75     RM_REVERSE_STEP_OVER = 7, RM_REVERSE_STEP_INTO = 8,
76     RM_REVERSE_STEP_OVER_LINE = 9, RM_REVERSE_STEP_INTO_LINE = 10,
77     RM_REVERSE_STEP_OUT = 11, RM_STEP_OVER_RANGE = 12,
78     RM_STEP_INTO_RANGE = 13, RM_REVERSE_STEP_OVER_RANGE = 14,
79     RM_REVERSE_STEP_INTO_RANGE = 15
80 };
81
82 SYMBIANUTILS_EXPORT const char *serviceName(Services s);
83 SYMBIANUTILS_EXPORT Services serviceFromName(const char *);
84
85 // Debug helpers
86 SYMBIANUTILS_EXPORT QString formatData(const QByteArray &a);
87 SYMBIANUTILS_EXPORT QString joinByteArrays(const QVector<QByteArray> &a, char sep = ',');
88
89 // Context used in 'RunControl contextAdded' events and in reply
90 // to 'Processes start'. Could be thread or process.
91 struct SYMBIANUTILS_EXPORT RunControlContext {
92     enum Flags {
93         Container = 0x1, HasState = 0x2, CanSuspend = 0x4,
94         CanTerminate = 0x8
95     };
96     enum Type { Process, Thread };
97
98     RunControlContext();
99     Type type() const;
100     unsigned processId() const;
101     unsigned threadId() const;
102
103     void clear();
104     bool parse(const JsonValue &v);
105     void format(QTextStream &str) const;
106     QString toString() const;
107
108     // Helper for converting the CODA ids ("p12" or "p12.t34")
109     static Type typeFromCodaId(const QByteArray &id);
110     static unsigned processIdFromTcdfId(const QByteArray &id);
111     static unsigned threadIdFromTcdfId(const QByteArray &id);
112     static QByteArray codaId(unsigned processId,  unsigned threadId = 0);
113
114     unsigned flags;
115     unsigned resumeFlags;
116     QByteArray id;     // "p434.t699"
117     QByteArray osid;   // Non-standard: Process or thread id
118     QByteArray parentId; // Parent process id of a thread.
119 };
120
121 // Module load information occurring with 'RunControl contextSuspended' events
122 struct SYMBIANUTILS_EXPORT ModuleLoadEventInfo {
123     ModuleLoadEventInfo();
124     void clear();
125     bool parse(const JsonValue &v);
126     void format(QTextStream &str) const;
127
128     QByteArray name;
129     QByteArray file;
130     bool loaded;
131     quint64 codeAddress;
132     quint64 dataAddress;
133     bool requireResume;
134 };
135
136 // Breakpoint as supported by Coda source June 2010
137 // TODO: Add watchpoints,etc once they are implemented
138 struct SYMBIANUTILS_EXPORT Breakpoint {
139     enum Type { Software, Hardware, Auto };
140
141     explicit Breakpoint(quint64 loc = 0);
142     void setContextId(unsigned processId, unsigned threadId = 0);
143     QString toString() const;
144
145     static QByteArray idFromLocation(quint64 loc); // Automagically determine from location
146
147     Type type;
148     bool enabled;
149     int ignoreCount;
150     QVector<QByteArray> contextIds;   // Process or thread ids.
151     QByteArray id;                    // Id of the breakpoint;
152     quint64 location;
153     unsigned size;
154     bool thumb;
155 };
156
157 SYMBIANUTILS_EXPORT JsonInputStream &operator<<(JsonInputStream &str, const Breakpoint &b);
158
159 // Event hierarchy
160 class SYMBIANUTILS_EXPORT CodaEvent
161 {
162     Q_DISABLE_COPY(CodaEvent)
163
164 public:
165     enum Type { None,
166                 LocatorHello,
167                 RunControlContextAdded,
168                 RunControlContextRemoved,
169                 RunControlSuspended,
170                 RunControlBreakpointSuspended,
171                 RunControlModuleLoadSuspended,
172                 RunControlResumed,
173                 LoggingWriteEvent, // Non-standard
174                 ProcessExitedEvent // Non-standard
175               };
176
177     virtual ~CodaEvent();
178
179     Type type() const;
180     virtual QString toString() const;
181
182     static CodaEvent *parseEvent(Services s, const QByteArray &name, const QVector<JsonValue> &val);
183
184 protected:
185     explicit CodaEvent(Type type = None);
186
187 private:
188     const Type m_type;
189 };
190
191 // ServiceHello
192 class SYMBIANUTILS_EXPORT CodaLocatorHelloEvent : public CodaEvent {
193 public:
194     explicit CodaLocatorHelloEvent(const QStringList &);
195
196     const QStringList &services() const { return m_services; }
197     virtual QString toString() const;
198
199 private:
200     QStringList m_services;
201 };
202
203 // Logging event (non-standard, CODA specific)
204 class SYMBIANUTILS_EXPORT CodaLoggingWriteEvent : public CodaEvent {
205 public:
206     explicit CodaLoggingWriteEvent(const QByteArray &console, const QByteArray &message);
207
208     QByteArray message() const { return m_message; }
209     QByteArray console() const { return m_console; }
210
211     virtual QString toString() const;
212
213 private:
214     const QByteArray m_console;
215     const QByteArray m_message;
216 };
217
218 // Base for events that just have one id as parameter
219 // (simple suspend)
220 class SYMBIANUTILS_EXPORT CodaIdEvent : public CodaEvent {
221 protected:
222     explicit CodaIdEvent(Type t, const QByteArray &id);
223 public:
224     QByteArray id() const { return m_id; }
225     QString idString() const { return QString::fromUtf8(m_id); }
226
227 private:
228     const QByteArray m_id;
229 };
230
231 // Base for events that just have some ids as parameter
232 // (context removed)
233 class SYMBIANUTILS_EXPORT CodaIdsEvent : public CodaEvent {
234 protected:
235     explicit CodaIdsEvent(Type t, const QVector<QByteArray> &ids);
236
237 public:
238     QVector<QByteArray> ids() const { return m_ids; }
239     QString joinedIdString(const char sep = ',') const;
240
241 private:
242     const QVector<QByteArray> m_ids;
243 };
244
245 // RunControlContextAdded
246 class SYMBIANUTILS_EXPORT CodaRunControlContextAddedEvent : public CodaEvent {
247 public:
248     typedef QVector<RunControlContext> RunControlContexts;
249
250     explicit CodaRunControlContextAddedEvent(const RunControlContexts &c);
251
252     const RunControlContexts &contexts() const { return m_contexts; }
253     virtual QString toString() const;
254
255     static CodaRunControlContextAddedEvent *parseEvent(const QVector<JsonValue> &val);
256
257 private:
258     const RunControlContexts m_contexts;
259 };
260
261 // RunControlContextRemoved
262 class SYMBIANUTILS_EXPORT CodaRunControlContextRemovedEvent : public CodaIdsEvent {
263 public:
264     explicit CodaRunControlContextRemovedEvent(const QVector<QByteArray> &id);
265     virtual QString toString() const;
266 };
267
268 // Simple RunControlContextSuspended (process/thread)
269 class SYMBIANUTILS_EXPORT CodaRunControlContextSuspendedEvent : public CodaIdEvent {
270 public:
271     enum Reason  { BreakPoint, ModuleLoad, Crash, Other } ;
272
273     explicit CodaRunControlContextSuspendedEvent(const QByteArray &id,
274                                                    const QByteArray &reason,
275                                                    const QByteArray &message,
276                                                    quint64 pc = 0);
277     virtual QString toString() const;
278
279     quint64 pc() const { return m_pc; }
280     QByteArray reasonID() const { return m_reason; }
281     Reason reason() const;
282     QByteArray message() const { return m_message; }
283
284 protected:
285     explicit CodaRunControlContextSuspendedEvent(Type t,
286                                                    const QByteArray &id,
287                                                    const QByteArray &reason,
288                                                    quint64 pc = 0);
289     void format(QTextStream &str) const;
290
291 private:
292     const quint64 m_pc;
293     const QByteArray m_reason;
294     const QByteArray m_message;
295 };
296
297 // RunControlContextSuspended due to module load
298 class SYMBIANUTILS_EXPORT CodaRunControlModuleLoadContextSuspendedEvent : public CodaRunControlContextSuspendedEvent {
299 public:
300     explicit CodaRunControlModuleLoadContextSuspendedEvent(const QByteArray &id,
301                                                              const QByteArray &reason,
302                                                              quint64 pc,
303                                                              const ModuleLoadEventInfo &mi);
304
305     virtual QString toString() const;
306     const ModuleLoadEventInfo &info() const { return m_mi; }
307
308 private:
309     const ModuleLoadEventInfo m_mi;
310 };
311
312 // Process exited event
313 class SYMBIANUTILS_EXPORT CodaProcessExitedEvent : public CodaEvent {
314 public:
315     explicit CodaProcessExitedEvent(const QByteArray &id);
316
317     QByteArray id() const { return m_id; }
318     QString idString() const { return QString::fromUtf8(m_id); }
319     virtual QString toString() const;
320
321 private:
322     const QByteArray m_id;
323 };
324
325 } // namespace Coda
326 #endif // CODAMESSAGE_H