Debugger: Implement #9961.

- FileManager now saves any explicitly located file mappings,
  and properly restores them when reloading the same team/files later.
This commit is contained in:
Rene Gollent
2013-09-17 14:41:59 +02:00
parent 64aae11716
commit ad054cf1e1
2 changed files with 61 additions and 15 deletions
+53 -13
View File
@@ -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<FileManager> locker(this);
fTargetDomain->EntryLocated(path, locatedPath);
@@ -625,7 +625,14 @@ FileManager::GetSourceFile(const BString& directory,
const BString& relativePath)
{
AutoLocker<FileManager> 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<FileManager> 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<FileManager> 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<FileManager> 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<FileManager> 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);
}
}
+8 -2
View File
@@ -6,6 +6,8 @@
#ifndef FILE_MANAGER_H
#define FILE_MANAGER_H
#include <map>
#include <Locker.h>
#include <Message.h>
#include <String.h>
@@ -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<EntryHashDefinition> LocatableEntryTable;
typedef DoublyLinkedList<LocatableEntry> DeadEntryList;
typedef BOpenHashTable<SourceFileHashDefinition> SourceFileTable;
typedef std::map<BString, BString> 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;
};