1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef SYMBIANUTILS_H
35 #define SYMBIANUTILS_H
37 #include <QtCore/QMap>
38 #include <QtCore/QByteArray>
39 #include <QtCore/QMetaType>
40 #include <QtCore/QVector>
41 #include <QtCore/QPair>
47 //#define DEBUG_MEMORY 1
49 # define MEMORY_DEBUG(s) qDebug() << s
51 # define MEMORY_DEBUG(s)
53 #define MEMORY_DEBUGX(s) qDebug() << s
57 class RegisterHandler;
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; }
74 uint from; // Inclusive.
75 uint to; // Exclusive.
78 QDebug operator<<(QDebug d, const MemoryRange &range);
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
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
103 MemoryChunkSize = 256
106 enum { KnownRegisters = RegisterPSGdb + 1};
108 const char *registerName(int i);
109 QByteArray dumpRegister(uint n, uint value);
111 inline bool isReadOnly(const MemoryRange &mr)
113 return mr.from >= 0x70000000 && mr.to < 0x80000000;
116 // Snapshot thread with cached registers
118 explicit Thread(unsigned id = 0);
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;
129 uint registers[RegisterCount];
131 QString state; // Stop reason, for qsThreadExtraInfo
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;
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);
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&);
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;
171 QVector<Thread> threadInfo;
173 typedef QMap<MemoryRange, QByteArray> Memory;
177 MemoryRange wantedMemory;
180 uint lineFromAddress;
187 Breakpoint(uint offset_ = 0)
199 extern const char *gdbQSupported;
200 extern const char *gdbArchitectureXml;
202 QVector<QByteArray> gdbStartupSequence();
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,
211 QString msgLoadLocalSymFile(const QString &symFileName,
212 const QByteArray &libName, quint64 code);
214 } // namespace Symbian
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);
223 } // namespace Internal
224 } // namespace Debugger
226 Q_DECLARE_METATYPE(Debugger::Internal::MemoryRange)
228 #endif // SYMBIANUTILS_H