2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
16 #ifndef __DEBUGGER_MANAGER_HXX__
17 #define __DEBUGGER_MANAGER_HXX__
21 #include "abstractdebugger.hxx"
22 #include "configvariable.hxx"
23 #include "breakpoint.hxx"
24 #include "dynlib_ast.h"
28 class EXTERN_AST DebuggerManager
42 std::string functionName;
50 typedef std::vector<StackRow> Stack;
58 static std::unique_ptr<DebuggerManager> me;
62 callstack(), pExp(nullptr), interrupted(false), currentBreakPoint(-1), action(Continue), level(0) {}
64 Breakpoints breakpoints;
71 int currentBreakPoint;
75 void internal_execution_released();
77 bool callstackAddFile(StackRow* _row, const std::wstring& _fileName);
82 for (auto d : debuggers)
87 for (auto b : breakpoints)
95 static DebuggerManager* getInstance();
98 void addDebugger(const std::string& _name, AbstractDebugger* _debug);
99 void removeDebugger(const std::string& _name);
100 AbstractDebugger* getDebugger(const std::string& _name);
101 int getDebuggerCount();
102 Debuggers& getAllDebugger();
104 void setExp(const ast::Exp* _pExp)
106 pExp = const_cast<ast::Exp*>(_pExp);
122 Breakpoint* getCurrentBreakPoint()
124 if (currentBreakPoint != -1)
126 return getBreakPoint(currentBreakPoint);
132 void generateCallStack();
133 inline void clearCallStack()
135 callstack.exp.clear();
136 callstack.stack.clear();
139 CallStack& getCallStack()
144 //send information to debuggers
145 void sendStop(int index);
146 void sendExecution();
147 void sendExecutionReleased();
148 void sendPrint(const std::string& variable);
149 void sendShow(int bp);
152 void sendErrorInFile(const std::wstring& filename) const;
153 void sendErrorInScript(const std::wstring& funcname) const;
155 void sendUpdate() const;
157 void stop(const ast::Exp* pExp, int index);
158 void errorInFile(const std::wstring filename, const ast::Exp* pExp);
159 void errorInScript(const std::wstring funcname, const ast::Exp* pExp);
161 //breakpoints functions
162 bool addBreakPoint(Breakpoint* bp);
163 bool updateBreakPoint(Breakpoint* bp);
164 bool removeBreakPoint(Breakpoint* bp);
165 Breakpoints::iterator findBreakPoint(Breakpoint* bp);
166 void removeBreakPoint(int _iBreakPoint);
167 void setAllBreakPoints(Breakpoints& _bps);
168 void removeAllBreakPoints();
169 void disableAllBreakPoints();
170 void disableBreakPoint(int _iBreakPoint);
171 void enableAllBreakPoints();
172 void enableBreakPoint(int _iBreakPoint);
173 bool isEnableBreakPoint(int _iBreakPoint);
174 Breakpoint* getBreakPoint(int _iBreakPoint);
175 int getBreakPointCount();
176 Breakpoints& getAllBreakPoint();
178 //actions called by debuggers
179 inline void setStepIn() //enter macro
182 level = symbol::Context::getInstance()->getScopeLevel();
185 inline bool isStepIn()
187 int l = symbol::Context::getInstance()->getScopeLevel();
188 //if stepIn failed ( not a macro ), stepIn become a stepNext
203 inline void resetStepIn()
211 inline void setStepOut() //exit macro
214 level = ConfigVariable::getWhere().size();
217 inline bool isStepOut()
219 int l = ConfigVariable::getWhere().size();
220 return action == StepOut && l < level;
223 inline void resetStepOut()
231 inline void setAborted() //next statement
236 inline bool isAborted()
238 return action == Aborted;
241 inline void resetAborted()
249 inline void setStepNext() //next statement
252 level = symbol::Context::getInstance()->getScopeLevel();
255 inline bool isStepNext()
257 int l = symbol::Context::getInstance()->getScopeLevel();
258 //if stepNext failed ( end of macro ), stepNext become a stepOut
259 return action == StepNext && l <= level;
262 inline void resetStepNext()
270 inline void resetStep()
272 if (isInterrupted() == false)
278 char* execute(const std::string& command); //execute a command
279 void print(const std::string& variable); //print a variable
280 void show(int bp); //print the breakpoint bp or all breakpoints (bp = -1)
281 void resume(); //resume execution
282 void abort(); //abort execution
283 void requestPause(); //pause execution
284 bool isPauseRequested(); //get pause request status
285 void resetPauseRequest(); //reset pause request status
289 #endif /* !__DEBUGGER_MANAGER_HXX__ */