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, 2015 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
32class XQQuery;
33class DynamicContext;
34class DebugCommand;
36
38{
39public:
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
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
75protected:
77
78 DebugCommand *findCommand(std::string &command) const;
79 void checkBreak(bool entering);
80 void breakForError(const char *message);
83
84 std::vector<DebugCommand*> commands_;
86
88
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;
98 };
99
100 std::vector<BreakPoint> breaks_;
101 bool step_;
102 unsigned int next_;
103};
104
105class XQILLA_API DebugCommand
106{
107public:
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
121protected:
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
132class XQILLA_API InteractiveDebugger : private BaseInteractiveDebugger,
133 private DebugListener
134{
135public:
136 static void debugQuery(const XQQuery *query, DynamicContext *context);
137 static void outputLocation(const LocationInfo *info, unsigned int context = 0);
138
139private:
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
Definition InteractiveDebugger.hpp:38
std::vector< DebugCommand * > commands_
Definition InteractiveDebugger.hpp:84
virtual void setDoFocusOptimizationsn(bool opt)=0
static std::string regexFind(const char *regex, const std::string &str, int groupNo=1)
void breakForError(const char *message)
bool queryStarted() const
Definition InteractiveDebugger.hpp:59
bool enableBreakPoint(unsigned int number)
static void outputLocationFromString(const XMLCh *query, unsigned int line, unsigned int column, unsigned int context=0)
virtual bool changeFrame(unsigned int number)=0
DebugCommand * prevcmd_
Definition InteractiveDebugger.hpp:85
bool step_
Definition InteractiveDebugger.hpp:101
virtual unsigned int getStackSize() const =0
void listBreakPoints() const
virtual void setDoLazyEvaluation(bool lazy)=0
virtual bool queryCurrentFrame(const char *queryString) const =0
virtual void stackTrace() const =0
virtual void setDoProjection(bool opt)=0
virtual bool outputCurrentFrame(unsigned int context=0) const =0
std::vector< BreakPoint > breaks_
Definition InteractiveDebugger.hpp:100
virtual bool currentFrameLocation(std::string &file, unsigned int &line, unsigned int &column) const =0
virtual void run()=0
virtual void outputCurrentFrameQueryPlan() const =0
void checkBreak(bool entering)
static void outputLocation(const XMLCh *file, unsigned int line, unsigned int column, unsigned int context=0)
bool queryStarted_
Definition InteractiveDebugger.hpp:87
unsigned int setBreakPoint(const std::string &file, unsigned int line, unsigned int column, bool temporary)
bool disableBreakPoint(unsigned int number)
virtual ~BaseInteractiveDebugger()
DebugCommand * findCommand(std::string &command) const
unsigned int next_
Definition InteractiveDebugger.hpp:102
Definition InteractiveDebugger.hpp:106
virtual bool matches(const std::string &command) const
virtual void execute(InputParser::Args &args, BaseInteractiveDebugger &env)=0
const char * name_
Definition InteractiveDebugger.hpp:126
virtual const char * getMoreHelp() const
Definition InteractiveDebugger.hpp:113
static bool matches(const std::string &command, const std::string &toMatch)
virtual const char * getCommandName() const
Definition InteractiveDebugger.hpp:110
const char * moreHelp_
Definition InteractiveDebugger.hpp:129
const char * compatName_
Definition InteractiveDebugger.hpp:127
DebugCommand(const char *name, const char *compatName, const char *briefHelp, const char *moreHelp)
Definition InteractiveDebugger.hpp:122
virtual const char * getCommandNameCompat() const
Definition InteractiveDebugger.hpp:111
const char * briefHelp_
Definition InteractiveDebugger.hpp:128
virtual ~DebugCommand()
Definition InteractiveDebugger.hpp:108
virtual const char * getBriefHelp() const
Definition InteractiveDebugger.hpp:112
A class used to listen for debugging information.
Definition DebugListener.hpp:34
The execution time dynamic context interface.
Definition DynamicContext.hpp:39
std::vector< std::string > Args
Definition InputParser.hpp:32
Definition InteractiveDebugger.hpp:134
static void outputLocation(const LocationInfo *info, unsigned int context=0)
static void debugQuery(const XQQuery *query, DynamicContext *context)
A class that gives records a location in the query.
Definition LocationInfo.hpp:30
A class that represents an item in a query call stack.
Definition StackFrame.hpp:46
Definition XQException.hpp:34
Encapsulates a query expression.
Definition XQQuery.hpp:76
unsigned int column
Definition InteractiveDebugger.hpp:95
bool disabled
Definition InteractiveDebugger.hpp:97
bool temporary
Definition InteractiveDebugger.hpp:96
std::string file
Definition InteractiveDebugger.hpp:94
BreakPoint(const std::string &f, unsigned int l, unsigned int c, bool t)
Definition InteractiveDebugger.hpp:91
unsigned int line
Definition InteractiveDebugger.hpp:95
Definition InteractiveDebugger.hpp:41
Definition InteractiveDebugger.hpp:42
Definition InteractiveDebugger.hpp:40