SourceForge.net Logo
InteractiveDebugger.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2008
3  * DecisionSoft Limited. All rights reserved.
4  * Copyright (c) 2004-2008
5  * Oracle. All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * $Id: MessageListener.hpp 475 2008-01-08 18:47:44Z jpcs $
20  */
21 
22 #ifndef _INTERACTIVEDEBUGGER_HPP
23 #define _INTERACTIVEDEBUGGER_HPP
24 
25 #include <string>
26 #include <vector>
27 #include <map>
28 
31 
33 
34 class XQQuery;
35 class DynamicContext;
36 class DebugCommand;
38 
39 class XQILLA_API BaseInteractiveDebugger
40 {
41 public:
42  struct XQILLA_API Run {};
43  struct XQILLA_API Continue {};
44  struct XQILLA_API Quit {};
45 
46  static void outputLocation(const XMLCh *file, unsigned int line, unsigned int column,
47  unsigned int context = 0);
48  static void outputLocationFromString(const XMLCh *query, unsigned int line, unsigned int column,
49  unsigned int context = 0);
50  static std::string regexFind(const char *regex, const std::string &str, int groupNo = 1);
51 
52  virtual ~BaseInteractiveDebugger();
53 
54  unsigned int setBreakPoint(const std::string &file, unsigned int line, unsigned int column, bool temporary);
55  bool disableBreakPoint(unsigned int number);
56  bool enableBreakPoint(unsigned int number);
57  void listBreakPoints() const;
58 
59  void setStep();
60  void setNext();
61  bool queryStarted() const { return queryStarted_; }
62 
63  virtual void run() = 0;
64 
65  virtual bool changeFrame(unsigned int number) = 0;
66  virtual unsigned int getStackSize() const = 0;
67  virtual void stackTrace() const = 0;
68  virtual bool outputCurrentFrame(unsigned int context = 0) const = 0;
69  virtual void outputCurrentFrameQueryPlan() const = 0;
70  virtual bool queryCurrentFrame(const char *queryString) const = 0;
71  virtual bool currentFrameLocation(std::string &file, unsigned int &line, unsigned int &column) const = 0;
72 
73  virtual void setDoLazyEvaluation(bool lazy) = 0;
74  virtual void setDoFocusOptimizationsn(bool opt) = 0;
75  virtual void setDoProjection(bool opt) = 0;
76 
77 protected:
79 
80  DebugCommand *findCommand(std::string &command) const;
81  void checkBreak(bool entering);
82  void breakForError(const char *message);
83  void interrupted();
84  void readCommand();
85 
86  std::vector<DebugCommand*> commands_;
88 
90 
91  struct BreakPoint
92  {
93  BreakPoint(const std::string &f, unsigned int l, unsigned int c, bool t)
94  : file(f), line(l), column(c), temporary(t), disabled(false) {}
95 
96  std::string file;
97  unsigned int line, column;
98  bool temporary;
99  bool disabled;
100  };
101 
102  std::vector<BreakPoint> breaks_;
103  bool step_;
104  unsigned int next_;
105 };
106 
107 class XQILLA_API DebugCommand
108 {
109 public:
110  virtual ~DebugCommand() {};
111 
112  virtual const char *getCommandName() const { return name_; }
113  virtual const char *getCommandNameCompat() const { return compatName_; }
114  virtual const char *getBriefHelp() const { return briefHelp_; }
115  virtual const char *getMoreHelp() const { return moreHelp_; }
116 
117  static bool matches(const std::string &command,
118  const std::string &toMatch);
119  virtual bool matches(const std::string &command) const;
120 
121  virtual void execute(InputParser::Args &args, BaseInteractiveDebugger &env) = 0;
122 
123 protected:
124  DebugCommand(const char *name, const char *compatName,
125  const char *briefHelp, const char *moreHelp)
126  : name_(name), compatName_(compatName), briefHelp_(briefHelp), moreHelp_(moreHelp) {}
127 
128  const char *name_;
129  const char *compatName_;
130  const char *briefHelp_;
131  const char *moreHelp_;
132 };
133 
134 class XQILLA_API InteractiveDebugger : private BaseInteractiveDebugger,
135  private DebugListener
136 {
137 public:
138  static void debugQuery(const XQQuery *query, DynamicContext *context);
139  static void outputLocation(const LocationInfo *info, unsigned int context = 0);
140 
141 private:
142  InteractiveDebugger(const XQQuery *query, DynamicContext *context);
143 
144  virtual void enter(const StackFrame *stack, const DynamicContext *context);
145  virtual void exit(const StackFrame *stack, const DynamicContext *context);
146  virtual void error(const XQException &error, const StackFrame *stack, const DynamicContext *context);
147  virtual bool doLazyEvaluation() const { return lazy_; }
148  virtual bool doFocusOptimizations() const { return focusOptimzations_; }
149 
150  virtual void run();
151 
152  virtual bool changeFrame(unsigned int number);
153  virtual unsigned int getStackSize() const;
154  virtual void stackTrace() const;
155  virtual bool outputCurrentFrame(unsigned int context) const;
156  virtual void outputCurrentFrameQueryPlan() const;
157  virtual bool queryCurrentFrame(const char *queryString) const;
158  virtual bool currentFrameLocation(std::string &file, unsigned int &line, unsigned int &column) const;
159 
160  virtual void setDoLazyEvaluation(bool lazy) { lazy_ = lazy; }
161  virtual void setDoFocusOptimizationsn(bool opt) { focusOptimzations_ = opt; }
162  virtual void setDoProjection(bool opt);
163 
164  unsigned int getCurrentFrameNumber() const;
165  void output(const StackFrame *frame) const;
166  void report(const StackFrame *frame) const;
167 
168  const StackFrame *stack_;
169  const StackFrame *currentFrame_;
170 
171  const XQQuery *query_;
172  DynamicContext *context_;
173  bool lazy_;
174  bool focusOptimzations_;
175 };
176 
177 #endif
virtual void run()=0
virtual const char * getCommandName() const
Definition: InteractiveDebugger.hpp:112
const char * moreHelp_
Definition: InteractiveDebugger.hpp:131
Definition: InteractiveDebugger.hpp:44
virtual bool queryCurrentFrame(const char *queryString) const =0
static void outputLocation(const XMLCh *file, unsigned int line, unsigned int column, unsigned int context=0)
Definition: XQException.hpp:35
A class that represents an item in a query call stack.
Definition: StackFrame.hpp:47
virtual void enter(const StackFrame *stack, const DynamicContext *context)
Definition: DebugListener.hpp:42
Definition: InteractiveDebugger.hpp:91
Definition: InteractiveDebugger.hpp:134
virtual bool changeFrame(unsigned int number)=0
DebugCommand(const char *name, const char *compatName, const char *briefHelp, const char *moreHelp)
Definition: InteractiveDebugger.hpp:124
virtual void stackTrace() const =0
std::string file
Definition: InteractiveDebugger.hpp:96
virtual void error(const XQException &error, const StackFrame *stack, const DynamicContext *context)
Definition: DebugListener.hpp:44
A class used to listen for debugging information.
Definition: DebugListener.hpp:36
virtual bool currentFrameLocation(std::string &file, unsigned int &line, unsigned int &column) const =0
bool step_
Definition: InteractiveDebugger.hpp:103
virtual ~DebugCommand()
Definition: InteractiveDebugger.hpp:110
unsigned int line
Definition: InteractiveDebugger.hpp:97
Definition: InteractiveDebugger.hpp:107
virtual void setDoFocusOptimizationsn(bool opt)=0
DebugCommand * prevcmd_
Definition: InteractiveDebugger.hpp:87
Encapsulates a query expression.
Definition: XQQuery.hpp:57
virtual void outputCurrentFrameQueryPlan() const =0
bool queryStarted_
Definition: InteractiveDebugger.hpp:89
virtual const char * getBriefHelp() const
Definition: InteractiveDebugger.hpp:114
std::vector< std::string > Args
Definition: InputParser.hpp:34
virtual const char * getCommandNameCompat() const
Definition: InteractiveDebugger.hpp:113
virtual void exit(const StackFrame *stack, const DynamicContext *context)
Definition: DebugListener.hpp:43
BreakPoint(const std::string &f, unsigned int l, unsigned int c, bool t)
Definition: InteractiveDebugger.hpp:93
virtual unsigned int getStackSize() const =0
std::vector< DebugCommand * > commands_
Definition: InteractiveDebugger.hpp:86
Definition: InteractiveDebugger.hpp:43
bool temporary
Definition: InteractiveDebugger.hpp:98
The execution time dynamic context interface.
Definition: DynamicContext.hpp:39
Definition: InteractiveDebugger.hpp:39
const char * compatName_
Definition: InteractiveDebugger.hpp:129
virtual bool doFocusOptimizations() const
Definition: DebugListener.hpp:47
bool disabled
Definition: InteractiveDebugger.hpp:99
std::vector< BreakPoint > breaks_
Definition: InteractiveDebugger.hpp:102
A class that gives records a location in the query.
Definition: LocationInfo.hpp:31
bool queryStarted() const
Definition: InteractiveDebugger.hpp:61
virtual bool outputCurrentFrame(unsigned int context=0) const =0
virtual bool doLazyEvaluation() const
Definition: DebugListener.hpp:46
Definition: InteractiveDebugger.hpp:42
virtual void setDoProjection(bool opt)=0
virtual void setDoLazyEvaluation(bool lazy)=0
const char * name_
Definition: InteractiveDebugger.hpp:128
const char * briefHelp_
Definition: InteractiveDebugger.hpp:130
unsigned int next_
Definition: InteractiveDebugger.hpp:104
virtual const char * getMoreHelp() const
Definition: InteractiveDebugger.hpp:115