breakpoint.cpp 4.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (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 http://qt.nokia.com/contact.
**
**************************************************************************/

Arvid Ephraim Picciani's avatar
Arvid Ephraim Picciani committed
30
#include "breakpoint.h"
31
32
33
34
35
36
37
38
39
40
41
42
43

#include <QtCore/QByteArray>
#include <QtCore/QDebug>

namespace Debugger {
namespace Internal {

//////////////////////////////////////////////////////////////////
//
// BreakpointData
//
//////////////////////////////////////////////////////////////////

44
45
46
const char *BreakpointData::throwFunction = "throw";
const char *BreakpointData::catchFunction = "catch";

47
BreakpointParameters::BreakpointParameters(BreakpointType t) :
48
49
    type(t), enabled(true), useFullPath(false),
    ignoreCount(0), lineNumber(0), address(0)
50
51
52
{
}

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
bool BreakpointParameters::equals(const BreakpointParameters &rhs) const
{
    return type != rhs.type && enabled == rhs.enabled
            && useFullPath == rhs.useFullPath
            && fileName == rhs.fileName && condition == rhs.condition
            && ignoreCount == rhs.ignoreCount && lineNumber == rhs.lineNumber
            && address == rhs.address && threadSpec == rhs.threadSpec
            && functionName == rhs.functionName;
}

BreakpointData::BreakpointData(BreakpointType type) :
    m_parameters(type), m_markerLineNumber(0)
{
}

BreakpointResponse::BreakpointResponse() :
    number(0), multiple(false)
70
{
71
72
}

hjk's avatar
hjk committed
73
#define SETIT(var, value) return (var != value) && (var = value, true)
74

hjk's avatar
hjk committed
75
bool BreakpointData::setUseFullPath(bool on)
76
{ SETIT(m_parameters.useFullPath, on); }
hjk's avatar
hjk committed
77
78
79
80
81
82
83
84

bool BreakpointData::setMarkerFileName(const QString &file)
{ SETIT(m_markerFileName, file); }

bool BreakpointData::setMarkerLineNumber(int line)
{ SETIT(m_markerLineNumber, line); }

bool BreakpointData::setFileName(const QString &file)
85
{ SETIT(m_parameters.fileName, file); }
hjk's avatar
hjk committed
86
87

bool BreakpointData::setEnabled(bool on)
88
{ SETIT(m_parameters.enabled, on); }
hjk's avatar
hjk committed
89

90
bool BreakpointData::setIgnoreCount(int count)
91
{ SETIT(m_parameters.ignoreCount, count); }
hjk's avatar
hjk committed
92
93

bool BreakpointData::setFunctionName(const QString &name)
94
{ SETIT(m_parameters.functionName, name); }
hjk's avatar
hjk committed
95
96

bool BreakpointData::setLineNumber(int line)
97
{ SETIT(m_parameters.lineNumber, line); }
hjk's avatar
hjk committed
98
99

bool BreakpointData::setAddress(quint64 address)
100
{ SETIT(m_parameters.address, address); }
101

hjk's avatar
hjk committed
102
bool BreakpointData::setThreadSpec(const QByteArray &spec)
103
{ SETIT(m_parameters.threadSpec, spec); }
hjk's avatar
hjk committed
104
105

bool BreakpointData::setType(BreakpointType type)
106
{ SETIT(m_parameters.type, type); }
hjk's avatar
hjk committed
107
108

bool BreakpointData::setCondition(const QByteArray &cond)
109
{ SETIT(m_parameters.condition, cond); }
hjk's avatar
hjk committed
110
111
112
113

#undef SETIT


Arvid Ephraim Picciani's avatar
Arvid Ephraim Picciani committed
114
115
116
117
118
119
120
121
122
123
// Compare file names case insensitively on Windows.
static inline bool fileNameMatch(const QString &f1, const QString &f2)
{
#ifdef Q_OS_WIN
    return f1.compare(f2, Qt::CaseInsensitive) == 0;
#else
    return f1 == f2;
#endif
}

124
bool BreakpointData::isLocatedAt(const QString &fileName, int lineNumber,
125
    bool useMarkerPosition) const
126
{
127
    int line = useMarkerPosition ? m_markerLineNumber : m_parameters.lineNumber;
hjk's avatar
hjk committed
128
    return lineNumber == line && fileNameMatch(fileName, m_markerFileName);
129
130
}

131
bool BreakpointData::conditionsMatch(const QByteArray &other) const
132
133
{
    // Some versions of gdb "beautify" the passed condition.
134
    QByteArray s1 = m_parameters.condition;
135
136
137
    s1.replace(' ', "");
    QByteArray s2 = other;
    s2.replace(' ', "");
138
139
140
    return s1 == s2;
}

hjk's avatar
hjk committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
QString BreakpointData::toString() const
{
    QString result;
    QTextStream ts(&result);
    ts << fileName();
    ts << condition();
    ts << ignoreCount();
    ts << lineNumber();
    ts << address();
    ts << functionName();
    ts << useFullPath();
    return result;
}

QString BreakpointResponse::toString() const
{
    QString result;
    QTextStream ts(&result);
159
160
161
162
163
164
165
166
167
    ts << number;
    ts << condition;
    ts << ignoreCount;
    ts << fileName;
    ts << fullName;
    ts << lineNumber;
    ts << threadSpec;
    ts << functionName;
    ts << address;
hjk's avatar
hjk committed
168
169
170
    return result;
}

171
172
} // namespace Internal
} // namespace Debugger