From 00a801f6a3913ac5435beb597f6b9b4175cdd182 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 26 Nov 2013 00:43:31 +0100 Subject: [PATCH] Don't overwrite label name if it already exists, get label value --- Core/Debugger/SymbolMap.cpp | 26 ++++++++++++++++++++++++-- Core/Debugger/SymbolMap.h | 3 ++- Core/MIPS/MIPSDebugInterface.cpp | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index a0e7f2e7a4..f14e7c1bec 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -108,6 +108,8 @@ void SymbolMap::Clear() { void SymbolMap::AddSymbol(const char *symbolname, unsigned int vaddress, size_t size, SymbolType st) { lock_guard guard(lock_); + symbolname = AddLabel(symbolname,vaddress); + MapEntry e; strncpy(e.name, symbolname, 127); e.name[127] = '\0'; @@ -121,7 +123,6 @@ void SymbolMap::AddSymbol(const char *symbolname, unsigned int vaddress, size_t entryRanges[e.vaddress + e.size] = e.vaddress; } - AddLabel(symbolname,vaddress); } void SymbolMap::RemoveSymbolNum(int symbolnum){ @@ -375,13 +376,19 @@ bool SymbolMap::getSymbolValue(char* symbol, u32& dest) return false; } -void SymbolMap::AddLabel(const char* name, u32 address) +const char* SymbolMap::AddLabel(const char* name, u32 address) { + // keep a label if it already exists + auto it = labels.find(address); + if (it != labels.end()) + return it->second.name; + Label label; strcpy(label.name,name); label.name[127] = 0; labels[address] = label; + return name; } const char* SymbolMap::GetLabelName(u32 address) @@ -393,6 +400,21 @@ const char* SymbolMap::GetLabelName(u32 address) return it->second.name; } +bool SymbolMap::GetLabelValue(const char* name, u32& dest) +{ + for (auto it = labels.begin(); it != labels.end(); it++) + { + if (strcasecmp(name,it->second.name) == 0) + { + dest = it->first; + return true; + } + } + + return false; +} + + static char descriptionTemp[256]; const char *SymbolMap::GetDescription(unsigned int address) const diff --git a/Core/Debugger/SymbolMap.h b/Core/Debugger/SymbolMap.h index ad39b9e7da..61157d5fe8 100644 --- a/Core/Debugger/SymbolMap.h +++ b/Core/Debugger/SymbolMap.h @@ -75,8 +75,9 @@ public: void UseFuncSignaturesFile(const char *filename, u32 maxAddress); void CompileFuncSignaturesFile(const char *filename) const; - void AddLabel(const char* name, u32 address); + const char* AddLabel(const char* name, u32 address); const char* GetLabelName(u32 address); + bool GetLabelValue(const char* name, u32& dest); private: struct MapEntryUniqueInfo { u32 address; diff --git a/Core/MIPS/MIPSDebugInterface.cpp b/Core/MIPS/MIPSDebugInterface.cpp index af3e351588..b096d0d716 100644 --- a/Core/MIPS/MIPSDebugInterface.cpp +++ b/Core/MIPS/MIPSDebugInterface.cpp @@ -109,7 +109,7 @@ public: virtual bool parseSymbol(char* str, uint32& symbolValue) { - return cpu->getSymbolValue(str,symbolValue); + return symbolMap.GetLabelValue(str,symbolValue); } virtual uint32 getReferenceValue(uint32 referenceIndex)