1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 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 DEBUGGER_TRK_UTILS
|
---|
43 | #define DEBUGGER_TRK_UTILS
|
---|
44 |
|
---|
45 | #include <QtCore/QByteArray>
|
---|
46 | #include <QtCore/QHash>
|
---|
47 | #include <QtCore/QStringList>
|
---|
48 | #include <QtCore/QVariant>
|
---|
49 |
|
---|
50 | typedef unsigned char byte;
|
---|
51 |
|
---|
52 | QT_BEGIN_NAMESPACE
|
---|
53 | class QDateTime;
|
---|
54 | QT_END_NAMESPACE
|
---|
55 |
|
---|
56 | namespace trk {
|
---|
57 |
|
---|
58 | enum Command {
|
---|
59 | TrkPing = 0x00,
|
---|
60 | TrkConnect = 0x01,
|
---|
61 | TrkDisconnect = 0x02,
|
---|
62 | TrkVersions = 0x04,
|
---|
63 | TrkSupported = 0x05,
|
---|
64 | TrkCpuType = 0x06,
|
---|
65 | TrkHostVersions = 0x09,
|
---|
66 | TrkContinue = 0x18,
|
---|
67 | TrkCreateItem = 0x40,
|
---|
68 | TrkDeleteItem = 0x41,
|
---|
69 |
|
---|
70 | TrkWriteFile = 0x48,
|
---|
71 | TrkOpenFile = 0x4a,
|
---|
72 | TrkCloseFile = 0x4b,
|
---|
73 | TrkInstallFile = 0x4d,
|
---|
74 | TrkInstallFile2 = 0x4e,
|
---|
75 |
|
---|
76 | TrkNotifyAck = 0x80,
|
---|
77 | TrkNotifyNak = 0xff,
|
---|
78 | TrkNotifyStopped = 0x90,
|
---|
79 | TrkNotifyException = 0x91,
|
---|
80 | TrkNotifyInternalError = 0x92,
|
---|
81 | TrkNotifyCreated = 0xa0,
|
---|
82 | TrkNotifyDeleted = 0xa1,
|
---|
83 | TrkNotifyProcessorStarted = 0xa2,
|
---|
84 | TrkNotifyProcessorStandBy = 0xa6,
|
---|
85 | TrkNotifyProcessorReset = 0xa7
|
---|
86 | };
|
---|
87 |
|
---|
88 | QByteArray decode7d(const QByteArray &ba);
|
---|
89 | QByteArray encode7d(const QByteArray &ba);
|
---|
90 |
|
---|
91 | inline byte extractByte(const char *data) { return *data; }
|
---|
92 | ushort extractShort(const char *data);
|
---|
93 | uint extractInt(const char *data);
|
---|
94 |
|
---|
95 | QString quoteUnprintableLatin1(const QByteArray &ba);
|
---|
96 |
|
---|
97 | // produces "xx xx xx "
|
---|
98 | QString stringFromArray(const QByteArray &ba, int maxLen = - 1);
|
---|
99 |
|
---|
100 | enum Endianness
|
---|
101 | {
|
---|
102 | LittleEndian,
|
---|
103 | BigEndian,
|
---|
104 | TargetByteOrder = BigEndian,
|
---|
105 | };
|
---|
106 |
|
---|
107 | void appendByte(QByteArray *ba, byte b);
|
---|
108 | void appendShort(QByteArray *ba, ushort s, Endianness = TargetByteOrder);
|
---|
109 | void appendInt(QByteArray *ba, uint i, Endianness = TargetByteOrder);
|
---|
110 | void appendString(QByteArray *ba, const QByteArray &str, Endianness = TargetByteOrder, bool appendNullTerminator = true);
|
---|
111 | void appendDateTime(QByteArray *ba, QDateTime dateTime, Endianness = TargetByteOrder);
|
---|
112 |
|
---|
113 | struct Library
|
---|
114 | {
|
---|
115 | Library() {}
|
---|
116 |
|
---|
117 | QByteArray name;
|
---|
118 | uint codeseg;
|
---|
119 | uint dataseg;
|
---|
120 | };
|
---|
121 |
|
---|
122 | struct TrkAppVersion
|
---|
123 | {
|
---|
124 | TrkAppVersion();
|
---|
125 | void reset();
|
---|
126 |
|
---|
127 | int trkMajor;
|
---|
128 | int trkMinor;
|
---|
129 | int protocolMajor;
|
---|
130 | int protocolMinor;
|
---|
131 | };
|
---|
132 |
|
---|
133 | struct Session
|
---|
134 | {
|
---|
135 | Session();
|
---|
136 | void reset();
|
---|
137 | QString deviceDescription(unsigned verbose) const;
|
---|
138 |
|
---|
139 | // Trk feedback
|
---|
140 | byte cpuMajor;
|
---|
141 | byte cpuMinor;
|
---|
142 | byte bigEndian;
|
---|
143 | byte defaultTypeSize;
|
---|
144 | byte fpTypeSize;
|
---|
145 | byte extended1TypeSize;
|
---|
146 | byte extended2TypeSize;
|
---|
147 | TrkAppVersion trkAppVersion;
|
---|
148 | uint pid;
|
---|
149 | uint tid;
|
---|
150 | uint codeseg;
|
---|
151 | uint dataseg;
|
---|
152 | QHash<uint, uint> addressToBP;
|
---|
153 |
|
---|
154 | typedef QList<Library> Libraries;
|
---|
155 | Libraries libraries;
|
---|
156 |
|
---|
157 | typedef uint Thread;
|
---|
158 | typedef QList<Thread> Threads;
|
---|
159 | Threads threads;
|
---|
160 |
|
---|
161 | // Gdb request
|
---|
162 | uint currentThread;
|
---|
163 | QStringList modules;
|
---|
164 | };
|
---|
165 |
|
---|
166 | struct TrkResult
|
---|
167 | {
|
---|
168 | TrkResult();
|
---|
169 | void clear();
|
---|
170 | QString toString() const;
|
---|
171 | // 0 for no error.
|
---|
172 | int errorCode() const;
|
---|
173 | QString errorString() const;
|
---|
174 |
|
---|
175 | byte code;
|
---|
176 | byte token;
|
---|
177 | QByteArray data;
|
---|
178 | QVariant cookie;
|
---|
179 | bool isDebugOutput;
|
---|
180 | };
|
---|
181 |
|
---|
182 | // returns a QByteArray containing optionally
|
---|
183 | // the serial frame [0x01 0x90 <len>] and 0x7e encoded7d(ba) 0x7e
|
---|
184 | QByteArray frameMessage(byte command, byte token, const QByteArray &data, bool serialFrame);
|
---|
185 | ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame);
|
---|
186 | bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, QByteArray *rawData = 0);
|
---|
187 | QByteArray errorMessage(byte code);
|
---|
188 | QByteArray hexNumber(uint n, int digits = 0);
|
---|
189 | QByteArray hexxNumber(uint n, int digits = 0); // prepends '0x', too
|
---|
190 | uint swapEndian(uint in);
|
---|
191 |
|
---|
192 | } // namespace trk
|
---|
193 |
|
---|
194 | #endif // DEBUGGER_TRK_UTILS
|
---|