breakpoint add, update, remove method added 04/21704/3
Cedric Delamarre [Mon, 22 Feb 2021 12:33:53 +0000 (13:33 +0100)]
Change-Id: Id93e04017304c380afa0ad4d3a6c910880340b97

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

index ebef8aa..d2b5300 100644 (file)
@@ -159,7 +159,10 @@ public:
     void errorInScript(const std::wstring funcname, const ast::Exp* pExp);
 
     //breakpoints functions
-    void addBreakPoint(Breakpoint* bp);
+    bool addBreakPoint(Breakpoint* bp);
+    bool updateBreakPoint(Breakpoint* bp);
+    bool removeBreakPoint(Breakpoint* bp);
+    Breakpoints::iterator findBreakPoint(Breakpoint* bp);
     void removeBreakPoint(int _iBreakPoint);
     void setAllBreakPoints(Breakpoints& _bps);
     void removeAllBreakPoints();
index 11d1f0d..ef5c55c 100644 (file)
@@ -172,27 +172,6 @@ void DebuggerManager::sendUpdate() const
     }
 }
 
-void DebuggerManager::addBreakPoint(Breakpoint* bp)
-{
-    //check if breakpoint does not exist
-    for (const auto b : breakpoints)
-    {
-        bool isMacro = b->getFunctioName() == bp->getFunctioName() &&
-                       b->getMacroLine() != bp->getMacroLine();
-        bool isFile  = b->getFileName() == bp->getFileName() &&
-                       b->getFileLine() != bp->getFileLine();
-        bool equalCondition = b->getCondition() != bp->getCondition();
-        if ((isMacro || isFile) && equalCondition)
-        {
-            //same breakpoint, cancel add
-            return;
-        }
-    }
-
-    breakpoints.push_back(bp);
-    sendUpdate();
-}
-
 void DebuggerManager::setAllBreakPoints(Breakpoints& _bps)
 {
     // remove existing breakpoints
@@ -207,6 +186,64 @@ void DebuggerManager::setAllBreakPoints(Breakpoints& _bps)
     sendUpdate();
 }
 
+Breakpoints::iterator DebuggerManager::findBreakPoint(Breakpoint* bp)
+{
+    Breakpoints::iterator found = std::find_if(breakpoints.begin(), breakpoints.end(),
+    [&](Breakpoint* b) {
+        bool isMacro = b->getFunctioName() != "" &&
+                       b->getFunctioName() == bp->getFunctioName() &&
+                       b->getMacroLine() == bp->getMacroLine();
+
+        bool isFile  = b->getFileName() != "" &&
+                       b->getFileName() == bp->getFileName() &&
+                       b->getFileLine() == bp->getFileLine();
+
+        return (isMacro || isFile);
+    });
+
+    return found;
+}
+
+bool DebuggerManager::addBreakPoint(Breakpoint* bp)
+{
+    //check if breakpoint does not exist
+    Breakpoints::iterator iter = findBreakPoint(bp);
+    if(iter == breakpoints.end())
+    {
+        breakpoints.push_back(bp);
+        sendUpdate();
+        return true;
+    }
+
+    return false;
+}
+
+bool DebuggerManager::updateBreakPoint(Breakpoint* bp)
+{
+    Breakpoints::iterator iter = findBreakPoint(bp);
+    if(iter != breakpoints.end())
+    {
+        std::swap(*iter, bp);
+        delete bp;
+        return true;
+    }
+
+    return false;
+}
+
+bool DebuggerManager::removeBreakPoint(Breakpoint* bp)
+{
+    Breakpoints::iterator iter = findBreakPoint(bp);
+    if(iter != breakpoints.end())
+    {
+        delete *iter;
+        breakpoints.erase(iter);
+        return true;
+    }
+
+    return false;
+}
+
 void DebuggerManager::removeBreakPoint(int _iBreakPoint)
 {
     if (_iBreakPoint >= 0 && _iBreakPoint <= (int)breakpoints.size())