KHtml

debugwindow.h
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2006 Matt Broadstone ([email protected])
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef DEBUGWINDOW_H
21 #define DEBUGWINDOW_H
22 
23 #include <kcomponentdata.h>
24 #include <kxmlguiwindow.h>
25 
26 #include <kjs/debugger.h>
27 #include <kjs/completion.h>
28 #include <kjs/interpreter.h>
29 #include <kjs/value.h>
30 #include <kjs_binding.h>
31 
32 #include <ktexteditor/document.h>
33 #include <ktexteditor/view.h>
34 #include <ktexteditor/editor.h>
35 #include <ktexteditor/markinterface.h>
36 
37 #include "khtml_pagecache.h"
38 #include "khtml_part.h"
39 #include "dom/dom_misc.h"
40 #include "misc/shared.h"
41 
42 #include <QStack>
43 #include <QVector>
44 
45 #include "interpreter_ctx.h"
46 #include "debugdocument.h"
47 
48 class QAction;
49 class KToggleAction;
50 class QTabWidget;
51 class QFrame;
52 class QEventLoop;
53 
54 namespace KJSDebugger
55 {
56 
57 class CallStackDock;
58 class WatchesDock;
59 class LocalVariablesDock;
60 class ScriptsDock;
61 class BreakpointsDock;
62 class ConsoleDock;
63 
73 class DebugWindow : public KXmlGuiWindow, public KJS::Debugger, public KComponentData,
74  public khtml::Shared<DebugWindow>
75 {
76  Q_OBJECT
77 
78 public:
80  virtual ~DebugWindow();
81 
82  static DebugWindow *window();
83 
84  // Returns true if the debugger is active, and has blocked the execution
85  // for some reason.
86  // ### seems like some of what we (mis-)use inSession() for should use this
87  static bool isBlocked();
88 
89  // Returns if we blocked execution; KHTML will attempt to use it
90  // to prevent some kinds of accidental recursion. Should go
91  // if proper modal dialog manager shows up
92  bool inSession() const
93  {
94  return !m_activeSessionCtxs.isEmpty();
95  }
96 
97 public:
98 
99  // All of the below are overridden from KJS::Debugger
100  bool sourceParsed(KJS::ExecState *exec, int sourceId, const KJS::UString &sourceURL,
101  const KJS::UString &source, int startingLineNumber, int errorLine, const KJS::UString &errorMsg);
102  bool exception(KJS::ExecState *exec, int sourceId, int lineno, KJS::JSValue *exceptionObj);
103  bool atStatement(KJS::ExecState *exec, int sourceId, int firstLine, int lastLine);
104  bool enterContext(KJS::ExecState *exec, int sourceId, int lineno, KJS::JSObject *function, const KJS::List &args);
105  bool exitContext(KJS::ExecState *exec, int sourceId, int lineno, KJS::JSObject *function);
106  void attach(KJS::Interpreter *interp);
107  void detach(KJS::Interpreter *interp);
108 
109  bool shouldReindentSources() const;
110 
111  // Called by KJSProxy when we navigate away from a page
112  void clearInterpreter(KJS::Interpreter *interp);
113 
114  // Hook for activating the debugger from gdb or such
115  static void forceStopAtNext();
116 
117 public Q_SLOTS:
118  void stopAtNext();
119  void continueExecution();
120  void stepInto();
121  void stepOut();
122  void stepOver();
123 
124  void markSet(KTextEditor::Document *document, KTextEditor::Mark mark,
126 
127 protected:
128  virtual void closeEvent(QCloseEvent *event);
129 
130  bool eventFilter(QObject *object, QEvent *event);
131  void disableOtherWindows();
132  void enableOtherWindows();
133 
134 private Q_SLOTS:
135  void settingsChanged();
136 
137  void displayScript(KJSDebugger::DebugDocument *document);
138  void displayScript(KJSDebugger::DebugDocument *document, int line); // -1 denotes not focusing on the line
139  void updateVarView();
140  void closeTab();
141  void documentDestroyed(KJSDebugger::DebugDocument *doc);
142 
143  void doEval(const QString &code);
144 private:
145  void createActions();
146  void createMenus();
147  void createToolBars();
148  void createStatusBar();
149  void createTabWidget();
150 
151  void enterDebugSession(KJS::ExecState *exec, DebugDocument *document, int line);
152  void leaveDebugSession();
153 
154  void enterModality();
155  void leaveModality();
156 
157  void enterLoop();
158  void exitLoop();
159 
160  enum RunMode { Running, Stopped };
161 
162  void setUIMode(RunMode mode);
163  void updateStoppedMark(RunMode mode);
164 private:
165  void cleanupDocument(DebugDocument::Ptr document);
166 
167  // Checks to see whether we should stop at the given location, based on the current
168  // mode and breakpoints. Returns false if we should abort
169  bool checkSourceLocation(KJS::ExecState *exec, int sourceId, int firstLine, int lastLine);
170 
171  // Standard actions
172  QAction *m_exitAct;
173 
174  // Flow control actions
175  QAction *m_continueAct;
176  QAction *m_stopAct;
177  QAction *m_stepIntoAct;
178  QAction *m_stepOutAct;
179  QAction *m_stepOverAct;
180 
181  KToggleAction *m_catchExceptionsAction;
182  KToggleAction *m_reindentAction;
183 
184 // WatchesDock *m_watches;
185  LocalVariablesDock *m_localVariables;
186  ScriptsDock *m_scripts;
187  CallStackDock *m_callStack;
188  BreakpointsDock *m_breakpoints;
189  ConsoleDock *m_console;
190 
191  QTabWidget *m_tabWidget;
192 
193  // e.g. not aborted
194  bool shouldContinue(InterpreterContext *ic);
195 
196  // This keeps track of modal dialogs we've put up
197  // that may disable the CPU guard.
198  int m_modalLevel;
199 
200  // This is all the nested event loops that are active
201  QStack<QEventLoop *> m_activeEventLoops;
202 
203  void resetTimeoutsIfNeeded();
204 
205  bool m_reindentSources;
206  bool m_catchExceptions;
207  void syncFromConfig();
208  void syncToConfig();
209 
210  // The handling of debugger modes is a bit funny.
211  // essentially, we want normal step/stepOver/stepOut
212  // to work per (dynamic) interpreter, but "break at next"
213  // should work globally.
214  bool m_breakAtNext;
215 
216  InterpreterContext *ctx()
217  {
218  return m_activeSessionCtxs.isEmpty() ? 0 : m_activeSessionCtxs.top();
219  }
220 
221  QHash<int, DebugDocument::Ptr> m_docForSid;
222 
223  // For each interpreter, we keep track of what documents belong to it
224  // so we can discard them when needed, as well as flush for reload
226 
227  // Some of the state we want to keep track of while debugging, such as backtraces,
228  // is per-interpreter, and this lets us look uit up.
230 
231  // This keeps track of the contexts for the various debuggers
232  // we may be in session for. It's needed because the same window is
233  // used for all, so we may occassionally be a few levels of recursion in,
234  // so we need to know exactly how to unwind, etc.
235  QStack<InterpreterContext *> m_activeSessionCtxs;
236 
237  // This denotes the session we were in once we entered the running UI
238  // mode. May be null
239  InterpreterContext *m_runningSessionCtx;
240 
241  // The documents that are currently open for viewing.
242  // The index matches that of the tab widget;
243  QList<DebugDocument *> m_openDocuments;
244 
245  static DebugWindow *s_debugger;
246 };
247 
248 } // namespace
249 
250 #endif // DEBUGWINDOW_H
DebuggerWindow.
Definition: debugwindow.h:73
bool event(QEvent *event) override
Q_OBJECTQ_OBJECT
QAction * action(const char *name) const
bool isEmpty() const const
Q_SLOTSQ_SLOTS
QObject * parent() const const
T & top()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 02:25:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.