debugger: error in try/catch and errcatch fixed
[scilab.git] / scilab / modules / ast / src / cpp / ast / debuggervisitor.cpp
index 54a98bd..762d9b6 100644 (file)
@@ -25,7 +25,6 @@
 
 extern "C"
 {
-#include "filemanager_interface.h"
 #include "FileExist.h"
 }
 
@@ -70,7 +69,8 @@ void DebuggerVisitor::visit(const SeqExp  &e)
 
         //debugger check !
         int iBreakPoint = -1;
-        if (ConfigVariable::getEnableDebug())
+        if (ConfigVariable::getEnableDebug() &&
+            manager->isInterrupted() == false) // avoid stopping execution if an execution is already paused
         {
             bool stopExecution = false;
             if (manager->isStepIn())
@@ -179,28 +179,40 @@ void DebuggerVisitor::visit(const SeqExp  &e)
                                 pCtx->scope_begin();
                                 bp->getConditionExp()->accept(execCond);
                                 types::InternalType* pIT = pCtx->getCurrentLevel(symbol::Symbol(L"ans"));
-                                if (pIT == NULL ||
-                                        pIT->isBool() == false ||
-                                        ((types::Bool*)pIT)->isScalar() == false ||
-                                        ((types::Bool*)pIT)->get(0) == 0)
+                                if (pIT == NULL)
                                 {
+                                    // no result ie: assignation
+                                    char pcError[256];
+                                    sprintf(pcError, _("Wrong breakpoint condition: A result expected.\n"));
+                                    bp->setConditionError(pcError);
+                                }
+                                else if(pIT->isTrue() == false)
+                                {
+                                    // bool scalar false
                                     pCtx->scope_end();
-                                    //not a boolean, not scalar or false
                                     stopExecution = false;
                                     continue;
                                 }
 
-                                pCtx->scope_end();
-                                //ok condition is valid and true
+                                // condition is invalid or true
                             }
-                            catch (ast::ScilabException &/*e*/)
+                            catch (ast::ScilabException& e)
                             {
-                                pCtx->scope_end();
-                                stopExecution = false;
                                 //not work !
                                 //invalid breakpoint
-                                continue;
+                                if(ConfigVariable::isError())
+                                {
+                                    bp->setConditionError(scilab::UTF8::toUTF8(ConfigVariable::getLastErrorMessage()));
+                                    ConfigVariable::clearLastError();
+                                    ConfigVariable::resetError();
+                                }
+                                else
+                                {
+                                    bp->setConditionError(scilab::UTF8::toUTF8(e.GetErrorMessage()));
+                                }
                             }
+
+                            pCtx->scope_end();
                         }
 
                         //we have a breakpoint !
@@ -213,8 +225,9 @@ void DebuggerVisitor::visit(const SeqExp  &e)
                 }
             }
 
-            if(stopExecution)
+            if(stopExecution || manager->isPauseRequested())
             {
+                manager->resetPauseRequest();
                 manager->stop(exp, iBreakPoint);
                 if (manager->isAborted())
                 {
@@ -240,20 +253,22 @@ void DebuggerVisitor::visit(const SeqExp  &e)
             setExpectedSize(iExpectedSize);
             types::InternalType * pIT = getResult();
 
-            // In case of exec file, set the file name in the Macro to store where it is defined.
-            int iFileID = ConfigVariable::getExecutedFileID();
-            if (iFileID && exp->isFunctionDec())
+            if(exp->isFunctionDec())
             {
-                types::InternalType* pITMacro = symbol::Context::getInstance()->get(exp->getAs<ast::FunctionDec>()->getSymbol());
-                if (pITMacro)
+                // In case of exec file, set the file name in the Macro to store where it is defined.
+                std::wstring strFile = ConfigVariable::getExecutedFile();
+                const std::vector<ConfigVariable::WhereEntry>& lWhereAmI = ConfigVariable::getWhere();
+
+                if (strFile != L"" &&  // check if we are executing a script or a macro
+                    lWhereAmI.empty() == false &&
+                    lWhereAmI.back().m_file_name != nullptr && // check the last function execution is a macro
+                    *(lWhereAmI.back().m_file_name) == strFile) // check the last execution is the same macro as the executed one
                 {
-                    types::Macro* pMacro = pITMacro->getAs<types::Macro>();
-                    const wchar_t* filename = getfile_filename(iFileID);
-                    // scilab.quit is not open with mopen
-                    // in this case filename is NULL because FileManager have not been filled.
-                    if (filename)
+                    types::InternalType* pITMacro = symbol::Context::getInstance()->get(exp->getAs<FunctionDec>()->getSymbol());
+                    if (pITMacro)
                     {
-                        pMacro->setFileName(filename);
+                        types::Macro* pMacro = pITMacro->getAs<types::Macro>();
+                        pMacro->setFileName(strFile);
                     }
                 }
             }
@@ -366,6 +381,13 @@ void DebuggerVisitor::visit(const SeqExp  &e)
         }
         catch (const InternalError& ie)
         {
+            // dont manage an error with the debugger
+            // in cases of try catch and errcatch
+            if(ConfigVariable::isSilentError())
+            {
+                throw ie;
+            }
+
             ConfigVariable::fillWhereError(ie.GetErrorLocation().first_line);
 
             const std::vector<ConfigVariable::WhereEntry>& lWhereAmI = ConfigVariable::getWhere();
@@ -457,6 +479,18 @@ void DebuggerVisitor::visit(const SeqExp  &e)
 bool getMacroSourceFile(std::string* filename)
 {
     const std::vector<ConfigVariable::WhereEntry>& lWhereAmI = ConfigVariable::getWhere();
+    // "Where" can be empty at the end of script execution
+    // this function is called when the script ends after a step out
+    if(lWhereAmI.empty())
+    {
+        return false;
+    }
+
+    if(lWhereAmI.back().m_file_name == nullptr)
+    {
+        return false;
+    }
+
     std::string file = scilab::UTF8::toUTF8(*lWhereAmI.back().m_file_name);
     if (file.rfind(".bin") != std::string::npos)
     {
@@ -474,4 +508,4 @@ bool getMacroSourceFile(std::string* filename)
     }
 
     return true;
-}
\ No newline at end of file
+}