File indexing completed on 2024-12-01 09:50:26
0001 /* 0002 * This file is part of the KDE libraries 0003 * Copyright (C) 2006 Matt Broadstone (mbroadst@gmail.com) 0004 * Copyright (C) 2007 Maksim Orlovich (maksim@kde.org) 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 #ifndef KJSDBG_ICTX_H 0021 #define KJSDBG_ICTX_H 0022 0023 #include <QStack> 0024 #include <QString> 0025 #include "debugdocument.h" 0026 0027 namespace KJS 0028 { 0029 class ExecState; 0030 } 0031 0032 namespace KTextEditor 0033 { 0034 class MarkInterface; 0035 } 0036 0037 namespace KJSDebugger 0038 { 0039 0040 enum Mode { 0041 Normal = 0, // Only stop at breakpoints 0042 StepOver = 1, // Will break on next statement in current context 0043 StepOut = 2, // Will break one or more contexts above. 0044 Step = 3, // Will break on next statement in current or deeper context 0045 Abort = 4 // The script will stop execution completely, 0046 // as soon as possible 0047 }; 0048 0049 struct CallStackEntry { 0050 QString name; 0051 int lineNumber; 0052 DebugDocument::Ptr doc; 0053 0054 bool operator==(const CallStackEntry &other) const 0055 { 0056 return ((other.name == name) && 0057 (other.lineNumber == lineNumber) && 0058 (other.doc == doc)); 0059 } 0060 }; 0061 0062 // This contains information we have to keep track of per-interpreter, 0063 // such as the stack information. 0064 struct InterpreterContext { 0065 Mode mode; 0066 QStack<KJS::ExecState *> execContexts; 0067 int depthAtSkip; // How far we were in on stepOut 0068 // our stepOver. 0069 QStack<CallStackEntry> callStack; 0070 0071 // Document and line we're currently in 0072 DebugDocument::Ptr activeDocument(); 0073 int activeLine(); 0074 0075 bool hasActiveDocument() const; 0076 0077 InterpreterContext() : mode(Normal), depthAtSkip(0) 0078 {} 0079 0080 /** 0081 * add a new entry to the call stack 0082 * 0083 * @param doc the document the function is in 0084 * @param function the function called 0085 * @param line the line number of the function 0086 */ 0087 void addCall(DebugDocument::Ptr doc, const QString &function, int line); 0088 /** 0089 * update the line number of the current context 0090 * 0091 * @param line the new line number within the current function 0092 */ 0093 void updateCall(int line); 0094 void removeCall(); 0095 0096 }; 0097 0098 } 0099 0100 #endif 0101