added Info.plist
[TestXSLT.git] / libsablot / src / engine / debugger.h
1 /* -*- mode: c++ -*-
2  * The contents of this file are subject to the Mozilla Public
3  * License Version 1.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.mozilla.org/MPL/
6  * 
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  * 
12  * The Original Code is the Sablotron XSLT Processor.
13  * 
14  * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15  * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16  * Ginger Alliance Ltd. All Rights Reserved.
17  * 
18  * Contributor(s):
19  * 
20  * Alternatively, the contents of this file may be used under the
21  * terms of the GNU General Public License Version 2 or later (the
22  * "GPL"), in which case the provisions of the GPL are applicable 
23  * instead of those above.  If you wish to allow use of your 
24  * version of this file only under the terms of the GPL and not to
25  * allow others to use your version of this file under the MPL,
26  * indicate your decision by deleting the provisions above and
27  * replace them with the notice and other provisions required by
28  * the GPL.  If you do not delete the provisions above, a recipient
29  * may use your version of this file under either the MPL or the
30  * GPL.
31  */
32
33 #ifndef DebuggerHIncl
34 #define DebuggerHIncl
35
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 #ifdef SABLOT_DEBUGGER
41
42 #include "base.h"
43 #include "datastr.h"
44 #include "shandler.h"
45
46 class Element;
47 class Context;
48 class Tree;
49 class SubtreeInfo;
50 class Expression;
51
52 /*helper classes */
53 class ArgList: public PList<Str*> {};
54
55 class Breakpoint {
56  public:
57   Breakpoint(): line(-1), enabled(true), 
58     valid(false), element(NULL), expr(NULL), ignoreNum(0),
59     hitTotal(0), hitEnabled(0), hitMatched(0), hitBreak(0) {};
60   ~Breakpoint();
61   //methods
62   Bool buildExpression(Sit);
63   Bool matches(Sit S, Context* c, Bool& wasError);
64   Bool countMatches(Sit S, Context* c, Bool& wasError);
65   void reset();
66   Bool countEnabled();
67   //fields
68   Str uri;
69   int line;
70   Str condition;
71   Bool enabled;
72   Bool valid;
73   Element* element;
74   Expression *expr;
75   int ignoreNum;
76   int hitTotal;
77   int hitEnabled;
78   int hitMatched;
79   int hitBreak;
80 };
81
82 class BPList: public PList<Breakpoint*> {
83  public:
84   ~BPList() { freeall(FALSE); };
85   Breakpoint* setBP(Str& uri, int line);
86   Breakpoint* getBP(Str& uri, int line);
87   Bool clearBP(int idx, Bool running);
88   Bool disableBP(int idx);
89   void clearAll(Bool);
90   void listAll(Bool);
91   void statAll(Bool);
92   void getLinesForURI(Str& uri, List<int>& lines);
93   void reset();
94   Bool ignore(long int idx, long int num);
95   Bool setExpression(Sit, int, ArgList&, Bool);
96 };
97
98
99 enum DbgCommand 
100 {
101   SDBG_NOOP,
102   SDBG_BATCH,
103   SDBG_BREAK,
104   SDBG_BREAK_CLEAR,
105   SDBG_BREAK_CLEARALL,
106   SDBG_BREAK_DISABLE,
107   SDBG_BREAK_LIST,
108   SDBG_BREAK_COND,
109   SDBG_BREAK_STAT,
110   SDBG_BREAK_IGNORE,
111   SDBG_CONTEXT,
112   SDBG_CONTINUE,
113   SDBG_KILL,
114   SDBG_DATA,
115   SDBG_EVAL,
116   SDBG_NEXT,
117   SDBG_FINISH,
118   SDBG_OUTPUT,
119   SDBG_STEP,
120   SDBG_PARAM,
121   SDBG_PARAM_CLEAR,
122   SDBG_PARAM_LIST,
123   SDBG_POINT,
124   SDBG_QUIT,
125   SDBG_RUN,
126   SDBG_SHEET,
127   SDBG_TEMPLATE,
128   SDBG_TEST,
129   SDBG_HELP
130 };
131
132 struct DbgCommandDescription {
133   const char* command;
134   int argsMin;
135   int argsMax;
136   Bool joinRest; //take rest params as one
137   Bool strict; //prevent ambiguous abbreviations
138   DbgCommand op;
139 };
140
141 class Debugger 
142 {
143  public:
144   Debugger();
145   ~Debugger();
146   Bool isRunning() { return running; };
147   Bool outputActive() {return output; };
148   void enterIdle();
149   eFlag prompt(Sit S, Element *e, Context *c, Bool& quited);
150   eFlag breakOnElement(Sit S, Element *e, Context *c);
151   void setBreakpoints(Sit S, Tree*);
152   void printOutput(const char* buff, int size);
153  private:
154   eFlag doCommand(Sit S, Element *e, Context *c, char* line, Bool&, Bool&);
155   void reportTrace(const char* msg, Str& uri, int line, Element *e);
156   Bool elementBreakable(Sit S, Element *e, Context *c, Bool report);
157   Bool tokenize(char* what, ArgList &where, DbgCommandDescription& desc);
158   Bool lookupArg(Str &str, char** lst, int &op);
159   Bool lookupCommand(Str& str, DbgCommandDescription& out);
160   const char* nodeTypeName(Vertex *v);
161   void listNode(Sit S, NodeHandle node, Bool detailed);
162   void listContext(Sit S, Element *e, Context *c, ArgList &args);
163   void setBreakpoint(Sit S, Element *e, ArgList& args);
164   void doSetBreakpoint(Str& uri, int line);
165   void setBreakpointsOnElement(Sit S, Element *e);
166   Bool findElementForBreakpoint(Element *e, Breakpoint* bp);
167   Bool setBreakpointRunning(Breakpoint *bp);
168   Bool checkIdle();
169   Bool checkRunning();
170   void run();
171   void reportError(const char* msg, Bool details);
172   void eval(Sit S, Context *c, Element *e, ArgList& args);
173   void playBatch(Sit S, Element *e, Context *c, Str& file);
174   void printUsage();
175   void addParam(ArgList& args);
176   void report(Sit S, MsgType type, MsgCode code, 
177               const Str& arg1, const Str& arg2) const;
178   Bool checkArgs(DbgCommandDescription& desc, ArgList& args);
179   static MH_ERROR mhMakeCode(void *userData, SablotHandle processor_,
180                              int severity, unsigned short facility, 
181                              unsigned short code);
182   static MH_ERROR mhLog(void *userData, SablotHandle processor_,
183                         MH_ERROR code, MH_LEVEL level, char **fields);
184   static MH_ERROR mhError(void *userData, SablotHandle processor_,
185                           MH_ERROR code, MH_LEVEL level, 
186                           char **fields);
187   BPList bpoints;
188   Bool running;
189   SablotHandle situa;
190   Str sheetURI;
191   Str dataURI;
192   Bool instep;
193   Bool intempl;
194   Element* nextele;
195   Bool output;
196   int outputLine;
197   int outputLastLine;
198   MessageHandler msgHandler;
199   StrStrList messages;
200   StrStrList params;
201   SubtreeInfo *currentInfo; //used for bp setting
202   List<int> currentLines; //used for bp setting
203   Bool inRightTree;
204   Tree *sheet;
205   int errorCode;
206 };
207
208
209 //globals
210 extern Debugger* debugger;
211
212 #endif //SABLOT_DEBUGGER
213 #endif //DebuggerHIncl