From ad054cf1e108c98b3a9ea22f3ee74ff800c1fa81 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Mon, 16 Sep 2013 15:22:05 +0200 Subject: [PATCH] Debugger: Implement #9961. - FileManager now saves any explicitly located file mappings, and properly restores them when reloading the same team/files later. --- src/apps/debugger/files/FileManager.cpp | 66 ++++++++++++++++++++----- src/apps/debugger/files/FileManager.h | 10 +++- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/src/apps/debugger/files/FileManager.cpp b/src/apps/debugger/files/FileManager.cpp index 36cd181aaf..66fbe6391b 100644 --- a/src/apps/debugger/files/FileManager.cpp +++ b/src/apps/debugger/files/FileManager.cpp @@ -543,8 +543,7 @@ FileManager::FileManager() fLock("file manager"), fTargetDomain(NULL), fSourceDomain(NULL), - fSourceFiles(NULL), - fLocationMappings() + fSourceFiles(NULL) { } @@ -613,7 +612,8 @@ FileManager::GetTargetFile(const BString& path) void -FileManager::TargetEntryLocated(const BString& path, const BString& locatedPath) +FileManager::TargetEntryLocated(const BString& path, + const BString& locatedPath) { AutoLocker locker(this); fTargetDomain->EntryLocated(path, locatedPath); @@ -625,7 +625,14 @@ FileManager::GetSourceFile(const BString& directory, const BString& relativePath) { AutoLocker locker(this); - return fSourceDomain->GetFile(directory, relativePath); + LocatableFile* file = fSourceDomain->GetFile(directory, relativePath); + + if (directory.Length() == 0 || relativePath[0] == '/') + _LocateFileIfMapped(relativePath, file); + else + _LocateFileIfMapped(BString(directory) << '/' << relativePath, file); + + return file; } @@ -633,23 +640,27 @@ LocatableFile* FileManager::GetSourceFile(const BString& path) { AutoLocker locker(this); - return fSourceDomain->GetFile(path); + LocatableFile* file = fSourceDomain->GetFile(path); + _LocateFileIfMapped(path, file); + + return file; } -void +status_t FileManager::SourceEntryLocated(const BString& path, const BString& locatedPath) { AutoLocker locker(this); fSourceDomain->EntryLocated(path, locatedPath); - BMessage archivedMapping; - if (archivedMapping.AddString("source:path", path) == B_OK - && archivedMapping.AddString("source:locatedpath", locatedPath) - == B_OK) { - fLocationMappings.AddMessage("source:mapping", &archivedMapping); + try { + fSourceLocationMappings[path] = locatedPath; + } catch (...) { + return B_NO_MEMORY; } + + return B_OK; } @@ -700,6 +711,8 @@ FileManager::LoadSourceFile(LocatableFile* file, SourceFile*& _sourceFile) status_t FileManager::LoadLocationMappings(TeamFileManagerSettings* settings) { + AutoLocker locker(this); + for (int32 i = 0; i < settings->CountSourceMappings(); i++) { BString sourcePath; BString locatedPath; @@ -707,7 +720,11 @@ FileManager::LoadLocationMappings(TeamFileManagerSettings* settings) if (settings->GetSourceMappingAt(i, sourcePath, locatedPath) != B_OK) return B_NO_MEMORY; - SourceEntryLocated(sourcePath, locatedPath); + try { + fSourceLocationMappings[sourcePath] = locatedPath; + } catch (...) { + return B_NO_MEMORY; + } } return B_OK; @@ -717,7 +734,16 @@ FileManager::LoadLocationMappings(TeamFileManagerSettings* settings) status_t FileManager::SaveLocationMappings(TeamFileManagerSettings* settings) { - return settings->SetTo(fLocationMappings); + AutoLocker locker(this); + + for (LocatedFileMap::const_iterator it = fSourceLocationMappings.begin(); + it != fSourceLocationMappings.end(); ++it) { + status_t error = settings->AddSourceMapping(it->first, it->second); + if (error != B_OK) + return error; + } + + return B_OK; } @@ -747,3 +773,17 @@ FileManager::_SourceFileUnused(SourceFileEntry* entry) if (otherEntry == entry) fSourceFiles->Remove(entry); } + + +void +FileManager::_LocateFileIfMapped(const BString& sourcePath, + LocatableFile* file) +{ + // called with lock held + LocatedFileMap::const_iterator it = fSourceLocationMappings.find( + sourcePath); + if (it != fSourceLocationMappings.end() + && file->State() != LOCATABLE_ENTRY_LOCATED_EXPLICITLY) { + fSourceDomain->EntryLocated(it->first, it->second); + } +} diff --git a/src/apps/debugger/files/FileManager.h b/src/apps/debugger/files/FileManager.h index 24396124cb..e008fa5b4b 100644 --- a/src/apps/debugger/files/FileManager.h +++ b/src/apps/debugger/files/FileManager.h @@ -6,6 +6,8 @@ #ifndef FILE_MANAGER_H #define FILE_MANAGER_H +#include + #include #include #include @@ -43,7 +45,7 @@ public: // returns a reference LocatableFile* GetSourceFile(const BString& path); // returns a reference - void SourceEntryLocated(const BString& path, + status_t SourceEntryLocated(const BString& path, const BString& locatedPath); status_t LoadSourceFile(LocatableFile* file, @@ -65,6 +67,7 @@ private: typedef BOpenHashTable LocatableEntryTable; typedef DoublyLinkedList DeadEntryList; typedef BOpenHashTable SourceFileTable; + typedef std::map LocatedFileMap; friend struct SourceFileEntry; // for gcc 2 @@ -72,13 +75,16 @@ private: private: SourceFileEntry* _LookupSourceFile(const BString& path); void _SourceFileUnused(SourceFileEntry* entry); + void _LocateFileIfMapped(const BString& sourcePath, + LocatableFile* file); private: BLocker fLock; Domain* fTargetDomain; Domain* fSourceDomain; SourceFileTable* fSourceFiles; - BMessage fLocationMappings; + + LocatedFileMap fSourceLocationMappings; };