From a3eb2a35984f132136560d0b526d3f477fcc95da Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Mon, 26 Aug 2019 10:11:41 +0200 Subject: [PATCH] return sorted list of breakpoints --- src/debugger/BreakpointMap.cxx | 4 +++- src/debugger/BreakpointMap.hxx | 14 ++++++++++---- src/debugger/DebuggerParser.cxx | 28 +++++++++++----------------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/debugger/BreakpointMap.cxx b/src/debugger/BreakpointMap.cxx index 1455980c5..181f21a3d 100644 --- a/src/debugger/BreakpointMap.cxx +++ b/src/debugger/BreakpointMap.cxx @@ -15,6 +15,7 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ +#include #include "BreakpointMap.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -82,8 +83,9 @@ bool BreakpointMap::check(const uInt16 addr, const uInt8 bank) const BreakpointMap::BreakpointList BreakpointMap::getBreakpoints() const { BreakpointList map; + std::map ordered(myMap.begin(), myMap.end()); - for(auto item : myMap) + for(auto item : ordered) map.push_back(item.first); return map; diff --git a/src/debugger/BreakpointMap.hxx b/src/debugger/BreakpointMap.hxx index bd9eb12b8..49074e58e 100644 --- a/src/debugger/BreakpointMap.hxx +++ b/src/debugger/BreakpointMap.hxx @@ -44,13 +44,18 @@ public: Breakpoint() : addr(0), bank(0) { } Breakpoint(const Breakpoint& bp) - : addr(bp.addr), bank(bp.bank) { } + : addr(bp.addr & ADDRESS_MASK), bank(bp.bank) { } explicit Breakpoint(uInt16 c_addr, uInt8 c_bank) - : addr(c_addr), bank(c_bank) { } + : addr(c_addr & ADDRESS_MASK), bank(c_bank) { } bool operator==(const Breakpoint& other) const { - return ((addr & ADDRESS_MASK) == (other.addr & ADDRESS_MASK) && bank == other.bank); + return (addr == other.addr && bank == other.bank); + } + bool operator<(const Breakpoint& other) const + { + return bank < other.bank || + (bank == other.bank && addr < other.addr); } }; using BreakpointList = std::vector; @@ -76,6 +81,7 @@ public: bool check(const Breakpoint& breakpoint) const; bool check(const uInt16 addr, const uInt8 bank) const; + /** Returns a sorted list of breakpoints */ BreakpointList getBreakpoints() const; /** clear all breakpoints */ @@ -86,7 +92,7 @@ private: struct BreakpointHash { size_t operator()(const Breakpoint& bp) const { return std::hash()( - uInt64(bp.addr & ADDRESS_MASK) * 13 + uInt64(bp.bank) + uInt64(bp.addr) * 13 + uInt64(bp.bank) ); } }; diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index b2d97b036..b8d5593a4 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -1445,25 +1445,19 @@ void DebuggerParser::executeListbreaks() int count = 0; uInt32 bankCount = debugger.cartDebug().bankCount(); - for(uInt32 bank = 0; bank < bankCount; ++bank) + for(const auto& bp : debugger.breakPoints().getBreakpoints()) { - for(uInt32 addr = 0; addr <= 0x1fff; ++addr) + if(bankCount == 1) { - if(debugger.breakPoints().check(addr, bank)) - { - if(bankCount == 1) - { - buf << debugger.cartDebug().getLabel(addr, true, 4) << " "; - if(!(++count % 8)) buf << endl; - } - else - { - if(count % 6) - buf << ", "; - buf << debugger.cartDebug().getLabel(addr, true, 4) << " #" << int(bank); - if(!(++count % 6)) buf << endl; - } - } + buf << debugger.cartDebug().getLabel(bp.addr, true, 4) << " "; + if(!(++count % 8)) buf << endl; + } + else + { + if(count % 6) + buf << ", "; + buf << debugger.cartDebug().getLabel(bp.addr, true, 4) << " #" << int(bp.bank); + if(!(++count % 6)) buf << endl; } } if(count)