00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _INTERACTIVEDEBUGGER_HPP
00023 #define _INTERACTIVEDEBUGGER_HPP
00024
00025 #include <string>
00026 #include <vector>
00027 #include <map>
00028
00029 #include <xqilla/debug/DebugListener.hpp>
00030 #include <xqilla/ast/LocationInfo.hpp>
00031
00032 #include <xqilla/debug/InputParser.hpp>
00033
00034 class XQQuery;
00035 class DynamicContext;
00036 class DebugCommand;
00037 class InteractiveDebugger;
00038
00039 class XQILLA_API BaseInteractiveDebugger
00040 {
00041 public:
00042 struct XQILLA_API Run {};
00043 struct XQILLA_API Continue {};
00044 struct XQILLA_API Quit {};
00045
00046 static void outputLocation(const XMLCh *file, unsigned int line, unsigned int column,
00047 unsigned int context = 0);
00048 static void outputLocationFromString(const XMLCh *query, unsigned int line, unsigned int column,
00049 unsigned int context = 0);
00050 static std::string regexFind(const char *regex, const std::string &str, int groupNo = 1);
00051
00052 virtual ~BaseInteractiveDebugger();
00053
00054 unsigned int setBreakPoint(const std::string &file, unsigned int line, unsigned int column, bool temporary);
00055 bool disableBreakPoint(unsigned int number);
00056 bool enableBreakPoint(unsigned int number);
00057 void listBreakPoints() const;
00058
00059 void setStep();
00060 void setNext();
00061 bool queryStarted() const { return queryStarted_; }
00062
00063 virtual void run() = 0;
00064
00065 virtual bool changeFrame(unsigned int number) = 0;
00066 virtual unsigned int getStackSize() const = 0;
00067 virtual void stackTrace() const = 0;
00068 virtual bool outputCurrentFrame(unsigned int context = 0) const = 0;
00069 virtual void outputCurrentFrameQueryPlan() const = 0;
00070 virtual bool queryCurrentFrame(const char *queryString) const = 0;
00071 virtual bool currentFrameLocation(std::string &file, unsigned int &line, unsigned int &column) const = 0;
00072
00073 virtual void setDoLazyEvaluation(bool lazy) = 0;
00074 virtual void setDoFocusOptimizationsn(bool opt) = 0;
00075 virtual void setDoProjection(bool opt) = 0;
00076
00077 protected:
00078 BaseInteractiveDebugger();
00079
00080 DebugCommand *findCommand(std::string &command) const;
00081 void checkBreak(bool entering);
00082 void breakForError(const char *message);
00083 void interrupted();
00084 void readCommand();
00085
00086 std::vector<DebugCommand*> commands_;
00087 DebugCommand *prevcmd_;
00088
00089 bool queryStarted_;
00090
00091 struct BreakPoint
00092 {
00093 BreakPoint(const std::string &f, unsigned int l, unsigned int c, bool t)
00094 : file(f), line(l), column(c), temporary(t), disabled(false) {}
00095
00096 std::string file;
00097 unsigned int line, column;
00098 bool temporary;
00099 bool disabled;
00100 };
00101
00102 std::vector<BreakPoint> breaks_;
00103 bool step_;
00104 unsigned int next_;
00105 };
00106
00107 class XQILLA_API DebugCommand
00108 {
00109 public:
00110 virtual ~DebugCommand() {};
00111
00112 virtual const char *getCommandName() const { return name_; }
00113 virtual const char *getCommandNameCompat() const { return compatName_; }
00114 virtual const char *getBriefHelp() const { return briefHelp_; }
00115 virtual const char *getMoreHelp() const { return moreHelp_; }
00116
00117 static bool matches(const std::string &command,
00118 const std::string &toMatch);
00119 virtual bool matches(const std::string &command) const;
00120
00121 virtual void execute(InputParser::Args &args, BaseInteractiveDebugger &env) = 0;
00122
00123 protected:
00124 DebugCommand(const char *name, const char *compatName,
00125 const char *briefHelp, const char *moreHelp)
00126 : name_(name), compatName_(compatName), briefHelp_(briefHelp), moreHelp_(moreHelp) {}
00127
00128 const char *name_;
00129 const char *compatName_;
00130 const char *briefHelp_;
00131 const char *moreHelp_;
00132 };
00133
00134 class XQILLA_API InteractiveDebugger : private BaseInteractiveDebugger,
00135 private DebugListener
00136 {
00137 public:
00138 static void debugQuery(const XQQuery *query, DynamicContext *context);
00139 static void outputLocation(const LocationInfo *info, unsigned int context = 0);
00140
00141 private:
00142 InteractiveDebugger(const XQQuery *query, DynamicContext *context);
00143
00144 virtual void enter(const StackFrame *stack, const DynamicContext *context);
00145 virtual void exit(const StackFrame *stack, const DynamicContext *context);
00146 virtual void error(const XQException &error, const StackFrame *stack, const DynamicContext *context);
00147 virtual bool doLazyEvaluation() const { return lazy_; }
00148 virtual bool doFocusOptimizations() const { return focusOptimzations_; }
00149
00150 virtual void run();
00151
00152 virtual bool changeFrame(unsigned int number);
00153 virtual unsigned int getStackSize() const;
00154 virtual void stackTrace() const;
00155 virtual bool outputCurrentFrame(unsigned int context) const;
00156 virtual void outputCurrentFrameQueryPlan() const;
00157 virtual bool queryCurrentFrame(const char *queryString) const;
00158 virtual bool currentFrameLocation(std::string &file, unsigned int &line, unsigned int &column) const;
00159
00160 virtual void setDoLazyEvaluation(bool lazy) { lazy_ = lazy; }
00161 virtual void setDoFocusOptimizationsn(bool opt) { focusOptimzations_ = opt; }
00162 virtual void setDoProjection(bool opt);
00163
00164 unsigned int getCurrentFrameNumber() const;
00165 void output(const StackFrame *frame) const;
00166 void report(const StackFrame *frame) const;
00167
00168 const StackFrame *stack_;
00169 const StackFrame *currentFrame_;
00170
00171 const XQQuery *query_;
00172 DynamicContext *context_;
00173 bool lazy_;
00174 bool focusOptimzations_;
00175 };
00176
00177 #endif