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