From d67ac42bbcc2f745ddc9f210db919d3cca13d527 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Thu, 13 Feb 2025 19:54:43 +0100 Subject: [PATCH] enhanced duplicated local label handling (fixes #1067) --- src/debugger/CartDebug.cxx | 20 ++++++++++++++++---- src/debugger/CartDebug.hxx | 5 +++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 460644226..0f4ab5a60 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -619,15 +619,27 @@ bool CartDebug::addLabel(const string& label, uInt16 address) case AddrType::IO: return false; default: - removeLabel(label); - myUserAddresses.emplace(label, address); - myUserLabels.emplace(address, label); - myLabelLength = std::max(myLabelLength, static_cast(label.size())); + string newLabel = uniqueLabel(label); + myUserAddresses.emplace(newLabel, address); + myUserLabels.emplace(address, newLabel); + myLabelLength = std::max(myLabelLength, static_cast(newLabel.size())); mySystem.setDirtyPage(address); return true; } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string CartDebug::uniqueLabel(const string& label) +{ + string uniqueLabel = label; + int count = 0; + + while(myUserAddresses.find(uniqueLabel) != myUserAddresses.end()) + uniqueLabel = label + "." + std::to_string(++count); + + return uniqueLabel; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartDebug::removeLabel(const string& label) { diff --git a/src/debugger/CartDebug.hxx b/src/debugger/CartDebug.hxx index e65060e80..2b9791224 100644 --- a/src/debugger/CartDebug.hxx +++ b/src/debugger/CartDebug.hxx @@ -195,6 +195,11 @@ class CartDebug : public DebuggerSystem */ bool addLabel(const string& label, uInt16 address); + /** + Make given (local) label unique by adding . to it + */ + string uniqueLabel(const string& label); + /** Remove the given label and its associated address. Labels that reference either TIA or RIOT spaces will not be processed.