1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Author: Frank Osterfeld, KDAB (frank.osterfeld@kdab.com)
9 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** No Commercial Usage
13 ** This file contains pre-release code and may not be distributed.
14 ** You may use this file in accordance with the terms and conditions
15 ** contained in the Technology Preview License Agreement accompanying
18 ** GNU Lesser General Public License Usage
20 ** Alternatively, this file may be used under the terms of the GNU Lesser
21 ** General Public License version 2.1 as published by the Free Software
22 ** Foundation and appearing in the file LICENSE.LGPL included in the
23 ** packaging of this file. Please review the following information to
24 ** ensure the GNU Lesser General Public License version 2.1 requirements
25 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
27 ** In addition, as a special exception, Nokia gives you certain additional
28 ** rights. These rights are described in the Nokia Qt LGPL Exception
29 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
31 ** If you have questions regarding the use of this file, please contact
32 ** Nokia at qt-info@nokia.com.
34 **************************************************************************/
39 #include "suppression.h"
41 #include <QtCore/QSharedData>
42 #include <QtCore/QString>
43 #include <QtCore/QTextStream>
44 #include <QtCore/QVector>
46 #include <QtCore/QtAlgorithms>
48 using namespace Valgrind;
49 using namespace Valgrind::XmlProtocol;
51 class Error::Private : public QSharedData {
66 QVector<Stack> stacks;
67 Suppression suppression;
72 bool operator==(const Private &other) const
74 return unique == other.unique
78 && stacks == other.stacks
79 && suppression == other.suppression
80 && leakedBytes == other.leakedBytes
81 && leakedBlocks == other.leakedBlocks
82 && hThreadId == other.hThreadId;
95 Error::Error(const Error &other) :
100 void Error::swap(Error &other)
105 Error &Error::operator=(const Error &other)
112 bool Error::operator ==(const Error &other) const
114 return *d == *other.d;
117 bool Error::operator !=(const Error &other) const
119 return !(*d == *other.d);
122 Suppression Error::suppression() const
124 return d->suppression;
127 void Error::setSuppression(const Suppression &supp)
129 d->suppression = supp;
132 qint64 Error::unique() const
137 void Error::setUnique(qint64 unique)
142 qint64 Error::tid() const
147 void Error::setTid(qint64 tid)
152 quint64 Error::leakedBytes() const
154 return d->leakedBytes;
157 void Error::setLeakedBytes(quint64 l)
162 qint64 Error::leakedBlocks() const
164 return d->leakedBlocks;
167 void Error::setLeakedBlocks(qint64 b)
172 QString Error::what() const
177 void Error::setWhat(const QString &what)
182 int Error::kind() const
187 void Error::setKind(int k)
192 QVector<Stack> Error::stacks() const
197 void Error::setStacks(const QVector<Stack> &stacks)
202 void Error::setHelgrindThreadId(qint64 id)
207 qint64 Error::helgrindThreadId() const
212 QString Error::toXml() const
215 QTextStream stream(&xml);
216 stream << "<error>\n";
217 stream << " <unique>" << d->unique << "</unique>\n";
218 stream << " <tid>" << d->tid << "</tid>\n";
219 stream << " <kind>" << d->kind << "</kind>\n";
220 if (d->leakedBlocks > 0 && d->leakedBytes > 0) {
221 stream << " <xwhat>\n"
222 << " <text>" << d->what << "</text>\n"
223 << " <leakedbytes>" << d->leakedBytes << "</leakedbytes>\n"
224 << " <leakedblocks>" << d->leakedBlocks << "</leakedblocks>\n"
227 stream << " <what>" << d->what << "</what>\n";
230 foreach(const Stack &stack, d->stacks) {
231 if (!stack.auxWhat().isEmpty()) {
232 stream << " <auxwhat>" << stack.auxWhat() << "</auxwhat>\n";
234 stream << " <stack>\n";
236 foreach(const Frame &frame, stack.frames()) {
237 stream << " <frame>\n";
238 stream << " <ip>0x" << QString::number(frame.instructionPointer(), 16) << "</ip>\n";
239 if (!frame.object().isEmpty()) {
240 stream << " <obj>" << frame.object() << "</obj>\n";
242 if (!frame.functionName().isEmpty()) {
243 stream << " <fn>" << frame.functionName() << "</fn>\n";
245 if (!frame.directory().isEmpty()) {
246 stream << " <dir>" << frame.directory() << "</dir>\n";
248 if (!frame.file().isEmpty()) {
249 stream << " <file>" << frame.file() << "</file>\n";
251 if (!frame.line() == -1) {
252 stream << " <line>" << frame.line() << "</line>";
254 stream << " </frame>\n";
257 stream << " </stack>\n";
260 stream << "</error>\n";