# XQilla Simple API Documentation

- Main Page
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

# InteractiveDebugger.hpp

Go to the documentation of this file.

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