From b9b126139a57e5c239f935dc5cef11188042bdc8 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Mon, 16 Sep 2013 13:28:28 +0200 Subject: [PATCH] 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. --- src/apps/debugger/Jamfile | 1 + .../debugger/controllers/TeamDebugger.cpp | 4 + src/apps/debugger/files/FileManager.cpp | 40 +++++- src/apps/debugger/files/FileManager.h | 9 ++ .../settings/TeamFileManagerSettings.cpp | 128 ++++++++++++++++++ .../settings/TeamFileManagerSettings.h | 41 ++++++ src/apps/debugger/settings/TeamSettings.cpp | 38 ++++++ src/apps/debugger/settings/TeamSettings.h | 9 ++ 8 files changed, 267 insertions(+), 3 deletions(-) create mode 100644 src/apps/debugger/settings/TeamFileManagerSettings.cpp create mode 100644 src/apps/debugger/settings/TeamFileManagerSettings.h diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index ac9212f809..1352fc5c36 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 b4a391b194..3226afa4b8 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 aaa78f27a2..36cd181aaf 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@gmx.de. - * Copyright 2011-2012, Rene Gollent, rene@gollent.com. + * Copyright 2011-2013, Rene Gollent, rene@gollent.com. * 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 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 559942152b..24396124cb 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@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef FILE_MANAGER_H #define FILE_MANAGER_H #include +#include #include #include @@ -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 0000000000..041b803ce1 --- /dev/null +++ b/src/apps/debugger/settings/TeamFileManagerSettings.cpp @@ -0,0 +1,128 @@ +/* + * Copyright 2013, Rene Gollent, rene@gollent.com. + * 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 0000000000..5663ce3000 --- /dev/null +++ b/src/apps/debugger/settings/TeamFileManagerSettings.h @@ -0,0 +1,41 @@ +/* + * Copyright 2013, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ +#ifndef TEAM_FILE_MANAGER_SETTINGS_H +#define TEAM_FILE_MANAGER_SETTINGS_H + +#include + + +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 cf3154151c..99c38a0be8 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 f41f2bf8bd..6f71cda7ef 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@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * 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 BreakpointList; typedef BObjectList UiSettingsList; @@ -51,6 +58,8 @@ private: private: BreakpointList fBreakpoints; UiSettingsList fUiSettings; + TeamFileManagerSettings* + fFileManagerSettings; BString fTeamName; };