Breakpoints condition 21/21621/2
Cedric Delamarre [Tue, 10 Nov 2020 11:05:11 +0000 (12:05 +0100)]
  * mute bp condition execution
  * add bo condition error
  * bp stop on condition changes:
     - Dont stop if the bp condition is valid and the result is false
     - stop if the bp condition is valid and the result true
     - stop if the bp condition exection return an error

Change-Id: Ia61868ad7c7978f31d5aa91ab3ac66d1340e052d

scilab/modules/ast/includes/ast/breakpoint.hxx
scilab/modules/ast/includes/exps/exp.hxx
scilab/modules/ast/src/cpp/ast/debuggervisitor.cpp

index 1628ee4..89247fa 100644 (file)
@@ -35,6 +35,7 @@ struct Breakpoint
                     _iFileLine(0),
                     _iFirstColumn(0),
                     _condition(""),
+                    _conditionError(""),
                     _conditionExp(NULL),
                     _enable(true) {}
     ~Breakpoint()
@@ -100,6 +101,16 @@ struct Breakpoint
         return _pFileName.empty() == false && _iFileLine >= 0;
     }
 
+    bool hasCondition() const
+    {
+        return _condition.empty() == false;
+    }
+
+    bool hasConditionError() const
+    {
+        return _conditionError.empty() == false;
+    }
+
     void setEnable()
     {
         _enable = true;
@@ -113,14 +124,26 @@ struct Breakpoint
         return _enable;
     }
 
+    const std::string& getConditionError(void)
+    {
+        return _conditionError;
+    }
+
+    void setConditionError(const std::string& error)
+    {
+        _conditionError = error;
+    }
+
     char* setCondition(const std::string& condition)
     {
+        _condition = condition;
         char* error = parseCommand(condition.data(), (void**)(&_conditionExp));
         if(error)
         {
+            _conditionError = error;
             return error;
         }
-        _condition = condition;
+        _conditionExp->mute();
         return nullptr;
     }
 
@@ -141,6 +164,7 @@ private:
     std::string _pFileName;
     int _iFileLine;
     std::string _condition;
+    std::string _conditionError;
     ast::Exp* _conditionExp;
     bool _enable;
 };
index d96e41c..0048098 100644 (file)
@@ -102,9 +102,16 @@ public:
     }
 
 public:
-    /** \brief Return if an expression should be displayed or not. */
+    /** \brief Set recursively if an expression should be displayed or not. */
     inline void mute(void)
     {
+        for (auto& e : _exps)
+        {
+            if(e)
+            {
+                e->mute();
+            }
+        }
         _verbose = false;
     }
 
index 1f0ce45..38438b1 100644 (file)
@@ -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 !