46 #include <QtCore/qcoreapplication.h> 47 #include <QtCore/qset.h> 48 #include <QtScript/qscriptengine.h> 67 : state(
NoState), stepDepth(0), stepCount(0),
68 targetScriptId(-1), targetLineNumber(-1), returnCounter(0),
69 nextBreakpointId(1), hitBreakpointId(0),
70 nextContextId(0), statementCounter(0)
102 d->contextIdStack.append(
d->nextContextId);
115 d->backend->agentDestroyed(
this);
128 d->stepCount = count;
141 if (
engine()->isEvaluating())
145 d->stepCount = count;
158 if (
engine()->isEvaluating())
193 d->targetLineNumber = lineNumber;
206 d->targetScriptId = scriptId;
208 d->targetLineNumber = lineNumber;
215 d->returnCounter = contextIndex + 1;
231 if (scriptId != -1) {
232 if (!
d->scripts.contains(scriptId)) {
242 int id =
d->nextBreakpointId;
243 ++
d->nextBreakpointId;
245 if (scriptId != -1) {
246 d->resolvedBreakpoints[scriptId].append(
id);
249 bool resolved =
false;
251 for (it =
d->scripts.constBegin(); it !=
d->scripts.constEnd(); ++
it) {
252 if (it.value().fileName() ==
fileName) {
253 d->resolvedBreakpoints[it.key()].append(
id);
259 d->unresolvedBreakpoints[
fileName].append(
id);
262 d->breakpoints.insert(
id, data);
275 if (!
d->breakpoints.contains(
id))
277 d->breakpoints.remove(
id);
281 it =
d->resolvedBreakpoints.begin();
282 for ( ; !found && (it !=
d->resolvedBreakpoints.end()); ) {
285 for (
int i = 0; i < lst.
size(); ++i) {
286 if (lst.
at(i) == id) {
293 it =
d->resolvedBreakpoints.erase(it);
300 it =
d->unresolvedBreakpoints.begin();
301 for ( ; !found && (it !=
d->unresolvedBreakpoints.end()); ) {
304 for (
int i = 0; i < lst.
size(); ++i) {
305 if (lst.
at(i) == id) {
312 it =
d->unresolvedBreakpoints.erase(it);
326 d->breakpoints.clear();
327 d->resolvedBreakpoints.clear();
328 d->unresolvedBreakpoints.clear();
338 return d->breakpoints.value(
id);
349 if (!
d->breakpoints.contains(
id))
351 d->breakpoints[id] =
data;
361 return d->breakpoints;
379 return d->scripts.value(
id);
388 d->previousCheckpointScripts =
d->checkpointScripts;
389 d->checkpointScripts =
d->scripts;
402 QSet<qint64> prevSet =
d->previousCheckpointScripts.keys().toSet();
417 for (it =
d->scripts.constBegin(); it !=
d->scripts.constEnd(); ++
it) {
418 if (it.value().fileName() ==
fileName)
427 return d->contextIdStack;
433 int i =
d->checkpointContextIdStack.size() - 1;
434 int j =
d->contextIdStack.size() - 1;
435 for ( ; (i >= 0) && (j >= 0); --i, --j) {
436 if (
d->checkpointContextIdStack.at(i) !=
d->contextIdStack.at(j))
441 d->checkpointContextIdStack =
d->contextIdStack;
459 d->scripts.insert(
id, data);
462 && (
d->targetScriptId == -1)
463 && ((
d->targetFileName == fileName) ||
d->targetFileName.isEmpty())) {
464 d->targetScriptId = id;
468 QList<int> lst =
d->unresolvedBreakpoints.take(fileName);
470 d->resolvedBreakpoints.insert(
id, lst);
484 && (
d->targetScriptId ==
id)) {
485 d->targetScriptId = -1;
492 d->unresolvedBreakpoints.insert(fileName, lst);
503 d->contextIdStack.prepend(
d->nextContextId);
513 d->scriptIdStack.removeLast();
514 d->contextIdStack.removeFirst();
544 if (--
d->stepDepth < 0) {
545 d->stepResult = returnValue;
549 if (--
d->returnCounter == 0) {
550 d->returnValue = returnValue;
561 int lineNumber,
int columnNumber)
564 if (
engine()->processEventsInterval() == -1) {
566 if ((++
d->statementCounter % 25000) == 0) {
567 if (!
d->processEventsTimer.isNull()) {
568 if (
d->processEventsTimer.elapsed() > 30) {
570 d->processEventsTimer.restart();
573 d->processEventsTimer.start();
580 QList<int> lst =
d->resolvedBreakpoints.value(scriptId);
581 for (
int i = 0; i < lst.
size(); ++i) {
603 d->hitBreakpointId = id;
616 if (--
d->stepCount == 0) {
619 d->backend->stepped(scriptId, lineNumber, columnNumber,
QScriptValue());
624 if ((
d->stepDepth > 0) || (--
d->stepCount != 0))
630 d->backend->stepped(scriptId, lineNumber, columnNumber,
d->stepResult);
636 d->backend->stepped(scriptId, lineNumber, columnNumber,
d->stepResult);
640 if (((lineNumber ==
d->targetLineNumber) || (
d->targetLineNumber == -1))
641 && (scriptId ==
d->targetScriptId)) {
644 d->backend->locationReached(scriptId, lineNumber, columnNumber);
651 d->backend->interrupted(scriptId, lineNumber, columnNumber);
657 d->backend->breakpoint(scriptId, lineNumber, columnNumber,
d->hitBreakpointId);
658 if (
d->breakpoints.value(
d->hitBreakpointId).isSingleShot())
665 d->backend->forcedReturn(scriptId, lineNumber, columnNumber,
d->returnValue);
691 d->backend->exception(scriptId, exception, hasHandler);
723 int lineNumber = lst.
at(1).
toInt();
724 int columnNumber = lst.
at(2).
toInt();
727 d->backend->debuggerInvocationRequest(
728 scriptId, lineNumber, columnNumber);
The QVariant class acts like a union for the most common Qt data types.
The QScriptContext class represents a Qt Script function invocation.
QScriptValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
#define QT_END_NAMESPACE
This macro expands to.
QScriptScriptData scriptData(qint64 id) const
Returns the data associated with the script with the given id.
void enterRunToLocationMode(const QString &fileName, int lineNumber)
Instructs the agent to continue evaluation until the location described by fileName and lineNumber is...
QScriptDebuggerAgent(QScriptDebuggerBackendPrivate *backend, QScriptEngine *engine)
Constructs a new agent for the given engine.
#define it(className, varName)
QScriptEngine * engine() const
Returns the QScriptEngine that this agent is associated with.
void enterReturnByForceMode(int contextIndex, const QScriptValue &value)
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
~QScriptDebuggerAgent()
Destroys this QScriptDebuggerAgent.
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
void removeLast()
Removes the last item in the list.
void exceptionCatch(qint64 scriptId, const QScriptValue &exception)
Reimplemented Function
QScriptBreakpointMap breakpoints() const
Returns all breakpoints.
void nullifyBackendPointer()
The QString class provides a Unicode character string.
static QScriptDebuggerAgentPrivate * get(QScriptDebuggerAgent *)
void enterStepIntoMode(int count=1)
Instructs the agent to perform a "step into" operation.
The QHash class is a template class that provides a hash-table-based dictionary.
QList< qint64 > contextIds() const
QVariant extension(Extension extension, const QVariant &argument=QVariant())
Reimplemented Function
const T value(const Key &key) const
Returns the value associated with the key.
void contextPush()
Reimplemented Function
void scriptLoad(qint64 id, const QString &program, const QString &fileName, int baseLineNumber)
Reimplemented Function
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
The QScriptScriptData class holds data associated with a script.
bool supportsExtension(Extension extension) const
Reimplemented Function
void append(const T &t)
Inserts value at the end of the list.
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptScriptMap scripts() const
Returns all scripts.
This class implements a state machine that uses the low-level events reported by the QScriptEngineAge...
#define QT_BEGIN_NAMESPACE
This macro expands to.
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
QList< T > toList() const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QScriptDebuggerAgentPrivate()
const T & at(int i) const
Returns the item at index position i in the list.
void positionChange(qint64 scriptId, int lineNumber, int columnNumber)
Reimplemented Function
void exceptionThrow(qint64 scriptId, const QScriptValue &exception, bool hasHandler)
Reimplemented Function
qint64 resolveScript(const QString &fileName) const
Returns the identifier of the script that has the given fileName, or -1 if there is no such script...
static const char * data(const QByteArray &arr)
void functionExit(qint64 scriptId, const QScriptValue &returnValue)
Reimplemented Function
void scriptUnload(qint64 id)
Reimplemented Function
void functionEntry(qint64 scriptId)
Reimplemented Function
void enterInterruptMode()
Instructs the agent to interrupt evaluation.
The QScriptBreakpointData class contains data associated with a breakpoint.
bool toBoolean() const
Use toBool() instead.
void enterStepOverMode(int count=1)
Instructs the agent to perform a "step over" operation.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
bool setBreakpointData(int id, const QScriptBreakpointData &data)
Sets the data associated with the breakpoint with the given id.
bool isEnabled() const
Returns true if the breakpoint is enabled, false otherwise.
~QScriptDebuggerAgentPrivate()
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
QScriptBreakpointData breakpointData(int id) const
Returns the data associated with the breakpoint with the given id.
QPair< QList< qint64 >, QList< qint64 > > contextsCheckpoint()
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
int setBreakpoint(const QScriptBreakpointData &data)
Sets a breakpoint defined by the given data.
int size() const
Returns the number of items in the list.
QScriptContext * currentContext() const
Returns the current context.
if(void) toggleToolbarShown
void enterStepOutMode()
Instructs the agent to perform a "step out" operation.
void clearExceptions()
Clears any uncaught exceptions in this engine.
QPair< QList< qint64 >, QList< qint64 > > scriptsDelta() const
Returns the difference between the current checkpoint and the previous checkpoint.
QScriptDebuggerBackendPrivate * backend
void contextPop()
Reimplemented Function
bool deleteBreakpoint(int id)
Deletes the breakpoint with the given id.
QString condition() const
Returns the condition of the breakpoint.
void scriptsCheckpoint()
Checkpoints the current scripts.
bool hit()
If the ignore count is 0, this function increments the hit count and returns true.
Extension
This enum specifies the possible extensions to a QScriptEngineAgent.
int lineNumber() const
Returns the breakpoint line number.
The QScriptValue class acts as a container for the Qt Script data types.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QString fileName(const QString &fileUrl)
The QScriptEngineAgent class provides an interface to report events pertaining to QScriptEngine execu...
void enterContinueMode()
Instructs the agent to continue evaluation.
void deleteAllBreakpoints()
Deletes all breakpoints.
QScriptContext * parentContext() const
Returns the parent context of this QScriptContext.
friend class const_iterator
QScriptValue throwValue(const QScriptValue &value)
Throws an exception with the given value.
void removeAt(int i)
Removes the item at index position i.