diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index 6cf994cb..6674fd3a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -465,6 +465,9 @@ void InsightWindow::createPanes() { auto& ramDescriptor = this->targetDescriptor.memoryDescriptorsByType.at(TargetMemoryType::RAM); this->ramInspectionPane = new TargetMemoryInspectionPane( ramDescriptor, + this->memoryInspectionPaneSettingsByMemoryType.contains(TargetMemoryType::RAM) ? + this->memoryInspectionPaneSettingsByMemoryType.at(TargetMemoryType::RAM) + : TargetMemoryInspectionPaneSettings(), this->insightWorker, this->bottomPanel ); @@ -478,6 +481,9 @@ void InsightWindow::createPanes() { auto& eepromDescriptor = this->targetDescriptor.memoryDescriptorsByType.at(TargetMemoryType::EEPROM); this->eepromInspectionPane = new TargetMemoryInspectionPane( eepromDescriptor, + this->memoryInspectionPaneSettingsByMemoryType.contains(TargetMemoryType::EEPROM) ? + this->memoryInspectionPaneSettingsByMemoryType.at(TargetMemoryType::EEPROM) + : TargetMemoryInspectionPaneSettings(), this->insightWorker, this->bottomPanel ); @@ -497,7 +503,13 @@ void InsightWindow::destroyPanes() { this->targetRegistersButton->setDisabled(true); } + /* + * Before we destroy the memory inspection pane widgets, we take a copy of their current settings (memory regions, + * hex viewer settings, etc), in order to persist them through debug sessions. + */ if (this->ramInspectionPane != nullptr) { + this->memoryInspectionPaneSettingsByMemoryType[TargetMemoryType::RAM] = this->ramInspectionPane->settings; + this->ramInspectionPane->deactivate(); this->ramInspectionPane->deleteLater(); this->ramInspectionPane = nullptr; @@ -508,6 +520,8 @@ void InsightWindow::destroyPanes() { } if (this->eepromInspectionPane != nullptr) { + this->memoryInspectionPaneSettingsByMemoryType[TargetMemoryType::EEPROM] = this->eepromInspectionPane->settings; + this->eepromInspectionPane->deactivate(); this->eepromInspectionPane->deleteLater(); this->eepromInspectionPane = nullptr; diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp index 12a99e57..feb3810b 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp @@ -20,6 +20,7 @@ #include "Widgets/TargetWidgets/TargetPackageWidget.hpp" #include "Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp" #include "Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp" +#include "Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp" #include "AboutWindow.hpp" namespace Bloom @@ -83,6 +84,10 @@ namespace Bloom Widgets::PanelWidget* bottomPanel = nullptr; Widgets::TargetMemoryInspectionPane* ramInspectionPane = nullptr; Widgets::TargetMemoryInspectionPane* eepromInspectionPane = nullptr; + std::map< + Targets::TargetMemoryType, + Widgets::TargetMemoryInspectionPaneSettings + > memoryInspectionPaneSettingsByMemoryType; QToolButton* ramInspectionButton = nullptr; QToolButton* eepromInspectionButton = nullptr; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp index 2ac3e0f6..67427452 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp @@ -29,7 +29,7 @@ namespace Bloom QString name; QDateTime createdDate = DateTime::currentDateTime(); MemoryRegionType type; - const Targets::TargetMemoryDescriptor& memoryDescriptor; + Targets::TargetMemoryDescriptor memoryDescriptor; Targets::TargetMemoryAddressRange addressRange; MemoryRegionAddressType addressRangeType = MemoryRegionAddressType::ABSOLUTE; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp index a4416374..447058fc 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp @@ -20,9 +20,16 @@ using Bloom::Targets::TargetMemoryType; TargetMemoryInspectionPane::TargetMemoryInspectionPane( const TargetMemoryDescriptor& targetMemoryDescriptor, + const TargetMemoryInspectionPaneSettings& settings, InsightWorker& insightWorker, PanelWidget* parent -): QWidget(parent), parent(parent), targetMemoryDescriptor(targetMemoryDescriptor), insightWorker(insightWorker) { +): + QWidget(parent), + targetMemoryDescriptor(targetMemoryDescriptor), + settings(settings), + insightWorker(insightWorker), + parent(parent) +{ this->setObjectName("target-memory-inspection-pane"); auto memoryInspectionPaneUiFile = QFile( @@ -47,12 +54,15 @@ TargetMemoryInspectionPane::TargetMemoryInspectionPane( this->targetMemoryDescriptor.type == TargetMemoryType::EEPROM ? "Internal EEPROM" : "Internal RAM" ); + // Quick sanity check to ensure the validity of persisted settings. + this->sanitiseSettings(); + auto* subContainerLayout = this->container->findChild("sub-container-layout"); this->manageMemoryRegionsButton = this->container->findChild("manage-memory-regions-btn"); this->hexViewerWidget = new HexViewerWidget( this->targetMemoryDescriptor, - this->focusedMemoryRegions, - this->excludedMemoryRegions, + this->settings.focusedMemoryRegions, + this->settings.excludedMemoryRegions, this->insightWorker, this ); @@ -167,6 +177,31 @@ void TargetMemoryInspectionPane::postDeactivate() { } +void TargetMemoryInspectionPane::sanitiseSettings() { + // Remove any invalid memory regions. It's very unlikely that there will be any, but not impossible. + this->settings.focusedMemoryRegions.erase( + std::remove_if( + this->settings.focusedMemoryRegions.begin(), + this->settings.focusedMemoryRegions.end(), + [this] (const FocusedMemoryRegion& region) { + return region.memoryDescriptor != this->targetMemoryDescriptor; + } + ), + this->settings.focusedMemoryRegions.end() + ); + + this->settings.excludedMemoryRegions.erase( + std::remove_if( + this->settings.excludedMemoryRegions.begin(), + this->settings.excludedMemoryRegions.end(), + [this] (const ExcludedMemoryRegion& region) { + return region.memoryDescriptor != this->targetMemoryDescriptor; + } + ), + this->settings.excludedMemoryRegions.end() + ); +} + void TargetMemoryInspectionPane::onTargetStateChanged(Targets::TargetState newState) { using Targets::TargetState; this->targetState = newState; @@ -189,9 +224,10 @@ void TargetMemoryInspectionPane::openMemoryRegionManagerWindow() { if (this->memoryRegionManagerWindow == nullptr) { this->memoryRegionManagerWindow = new MemoryRegionManagerWindow( this->targetMemoryDescriptor, - this->focusedMemoryRegions, - this->excludedMemoryRegions, + this->settings.focusedMemoryRegions, + this->settings.excludedMemoryRegions, this + ); QObject::connect( diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp index 6ce4e019..fcf818d7 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp @@ -13,11 +13,9 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp" #include "HexViewerWidget/HexViewerWidget.hpp" - #include "MemoryRegionManager/MemoryRegionManagerWindow.hpp" -#include "MemoryRegion.hpp" -#include "FocusedMemoryRegion.hpp" -#include "ExcludedMemoryRegion.hpp" + +#include "TargetMemoryInspectionPaneSettings.hpp" namespace Bloom::Widgets { @@ -26,10 +24,12 @@ namespace Bloom::Widgets Q_OBJECT public: + TargetMemoryInspectionPaneSettings settings; bool activated = false; TargetMemoryInspectionPane( const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const TargetMemoryInspectionPaneSettings& settings, InsightWorker& insightWorker, PanelWidget *parent ); @@ -57,10 +57,9 @@ namespace Bloom::Widgets Targets::TargetState targetState = Targets::TargetState::UNKNOWN; - std::vector focusedMemoryRegions; - std::vector excludedMemoryRegions; MemoryRegionManagerWindow* memoryRegionManagerWindow = nullptr; + void sanitiseSettings(); void onTargetStateChanged(Targets::TargetState newState); void onMemoryRead(const Targets::TargetMemoryBuffer& buffer); void openMemoryRegionManagerWindow(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp new file mode 100644 index 00000000..a18e2713 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "FocusedMemoryRegion.hpp" +#include "ExcludedMemoryRegion.hpp" + +#include "HexViewerWidget/HexViewerWidgetSettings.hpp" + +namespace Bloom::Widgets +{ + struct TargetMemoryInspectionPaneSettings + { + std::vector focusedMemoryRegions; + std::vector excludedMemoryRegions; + + HexViewerWidgetSettings hexViewerWidgetSettings; + }; +}