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, 2018 Oracle and/or its affiliates. All rights reserved.
5  *
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 
20 #ifndef _INTERACTIVEDEBUGGER_HPP
21 #define _INTERACTIVEDEBUGGER_HPP
22 
23 #include <string>
24 #include <vector>
25 #include <map>
26 
29 
31 
32 class XQQuery;
33 class DynamicContext;
34 class DebugCommand;
36 
37 class XQILLA_API BaseInteractiveDebugger
38 {
39 public:
40  struct XQILLA_API Run {};
41  struct XQILLA_API Continue {};
42  struct XQILLA_API Quit {};
43 
44  static void outputLocation(const XMLCh *file, unsigned int line, unsigned int column,
45  unsigned int context = 0);
46  static void outputLocationFromString(const XMLCh *query, unsigned int line, unsigned int column,
47  unsigned int context = 0);
48  static std::string regexFind(const char *regex, const std::string &str, int groupNo = 1);
49 
50  virtual ~BaseInteractiveDebugger();
51 
52  unsigned int setBreakPoint(const std::string &file, unsigned int line, unsigned int column, bool temporary);
53  bool disableBreakPoint(unsigned int number);
54  bool enableBreakPoint(unsigned int number);
55  void listBreakPoints() const;
56 
57  void setStep();
58  void setNext();
59  bool queryStarted() const { return queryStarted_; }
60 
61  virtual void run() = 0;
62 
63  virtual bool changeFrame(unsigned int number) = 0;
64  virtual unsigned int getStackSize() const = 0;
65  virtual void stackTrace() const = 0;
66  virtual bool outputCurrentFrame(unsigned int context = 0) const = 0;
67  virtual void outputCurrentFrameQueryPlan() const = 0;
68  virtual bool queryCurrentFrame(const char *queryString) const = 0;
69  virtual bool currentFrameLocation(std::string &file, unsigned int &line, unsigned int &column) const = 0;
70 
71  virtual void setDoLazyEvaluation(bool lazy) = 0;
72  virtual void setDoFocusOptimizationsn(bool opt) = 0;
73  virtual void setDoProjection(bool opt) = 0;
74 
75 protected:
77 
78  DebugCommand *findCommand(std::string &command) const;
79  void checkBreak(bool entering);
80  void breakForError(const char *message);
81  void interrupted();
82  void readCommand();
83 
84  std::vector<DebugCommand*> commands_;
86 
88 
89  struct BreakPoint
90  {
91  BreakPoint(const std::string &f, unsigned int l, unsigned int c, bool t)
92  : file(f), line(l), column(c), temporary(t), disabled(false) {}
93 
94  std::string file;
95  unsigned int line, column;
96  bool temporary;
97  bool disabled;
98  };
99 
100  std::vector<BreakPoint> breaks_;
101  bool step_;
102  unsigned int next_;
103 };
104 
105 class XQILLA_API DebugCommand
106 {
107 public:
108  virtual ~DebugCommand() {};
109 
110  virtual const char *getCommandName() const { return name_; }
111  virtual const char *getCommandNameCompat() const { return compatName_; }
112  virtual const char *getBriefHelp() const { return briefHelp_; }
113  virtual const char *getMoreHelp() const { return moreHelp_; }
114 
115  static bool matches(const std::string &command,
116  const std::string &toMatch);
117  virtual bool matches(const std::string &command) const;
118 
119  virtual void execute(InputParser::Args &args, BaseInteractiveDebugger &env) = 0;
120 
121 protected:
122  DebugCommand(const char *name, const char *compatName,
123  const char *briefHelp, const char *moreHelp)
124  : name_(name), compatName_(compatName), briefHelp_(briefHelp), moreHelp_(moreHelp) {}
125 
126  const char *name_;
127  const char *compatName_;
128  const char *briefHelp_;
129  const char *moreHelp_;
130 };
131 
132 class XQILLA_API InteractiveDebugger : private BaseInteractiveDebugger,
133  private DebugListener
134 {
135 public:
136  static void debugQuery(const XQQuery *query, DynamicContext *context);
137  static void outputLocation(const LocationInfo *info, unsigned int context = 0);
138 
139 private:
140  InteractiveDebugger(const XQQuery *query, DynamicContext *context);
141 
142  virtual void enter(const StackFrame *stack, const DynamicContext *context);
143  virtual void exit(const StackFrame *stack, const DynamicContext *context);
144  virtual void error(const XQException &error, const StackFrame *stack, const DynamicContext *context);
145  virtual bool doLazyEvaluation() const { return lazy_; }
146  virtual bool doFocusOptimizations() const { return focusOptimzations_; }
147 
148  virtual void run();
149 
150  virtual bool changeFrame(unsigned int number);
151  virtual unsigned int getStackSize() const;
152  virtual void stackTrace() const;
153  virtual bool outputCurrentFrame(unsigned int context) const;
154  virtual void outputCurrentFrameQueryPlan() const;
155  virtual bool queryCurrentFrame(const char *queryString) const;
156  virtual bool currentFrameLocation(std::string &file, unsigned int &line, unsigned int &column) const;
157 
158  virtual void setDoLazyEvaluation(bool lazy) { lazy_ = lazy; }
159  virtual void setDoFocusOptimizationsn(bool opt) { focusOptimzations_ = opt; }
160  virtual void setDoProjection(bool opt);
161 
162  unsigned int getCurrentFrameNumber() const;
163  void output(const StackFrame *frame) const;
164  void report(const StackFrame *frame) const;
165 
166  const StackFrame *stack_;
167  const StackFrame *currentFrame_;
168 
169  const XQQuery *query_;
170  DynamicContext *context_;
171  bool lazy_;
172  bool focusOptimzations_;
173 };
174 
175 #endif
virtual void run()=0
virtual const char * getCommandName() const
Definition: InteractiveDebugger.hpp:110
const char * moreHelp_
Definition: InteractiveDebugger.hpp:129
Definition: InteractiveDebugger.hpp:42
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:33
A class that represents an item in a query call stack.
Definition: StackFrame.hpp:45
virtual void enter(const StackFrame *stack, const DynamicContext *context)
Definition: DebugListener.hpp:40
Definition: InteractiveDebugger.hpp:89
Definition: InteractiveDebugger.hpp:132
virtual bool changeFrame(unsigned int number)=0
DebugCommand(const char *name, const char *compatName, const char *briefHelp, const char *moreHelp)
Definition: InteractiveDebugger.hpp:122
virtual void stackTrace() const =0
std::string file
Definition: InteractiveDebugger.hpp:94
virtual void error(const XQException &error, const StackFrame *stack, const DynamicContext *context)
Definition: DebugListener.hpp:42
A class used to listen for debugging information.
Definition: DebugListener.hpp:34
virtual bool currentFrameLocation(std::string &file, unsigned int &line, unsigned int &column) const =0
bool step_
Definition: InteractiveDebugger.hpp:101
virtual ~DebugCommand()
Definition: InteractiveDebugger.hpp:108
unsigned int line
Definition: InteractiveDebugger.hpp:95
Definition: InteractiveDebugger.hpp:105
virtual void setDoFocusOptimizationsn(bool opt)=0
DebugCommand * prevcmd_
Definition: InteractiveDebugger.hpp:85
Encapsulates a query expression.
Definition: XQQuery.hpp:75
virtual void outputCurrentFrameQueryPlan() const =0
bool queryStarted_
Definition: InteractiveDebugger.hpp:87
virtual const char * getBriefHelp() const
Definition: InteractiveDebugger.hpp:112
std::vector< std::string > Args
Definition: InputParser.hpp:32
virtual const char * getCommandNameCompat() const
Definition: InteractiveDebugger.hpp:111
virtual void exit(const StackFrame *stack, const DynamicContext *context)
Definition: DebugListener.hpp:41
BreakPoint(const std::string &f, unsigned int l, unsigned int c, bool t)
Definition: InteractiveDebugger.hpp:91
virtual unsigned int getStackSize() const =0
std::vector< DebugCommand * > commands_
Definition: InteractiveDebugger.hpp:84
Definition: InteractiveDebugger.hpp:41
bool temporary
Definition: InteractiveDebugger.hpp:96
The execution time dynamic context interface.
Definition: DynamicContext.hpp:38
Definition: InteractiveDebugger.hpp:37
const char * compatName_
Definition: InteractiveDebugger.hpp:127
virtual bool doFocusOptimizations() const
Definition: DebugListener.hpp:45
bool disabled
Definition: InteractiveDebugger.hpp:97
std::vector< BreakPoint > breaks_
Definition: InteractiveDebugger.hpp:100
A class that gives records a location in the query.
Definition: LocationInfo.hpp:29
bool queryStarted() const
Definition: InteractiveDebugger.hpp:59
virtual bool outputCurrentFrame(unsigned int context=0) const =0
virtual bool doLazyEvaluation() const
Definition: DebugListener.hpp:44
Definition: InteractiveDebugger.hpp:40
virtual void setDoProjection(bool opt)=0
virtual void setDoLazyEvaluation(bool lazy)=0
const char * name_
Definition: InteractiveDebugger.hpp:126
const char * briefHelp_
Definition: InteractiveDebugger.hpp:128
unsigned int next_
Definition: InteractiveDebugger.hpp:102
virtual const char * getMoreHelp() const
Definition: InteractiveDebugger.hpp:113