Newer
Older
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#ifndef WATCHUTILS_H
#define WATCHUTILS_H
#include <QtCore/QString>
QT_END_NAMESPACE
namespace Debugger {
namespace Internal {
QString dotEscape(QString str);
QString currentTime();
bool isSkippableFunction(const QString &funcName, const QString &fileName);
bool isLeavableFunction(const QString &funcName, const QString &fileName);
inline bool isNameChar(char c)
{
// could be 'stopped' or 'shlibs-added'
return (c >= 'a' && c <= 'z') || c == '-';
}
bool hasLetterOrNumber(const QString &exp);
bool hasSideEffects(const QString &exp);
bool isKeyWord(const QString &exp);
bool isPointerType(const QString &type);
bool isAccessSpecifier(const QString &str);
bool startsWithDigit(const QString &str);
QString stripPointerType(QString type);
QString gdbQuoteTypes(const QString &type);
bool extractTemplate(const QString &type, QString *tmplate, QString *inner);
QString extractTypeFromPTypeOutput(const QString &str);
bool isIntOrFloatType(const QString &type);
QString sizeofTypeExpression(const QString &type);
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Decode string data as returned by the dumper helpers.
QString decodeData(const QByteArray &baIn, int encoding);
// Result of a dumper call.
struct QtDumperResult
{
struct Child {
Child();
int valueEncoded;
QString name;
QString address;
QByteArray value;
};
QtDumperResult();
void clear();
QList<WatchData> toWatchData(int source = 0) const;
QString iname;
QString address;
QString type;
QByteArray value;
int valueEncoded;
bool valuedisabled;
int childCount;
bool internal;
QString childType;
QList <Child> children;
};
QDebug operator<<(QDebug in, const QtDumperResult &d);
/* Attempt to put common code of the dumper handling into a helper
* class.
* "Custom dumper" is a library compiled against the current
* Qt containing functions to evaluate values of Qt classes
* (such as QString, taking pointers to their addresses).
* The library must be loaded into the debuggee.
* It provides a function that takes input from an input buffer
* and some parameters and writes output into an output buffer.
* Parameter 1 is the protocol:
* 1) Query. Fills output buffer with known types, Qt version and namespace.
* This information is parsed and stored by this class (special type
* enumeration).
* 2) Evaluate symbol, taking address and some additional parameters
* depending on type. */
class QtDumperHelper {
public:
enum Debugger {
GdbDebugger, // Can evalulate expressions in function calls
CdbDebugger // Can only handle scalar, simple types in function calls
};
enum Type {
UnknownType,
SupportedType, // A type that requires no special handling by the dumper
// Below types require special handling
QObjectType, QWidgetType, QObjectSlotType, QObjectSignalType,
QVectorType, QMapType, QMultiMapType, QMapNodeType,
StdVectorType, StdDequeType, StdSetType,StdMapType, StdStackType,
StdStringType
};
// Type/Parameter struct required for building a value query
struct TypeData {
TypeData();
void clear();
Type type;
bool isTemplate;
QString tmplate;
QString inner;
};
QtDumperHelper();
void clear();
int typeCount() const;
// Look up a simple, non-template type
Type simpleType(const QString &simpleType) const;
// Look up a (potentially) template type and fill parameter struct
TypeData typeData(const QString &typeName) const;
Type type(const QString &typeName) const;
int qtVersion() const;
QString qtVersionString() const;
void setQtVersion(int v);
void setQtVersion(const QString &v);
QString qtNamespace() const;
void setQtNamespace(const QString &qtNamespace);
// Complete parse of "query" (protocol 1) response from debuggee buffer.
// 'data' excludes the leading indicator character.
bool parseQuery(const char *data, Debugger debugger);
// Set up from pre-parsed type list
void parseQueryTypes(const QStringList &l, Debugger debugger);
// Determine the parameters required for an "evaluate" (protocol 2) call
void evaluationParameters(const WatchData &data,
const TypeData &td,
Debugger debugger,
QByteArray *inBuffer,
QStringList *extraParameters) const;
// Parse the value response (protocol 2) from debuggee buffer.
// 'data' excludes the leading indicator character.
static bool parseValue(const char *data, QtDumperResult *r);
static bool needsExpressionSyntax(Type t);
QString toString(bool debug = false) const;
private:
typedef QMap<QString, Type> NameTypeMap;
// Look up a simple (namespace) type
static Type specialType(QString s);
NameTypeMap m_nameTypeMap;
int m_qtVersion;
QString m_qtNamespace;
};
} // namespace Internal
} // namespace Debugger
#endif // WATCHUTILS_H