diff --git a/gui/qt/debugger.cpp b/gui/qt/debugger.cpp index dc16e9cd9..37d060788 100644 --- a/gui/qt/debugger.cpp +++ b/gui/qt/debugger.cpp @@ -1918,26 +1918,36 @@ void MainWindow::equatesAddEquate(const QString &name, uint32_t address) { if (address < 0x80) { return; } - map_value_t::const_iterator item = disasm.reverse.find(name.toUpper().toStdString()); - if (item != disasm.reverse.end()) { - if (address == item->second) { - return; - } else { - disasm.reverse.erase(item); - } + if (!equatesAddEquateInternal(name, address)) { + return; } - uint32_t &itemReverse = disasm.reverse[name.toUpper().toStdString()]; - itemReverse = address; - disasm.map.emplace(address, name.toStdString()); uint8_t *ptr = static_cast(phys_mem_ptr(address - 4, 9)); if (ptr && ptr[4] == 0xC3 && (ptr[0] == 0xC3 || ptr[8] == 0xC3)) { // jump table? uint32_t address2 = ptr[5] | ptr[6] << 8 | ptr[7] << 16; if (phys_mem_ptr(address2, 1)) { - disasm.map.emplace(address2, "_" + name.toStdString()); - uint32_t &itemReverse2 = disasm.reverse["_" + name.toUpper().toStdString()]; - itemReverse2 = address2; + equatesAddEquateInternal(QStringLiteral("_") + name, address2); + } + } +} + +bool MainWindow::equatesAddEquateInternal(const QString &name, uint32_t address) { + std::pair inserted = disasm.reverse.emplace(name.toUpper().toStdString(), address); + if (!inserted.second) { + uint32_t oldAddress = std::exchange(inserted.first->second, address); + if (oldAddress == address) { + return false; + } + std::pair range = disasm.map.equal_range(oldAddress); + for (map_t::iterator it = range.first; it != range.second; ) { + if (name.compare(QString::fromStdString(it->second), Qt::CaseInsensitive) == 0) { + it = disasm.map.erase(it); + } else { + ++it; + } } } + disasm.map.emplace(address, name.toStdString()); + return true; } void MainWindow::disasmUpdate() { diff --git a/gui/qt/mainwindow.h b/gui/qt/mainwindow.h index 9b2e87b58..c2b13eb96 100644 --- a/gui/qt/mainwindow.h +++ b/gui/qt/mainwindow.h @@ -391,6 +391,7 @@ class MainWindow : public QMainWindow { void equatesAddDialog(); void equatesAddFile(const QString &file); void equatesAddEquate(const QString &name, uint32_t addr); + bool equatesAddEquateInternal(const QString &name, uint32_t addr); void equatesClear(); void equatesRefresh(); QString getAddressString(const QString &string, bool *ok);