summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine ELIAS <antoine.elias@esi-group.com>2019-07-30 15:30:28 +0200
committerAntoine ELIAS <antoine.elias@esi-group.com>2019-07-31 12:02:03 +0200
commit59989ac47463fc47ca5c246dd4597dd4440329dd (patch)
tree4f90e96ef629748a7117b9c5010765a5459af6ad
parent11e9ecd2cd83a83921a4ed568ee0c3c89fe2a34b (diff)
downloadscilab-59989ac47463fc47ca5c246dd4597dd4440329dd.zip
scilab-59989ac47463fc47ca5c246dd4597dd4440329dd.tar.gz
reduce overhead of debugger and improve output of functions
Change-Id: I2e628ffb6acb06a06fba58f4d4e03c76ecb57426
-rw-r--r--scilab/modules/ast/includes/ast/debugmanager.hxx13
-rw-r--r--scilab/modules/ast/src/cpp/ast/debuggervisitor.cpp118
-rw-r--r--scilab/modules/ast/src/cpp/ast/debugmanager.cpp2
3 files changed, 98 insertions, 35 deletions
diff --git a/scilab/modules/ast/includes/ast/debugmanager.hxx b/scilab/modules/ast/includes/ast/debugmanager.hxx
index 7b95732..9b1bdb6 100644
--- a/scilab/modules/ast/includes/ast/debugmanager.hxx
+++ b/scilab/modules/ast/includes/ast/debugmanager.hxx
@@ -83,6 +83,7 @@ public:
83 { 83 {
84 delete d.second; 84 delete d.second;
85 } 85 }
86
86 for (auto b : breakpoints) 87 for (auto b : breakpoints)
87 { 88 {
88 delete b; 89 delete b;
@@ -135,7 +136,7 @@ public:
135 callstack.stack.clear(); 136 callstack.stack.clear();
136 } 137 }
137 138
138 CallStack getCallStack() 139 CallStack& getCallStack()
139 { 140 {
140 return callstack; 141 return callstack;
141 } 142 }
@@ -172,7 +173,7 @@ public:
172 Breakpoints& getAllBreakPoint(); 173 Breakpoints& getAllBreakPoint();
173 174
174 //watches functions 175 //watches functions
175 void setWatches(Watches _w); 176 void setWatches(const Watches& _w);
176 void removeWatches(); 177 void removeWatches();
177 void updateWatches(int _iScopeLvl = -1); 178 void updateWatches(int _iScopeLvl = -1);
178 Watches& getWatches(); 179 Watches& getWatches();
@@ -183,6 +184,7 @@ public:
183 action = StepIn; 184 action = StepIn;
184 level = symbol::Context::getInstance()->getScopeLevel(); 185 level = symbol::Context::getInstance()->getScopeLevel();
185 } 186 }
187
186 inline bool isStepIn() 188 inline bool isStepIn()
187 { 189 {
188 int l = symbol::Context::getInstance()->getScopeLevel(); 190 int l = symbol::Context::getInstance()->getScopeLevel();
@@ -200,6 +202,7 @@ public:
200 202
201 return true; 203 return true;
202 } 204 }
205
203 inline void resetStepIn() 206 inline void resetStepIn()
204 { 207 {
205 if (isStepIn()) 208 if (isStepIn())
@@ -213,11 +216,13 @@ public:
213 action = StepOut; 216 action = StepOut;
214 level = ConfigVariable::getWhere().size(); 217 level = ConfigVariable::getWhere().size();
215 } 218 }
219
216 inline bool isStepOut() 220 inline bool isStepOut()
217 { 221 {
218 int l = ConfigVariable::getWhere().size(); 222 int l = ConfigVariable::getWhere().size();
219 return action == StepOut && l < level; 223 return action == StepOut && l < level;
220 } 224 }
225
221 inline void resetStepOut() 226 inline void resetStepOut()
222 { 227 {
223 if (isStepOut()) 228 if (isStepOut())
@@ -230,10 +235,12 @@ public:
230 { 235 {
231 action = Aborted; 236 action = Aborted;
232 } 237 }
238
233 inline bool isAborted() 239 inline bool isAborted()
234 { 240 {
235 return action == Aborted; 241 return action == Aborted;
236 } 242 }
243
237 inline void resetAborted() 244 inline void resetAborted()
238 { 245 {
239 if (isAborted()) 246 if (isAborted())
@@ -247,12 +254,14 @@ public:
247 action = StepNext; 254 action = StepNext;
248 level = symbol::Context::getInstance()->getScopeLevel(); 255 level = symbol::Context::getInstance()->getScopeLevel();
249 } 256 }
257
250 inline bool isStepNext() 258 inline bool isStepNext()
251 { 259 {
252 int l = symbol::Context::getInstance()->getScopeLevel(); 260 int l = symbol::Context::getInstance()->getScopeLevel();
253 //if stepNext failed ( end of macro ), stepNext become a stepOut 261 //if stepNext failed ( end of macro ), stepNext become a stepOut
254 return action == StepNext && l <= level; 262 return action == StepNext && l <= level;
255 } 263 }
264
256 inline void resetStepNext() 265 inline void resetStepNext()
257 { 266 {
258 if (isStepNext()) 267 if (isStepNext())
diff --git a/scilab/modules/ast/src/cpp/ast/debuggervisitor.cpp b/scilab/modules/ast/src/cpp/ast/debuggervisitor.cpp
index 7a504ae..bd803c0 100644
--- a/scilab/modules/ast/src/cpp/ast/debuggervisitor.cpp
+++ b/scilab/modules/ast/src/cpp/ast/debuggervisitor.cpp
@@ -18,6 +18,8 @@
18#include "printvisitor.hxx" 18#include "printvisitor.hxx"
19#include "execvisitor.hxx" 19#include "execvisitor.hxx"
20#include "threadId.hxx" 20#include "threadId.hxx"
21#include "macrofile.hxx"
22#include "commentexp.hxx"
21 23
22extern "C" 24extern "C"
23{ 25{
@@ -35,6 +37,11 @@ void DebuggerVisitor::visit(const SeqExp &e)
35 37
36 for (const auto & exp : e.getExps()) 38 for (const auto & exp : e.getExps())
37 { 39 {
40 if (exp->isCommentExp())
41 {
42 continue;
43 }
44
38 if (e.isBreakable()) 45 if (e.isBreakable())
39 { 46 {
40 exp->resetBreak(); 47 exp->resetBreak();
@@ -69,11 +76,11 @@ void DebuggerVisitor::visit(const SeqExp &e)
69 } 76 }
70 else 77 else
71 { 78 {
72 std::vector<ConfigVariable::WhereEntry> lWhereAmI = ConfigVariable::getWhere(); 79 const std::vector<ConfigVariable::WhereEntry>& lWhereAmI = ConfigVariable::getWhere();
73 //set information from debugger commands 80 //set information from debugger commands
74 if (lWhereAmI.size() != 0 && manager->getBreakPointCount() != 0) 81 if (lWhereAmI.size() != 0 && manager->getBreakPointCount() != 0)
75 { 82 {
76 debugger::Breakpoints bps = manager->getAllBreakPoint(); 83 debugger::Breakpoints& bps = manager->getAllBreakPoint();
77 84
78 int i = -1; 85 int i = -1;
79 for (const auto & bp : bps) 86 for (const auto & bp : bps)
@@ -85,52 +92,56 @@ void DebuggerVisitor::visit(const SeqExp &e)
85 } 92 }
86 93
87 // look for a breakpoint on this line and update breakpoint information when possible 94 // look for a breakpoint on this line and update breakpoint information when possible
88 char* functionName = wide_string_to_UTF8(lWhereAmI.back().call->getName().data());
89 std::wstring pstrFileName = *lWhereAmI.back().m_file_name;
90 char* fileName = wide_string_to_UTF8(pstrFileName.data());
91
92 int iLine = exp->getLocation().first_line - ConfigVariable::getMacroFirstLines(); 95 int iLine = exp->getLocation().first_line - ConfigVariable::getMacroFirstLines();
93 if (bp->hasMacro() && 96 if (bp->hasMacro())
94 bp->getFunctioName().compare(functionName) == 0)
95 { 97 {
96 if (bp->getMacroLine() == 0) 98 char* functionName = wide_string_to_UTF8(lWhereAmI.back().call->getName().data());
99 if (bp->getFunctioName().compare(functionName) == 0)
97 { 100 {
98 //first pass in macro. 101 if (bp->getMacroLine() == 0)
99 //update first line with real value 102 {
100 bp->setMacroLine(iLine); 103 //first pass in macro.
104 //update first line with real value
105 bp->setMacroLine(iLine);
106 }
107
108 stopExecution = bp->getMacroLine() == iLine;
101 } 109 }
102 110
103 stopExecution = bp->getMacroLine() == iLine; 111 FREE(functionName);
104 } 112 }
105 else if(bp->hasFile() && 113 else if (bp->hasFile())
106 bp->getFileLine() == exp->getLocation().first_line)
107 { 114 {
108 if(pstrFileName.rfind(L".bin") != std::string::npos) 115 if (bp->getFileLine() == exp->getLocation().first_line)
109 { 116 {
110 pstrFileName.replace(pstrFileName.size() - 4, 4, L".sci"); 117 std::wstring pstrFileName = *lWhereAmI.back().m_file_name;
111 // stop on bp only if the file exist 118 char* fileName = wide_string_to_UTF8(pstrFileName.data());
112 if (FileExistW(pstrFileName.data())) 119
120 if (pstrFileName.rfind(L".bin") != std::string::npos)
113 { 121 {
114 FREE(fileName); 122 pstrFileName.replace(pstrFileName.size() - 4, 4, L".sci");
115 fileName = wide_string_to_UTF8(pstrFileName.data()); 123 // stop on bp only if the file exist
124 if (FileExistW(pstrFileName.data()))
125 {
126 FREE(fileName);
127 fileName = wide_string_to_UTF8(pstrFileName.data());
128 }
116 } 129 }
117 }
118 130
119 if(bp->getFileName().compare(fileName) == 0) 131 if (bp->getFileName().compare(fileName) == 0)
120 {
121 stopExecution = true;
122 // set function information
123 if(lWhereAmI.back().call->getFirstLine())
124 { 132 {
125 bp->setFunctionName(functionName); 133 char* functionName = wide_string_to_UTF8(lWhereAmI.back().call->getName().data());
126 bp->setMacroLine(iLine); 134 stopExecution = true;
135 // set function information
136 if (lWhereAmI.back().call->getFirstLine())
137 {
138 bp->setFunctionName(functionName);
139 bp->setMacroLine(iLine);
140 }
127 } 141 }
128 } 142 }
129 } 143 }
130 144
131 FREE(functionName);
132 FREE(fileName);
133
134 if(stopExecution == false) 145 if(stopExecution == false)
135 { 146 {
136 // no breakpoint for this line 147 // no breakpoint for this line
@@ -369,5 +380,48 @@ void DebuggerVisitor::visit(const SeqExp &e)
369 setResult(NULL); 380 setResult(NULL);
370 381
371 } 382 }
383
384 if (e.getParent() == NULL && e.getExecFrom() == SeqExp::SCRIPT && manager->isStepNext())
385 {
386 const std::vector<ConfigVariable::WhereEntry>& lWhereAmI = ConfigVariable::getWhere();
387 if (lWhereAmI.size())
388 {
389 std::wstring functionName = lWhereAmI.back().call->getName();
390 types::InternalType* pIT = symbol::Context::getInstance()->get(symbol::Symbol(functionName));
391 if (pIT && (pIT->isMacro() || pIT->isMacroFile()))
392 {
393 types::Macro* m = nullptr;
394 if (pIT->isMacroFile())
395 {
396 types::MacroFile* mf = pIT->getAs<types::MacroFile>();
397 m = mf->getMacro();
398 }
399 else
400 {
401 m = pIT->getAs<types::Macro>();
402 }
403
404 //create a fake exp to represente end/enfunction
405
406 //will be deleted by CommentExp
407 std::wstring* comment = new std::wstring(L"end of function");
408 Location loc(m->getLastLine(), m->getLastLine(), 0, 0);
409 CommentExp fakeExp(loc, comment);
410 manager->stop(&fakeExp, -1);
411
412 if (manager->isAborted())
413 {
414 throw ast::InternalAbort();
415 }
416
417 //transform stepnext after endfunction as a stepout to show line marker on current statement
418 if (manager->isStepNext())
419 {
420 manager->resetStepNext();
421 manager->setStepOut();
422 }
423 }
424 }
425 }
372} 426}
373} 427}
diff --git a/scilab/modules/ast/src/cpp/ast/debugmanager.cpp b/scilab/modules/ast/src/cpp/ast/debugmanager.cpp
index 529251c..83da5c3 100644
--- a/scilab/modules/ast/src/cpp/ast/debugmanager.cpp
+++ b/scilab/modules/ast/src/cpp/ast/debugmanager.cpp
@@ -298,7 +298,7 @@ Breakpoints& DebuggerManager::getAllBreakPoint()
298 return breakpoints; 298 return breakpoints;
299} 299}
300 300
301void DebuggerManager::setWatches(Watches _w) 301void DebuggerManager::setWatches(const Watches& _w)
302{ 302{
303 watches.clear(); 303 watches.clear();
304 watches = _w; 304 watches = _w;