hrev46070 adds 3 changesets to branch 'master' old head: e968e4b09049ceef142d18f18a71b687813e7d66 new head: 29fdf5e8aed6e54ff039ffecf4abb8a77897b836 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=29fdf5e+%5Ee968e4b ---------------------------------------------------------------------------- b9b1261: Debugger: add settings manager for source location mappings. - If it was necessary to help the debugger locate a particular source file due to it not being found on disk at the location specified in the debug information, the associated user-supplied path mappings are now saved and restored in the team settings. The file manager still needs a bit of extra work to apply these as files are added though. 37fc996: Fix incorrect name usage. 29fdf5e: Debugger: Implement #9961. - FileManager now saves any explicitly located file mappings, and properly restores them when reloading the same team/files later. [ Rene Gollent <anevilyak@xxxxxxxxx> ] ---------------------------------------------------------------------------- 8 files changed, 317 insertions(+), 7 deletions(-) src/apps/debugger/Jamfile | 1 + src/apps/debugger/controllers/TeamDebugger.cpp | 4 + src/apps/debugger/files/FileManager.cpp | 86 ++++++++++++- src/apps/debugger/files/FileManager.h | 17 ++- .../settings/TeamFileManagerSettings.cpp | 128 +++++++++++++++++++ .../debugger/settings/TeamFileManagerSettings.h | 41 ++++++ src/apps/debugger/settings/TeamSettings.cpp | 38 ++++++ src/apps/debugger/settings/TeamSettings.h | 9 ++ ############################################################################ Commit: b9b126139a57e5c239f935dc5cef11188042bdc8 URL: http://cgit.haiku-os.org/haiku/commit/?id=b9b1261 Author: Rene Gollent <anevilyak@xxxxxxxxx> Date: Mon Sep 16 11:28:28 2013 UTC Debugger: add settings manager for source location mappings. - If it was necessary to help the debugger locate a particular source file due to it not being found on disk at the location specified in the debug information, the associated user-supplied path mappings are now saved and restored in the team settings. The file manager still needs a bit of extra work to apply these as files are added though. ---------------------------------------------------------------------------- diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index ac9212f..1352fc5 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -181,6 +181,7 @@ Application Debugger : BreakpointSetting.cpp GuiTeamUiSettings.cpp SettingsManager.cpp + TeamFileManagerSettings.cpp TeamSettings.cpp TeamUiSettings.cpp TeamUiSettingsFactory.cpp diff --git a/src/apps/debugger/controllers/TeamDebugger.cpp b/src/apps/debugger/controllers/TeamDebugger.cpp index b4a391b..3226afa 100644 --- a/src/apps/debugger/controllers/TeamDebugger.cpp +++ b/src/apps/debugger/controllers/TeamDebugger.cpp @@ -1991,6 +1991,8 @@ TeamDebugger::_LoadSettings() breakpointSetting->IsEnabled()); } + fFileManager->LoadLocationMappings(fTeamSettings.FileManagerSettings()); + const TeamUiSettings* uiSettings = fTeamSettings.UiSettingFor( fUserInterface->ID()); if (uiSettings != NULL) @@ -2022,6 +2024,8 @@ TeamDebugger::_SaveSettings() settings.AddUiSettings(clonedSettings); } } + + fFileManager->SaveLocationMappings(settings.FileManagerSettings()); locker.Unlock(); // save the settings diff --git a/src/apps/debugger/files/FileManager.cpp b/src/apps/debugger/files/FileManager.cpp index aaa78f2..36cd181 100644 --- a/src/apps/debugger/files/FileManager.cpp +++ b/src/apps/debugger/files/FileManager.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx. - * Copyright 2011-2012, Rene Gollent, rene@xxxxxxxxxxx. + * Copyright 2011-2013, Rene Gollent, rene@xxxxxxxxxxx. * Distributed under the terms of the MIT License. */ @@ -15,6 +15,7 @@ #include "LocatableFile.h" #include "SourceFile.h" #include "StringUtils.h" +#include "TeamFileManagerSettings.h" // #pragma mark - EntryPath @@ -542,7 +543,8 @@ FileManager::FileManager() fLock("file manager"), fTargetDomain(NULL), fSourceDomain(NULL), - fSourceFiles(NULL) + fSourceFiles(NULL), + fLocationMappings() { } @@ -636,10 +638,18 @@ FileManager::GetSourceFile(const BString& path) void -FileManager::SourceEntryLocated(const BString& path, const BString& locatedPath) +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); + } } @@ -687,6 +697,30 @@ FileManager::LoadSourceFile(LocatableFile* file, SourceFile*& _sourceFile) } +status_t +FileManager::LoadLocationMappings(TeamFileManagerSettings* settings) +{ + for (int32 i = 0; i < settings->CountSourceMappings(); i++) { + BString sourcePath; + BString locatedPath; + + if (settings->GetSourceMappingAt(i, sourcePath, locatedPath) != B_OK) + return B_NO_MEMORY; + + SourceEntryLocated(sourcePath, locatedPath); + } + + return B_OK; +} + + +status_t +FileManager::SaveLocationMappings(TeamFileManagerSettings* settings) +{ + return settings->SetTo(fLocationMappings); +} + + FileManager::SourceFileEntry* FileManager::_LookupSourceFile(const BString& path) { diff --git a/src/apps/debugger/files/FileManager.h b/src/apps/debugger/files/FileManager.h index 5599421..2439612 100644 --- a/src/apps/debugger/files/FileManager.h +++ b/src/apps/debugger/files/FileManager.h @@ -1,11 +1,13 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx. + * Copyright 2013, Rene Gollent, rene@xxxxxxxxxxx. * Distributed under the terms of the MIT License. */ #ifndef FILE_MANAGER_H #define FILE_MANAGER_H #include <Locker.h> +#include <Message.h> #include <String.h> #include <util/DoublyLinkedList.h> @@ -15,6 +17,7 @@ class LocatableEntry; class LocatableFile; class SourceFile; +class TeamFileManagerSettings; class FileManager { @@ -47,6 +50,11 @@ public: SourceFile*& _sourceFile); // returns a reference + status_t LoadLocationMappings(TeamFileManagerSettings* + settings); + status_t SaveLocationMappings(TeamFileManagerSettings* + settings); + private: struct EntryPath; struct EntryHashDefinition; @@ -70,6 +78,7 @@ private: Domain* fTargetDomain; Domain* fSourceDomain; SourceFileTable* fSourceFiles; + BMessage fLocationMappings; }; diff --git a/src/apps/debugger/settings/TeamFileManagerSettings.cpp b/src/apps/debugger/settings/TeamFileManagerSettings.cpp new file mode 100644 index 0000000..041b803 --- /dev/null +++ b/src/apps/debugger/settings/TeamFileManagerSettings.cpp @@ -0,0 +1,128 @@ +/* + * Copyright 2013, Rene Gollent, rene@xxxxxxxxxxx. + * Distributed under the terms of the MIT License. + */ +#include "TeamFileManagerSettings.h" + +TeamFileManagerSettings::TeamFileManagerSettings() + : + fValues() +{ +} + + +TeamFileManagerSettings::~TeamFileManagerSettings() +{ +} + + +TeamFileManagerSettings& +TeamFileManagerSettings::operator=(const TeamFileManagerSettings& other) +{ + fValues = other.fValues; + + return *this; +} + + +const char* +TeamFileManagerSettings::ID() const +{ + return "FileManager"; +} + + +status_t +TeamFileManagerSettings::SetTo(const BMessage& archive) +{ + try { + fValues = archive; + } catch (...) { + return B_NO_MEMORY; + } + + return B_OK; +} + + +status_t +TeamFileManagerSettings::WriteTo(BMessage& archive) const +{ + try { + archive = fValues; + } catch (...) { + return B_NO_MEMORY; + } + + return B_OK; +} + + +int32 +TeamFileManagerSettings::CountSourceMappings() const +{ + type_code type; + int32 count = 0; + + if (fValues.GetInfo("source:mapping", &type, &count) == B_OK) + return count; + + return 0; +} + + +status_t +TeamFileManagerSettings::AddSourceMapping(const BString& sourcePath, + const BString& locatedPath) +{ + BMessage mapping; + if (mapping.AddString("source:path", sourcePath) != B_OK + || mapping.AddString("source:locatedpath", locatedPath) != B_OK + || fValues.AddMessage("source:mapping", &mapping) != B_OK) { + return B_NO_MEMORY; + } + + return B_OK; +} + + +status_t +TeamFileManagerSettings::RemoveSourceMappingAt(int32 index) +{ + return fValues.RemoveData("mapping", index); +} + + +status_t +TeamFileManagerSettings::GetSourceMappingAt(int32 index, BString& sourcePath, + BString& locatedPath) +{ + BMessage mapping; + status_t error = fValues.FindMessage("mapping", index, &mapping); + if (error != B_OK) + return error; + + error = mapping.FindString("source:path", &sourcePath); + if (error != B_OK) + return error; + + return mapping.FindString("source:locatedpath", &locatedPath); +} + + +TeamFileManagerSettings* +TeamFileManagerSettings::Clone() const +{ + TeamFileManagerSettings* settings = new(std::nothrow) + TeamFileManagerSettings(); + + if (settings == NULL) + return NULL; + + if (settings->SetTo(fValues) != B_OK) { + delete settings; + return NULL; + } + + return settings; +} diff --git a/src/apps/debugger/settings/TeamFileManagerSettings.h b/src/apps/debugger/settings/TeamFileManagerSettings.h new file mode 100644 index 0000000..5663ce3 --- /dev/null +++ b/src/apps/debugger/settings/TeamFileManagerSettings.h @@ -0,0 +1,41 @@ +/* + * Copyright 2013, Rene Gollent, rene@xxxxxxxxxxx. + * Distributed under the terms of the MIT License. + */ +#ifndef TEAM_FILE_MANAGER_SETTINGS_H +#define TEAM_FILE_MANAGER_SETTINGS_H + +#include <Message.h> + + +class TeamFileManagerSettings { +public: + TeamFileManagerSettings(); + virtual ~TeamFileManagerSettings(); + + TeamFileManagerSettings& + operator=( + const TeamFileManagerSettings& other); + // throws std::bad_alloc; + + const char* ID() const; + status_t SetTo(const BMessage& archive); + status_t WriteTo(BMessage& archive) const; + + int32 CountSourceMappings() const; + status_t AddSourceMapping(const BString& sourcePath, + const BString& locatedPath); + status_t RemoveSourceMappingAt(int32 index); + status_t GetSourceMappingAt(int32 index, + BString& sourcePath, BString& locatedPath); + + virtual TeamFileManagerSettings* + Clone() const; + // throws std::bad_alloc + +private: + BMessage fValues; +}; + + +#endif // TEAM_FILE_MANAGER_SETTINGS_H diff --git a/src/apps/debugger/settings/TeamSettings.cpp b/src/apps/debugger/settings/TeamSettings.cpp index cf31541..99c38a0 100644 --- a/src/apps/debugger/settings/TeamSettings.cpp +++ b/src/apps/debugger/settings/TeamSettings.cpp @@ -16,6 +16,7 @@ #include "ArchivingUtils.h" #include "BreakpointSetting.h" #include "Team.h" +#include "TeamFileManagerSettings.h" #include "TeamUiSettings.h" #include "TeamUiSettingsFactory.h" #include "UserBreakpoint.h" @@ -23,6 +24,7 @@ TeamSettings::TeamSettings() { + fFileManagerSettings = new TeamFileManagerSettings(); } @@ -115,6 +117,12 @@ TeamSettings::SetTo(const BMessage& archive) } } + if (archive.FindMessage("filemanagersettings", &childArchive) == B_OK) { + error = fFileManagerSettings->SetTo(childArchive); + if (error != B_OK) + return error; + } + return B_OK; } @@ -149,6 +157,14 @@ TeamSettings::WriteTo(BMessage& archive) const return error; } + error = fFileManagerSettings->WriteTo(childArchive); + if (error != B_OK) + return error; + + error = archive.AddMessage("filemanagersettings", &childArchive); + if (error != B_OK) + return error; + return B_OK; } @@ -234,10 +250,32 @@ TeamSettings::operator=(const TeamSettings& other) } } + *fFileManagerSettings = *other.fFileManagerSettings; + return *this; } +TeamFileManagerSettings* +TeamSettings::FileManagerSettings() const +{ + return fFileManagerSettings; +} + + +status_t +TeamSettings::SetFileManagerSettings(TeamFileManagerSettings* settings) +{ + try { + *fFileManagerSettings = *settings; + } catch (...) { + return B_NO_MEMORY; + } + + return B_OK; +} + + void TeamSettings::_Unset() { diff --git a/src/apps/debugger/settings/TeamSettings.h b/src/apps/debugger/settings/TeamSettings.h index f41f2bf..6f71cda 100644 --- a/src/apps/debugger/settings/TeamSettings.h +++ b/src/apps/debugger/settings/TeamSettings.h @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx. + * Copyright 2013, Rene Gollent, rene@xxxxxxxxxxx. * Distributed under the terms of the MIT License. */ #ifndef TEAM_SETTINGS_H @@ -15,6 +16,7 @@ class BMessage; class Team; class BreakpointSetting; class TeamUiSettings; +class TeamFileManagerSettings; class TeamSettings { @@ -41,6 +43,11 @@ public: TeamSettings& operator=(const TeamSettings& other); // throws std::bad_alloc + TeamFileManagerSettings* + FileManagerSettings() const; + status_t SetFileManagerSettings( + TeamFileManagerSettings* settings); + private: typedef BObjectList<BreakpointSetting> BreakpointList; typedef BObjectList<TeamUiSettings> UiSettingsList; @@ -51,6 +58,8 @@ private: private: BreakpointList fBreakpoints; UiSettingsList fUiSettings; + TeamFileManagerSettings* + fFileManagerSettings; BString fTeamName; }; ############################################################################ Commit: 37fc9962f8ef8df69f2ad41ff0cdaa0f32fa8dda URL: http://cgit.haiku-os.org/haiku/commit/?id=37fc996 Author: Rene Gollent <anevilyak@xxxxxxxxx> Date: Mon Sep 16 13:21:18 2013 UTC Fix incorrect name usage. ---------------------------------------------------------------------------- diff --git a/src/apps/debugger/settings/TeamFileManagerSettings.cpp b/src/apps/debugger/settings/TeamFileManagerSettings.cpp index 041b803..dae7c79 100644 --- a/src/apps/debugger/settings/TeamFileManagerSettings.cpp +++ b/src/apps/debugger/settings/TeamFileManagerSettings.cpp @@ -89,7 +89,7 @@ TeamFileManagerSettings::AddSourceMapping(const BString& sourcePath, status_t TeamFileManagerSettings::RemoveSourceMappingAt(int32 index) { - return fValues.RemoveData("mapping", index); + return fValues.RemoveData("source:mapping", index); } @@ -98,7 +98,7 @@ TeamFileManagerSettings::GetSourceMappingAt(int32 index, BString& sourcePath, BString& locatedPath) { BMessage mapping; - status_t error = fValues.FindMessage("mapping", index, &mapping); + status_t error = fValues.FindMessage("source:mapping", index, &mapping); if (error != B_OK) return error; ############################################################################ Revision: hrev46070 Commit: 29fdf5e8aed6e54ff039ffecf4abb8a77897b836 URL: http://cgit.haiku-os.org/haiku/commit/?id=29fdf5e Author: Rene Gollent <anevilyak@xxxxxxxxx> Date: Mon Sep 16 13:22:05 2013 UTC Ticket: https://dev.haiku-os.org/ticket/9961 Debugger: Implement #9961. - FileManager now saves any explicitly located file mappings, and properly restores them when reloading the same team/files later. ---------------------------------------------------------------------------- diff --git a/src/apps/debugger/files/FileManager.cpp b/src/apps/debugger/files/FileManager.cpp index 36cd181..66fbe63 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<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); + } +} diff --git a/src/apps/debugger/files/FileManager.h b/src/apps/debugger/files/FileManager.h index 2439612..e008fa5 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 <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; };