reduce overhead of debugger and improve output of functions 60/21060/2
Antoine ELIAS [Tue, 30 Jul 2019 13:30:28 +0000 (15:30 +0200)]
Change-Id: I2e628ffb6acb06a06fba58f4d4e03c76ecb57426

scilab/modules/ast/includes/ast/debugmanager.hxx
scilab/modules/ast/src/cpp/ast/debuggervisitor.cpp
scilab/modules/ast/src/cpp/ast/debugmanager.cpp

index 7b95732..9b1bdb6 100644 (file)
@@ -83,6 +83,7 @@ public:
         {
             delete d.second;
         }
+
         for (auto b : breakpoints)
         {
             delete b;
@@ -135,7 +136,7 @@ public:
         callstack.stack.clear();
     }
 
-    CallStack getCallStack()
+    CallStack& getCallStack()
     {
         return callstack;
     }
@@ -172,7 +173,7 @@ public:
     Breakpoints& getAllBreakPoint();
 
     //watches functions
-    void setWatches(Watches _w);
+    void setWatches(const Watches& _w);
     void removeWatches();
     void updateWatches(int _iScopeLvl = -1);
     Watches& getWatches();
@@ -183,6 +184,7 @@ public:
         action = StepIn;
         level = symbol::Context::getInstance()->getScopeLevel();
     }
+
     inline bool isStepIn()
     {
         int l = symbol::Context::getInstance()->getScopeLevel();
@@ -200,6 +202,7 @@ public:
 
         return true;
     }
+
     inline void resetStepIn()
     {
         if (isStepIn())
@@ -213,11 +216,13 @@ public:
         action = StepOut;
         level = ConfigVariable::getWhere().size();
     }
+
     inline bool isStepOut()
     {
         int l = ConfigVariable::getWhere().size();
         return action == StepOut && l < level;
     }
+
     inline void resetStepOut()
     {
         if (isStepOut())
@@ -230,10 +235,12 @@ public:
     {
         action = Aborted;
     }
+
     inline bool isAborted()
     {
         return action == Aborted;
     }
+
     inline void resetAborted()
     {
         if (isAborted())
@@ -247,12 +254,14 @@ public:
         action = StepNext;
         level = symbol::Context::getInstance()->getScopeLevel();
     }
+
     inline bool isStepNext()
     {
         int l = symbol::Context::getInstance()->getScopeLevel();
         //if stepNext failed ( end of macro ), stepNext become a stepOut
         return action == StepNext && l <= level;
     }
+
     inline void resetStepNext()
     {
         if (isStepNext())
index 7a504ae..bd803c0 100644 (file)
@@ -18,6 +18,8 @@
 #include "printvisitor.hxx"
 #include "execvisitor.hxx"
 #include "threadId.hxx"
+#include "macrofile.hxx"
+#include "commentexp.hxx"
 
 extern "C"
 {
@@ -35,6 +37,11 @@ void DebuggerVisitor::visit(const SeqExp  &e)
 
     for (const auto & exp : e.getExps())
     {
+        if (exp->isCommentExp())
+        {
+            continue;
+        }
+
         if (e.isBreakable())
         {
             exp->resetBreak();
@@ -69,11 +76,11 @@ void DebuggerVisitor::visit(const SeqExp  &e)
             }
             else
             {
-                std::vector<ConfigVariable::WhereEntry> lWhereAmI = ConfigVariable::getWhere();
+                const std::vector<ConfigVariable::WhereEntry>& lWhereAmI = ConfigVariable::getWhere();
                 //set information from debugger commands
                 if (lWhereAmI.size() != 0 && manager->getBreakPointCount() != 0)
                 {
-                    debugger::Breakpoints bps = manager->getAllBreakPoint();
+                    debugger::Breakpoints& bps = manager->getAllBreakPoint();
 
                     int i = -1;
                     for (const auto & bp : bps)
@@ -85,52 +92,56 @@ void DebuggerVisitor::visit(const SeqExp  &e)
                         }
 
                         // look for a breakpoint on this line and update breakpoint information when possible
-                        char* functionName = wide_string_to_UTF8(lWhereAmI.back().call->getName().data());
-                        std::wstring pstrFileName = *lWhereAmI.back().m_file_name;
-                        char* fileName = wide_string_to_UTF8(pstrFileName.data());
-
                         int iLine = exp->getLocation().first_line - ConfigVariable::getMacroFirstLines();
-                        if (bp->hasMacro() &&
-                            bp->getFunctioName().compare(functionName) == 0)
+                        if (bp->hasMacro())
                         {
-                            if (bp->getMacroLine() == 0)
+                            char* functionName = wide_string_to_UTF8(lWhereAmI.back().call->getName().data());
+                            if (bp->getFunctioName().compare(functionName) == 0)
                             {
-                                //first pass in macro.
-                                //update first line with real value
-                                bp->setMacroLine(iLine);
+                                if (bp->getMacroLine() == 0)
+                                {
+                                    //first pass in macro.
+                                    //update first line with real value
+                                    bp->setMacroLine(iLine);
+                                }
+
+                                stopExecution = bp->getMacroLine() == iLine;
                             }
 
-                            stopExecution = bp->getMacroLine() == iLine;
+                            FREE(functionName);
                         }
-                        else if(bp->hasFile() &&
-                                bp->getFileLine() == exp->getLocation().first_line)
+                        else if (bp->hasFile())
                         {
-                            if(pstrFileName.rfind(L".bin") != std::string::npos)
+                            if (bp->getFileLine() == exp->getLocation().first_line)
                             {
-                                pstrFileName.replace(pstrFileName.size() - 4, 4, L".sci");
-                                // stop on bp only if the file exist
-                                if (FileExistW(pstrFileName.data()))
+                                std::wstring pstrFileName = *lWhereAmI.back().m_file_name;
+                                char* fileName = wide_string_to_UTF8(pstrFileName.data());
+
+                                if (pstrFileName.rfind(L".bin") != std::string::npos)
                                 {
-                                    FREE(fileName);
-                                    fileName = wide_string_to_UTF8(pstrFileName.data());
+                                    pstrFileName.replace(pstrFileName.size() - 4, 4, L".sci");
+                                    // stop on bp only if the file exist
+                                    if (FileExistW(pstrFileName.data()))
+                                    {
+                                        FREE(fileName);
+                                        fileName = wide_string_to_UTF8(pstrFileName.data());
+                                    }
                                 }
-                            }
 
-                            if(bp->getFileName().compare(fileName) == 0)
-                            {
-                                stopExecution = true;
-                                // set function information
-                                if(lWhereAmI.back().call->getFirstLine())
+                                if (bp->getFileName().compare(fileName) == 0)
                                 {
-                                    bp->setFunctionName(functionName);
-                                    bp->setMacroLine(iLine);
+                                    char* functionName = wide_string_to_UTF8(lWhereAmI.back().call->getName().data());
+                                    stopExecution = true;
+                                    // set function information
+                                    if (lWhereAmI.back().call->getFirstLine())
+                                    {
+                                        bp->setFunctionName(functionName);
+                                        bp->setMacroLine(iLine);
+                                    }
                                 }
                             }
                         }
 
-                        FREE(functionName);
-                        FREE(fileName);
-
                         if(stopExecution == false)
                         {
                             // no breakpoint for this line
@@ -369,5 +380,48 @@ void DebuggerVisitor::visit(const SeqExp  &e)
         setResult(NULL);
 
     }
+
+    if (e.getParent() == NULL && e.getExecFrom() == SeqExp::SCRIPT && manager->isStepNext())
+    {
+        const std::vector<ConfigVariable::WhereEntry>& lWhereAmI = ConfigVariable::getWhere();
+        if (lWhereAmI.size())
+        {
+            std::wstring functionName = lWhereAmI.back().call->getName();
+            types::InternalType* pIT = symbol::Context::getInstance()->get(symbol::Symbol(functionName));
+            if (pIT && (pIT->isMacro() || pIT->isMacroFile()))
+            {
+                types::Macro* m = nullptr;
+                if (pIT->isMacroFile())
+                {
+                    types::MacroFile* mf = pIT->getAs<types::MacroFile>();
+                    m = mf->getMacro();
+                }
+                else
+                {
+                    m = pIT->getAs<types::Macro>();
+                }
+
+                //create a fake exp to represente end/enfunction
+
+                //will be deleted by CommentExp
+                std::wstring* comment = new std::wstring(L"end of function");
+                Location loc(m->getLastLine(), m->getLastLine(), 0, 0);
+                CommentExp fakeExp(loc, comment);
+                manager->stop(&fakeExp, -1);
+
+                if (manager->isAborted())
+                {
+                    throw ast::InternalAbort();
+                }
+
+                //transform stepnext after endfunction as a stepout to show line marker on current statement
+                if (manager->isStepNext())
+                {
+                    manager->resetStepNext();
+                    manager->setStepOut();
+                }
+            }
+        }
+    }
 }
 }
index 529251c..83da5c3 100644 (file)
@@ -298,7 +298,7 @@ Breakpoints& DebuggerManager::getAllBreakPoint()
     return breakpoints;
 }
 
-void DebuggerManager::setWatches(Watches _w)
+void DebuggerManager::setWatches(const Watches& _w)
 {
     watches.clear();
     watches = _w;