source: branches/4.5.1/src/scripttools/debugging/qscriptdebuggeragent.cpp@ 1066

Last change on this file since 1066 was 2, checked in by Dmitry A. Kuminov, 17 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 22.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtSCriptTools module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qscriptdebuggeragent_p.h"
43#include "qscriptdebuggeragent_p_p.h"
44#include "qscriptdebuggerbackend_p_p.h"
45
46#include <QtCore/qcoreapplication.h>
47#include <QtCore/qset.h>
48#include <QtScript/qscriptengine.h>
49
50QT_BEGIN_NAMESPACE
51
52/*!
53 \since 4.5
54 \class QScriptDebuggerAgent
55 \internal
56
57 This class implements a state machine that uses the low-level events
58 reported by the QScriptEngineAgent interface to implement debugging-
59 specific functionality such as stepping and breakpoints. It is used
60 internally by the QScriptDebuggerBackend class.
61*/
62
63QScriptDebuggerAgentPrivate::QScriptDebuggerAgentPrivate()
64{
65 state = NoState;
66 nextBreakpointId = 1;
67 nextContextId = 0;
68 statementCounter = 0;
69}
70
71QScriptDebuggerAgentPrivate::~QScriptDebuggerAgentPrivate()
72{
73}
74
75QScriptDebuggerAgentPrivate *QScriptDebuggerAgentPrivate::get(
76 QScriptDebuggerAgent *q)
77{
78 if (!q)
79 return 0;
80 return q->d_func();
81}
82
83
84/*!
85 Constructs a new agent for the given \a engine. The agent will
86 report debugging-related events (e.g. step completion) to the given
87 \a backend.
88*/
89QScriptDebuggerAgent::QScriptDebuggerAgent(
90 QScriptDebuggerBackendPrivate *backend, QScriptEngine *engine)
91#if QT_VERSION >= 0x040500
92 : QScriptEngineAgent(*new QScriptDebuggerAgentPrivate, engine)
93#else
94 : QScriptEngineAgent(engine), d_ptr(new QScriptDebuggerAgentPrivate)
95#endif
96{
97 Q_D(QScriptDebuggerAgent);
98#if QT_VERSION < 0x040500
99 d_ptr->q_ptr = this;
100#endif
101 d->backend = backend;
102
103 QScriptContext *ctx = engine->currentContext();
104 while (ctx) {
105 d->scriptIdStack.append(QList<qint64>());
106 d->contextIdStack.append(d->nextContextId);
107 ++d->nextContextId;
108 ctx = ctx->parentContext();
109 }
110}
111
112/*!
113 Destroys this QScriptDebuggerAgent.
114*/
115QScriptDebuggerAgent::~QScriptDebuggerAgent()
116{
117 Q_D(QScriptDebuggerAgent);
118 if (d->backend)
119 d->backend->agentDestroyed(this);
120#if QT_VERSION < 0x040500
121 delete d_ptr;
122#endif
123}
124
125/*!
126 Instructs the agent to perform a "step into" operation. This
127 function returns immediately. The agent will report step completion
128 at a later time, i.e. when script statements are evaluted.
129*/
130void QScriptDebuggerAgent::enterStepIntoMode(int count)
131{
132 Q_D(QScriptDebuggerAgent);
133 d->state = QScriptDebuggerAgentPrivate::SteppingIntoState;
134 d->stepCount = count;
135 d->stepResult = QScriptValue();
136}
137
138/*!
139 Instructs the agent to perform a "step over" operation. This
140 function returns immediately. The agent will report step completion
141 at a later time, i.e. when script statements are evaluted.
142*/
143void QScriptDebuggerAgent::enterStepOverMode(int count)
144{
145 Q_D(QScriptDebuggerAgent);
146 d->state = QScriptDebuggerAgentPrivate::SteppingOverState;
147 if (engine()->isEvaluating())
148 d->stepDepth = 0;
149 else
150 d->stepDepth = -1;
151 d->stepCount = count;
152 d->stepResult = QScriptValue();
153}
154
155/*!
156 Instructs the agent to perform a "step out" operation. This
157 function returns immediately. The agent will report step completion
158 at a later time, i.e. when script statements are evaluted.
159*/
160void QScriptDebuggerAgent::enterStepOutMode()
161{
162 Q_D(QScriptDebuggerAgent);
163 d->state = QScriptDebuggerAgentPrivate::SteppingOutState;
164 if (engine()->isEvaluating())
165 d->stepDepth = 0;
166 else
167 d->stepDepth = -1;
168}
169
170/*!
171 Instructs the agent to continue evaluation.
172 This function returns immediately.
173*/
174void QScriptDebuggerAgent::enterContinueMode()
175{
176 Q_D(QScriptDebuggerAgent);
177 d->state = QScriptDebuggerAgentPrivate::NoState;
178}
179
180/*!
181 Instructs the agent to interrupt evaluation.
182 This function returns immediately.
183*/
184void QScriptDebuggerAgent::enterInterruptMode()
185{
186 Q_D(QScriptDebuggerAgent);
187 d->state = QScriptDebuggerAgentPrivate::InterruptingState;
188}
189
190/*!
191 Instructs the agent to continue evaluation until the location
192 described by \a fileName and \a lineNumber is reached. This
193 function returns immediately.
194*/
195void QScriptDebuggerAgent::enterRunToLocationMode(const QString &fileName, int lineNumber)
196{
197 Q_D(QScriptDebuggerAgent);
198 d->targetFileName = fileName;
199 d->targetLineNumber = lineNumber;
200 d->targetScriptId = resolveScript(fileName);
201 d->state = QScriptDebuggerAgentPrivate::RunningToLocationState;
202}
203