diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index 4ac18c9c4b..ffda22eddc 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -219,6 +219,35 @@ void SymbolMap::SaveSymbolMap(const char *filename) const fclose(f); } +bool SymbolMap::LoadNocashSym(const char *filename) +{ + FILE *f = fopen(filename,"r"); + if (!f) + return false; + + while (!feof(f)) + { + char line[256],value[256]; + char *p = fgets(line,256,f); + if(p == NULL) + break; + + u32 address; + if (sscanf(line,"%08X %s",&address,value) != 2) continue; + if (address == 0 && strcmp(value,"0") == 0) continue; + + if (value[0] == '.') // data directives + { + continue; // not supported yet + } else { // labels + AddSymbol(value,address,0,ST_FUNCTION); + } + } + + fclose(f); + return true; +} + int SymbolMap::GetSymbolNum(unsigned int address, SymbolType symmask) const { for (size_t i = 0, n = entries.size(); i < n; i++) diff --git a/Core/Debugger/SymbolMap.h b/Core/Debugger/SymbolMap.h index c29494ed39..8ea01a94e4 100644 --- a/Core/Debugger/SymbolMap.h +++ b/Core/Debugger/SymbolMap.h @@ -45,6 +45,7 @@ public: SymbolMap() {} bool LoadSymbolMap(const char *filename); void SaveSymbolMap(const char *filename) const; + bool LoadNocashSym(const char *ilename); void AddSymbol(const char *symbolname, unsigned int vaddress, size_t size, SymbolType symbol); void ResetSymbolMap(); void AnalyzeBackwards(); diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index c804f2fdcf..9df56e80dd 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -35,6 +35,8 @@ #include "Core/Debugger/SymbolMap.h" +#include "Common/StringUtils.h" +#include "file/file_util.h" #include "main.h" @@ -181,25 +183,45 @@ void WindowsHost::BootDone() Core_EnableStepping(!g_Config.bAutoRun); } -static std::string SymbolMapFilename(const char *currentFilename) +static std::string SymbolMapFilename(const char *currentFilename, char* ext) { - std::string result = currentFilename; - size_t dot = result.rfind('.'); - if (dot == result.npos) - return result + ".map"; + FileInfo info; - result.replace(dot, result.npos, ".map"); - return result; + std::string result = currentFilename; + + // can't fail, definitely exists if it gets this far + getFileInfo(currentFilename, &info); + if (info.isDirectory) + { +#ifdef _WIN32 + char* slash = "\\"; +#else + char* slash = "/"; +#endif + if (!endsWith(result,slash)) + result += slash; + + return result + ".ppsspp-symbols" + ext; + } else { + size_t dot = result.rfind('.'); + if (dot == result.npos) + return result + ext; + + result.replace(dot, result.npos, ext); + return result; + } } bool WindowsHost::AttemptLoadSymbolMap() { - return symbolMap.LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str()).c_str()); + bool result1 = symbolMap.LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".map").c_str()); + bool result2 = symbolMap.LoadNocashSym(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".sym").c_str()); + return result1 || result2; } void WindowsHost::SaveSymbolMap() { - symbolMap.SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str()).c_str()); + symbolMap.SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".map").c_str()); } void WindowsHost::AddSymbol(std::string name, u32 addr, u32 size, int type=0)