00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _KJS_DEBUGGER_H_
00022 #define _KJS_DEBUGGER_H_
00023
00024 #include <qglobal.h>
00025
00026
00027
00028 #ifdef KJS_DEBUGGER
00029
00030 #include <qwidget.h>
00031 #include <qpixmap.h>
00032 #include <qptrlist.h>
00033
00034 #include <kjs/debugger.h>
00035
00036 #include "dom/dom_misc.h"
00037
00038 class QListBox;
00039 class QComboBox;
00040 class QLineEdit;
00041 class QPushButton;
00042
00043 namespace KJS {
00044 class FunctionImp;
00045 class List;
00046 class ScriptInterpreter;
00047 };
00048
00056 class FakeModal : public QWidget
00057 {
00058 Q_OBJECT
00059 public:
00060 FakeModal() {}
00061 void enable(QWidget *modal);
00062 void disable();
00063
00064 protected:
00065 bool eventFilter( QObject *obj, QEvent *evt );
00066 QWidget *modalWidget;
00067 };
00068
00069
00076 class StackFrame {
00077 public:
00078 StackFrame(int s, int l, QString n, bool stepped)
00079 : sourceId(s), lineno(l), name(n), step(stepped),
00080 next(stepped) {}
00081 QString toString();
00082
00083 int sourceId;
00084 int lineno;
00085 QString name;
00086 bool step;
00087 bool next;
00088 };
00089
00090 class SourceFile : public DOM::DomShared {
00091 public:
00092 SourceFile(QString u, QString c, int i) : url(u), code(c), index(i) {}
00093 QString url;
00094 QString code;
00095 int index;
00096 };
00097
00113 class SourceFragment {
00114 public:
00115 SourceFragment(int sid, int bl, SourceFile *sf);
00116 ~SourceFragment();
00117
00118 int sourceId;
00119 int baseLine;
00120 SourceFile *sourceFile;
00121 };
00122
00132 class KJSDebugWin : public QWidget, public KJS::Debugger {
00133 Q_OBJECT
00134 public:
00135 KJSDebugWin(QWidget *parent=0, const char *name=0);
00136 virtual ~KJSDebugWin();
00137
00138 static KJSDebugWin *createInstance();
00139 static void destroyInstance();
00140 static KJSDebugWin *instance() { return kjs_html_debugger; }
00141
00142 enum Mode { Disabled = 0,
00143 Next = 1,
00144 Step = 2,
00145 Continue = 3,
00146 Stop = 4
00147
00148 };
00149
00150 void highLight(int sourceId, int line);
00151 void setNextSourceInfo(QString url, int baseLine);
00152 void setSourceFile(QString url, QString code);
00153 void appendSourceFile(QString url, QString code);
00154 bool inSession() const { return m_inSession; }
00155 void setMode(Mode m) { m_mode = m; }
00156
00157
00158 bool sourceParsed(KJS::ExecState *exec, int sourceId,
00159 const KJS::UString &source, int errorLine);
00160 bool sourceUnused(KJS::ExecState * exec, int sourceId);
00161 bool exception(KJS::ExecState *exec, int sourceId,
00162 int lineno, KJS::Object &exceptionObj);
00163 bool atStatement(KJS::ExecState *exec, int sourceId,
00164 int firstLine, int lastLine);
00165 bool callEvent(KJS::ExecState *exec, int sourceId, int lineno,
00166 KJS::Object &function, const KJS::List &args);
00167 bool returnEvent(KJS::ExecState *exec, int sourceId,
00168 int lineno, KJS::Object &function);
00169 public slots:
00170 void next();
00171 void step();
00172 void cont();
00173 void stop();
00174 void breakNext();
00175 void toggleBreakpoint();
00176 void showFrame(int frameno);
00177 void sourceSelected(int sourceSelIndex);
00178 void eval();
00179
00180 protected:
00181
00182 virtual void closeEvent(QCloseEvent *e);
00183
00184 private:
00185 void enterSession();
00186 void leaveSession();
00187 void setCode(const QString &code,int SourceId);
00188 void updateFrameList();
00189
00190 struct Breakpoint {
00191 int lineno;
00192 Breakpoint *next;
00193 };
00194 struct SourceBreakpoints {
00195 int sourceId;
00196 Breakpoint *breakpoints;
00197 SourceBreakpoints *next;
00198 };
00199 SourceBreakpoints *m_sourceBreakpoints;
00200
00201 bool setBreakpoint(int sourceId, int line);
00202 bool deleteBreakpoint(int sourceId, int line);
00203 void clearAllBreakpoints(int sourceId = -1);
00204 int breakpointLine(int sourceId, int line0, int line1);
00205 bool haveBreakpoint(int sourceId, int line0, int line1);
00206
00207 bool m_inSession;
00208
00209 QListBox *m_sourceDisplay;
00210 QListBox *m_frameList;
00211 QPushButton *m_stepButton;
00212 QPushButton *m_nextButton;
00213 QPushButton *m_continueButton;
00214 QPushButton *m_stopButton;
00215 QPushButton *m_breakButton;
00216 QPushButton *m_breakpointButton;
00217 QComboBox *m_sourceSel;
00218 QPixmap m_stopIcon;
00219 QPixmap m_emptyIcon;
00220 QLineEdit *m_evalEdit;
00221 QPushButton *m_evalButton;
00222
00223 SourceFile *m_curSourceFile;
00224 QPtrList<StackFrame> m_frames;
00225 Mode m_mode;
00226
00227 QMap<QString,SourceFile*> m_sourceFiles;
00228
00229 QMap<int,SourceFragment*> m_sourceFragments;
00230
00231 QMap<int,SourceFile*> m_sourceSelFiles;
00232
00233 QString m_nextSourceUrl;
00234 int m_nextSourceBaseLine;
00235 FakeModal m_fakeModal;
00236
00237
00238 KJS::ExecState *m_curExecState;
00239 static KJSDebugWin *kjs_html_debugger;
00240 };
00241
00242 #endif // KJS_DEBUGGER
00243
00244 #endif // _KJS_DEBUGGER_H_