Commits

Neive committed ef19045

Fixed breakpoint corruption

Comments (0)

Files changed (2)

debugger/breakpoint.cpp

     Clear();
 }
 
-bool BreakpointInterface::RawAdd(Breakpoint *bpt)
+bool BreakpointInterface::AddToCore(Breakpoint *bpt)
 {
     breakpoint raw_bpt;
     raw_bpt.address = bpt->address;
     if (bpt->id == -1)
         return false;
 
-    bpt->enabled = true;
     return true;
 }
 
     if (Find(bpt->address, bpt->length))
         return false; // Well, this could edit the existing breakpoint to merge or something it with this one
 
-    if (!RawAdd(bpt))
+    if (!AddToCore(bpt))
         return false;
 
     for (int i = 0; i < bpt->length; i++)
         breaks.insert(pair<wxString *, Breakpoint *>(&bpt->name, bpt));
     }
 
-    if (!bpt->enabled)
+    if (!bpt->IsEnabled())
     {
         bpt->SetValues(address, length, type);
         return true;
 
 }
 
-void BreakpointInterface::Remove(Breakpoint *bpt)
+void BreakpointInterface::RemoveFromCore(Breakpoint *bpt)
 {
     if (bpt->id == -1)
         return;
     int old_id = bpt->id;
     (*DebugBreakpointCommand)(M64P_BKP_CMD_REMOVE_IDX, bpt->id, 0);
     bpt->id = -1;
-    bpt->enabled = false;
 
-    for (int i = 0; i < bpt->length; i++)
-        breakmap.erase(bpt->address + i);
-
-    auto range = breaks.equal_range(&bpt->name);
-    auto to_be_deleted = breaks.end();
-    for (auto it = range.first; it != range.second; ++it)
+    for (auto it = breaks.begin(); it != breaks.end(); ++it)
     {
         Breakpoint *entry = it->second;
-        if (entry == bpt)
-        {
-            to_be_deleted = it;
-        }
-        else if (entry->id > old_id) // Core does this too, so it has to be mimiced (maybe shouldn't use ids at all)
+         if (entry->id > old_id) // Core does this too, so it has to be mimiced (maybe shouldn't use ids at all)
         {
             entry->id -= 1;
         }
     }
-    if (to_be_deleted != breaks.end())
-        breaks.erase(to_be_deleted);
 }
 
 unique_ptr<Breakpoint *[]> BreakpointInterface::FindByName(const wxString &name, int *amt)
 
 void BreakpointInterface::Delete(Breakpoint *bpt)
 {
-    Remove(bpt);
+    RemoveFromCore(bpt);
+    for (int i = 0; i < bpt->length; i++)
+        breakmap.erase(bpt->address + i);
+
+    auto range = breaks.equal_range(&bpt->GetName());
+    for (auto it = range.first; it != range.second; ++it)
+    {
+        if (it->second == bpt)
+        {
+            breaks.erase(it);
+            break;
+        }
+    }
     delete bpt;
 }
 
 bool BreakpointInterface::Enable(Breakpoint *bpt)
 {
-    if (bpt->enabled)
+    if (bpt->IsEnabled())
         return true;
 
-    return RawAdd(bpt);
+    return AddToCore(bpt);
 }
 
 void BreakpointInterface::Disable(Breakpoint *bpt)
 {
-    if (!bpt->enabled)
+    if (!bpt->IsEnabled())
         return;
 
-    (*DebugBreakpointCommand)(M64P_BKP_CMD_REMOVE_IDX, bpt->id, 0);
-    bpt->id = -1;
-    bpt->enabled = false;
+    RemoveFromCore(bpt);
 }
 
 Breakpoint *BreakpointInterface::Find(uint32_t address, uint32_t length)

debugger/breakpoint.h

         const BreakContainer *GetAllBreakpoints() { return &breaks; }
 
     private:
-        bool RawAdd(Breakpoint *bpt);
-        void Remove(Breakpoint *bpt);
+        bool AddToCore(Breakpoint *bpt);
+        void RemoveFromCore(Breakpoint *bpt);
+        
         // I don't think hash table is the best option for data ranges far aways each other, but it shall be enough for now
         std::unordered_map<uint32_t, Breakpoint *> breakmap;
         BreakContainer breaks;
         Breakpoint(const wxString &name, uint32_t address, int length, char type);
         ~Breakpoint();
 
-
         BreakValidity IsValid() const;
         static BreakValidity IsValid(const wxString &name, uint32_t address, int length, char type);
 
-        bool IsEnabled() const { return enabled; }
+        bool IsEnabled() const { return id != -1; }
         char GetType() const { return type; }
         const wxString &GetName() const { return name; }
         uint32_t GetAddress() const { return address; }
         uint32_t address;
         int length;
         char type;
-        bool enabled;
 };
 
 #endif // BREAKPOINT_H