Skip to content

Commit

Permalink
enhanced duplicated local label handling (fixes #1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
thrust26 committed Feb 13, 2025
1 parent 60e0766 commit d67ac42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/debugger/CartDebug.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<uInt16>(label.size()));
string newLabel = uniqueLabel(label);
myUserAddresses.emplace(newLabel, address);
myUserLabels.emplace(address, newLabel);
myLabelLength = std::max(myLabelLength, static_cast<uInt16>(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)
{
Expand Down
5 changes: 5 additions & 0 deletions src/debugger/CartDebug.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ class CartDebug : public DebuggerSystem
*/
bool addLabel(const string& label, uInt16 address);

/**
Make given (local) label unique by adding .<count> 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.
Expand Down

0 comments on commit d67ac42

Please sign in to comment.