diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-03-03 14:20:54 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-07 16:55:12 +0100 |
commit | 4c4bddb0254acbc53b80e804bbbc26cfdd4e87a1 (patch) | |
tree | 9f2734f313f8feb7abb8355e1fed86b63a71f5d9 /src/qml/jsruntime/qv4debugging_p.h | |
parent | 99efe4309379482fce5c231885883e359bf85290 (diff) |
Simplify our breakpoint handling
Only store a Hash of break points in the debugger,
instead of the involved logic that currently adds and
removes break points. Add the current line number to
the Debug statements in the interpreter, and pass them
on to the debugger for checking whether we should really
break.
This adds a slight additional overhead to running inside the
debugger, but greatly simplifies the logic and doesn't require
modifying the bytecode anymore. This in turn opens up the
possibility to run the debugger on JIT generated code later on.
Change-Id: If2a3ae8f8d08b69a3a704cbbe0a84000f917a32e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4debugging_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4debugging_p.h | 86 |
1 files changed, 29 insertions, 57 deletions
diff --git a/src/qml/jsruntime/qv4debugging_p.h b/src/qml/jsruntime/qv4debugging_p.h index 0e19c51935..aec2cc64ae 100644 --- a/src/qml/jsruntime/qv4debugging_p.h +++ b/src/qml/jsruntime/qv4debugging_p.h @@ -69,6 +69,25 @@ enum PauseReason { class DebuggerAgent; +struct DebuggerBreakPoint { + DebuggerBreakPoint(QString fileName, int line) + : fileName(fileName), lineNumber(line) + {} + QString fileName; + int lineNumber; +}; +inline uint qHash(const DebuggerBreakPoint &b, uint seed = 0) Q_DECL_NOTHROW +{ + return qHash(b.fileName, seed) ^ b.lineNumber; +} +inline bool operator==(const DebuggerBreakPoint &a, const DebuggerBreakPoint &b) +{ + return a.lineNumber == b.lineNumber && a.fileName == b.fileName; +} + +typedef QHash<DebuggerBreakPoint, QString> BreakPoints; + + class Q_QML_EXPORT Debugger { public: @@ -114,9 +133,9 @@ public: enum Speed { FullThrottle = 0, - StepIn, StepOut, StepOver, + StepIn, NotStepping = FullThrottle }; @@ -150,12 +169,11 @@ public: Function *function; }; - ExecutionState currentExecutionState(const uchar *code = 0) const; + ExecutionState currentExecutionState(int lineNumber) const; bool pauseAtNextOpportunity() const { - return m_pauseRequested || m_havePendingBreakPoints || m_gatherSources; + return m_pauseRequested || m_haveBreakPoints || m_gatherSources || m_stepping >= StepOver; } - void setPendingBreakpoints(Function *function); QVector<StackFrame> stackTrace(int frameLimit = -1) const; void collectArgumentsInContext(Collector *collector, int frameNr = 0, int scopeNr = 0); @@ -166,7 +184,7 @@ public: QVector<ExecutionContext::ContextType> getScopeTypes(int frame = 0) const; public: // compile-time interface - void maybeBreakAtInstruction(const uchar *code, bool breakPointHit); + void maybeBreakAtInstruction(int line); public: // execution hooks void enteringFunction(); @@ -178,77 +196,31 @@ private: // requires lock to be held void pauseAndWait(PauseReason reason); - // requires lock to be held - void setTemporaryBreakPointOnNextLine(); - // requires lock to be held - void clearTemporaryBreakPoints(); - // requires lock to be held - bool temporaryBreakPointInFunction(ExecutionContext *context) const; - void applyPendingBreakPoints(); - static void setBreakOnInstruction(Function *function, qptrdiff codeOffset, bool onoff); - static bool hasBreakOnInstruction(Function *function, qptrdiff codeOffset); bool reallyHitTheBreakPoint(const QString &filename, int linenr); void runInEngine(Job *job); void runInEngine_havingLock(Debugger::Job *job); private: - struct BreakPoints : public QHash<QString, QList<int> > - { - void add(const QString &fileName, int lineNumber); - bool remove(const QString &fileName, int lineNumber); - bool contains(const QString &fileName, int lineNumber) const; - void applyToFunction(Function *function, bool removeBreakPoints); - }; QV4::ExecutionEngine *m_engine; DebuggerAgent *m_agent; QMutex m_lock; QWaitCondition m_runningCondition; State m_state; - bool m_pauseRequested; - Job *m_gatherSources; - bool m_havePendingBreakPoints; - BreakPoints m_pendingBreakPointsToAdd; - BreakPoints m_pendingBreakPointsToAddToFutureCode; - BreakPoints m_pendingBreakPointsToRemove; - const uchar *m_currentInstructionPointer; Speed m_stepping; + bool m_pauseRequested; + bool m_haveBreakPoints; bool m_stopForStepping; - QV4::PersistentValue m_returnedValue; - - struct TemporaryBreakPoint { - Function *function; - QVector<qptrdiff> codeOffsets; - ExecutionContext *context; - TemporaryBreakPoint(): function(0), context(0) {} - TemporaryBreakPoint(Function *function, ExecutionContext *context) - : function(function) - , context(context) - {} - } m_temporaryBreakPoints; - bool m_breakOnThrow; + BreakPoints m_breakPoints; + QV4::PersistentValue m_returnedValue; + + Job *m_gatherSources; Job *m_runningJob; QWaitCondition m_jobIsRunning; - - struct BreakPointConditions: public QHash<QString, QString> - { - static QString genKey(const QString &fileName, int lineNumber) - { - return fileName + QLatin1Char(':') + QString::number(lineNumber); - } - - QString condition(const QString &fileName, int lineNumber) - { return value(genKey(fileName, lineNumber)); } - void add(const QString &fileName, int lineNumber, const QString &condition) - { insert(genKey(fileName, lineNumber), condition); } - void remove(const QString &fileName, int lineNumber) - { take(genKey(fileName, lineNumber)); } - }; - BreakPointConditions m_breakPointConditions; }; class Q_QML_EXPORT DebuggerAgent : public QObject |