From b1af4f49113adde4057f38c5a5b0a4e56db510dc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 25 Jan 2014 21:12:16 -0800 Subject: [PATCH] Write symbol maps as ".ppmap" instead. This has some benefits: * They are smaller, but zgrep/zcat etc. still work. * Since the format is slightly different, bisecting won't overwrite. * It avoids conflicts with .map file associations. --- Core/Debugger/SymbolMap.cpp | 39 ++++++++++++++++++++++++------------- Windows/WindowsHost.cpp | 7 +++++-- Windows/WndMainWindow.cpp | 4 ++-- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index 29349e325d..d4c900ea56 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -24,6 +24,8 @@ #include +#include "util/text/utf8.h" +#include "zlib.h" #include "Common/CommonTypes.h" #include "Common/FileUtil.h" #include "Core/MemMap.h" @@ -52,8 +54,14 @@ void SymbolMap::Clear() { bool SymbolMap::LoadSymbolMap(const char *filename) { lock_guard guard(lock_); Clear(); - FILE *f = File::OpenCFile(filename, "r"); - if (!f) + +#if defined(_WIN32) && defined(UNICODE) + gzFile f = gzopen_w(ConvertUTF8ToWString(filename).c_str(), "r"); +#else + gzFile f = gzopen(filename, "r"); +#endif + + if (f == Z_NULL) return false; //char temp[256]; @@ -65,9 +73,9 @@ bool SymbolMap::LoadSymbolMap(const char *filename) { bool started = false; bool hasModules = false; - while (!feof(f)) { + while (!gzeof(f)) { char line[512], temp[256] = {0}; - char *p = fgets(line, 512, f); + char *p = gzgets(f, line, 512); if (p == NULL) break; @@ -156,9 +164,9 @@ bool SymbolMap::LoadSymbolMap(const char *filename) { } } } - fclose(f); + gzclose(f); SortSymbols(); - return true; + return started; } void SymbolMap::SaveSymbolMap(const char *filename) const { @@ -169,27 +177,32 @@ void SymbolMap::SaveSymbolMap(const char *filename) const { return; } - FILE *f = File::OpenCFile(filename, "w"); - if (!f) +#if defined(_WIN32) && defined(UNICODE) + gzFile f = gzopen_w(ConvertUTF8ToWString(filename).c_str(), "w9"); +#else + gzFile f = gzopen(filename, "w9"); +#endif + + if (f == Z_NULL) return; - fprintf(f,".text\n"); + gzprintf(f, ".text\n"); for (auto it = modules.begin(), end = modules.end(); it != end; ++it) { const ModuleEntry &mod = *it; - fprintf(f, ".module %x %08x %08x %s\n", mod.index, mod.start, mod.size, mod.name); + gzprintf(f, ".module %x %08x %08x %s\n", mod.index, mod.start, mod.size, mod.name); } for (auto it = functions.begin(), end = functions.end(); it != end; ++it) { const FunctionEntry& e = it->second; - fprintf(f, "%08x %08x %x %i %s\n", e.start, e.size, e.module, ST_FUNCTION, GetLabelNameRel(e.start, e.module)); + gzprintf(f, "%08x %08x %x %i %s\n", e.start, e.size, e.module, ST_FUNCTION, GetLabelNameRel(e.start, e.module)); } for (auto it = data.begin(), end = data.end(); it != end; ++it) { const DataEntry& e = it->second; - fprintf(f, "%08x %08x %x %i %s\n", e.start, e.size, e.module, ST_DATA, GetLabelNameRel(e.start, e.module)); + gzprintf(f, "%08x %08x %x %i %s\n", e.start, e.size, e.module, ST_DATA, GetLabelNameRel(e.start, e.module)); } - fclose(f); + gzclose(f); } bool SymbolMap::LoadNocashSym(const char *filename) { diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index b536ae37f7..dd0d443153 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -241,14 +241,17 @@ static std::string SymbolMapFilename(const char *currentFilename, char* ext) bool WindowsHost::AttemptLoadSymbolMap() { - bool result1 = symbolMap.LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".map").c_str()); + bool result1 = symbolMap.LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".ppmap").c_str()); + // Load the old-style map file. + if (!result1) + 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(),".map").c_str()); + symbolMap.SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".ppmap").c_str()); } bool WindowsHost::IsDebuggingEnabled() diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 40a535401b..a7be71dbce 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -1286,7 +1286,7 @@ namespace MainWindow break; case ID_DEBUG_LOADMAPFILE: - if (W32Util::BrowseForFileName(true, hWnd, L"Load .MAP",0,L"Maps\0*.map\0All files\0*.*\0\0",L"map",fn)) { + if (W32Util::BrowseForFileName(true, hWnd, L"Load .ppmap",0,L"Maps\0*.ppmap\0All files\0*.*\0\0",L"ppmap",fn)) { symbolMap.LoadSymbolMap(fn.c_str()); if (disasmWindow[0]) @@ -1298,7 +1298,7 @@ namespace MainWindow break; case ID_DEBUG_SAVEMAPFILE: - if (W32Util::BrowseForFileName(false, hWnd, L"Save .MAP",0,L"Maps\0*.map\0All files\0*.*\0\0",L"map",fn)) + if (W32Util::BrowseForFileName(false, hWnd, L"Save .ppmap",0,L"Maps\0*.ppmap\0All files\0*.*\0\0",L"ppmap",fn)) symbolMap.SaveSymbolMap(fn.c_str()); break;