OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / gdb / symbian.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 SYMBIANUTILS_H
35 #define SYMBIANUTILS_H
36
37 #include <QtCore/QMap>
38 #include <QtCore/QByteArray>
39 #include <QtCore/QMetaType>
40 #include <QtCore/QVector>
41 #include <QtCore/QPair>
42
43 QT_BEGIN_NAMESPACE
44 class QDebug;
45 QT_END_NAMESPACE
46
47 //#define DEBUG_MEMORY  1
48 #if DEBUG_MEMORY
49 #   define MEMORY_DEBUG(s) qDebug() << s
50 #else
51 #   define MEMORY_DEBUG(s)
52 #endif
53 #define MEMORY_DEBUGX(s) qDebug() << s
54
55 namespace Debugger {
56 namespace Internal {
57 class RegisterHandler;
58 class ThreadsHandler;
59 struct GdbResult {
60     QByteArray data;
61 };
62
63 struct MemoryRange
64 {
65     MemoryRange() : from(0), to(0) {}
66     MemoryRange(uint f, uint t);
67     void operator-=(const MemoryRange &other);
68     bool intersects(const MemoryRange &other) const;
69     quint64 hash() const { return (quint64(from) << 32) + to; }
70     bool operator==(const MemoryRange &other) const { return hash() == other.hash(); }
71     bool operator<(const MemoryRange &other) const { return hash() < other.hash(); }
72     uint size() const { return to - from; }
73
74     uint from; // Inclusive.
75     uint to;   // Exclusive.
76 };
77
78 QDebug operator<<(QDebug d, const MemoryRange &range);
79
80 // Signals to be passed to gdb server as stop reason (2 digit hex)
81 enum GdbServerStopReason {
82     gdbServerSignalTrap = 5,     // Trap/Breakpoint, etc.
83     gdbServerSignalSegfault = 11 // Segfault
84 };
85
86 namespace Symbian {
87
88 enum CodeMode
89 {
90     ArmMode = 0,
91     ThumbMode
92 };
93
94 enum TargetConstants
95 {
96     RegisterCount = 17,
97     RegisterSP = 13, // Stack Pointer
98     RegisterLR = 14, // Return address
99     RegisterPC = 15, // Program counter
100     RegisterPSGdb = 25, // gdb's view of the world
101     RegisterPSTrk = 16, // TRK's view of the world
102
103     MemoryChunkSize = 256
104 };
105
106 enum { KnownRegisters = RegisterPSGdb + 1};
107
108 const char *registerName(int i);
109 QByteArray dumpRegister(uint n, uint value);
110
111 inline bool isReadOnly(const MemoryRange &mr)
112 {
113     return  mr.from >= 0x70000000 && mr.to < 0x80000000;
114 }
115
116 // Snapshot thread with cached registers
117 struct Thread {
118     explicit Thread(unsigned id = 0);
119
120     void resetRegisters();
121     // Gdb helpers for reporting values
122     QByteArray gdbReportRegisters() const;
123     QByteArray registerContentsLogMessage() const;
124     QByteArray gdbRegisterLogMessage(bool verbose) const;
125     QByteArray gdbReportSingleRegister(unsigned i) const;
126     QByteArray gdbSingleRegisterLogMessage(unsigned i) const;
127
128     uint id;
129     uint registers[RegisterCount];
130     bool registerValid;
131     QString state; // Stop reason, for qsThreadExtraInfo
132 };
133
134 struct Snapshot
135 {
136     Snapshot();
137
138     void reset(); // Leaves read-only memory cache and threads alive.
139     void resetMemory(); // Completely clears memory, leaves threads alive.
140     void fullReset(); // Clear everything.
141     void insertMemory(const MemoryRange &range, const QByteArray &ba);
142     QString toString() const;
143
144     // Helpers to format gdb query packets
145     QByteArray gdbQsThreadInfo() const;
146     QByteArray gdbQThreadExtraInfo(const QByteArray &cmd) const;
147     // Format a gdb T05 stop message with thread and register set
148     QByteArray gdbStopMessage(uint threadId, int signalNumber, bool reportThreadId) const;
149     // Format a log message for memory access with some smartness about registers
150     QByteArray memoryReadLogMessage(uint addr, uint threadId, bool verbose, const QByteArray &ba) const;
151     // Gdb command parse helpers: 'salnext'
152     void parseGdbStepRange(const QByteArray &cmd, bool stepOver);
153
154     void addThread(uint threadId);
155     void removeThread(uint threadId);
156     int indexOfThread(uint threadId) const;
157     // Access registers by thread
158     const uint *registers(uint threadId) const;
159     uint *registers(uint threadId);
160     uint registerValue(uint threadId, uint index);
161     void setRegisterValue(uint threadId, uint index, uint value);
162     bool registersValid(uint threadId) const;
163     void setRegistersValid(uint threadId, bool e);
164     void setThreadState(uint threadId, const QString&);
165
166     // Debugger view helpers: Synchronize registers of thread with register handler.
167     void syncRegisters(uint threadId, RegisterHandler *handler) const;
168     // Debugger view helpers: Synchronize threads with threads handler.
169     void syncThreads(ThreadsHandler *handler) const;
170
171     QVector<Thread> threadInfo;
172
173     typedef QMap<MemoryRange, QByteArray> Memory;
174     Memory memory;
175
176     // Current state.
177     MemoryRange wantedMemory;
178
179     // For next step.
180     uint lineFromAddress;
181     uint lineToAddress;
182     bool stepOver;
183 };
184
185 struct Breakpoint
186 {
187     Breakpoint(uint offset_ = 0)
188     {
189         number = 0;
190         offset = offset_;
191         mode = ArmMode;
192     }
193     uint offset;
194     ushort number;
195     CodeMode mode;
196 };
197
198 // Gdb helpers
199 extern const char *gdbQSupported;
200 extern const char *gdbArchitectureXml;
201
202 QVector<QByteArray> gdbStartupSequence();
203
204 // Look up in symbol file matching library name in local cache
205 QString localSymFileForLibrary(const QByteArray &libName,
206                                const QString &standardSymDirectory = QString());
207 // Return a load command for a local symbol file for a library
208 QByteArray symFileLoadCommand(const QString &symFileName, quint64 code,
209                               quint64 data = 0);
210 // Utility message
211 QString msgLoadLocalSymFile(const QString &symFileName,
212                             const QByteArray &libName, quint64 code);
213
214 } // namespace Symbian
215
216 // Generic gdb server helpers: read 'm','X' commands.
217 QPair<quint64, unsigned> parseGdbReadMemoryRequest(const QByteArray &cmd);
218 // Parse 'register write' ('P') request, return register number/value
219 QPair<uint, uint> parseGdbWriteRegisterWriteRequest(const QByteArray &cmd);
220 // Parse 'set breakpoint' ('Z0') request, return address/length
221 QPair<quint64, unsigned> parseGdbSetBreakpointRequest(const QByteArray &cmd);
222
223 } // namespace Internal
224 } // namespace Debugger
225
226 Q_DECLARE_METATYPE(Debugger::Internal::MemoryRange)
227
228 #endif // SYMBIANUTILS_H