OSDN Git Service

6b43f4bf7986c8dfd1fc05413b9f3ede000c9990
[qt-creator-jp/qt-creator-jp.git] / src / libs / valgrind / xmlprotocol / error.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Author: Frank Osterfeld, KDAB (frank.osterfeld@kdab.com)
8 **
9 ** Contact: Nokia Corporation (qt-info@nokia.com)
10 **
11 ** No Commercial Usage
12 **
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
16 ** this package.
17 **
18 ** GNU Lesser General Public License Usage
19 **
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.
26 **
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.
30 **
31 ** If you have questions regarding the use of this file, please contact
32 ** Nokia at qt-info@nokia.com.
33 **
34 **************************************************************************/
35
36 #include "error.h"
37 #include "frame.h"
38 #include "stack.h"
39 #include "suppression.h"
40
41 #include <QtCore/QSharedData>
42 #include <QtCore/QString>
43 #include <QtCore/QTextStream>
44 #include <QtCore/QVector>
45
46 #include <QtCore/QtAlgorithms>
47
48 using namespace Valgrind;
49 using namespace Valgrind::XmlProtocol;
50
51 class Error::Private : public QSharedData {
52 public:
53     explicit Private() :
54         unique(0),
55         tid(0),
56         kind(0),
57         leakedBytes(0),
58         leakedBlocks(0),
59         hThreadId(-1)
60     {}
61
62     qint64 unique;
63     qint64 tid;
64     QString what;
65     int kind;
66     QVector<Stack> stacks;
67     Suppression suppression;
68     quint64 leakedBytes;
69     qint64 leakedBlocks;
70     qint64 hThreadId;
71
72     bool operator==(const Private &other) const
73     {
74         return unique == other.unique
75                 && tid == other.tid
76                 && what == other.what
77                 && kind == other.kind
78                 && stacks == other.stacks
79                 && suppression == other.suppression
80                 && leakedBytes == other.leakedBytes
81                 && leakedBlocks == other.leakedBlocks
82                 && hThreadId == other.hThreadId;
83     }
84 };
85
86 Error::Error() :
87     d(new Private)
88 {
89 }
90
91 Error::~Error()
92 {
93 }
94
95 Error::Error(const Error &other) :
96     d( other.d )
97 {
98 }
99
100 void Error::swap(Error &other)
101 {
102     qSwap(d, other.d);
103 }
104
105 Error &Error::operator=(const Error &other)
106 {
107     Error tmp(other);
108     swap(tmp);
109     return *this;
110 }
111
112 bool Error::operator ==(const Error &other) const
113 {
114     return *d == *other.d;
115 }
116
117 bool Error::operator !=(const Error &other) const
118 {
119     return !(*d == *other.d);
120 }
121
122 Suppression Error::suppression() const
123 {
124     return d->suppression;
125 }
126
127 void Error::setSuppression(const Suppression &supp)
128 {
129     d->suppression = supp;
130 }
131
132 qint64 Error::unique() const
133 {
134     return d->unique;
135 }
136
137 void Error::setUnique(qint64 unique)
138 {
139     d->unique = unique;
140 }
141
142 qint64 Error::tid() const
143 {
144     return d->tid;
145 }
146
147 void Error::setTid(qint64 tid)
148 {
149     d->tid = tid;
150 }
151
152 quint64 Error::leakedBytes() const
153 {
154     return d->leakedBytes;
155 }
156
157 void Error::setLeakedBytes(quint64 l)
158 {
159     d->leakedBytes = l;
160 }
161
162 qint64 Error::leakedBlocks() const
163 {
164     return d->leakedBlocks;
165 }
166
167 void Error::setLeakedBlocks(qint64 b)
168 {
169     d->leakedBlocks = b;
170 }
171
172 QString Error::what() const
173 {
174     return d->what;
175 }
176
177 void Error::setWhat(const QString &what)
178 {
179     d->what = what;
180 }
181
182 int Error::kind() const
183 {
184     return d->kind;
185 }
186
187 void Error::setKind(int k)
188 {
189     d->kind = k;
190 }
191
192 QVector<Stack> Error::stacks() const
193 {
194     return d->stacks;
195 }
196
197 void Error::setStacks(const QVector<Stack> &stacks)
198 {
199     d->stacks = stacks;
200 }
201
202 void Error::setHelgrindThreadId(qint64 id)
203 {
204     d->hThreadId = id;
205 }
206
207 qint64 Error::helgrindThreadId() const
208 {
209     return d->hThreadId;
210 }
211
212 QString Error::toXml() const
213 {
214     QString xml;
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"
225                << "  </xwhat>\n";
226     } else {
227         stream << "  <what>" << d->what << "</what>\n";
228     }
229
230     foreach(const Stack &stack, d->stacks) {
231         if (!stack.auxWhat().isEmpty()) {
232             stream << "  <auxwhat>" << stack.auxWhat() << "</auxwhat>\n";
233         }
234         stream << "  <stack>\n";
235
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";
241             }
242             if (!frame.functionName().isEmpty()) {
243                 stream << "      <fn>" << frame.functionName() << "</fn>\n";
244             }
245             if (!frame.directory().isEmpty()) {
246                 stream << "      <dir>" << frame.directory() << "</dir>\n";
247             }
248             if (!frame.file().isEmpty()) {
249                 stream << "      <file>" << frame.file() << "</file>\n";
250             }
251             if (!frame.line() == -1) {
252                 stream << "      <line>" << frame.line() << "</line>";
253             }
254             stream << "    </frame>\n";
255         }
256
257         stream << "  </stack>\n";
258     }
259
260     stream << "</error>\n";
261
262     return xml;
263 }