1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24** * Redistributions of source code must retain the above copyright
25** notice, this list of conditions and the following disclaimer.
26** * Redistributions in binary form must reproduce the above copyright
27** notice, this list of conditions and the following disclaimer in
28** the documentation and/or other materials provided with the
29** distribution.
30** * Neither the name of The Qt Company Ltd nor the names of its
31** contributors may be used to endorse or promote products derived
32** from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
50
51#include "scriptbreakpointmanager.h"
52
53ScriptBreakpointManager::ScriptBreakpointManager()
54{
55}
56
57ScriptBreakpointManager::~ScriptBreakpointManager()
58{
59}
60
61bool ScriptBreakpointManager::hasBreakpoints() const
62{
63 return !breakpoints.isEmpty();
64}
65
66int ScriptBreakpointManager::setBreakpoint(const QString &fileName, int lineNumber)
67{
68 breakpoints.append(t: ScriptBreakpointInfo(fileName, lineNumber));
69 return breakpoints.size() - 1;
70}
71
72int ScriptBreakpointManager::setBreakpoint(const QString &functionName, const QString &fileName)
73{
74 breakpoints.append(t: ScriptBreakpointInfo(functionName, fileName));
75 return breakpoints.size() - 1;
76}
77
78int ScriptBreakpointManager::setBreakpoint(const QScriptValue &function)
79{
80 breakpoints.append(t: ScriptBreakpointInfo(function));
81 return breakpoints.size() - 1;
82}
83
84void ScriptBreakpointManager::removeBreakpoint(int id)
85{
86 if (id >= 0 && id < breakpoints.size())
87 breakpoints[id] = ScriptBreakpointInfo();
88}
89
90int ScriptBreakpointManager::findBreakpoint(const QString &fileName, int lineNumber) const
91{
92 for (int i = 0; i < breakpoints.size(); ++i) {
93 const ScriptBreakpointInfo &brk = breakpoints.at(i);
94 if (brk.type != ScriptBreakpointInfo::File)
95 continue;
96 if (brk.fileName == fileName && brk.lineNumber == lineNumber)
97 return i;
98 }
99 return -1;
100}
101
102int ScriptBreakpointManager::findBreakpoint(const QString &functionName, const QString &fileName) const
103{
104 for (int i = 0; i < breakpoints.size(); ++i) {
105 const ScriptBreakpointInfo &brk = breakpoints.at(i);
106 if (brk.type != ScriptBreakpointInfo::FunctionName)
107 continue;
108 if (brk.functionName == functionName && brk.fileName == fileName)
109 return i;
110 }
111 return -1;
112}
113
114int ScriptBreakpointManager::findBreakpoint(const QScriptValue &function) const
115{
116 for (int i = 0; i < breakpoints.size(); ++i) {
117 const ScriptBreakpointInfo &brk = breakpoints.at(i);
118 if (brk.type != ScriptBreakpointInfo::Function)
119 continue;
120 if (brk.function.strictlyEquals(other: function))
121 return i;
122 }
123 return -1;
124}
125
126bool ScriptBreakpointManager::isBreakpointEnabled(int id) const
127{
128 return breakpoints.value(i: id).enabled;
129}
130
131void ScriptBreakpointManager::setBreakpointEnabled(int id, bool enabled)
132{
133 if (id >= 0 && id < breakpoints.size())
134 breakpoints[id].enabled = enabled;
135}
136
137QString ScriptBreakpointManager::breakpointCondition(int id) const
138{
139 return breakpoints.value(i: id).condition;
140}
141
142void ScriptBreakpointManager::setBreakpointCondition(int id, const QString &expression)
143{
144 if (id >= 0 && id < breakpoints.size())
145 breakpoints[id].condition = expression;
146}
147
148int ScriptBreakpointManager::breakpointIgnoreCount(int id) const
149{
150 return breakpoints.value(i: id).ignoreCount;
151}
152
153void ScriptBreakpointManager::setBreakpointIgnoreCount(int id, int ignoreCount)
154{
155 if (id >= 0 && id < breakpoints.size())
156 breakpoints[id].ignoreCount = ignoreCount;
157}
158
159bool ScriptBreakpointManager::isBreakpointSingleShot(int id) const
160{
161 return breakpoints.value(i: id).singleShot;
162}
163
164void ScriptBreakpointManager::setBreakpointSingleShot(int id, bool singleShot)
165{
166 if (id >= 0 && id < breakpoints.size())
167 breakpoints[id].singleShot = singleShot;
168}
169

source code of qtscript/examples/script/qsdbg/scriptbreakpointmanager.cpp