ImDebugger: fix stale symbol list after a game is reloaded

The disasm window cached the flattened symbol list and only rebuilt it when one
of three menu items said so. Nothing marked it dirty when a game booted or
exited, and a new SymbolMap is allocated per boot, so the list kept showing the
previous game's functions.

Give SymbolMap a version counter that every mutator bumps, and let the window
compare against it instead. The counter is process-wide rather than per-map, so
a fresh map can't hand out a version a cached copy already holds.

Also re-find the selected symbol by address after a rebuild (the index means
something else afterwards), and drop the unused symbol cache members in
ImMemWindow.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SfY7iFJEjmRXf1XGrTs4MF
This commit is contained in:
Henrik Rydgård
2026-08-27 10:43:08 +02:00
co-authored by Claude Opus 5
parent adccd302e5
commit daa18fc25a
7 changed files with 95 additions and 23 deletions
+30
View File
@@ -50,11 +50,24 @@
SymbolMap *g_symbolMap;
// Not per-instance, so that versions from a map that's been thrown away (one is created and
// destroyed per game boot) can't collide with the current one's. See SymbolMap::Version.
static uint32_t g_symbolMapVersionCounter;
SymbolMap::SymbolMap() {
Bump();
}
void SymbolMap::Bump() {
version_ = ++g_symbolMapVersionCounter;
}
void SymbolMap::SortSymbols() {
AssignFunctionIndices();
}
void SymbolMap::Clear() {
Bump();
functions.clear();
labels.clear();
data.clear();
@@ -768,6 +781,8 @@ std::vector<SymbolEntry> SymbolMap::GetAllActiveSymbols(SymbolType symbolMask) {
}
void SymbolMap::AddModule(const char *name, u32 address, u32 size, u32 crc) {
Bump();
for (auto &module : modules) {
if (equals(module.name, name)) {
// A name match alone isn't proof it's really the same module reloading - some
@@ -803,6 +818,7 @@ void SymbolMap::AddModule(const char *name, u32 address, u32 size, u32 crc) {
}
void SymbolMap::UnloadModule(u32 address, u32 size) {
Bump();
activeModuleEnds.erase(address + size);
activeNeedUpdate_ = true;
}
@@ -907,6 +923,8 @@ std::vector<LoadedModuleInfo> SymbolMap::getAllModules() const {
}
void SymbolMap::AddFunction(const char* name, u32 address, u32 size, int moduleIndex, bool updateName) {
Bump();
moduleIndex = ResolveModuleIndex(address, moduleIndex);
// Is there an existing one?
@@ -1116,6 +1134,8 @@ void SymbolMap::UpdateActiveSymbols() {
}
bool SymbolMap::SetFunctionSize(u32 startAddress, u32 newSize) {
Bump();
if (activeNeedUpdate_)
UpdateActiveSymbols();
@@ -1136,6 +1156,8 @@ bool SymbolMap::SetFunctionSize(u32 startAddress, u32 newSize) {
}
bool SymbolMap::RemoveFunction(u32 startAddress, bool removeName) {
Bump();
if (activeNeedUpdate_)
UpdateActiveSymbols();
@@ -1167,6 +1189,8 @@ bool SymbolMap::RemoveFunction(u32 startAddress, bool removeName) {
}
void SymbolMap::AddLabel(const char* name, u32 address, int moduleIndex, bool updateName) {
Bump();
moduleIndex = ResolveModuleIndex(address, moduleIndex);
// Is there an existing one?
@@ -1225,6 +1249,8 @@ void SymbolMap::AddLabel(const char* name, u32 address, int moduleIndex, bool up
}
void SymbolMap::SetLabelName(const char* name, u32 address) {
Bump();
if (activeNeedUpdate_)
UpdateActiveSymbols();
@@ -1289,6 +1315,8 @@ bool SymbolMap::GetLabelValue(const char* name, u32& dest) {
}
void SymbolMap::AddData(u32 address, u32 size, DataType type, int moduleIndex) {
Bump();
moduleIndex = ResolveModuleIndex(address, moduleIndex);
// Is there an existing one?
@@ -1395,6 +1423,8 @@ DataType SymbolMap::GetDataType(u32 startAddress) {
}
bool SymbolMap::RemoveData(u32 startAddress, bool removeName) {
Bump();
if (activeNeedUpdate_)
UpdateActiveSymbols();