From b9d05e03eb75f3a5c7f40f5934b7b7ef8954d081 Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 16 Jan 2022 18:50:12 +0000 Subject: [PATCH] Removed TargetMemoryDescriptor dependency in MemoryRegion class (in preparation for saving & loading memory regions from Bloom's project settings file) --- CMakeLists.txt | 1 - .../ExcludedMemoryRegion.hpp | 3 +- .../FocusedMemoryRegion.hpp | 3 +- .../HexViewerWidget/AnnotationItem.cpp | 2 +- .../HexViewerWidget/ByteItemGraphicsScene.cpp | 10 ++-- .../MemoryRegion.cpp | 27 --------- .../MemoryRegion.hpp | 28 ++++++--- .../ExcludedRegionItem.cpp | 18 ++++-- .../ExcludedRegionItem.hpp | 10 +++- .../MemoryRegionManager/FocusedRegionItem.cpp | 18 ++++-- .../MemoryRegionManager/FocusedRegionItem.hpp | 10 +++- .../MemoryRegionManagerWindow.cpp | 12 ++-- .../MemoryRegionManager/RegionItem.cpp | 59 ++++++++++++------- .../MemoryRegionManager/RegionItem.hpp | 17 +++++- .../TargetMemoryInspectionPane.cpp | 10 ++-- src/Targets/TargetMemory.hpp | 4 ++ 16 files changed, 136 insertions(+), 96 deletions(-) delete mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ceaf0f5..e0959140 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,7 +192,6 @@ add_executable(Bloom # Target memory inspection pane src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp - src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp index 91469983..4aa7aade 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp @@ -9,8 +9,7 @@ namespace Bloom public: explicit ExcludedMemoryRegion( const QString& name, - const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetMemoryAddressRange& addressRange - ): MemoryRegion(name, MemoryRegionType::EXCLUDED, memoryDescriptor, addressRange) {}; + ): MemoryRegion(name, MemoryRegionType::EXCLUDED, addressRange) {}; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp index 2d030ea7..818cb243 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp @@ -20,8 +20,7 @@ namespace Bloom explicit FocusedMemoryRegion( const QString& name, - const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetMemoryAddressRange& addressRange - ): MemoryRegion(name, MemoryRegionType::FOCUSED, memoryDescriptor, addressRange) {}; + ): MemoryRegion(name, MemoryRegionType::FOCUSED, addressRange) {}; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/AnnotationItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/AnnotationItem.cpp index 97069cd2..1fc2c3d2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/AnnotationItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/AnnotationItem.cpp @@ -38,7 +38,7 @@ AnnotationItem::AnnotationItem( AnnotationItem::AnnotationItem(const FocusedMemoryRegion& focusedMemoryRegion, AnnotationItemPosition position) : AnnotationItem( - focusedMemoryRegion.getAbsoluteAddressRange(), + focusedMemoryRegion.addressRange, focusedMemoryRegion.name, position ) {} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp index 314201a9..636e71f1 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp @@ -89,16 +89,18 @@ void ByteItemGraphicsScene::refreshRegions() { byteWidget->excludedMemoryRegion = nullptr; for (const auto& focusedRegion : this->focusedMemoryRegions) { - const auto addressRange = focusedRegion.getAbsoluteAddressRange(); - if (byteAddress >= addressRange.startAddress && byteAddress <= addressRange.endAddress) { + if (byteAddress >= focusedRegion.addressRange.startAddress + && byteAddress <= focusedRegion.addressRange.endAddress + ) { byteWidget->focusedMemoryRegion = &focusedRegion; break; } } for (const auto& excludedRegion : this->excludedMemoryRegions) { - const auto addressRange = excludedRegion.getAbsoluteAddressRange(); - if (byteAddress >= addressRange.startAddress && byteAddress <= addressRange.endAddress) { + if (byteAddress >= excludedRegion.addressRange.startAddress + && byteAddress <= excludedRegion.addressRange.endAddress + ) { byteWidget->excludedMemoryRegion = &excludedRegion; break; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp deleted file mode 100644 index 6a9dbdd8..00000000 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "MemoryRegion.hpp" - -using namespace Bloom; - -using Bloom::Targets::TargetMemoryAddressRange; - -TargetMemoryAddressRange MemoryRegion::getAbsoluteAddressRange() const { - if (this->addressRangeType == MemoryRegionAddressType::ABSOLUTE) { - return this->addressRange; - } - - return TargetMemoryAddressRange( - this->addressRange.startAddress + this->memoryDescriptor.addressRange.startAddress, - this->addressRange.endAddress + this->memoryDescriptor.addressRange.startAddress - ); -} - -TargetMemoryAddressRange MemoryRegion::getRelativeAddressRange() const { - if (this->addressRangeType == MemoryRegionAddressType::RELATIVE) { - return this->addressRange; - } - - return TargetMemoryAddressRange( - this->addressRange.startAddress - this->memoryDescriptor.addressRange.startAddress, - this->addressRange.endAddress - this->memoryDescriptor.addressRange.startAddress - ); -} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp index a4dc5a3b..41885573 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp @@ -29,16 +29,31 @@ namespace Bloom QString name; QDateTime createdDate = DateTime::currentDateTime(); MemoryRegionType type; - Targets::TargetMemoryDescriptor memoryDescriptor; - Targets::TargetMemoryAddressRange addressRange; + + /** + * The addressRangeType holds the user's preference when inputting address ranges in the memory region manager + * window, for this particular memory region. + * + * It has no significance anywhere else. We never store the address in relative form - this->addressRange will + * always be in absolute form. Conversion is done at the point of applying the changes. + * + * For more, see the following and their call sites: + * See RegionItem::convertRelativeToAbsoluteAddressRange() + * See RegionItem::convertAbsoluteToRelativeAddressRange() + */ MemoryRegionAddressType addressRangeType = MemoryRegionAddressType::ABSOLUTE; + /** + * This address range will always be in absolute form. Regardless of the value of this->addressRangeType. + * See the comment above, for this->addressRangeType, for more. + */ + Targets::TargetMemoryAddressRange addressRange; + MemoryRegion( QString name, MemoryRegionType type, - const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetMemoryAddressRange& addressRange - ): name(std::move(name)), type(type), memoryDescriptor(memoryDescriptor), addressRange(addressRange) {}; + ): name(std::move(name)), type(type), addressRange(addressRange) {}; virtual ~MemoryRegion() = default; @@ -57,12 +72,9 @@ namespace Bloom } [[nodiscard]] bool intersectsWith(const MemoryRegion& other) const { - return this->getAbsoluteAddressRange().intersectsWith(other.getAbsoluteAddressRange()); + return this->addressRange.intersectsWith(other.addressRange); } - [[nodiscard]] Targets::TargetMemoryAddressRange getAbsoluteAddressRange() const; - [[nodiscard]] Targets::TargetMemoryAddressRange getRelativeAddressRange() const; - private: static inline std::atomic lastId = 0; }; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.cpp index 98ea573c..1111b270 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.cpp @@ -9,10 +9,13 @@ using namespace Bloom; using namespace Bloom::Widgets; +using Targets::TargetMemoryAddressRange; + ExcludedRegionItem::ExcludedRegionItem( const ExcludedMemoryRegion& region, + const Targets::TargetMemoryDescriptor& memoryDescriptor, QWidget* parent -): memoryRegion(region), RegionItem(region, parent) { +): memoryRegion(region), RegionItem(region, memoryDescriptor, parent) { auto formUiFile = QFile( QString::fromStdString(Paths::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" @@ -30,11 +33,14 @@ ExcludedRegionItem::ExcludedRegionItem( this->initFormInputs(); } -ExcludedMemoryRegion ExcludedRegionItem::generateExcludedMemoryRegionFromInput() { +void ExcludedRegionItem::applyChanges() { this->memoryRegion.name = this->nameInput->text(); - this->memoryRegion.addressRange.startAddress = this->startAddressInput->text().toUInt(nullptr, 16); - this->memoryRegion.addressRange.endAddress = this->endAddressInput->text().toUInt(nullptr, 16); - this->memoryRegion.addressRangeType = this->getSelectedAddressType(); - return this->memoryRegion; + const auto inputAddressRange = TargetMemoryAddressRange( + this->startAddressInput->text().toUInt(nullptr, 16), + this->endAddressInput->text().toUInt(nullptr, 16) + ); + this->memoryRegion.addressRangeType = this->getSelectedAddressType(); + this->memoryRegion.addressRange = this->memoryRegion.addressRangeType == MemoryRegionAddressType::RELATIVE ? + this->convertRelativeToAbsoluteAddressRange(inputAddressRange) : inputAddressRange; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.hpp index 6cabca7f..9dae69de 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.hpp @@ -10,13 +10,17 @@ namespace Bloom::Widgets Q_OBJECT public: - ExcludedRegionItem(const ExcludedMemoryRegion& region, QWidget *parent); + ExcludedRegionItem( + const ExcludedMemoryRegion& region, + const Targets::TargetMemoryDescriptor& memoryDescriptor, + QWidget *parent + ); - [[nodiscard]] const MemoryRegion& getMemoryRegion() const override { + [[nodiscard]] const ExcludedMemoryRegion& getMemoryRegion() const override { return this->memoryRegion; }; - [[nodiscard]] virtual ExcludedMemoryRegion generateExcludedMemoryRegionFromInput(); + virtual void applyChanges(); private: ExcludedMemoryRegion memoryRegion; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp index e383b564..e3727143 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp @@ -9,10 +9,13 @@ using namespace Bloom; using namespace Bloom::Widgets; +using Targets::TargetMemoryAddressRange; + FocusedRegionItem::FocusedRegionItem( const FocusedMemoryRegion& region, + const Targets::TargetMemoryDescriptor& memoryDescriptor, QWidget* parent -): memoryRegion(region), RegionItem(region, parent) { +): memoryRegion(region), RegionItem(region, memoryDescriptor, parent) { auto formUiFile = QFile( QString::fromStdString(Paths::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" @@ -30,18 +33,21 @@ FocusedRegionItem::FocusedRegionItem( this->initFormInputs(); } -FocusedMemoryRegion FocusedRegionItem::generateFocusedMemoryRegionFromInput() { +void FocusedRegionItem::applyChanges() { this->memoryRegion.name = this->nameInput->text(); - this->memoryRegion.addressRange.startAddress = this->startAddressInput->text().toUInt(nullptr, 16); - this->memoryRegion.addressRange.endAddress = this->endAddressInput->text().toUInt(nullptr, 16); + + const auto inputAddressRange = TargetMemoryAddressRange( + this->startAddressInput->text().toUInt(nullptr, 16), + this->endAddressInput->text().toUInt(nullptr, 16) + ); this->memoryRegion.addressRangeType = this->getSelectedAddressType(); + this->memoryRegion.addressRange = this->memoryRegion.addressRangeType == MemoryRegionAddressType::RELATIVE ? + this->convertRelativeToAbsoluteAddressRange(inputAddressRange) : inputAddressRange; auto selectedDataTypeOptionName = this->dataTypeInput->currentData().toString(); if (FocusedRegionItem::dataTypeOptionsByName.contains(selectedDataTypeOptionName)) { this->memoryRegion.dataType = FocusedRegionItem::dataTypeOptionsByName.at(selectedDataTypeOptionName).dataType; } - - return this->memoryRegion; } void FocusedRegionItem::initFormInputs() { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp index 4ab8dde1..d5135ee5 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp @@ -19,13 +19,17 @@ namespace Bloom::Widgets Q_OBJECT public: - FocusedRegionItem(const FocusedMemoryRegion& region, QWidget *parent); + FocusedRegionItem( + const FocusedMemoryRegion& region, + const Targets::TargetMemoryDescriptor& memoryDescriptor, + QWidget *parent + ); - [[nodiscard]] const MemoryRegion& getMemoryRegion() const override { + [[nodiscard]] const FocusedMemoryRegion& getMemoryRegion() const override { return this->memoryRegion; }; - [[nodiscard]] virtual FocusedMemoryRegion generateFocusedMemoryRegionFromInput(); + virtual void applyChanges(); protected: void initFormInputs() override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp index 9b2e641d..9531239c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp @@ -195,7 +195,7 @@ void MemoryRegionManagerWindow::sortRegionItems() { } FocusedRegionItem* MemoryRegionManagerWindow::addFocusedRegion(const FocusedMemoryRegion& region) { - auto* focusedRegionItem = new FocusedRegionItem(region, this->regionItemScrollAreaViewport); + auto* focusedRegionItem = new FocusedRegionItem(region, this->memoryDescriptor, this->regionItemScrollAreaViewport); this->focusedRegionItems.insert(focusedRegionItem); this->regionItemScrollAreaViewportLayout->addWidget(focusedRegionItem); @@ -207,7 +207,7 @@ FocusedRegionItem* MemoryRegionManagerWindow::addFocusedRegion(const FocusedMemo } ExcludedRegionItem* MemoryRegionManagerWindow::addExcludedRegion(const ExcludedMemoryRegion& region) { - auto* excludedRegionItem = new ExcludedRegionItem(region, this->regionItemScrollAreaViewport); + auto* excludedRegionItem = new ExcludedRegionItem(region, this->memoryDescriptor, this->regionItemScrollAreaViewport); this->excludedRegionItems.insert(excludedRegionItem); this->regionItemScrollAreaViewportLayout->addWidget(excludedRegionItem); @@ -232,7 +232,6 @@ void MemoryRegionManagerWindow::onNewFocusedRegionTrigger() { auto* region = this->addFocusedRegion(FocusedMemoryRegion( "Untitled Region", - this->memoryDescriptor, TargetMemoryAddressRange( this->memoryDescriptor.addressRange.startAddress, this->memoryDescriptor.addressRange.startAddress + 10 @@ -247,7 +246,6 @@ void MemoryRegionManagerWindow::onNewExcludedRegionTrigger() { auto* region = this->addExcludedRegion(ExcludedMemoryRegion( "Untitled Region", - this->memoryDescriptor, TargetMemoryAddressRange( this->memoryDescriptor.addressRange.startAddress, this->memoryDescriptor.addressRange.startAddress + 10 @@ -315,7 +313,8 @@ void MemoryRegionManagerWindow::applyChanges() { return; } - auto focusedRegion = focusedRegionItem->generateFocusedMemoryRegionFromInput(); + focusedRegionItem->applyChanges(); + const auto& focusedRegion = focusedRegionItem->getMemoryRegion(); for (const auto& processedFocusedRegion : processedFocusedMemoryRegions) { if (processedFocusedRegion.intersectsWith(focusedRegion)) { auto* errorDialogue = new ErrorDialogue( @@ -347,7 +346,8 @@ void MemoryRegionManagerWindow::applyChanges() { return; } - auto excludedRegion = excludedRegionItem->generateExcludedMemoryRegionFromInput(); + excludedRegionItem->applyChanges(); + auto excludedRegion = excludedRegionItem->getMemoryRegion(); for (const auto& processedFocusedRegion : processedFocusedMemoryRegions) { if (processedFocusedRegion.intersectsWith(excludedRegion)) { auto* errorDialogue = new ErrorDialogue( diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.cpp index bb823234..0e2e07d2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.cpp @@ -6,10 +6,13 @@ using namespace Bloom; using namespace Bloom::Widgets; +using Targets::TargetMemoryAddressRange; + RegionItem::RegionItem( const MemoryRegion& region, + const Targets::TargetMemoryDescriptor& memoryDescriptor, QWidget* parent -): ClickableWidget(parent) { +): memoryDescriptor(memoryDescriptor), ClickableWidget(parent) { this->setObjectName("region-item"); this->setFixedHeight(50); this->layout->setContentsMargins(5, 5, 5, 0); @@ -25,10 +28,9 @@ RegionItem::RegionItem( this->typeLabel->setText(region.type == MemoryRegionType::FOCUSED ? "Focused" : "Excluded"); this->typeLabel->setObjectName("type-label"); - auto addressRange = region.getAbsoluteAddressRange(); this->addressRangeLabel->setText( - "0x" + QString::number(addressRange.startAddress, 16).toUpper() + QString(" -> ") - + "0x" + QString::number(addressRange.endAddress, 16).toUpper() + "0x" + QString::number(region.addressRange.startAddress, 16).toUpper() + QString(" -> ") + + "0x" + QString::number(region.addressRange.endAddress, 16).toUpper() ); this->addressRangeLabel->setObjectName("address-label"); @@ -74,8 +76,6 @@ void RegionItem::setSelected(bool selected) { QStringList RegionItem::getValidationFailures() const { auto validationFailures = QStringList(); - const auto& memoryDescriptor = this->getMemoryRegion().memoryDescriptor; - if (this->nameInput->text().isEmpty()) { validationFailures.emplace_back("Missing region name."); } @@ -97,28 +97,28 @@ QStringList RegionItem::getValidationFailures() const { } auto addressType = this->getSelectedAddressType(); - const auto memoryAddressRange = memoryDescriptor.addressRange; + const auto memoryAddressRange = this->memoryDescriptor.addressRange; const auto memoryAddressRangeStr = QString( "0x" + QString::number(memoryAddressRange.startAddress, 16).toUpper() + QString(" -> ") + "0x" + QString::number(memoryAddressRange.endAddress, 16).toUpper() ); - std::uint32_t absoluteStartAddress = addressType == MemoryRegionAddressType::RELATIVE ? - memoryAddressRange.startAddress + startAddress : startAddress; + const auto absoluteAddressRange = addressType == MemoryRegionAddressType::RELATIVE ? + this->convertRelativeToAbsoluteAddressRange(TargetMemoryAddressRange(startAddress, endAddress)) + : TargetMemoryAddressRange(startAddress, endAddress); - std::uint32_t absoluteEndAddress = addressType == MemoryRegionAddressType::RELATIVE ? - memoryAddressRange.startAddress + endAddress : endAddress; - - if (absoluteStartAddress < memoryAddressRange.startAddress - || absoluteStartAddress > memoryAddressRange.endAddress + if (absoluteAddressRange.startAddress < memoryAddressRange.startAddress + || absoluteAddressRange.startAddress > memoryAddressRange.endAddress ) { validationFailures.emplace_back( "The start address is not within the absolute memory address range (" + memoryAddressRangeStr + ")." ); } - if (absoluteEndAddress < memoryAddressRange.startAddress || absoluteEndAddress > memoryAddressRange.endAddress) { + if (absoluteAddressRange.endAddress < memoryAddressRange.startAddress + || absoluteAddressRange.endAddress > memoryAddressRange.endAddress + ) { validationFailures.emplace_back( "The end address not within the absolute memory address range (" + memoryAddressRangeStr + ")." ); @@ -144,18 +144,17 @@ void RegionItem::initFormInputs() { } if (region.addressRangeType == MemoryRegionAddressType::RELATIVE) { + auto relativeAddressRange = this->convertAbsoluteToRelativeAddressRange(region.addressRange); this->addressTypeInput->setCurrentText(RegionItem::addressRangeTypeOptionsByName.at("relative").text); - auto addressRange = region.getRelativeAddressRange(); - this->startAddressInput->setText("0x" + QString::number(addressRange.startAddress, 16).toUpper()); - this->endAddressInput->setText("0x" + QString::number(addressRange.endAddress, 16).toUpper()); + this->startAddressInput->setText("0x" + QString::number(relativeAddressRange.startAddress, 16).toUpper()); + this->endAddressInput->setText("0x" + QString::number(relativeAddressRange.endAddress, 16).toUpper()); } else { this->addressTypeInput->setCurrentText(RegionItem::addressRangeTypeOptionsByName.at("absolute").text); - auto addressRange = region.getAbsoluteAddressRange(); - this->startAddressInput->setText("0x" + QString::number(addressRange.startAddress, 16).toUpper()); - this->endAddressInput->setText("0x" + QString::number(addressRange.endAddress, 16).toUpper()); + this->startAddressInput->setText("0x" + QString::number(region.addressRange.startAddress, 16).toUpper()); + this->endAddressInput->setText("0x" + QString::number(region.addressRange.endAddress, 16).toUpper()); } QObject::connect(this->startAddressInput, &QLineEdit::textEdited, this, &RegionItem::onAddressRangeInputChange); @@ -173,6 +172,24 @@ MemoryRegionAddressType RegionItem::getSelectedAddressType() const { return MemoryRegionAddressType::ABSOLUTE; } +TargetMemoryAddressRange RegionItem::convertAbsoluteToRelativeAddressRange( + const TargetMemoryAddressRange& absoluteAddressRange +) const { + return TargetMemoryAddressRange( + absoluteAddressRange.startAddress - this->memoryDescriptor.addressRange.startAddress, + absoluteAddressRange.endAddress - this->memoryDescriptor.addressRange.startAddress + ); +} + +TargetMemoryAddressRange RegionItem::convertRelativeToAbsoluteAddressRange( + const TargetMemoryAddressRange& relativeAddressRange +) const { + return TargetMemoryAddressRange( + relativeAddressRange.startAddress + this->memoryDescriptor.addressRange.startAddress, + relativeAddressRange.endAddress + this->memoryDescriptor.addressRange.startAddress + ); +} + void RegionItem::onAddressRangeInputChange() { bool startAddressConversionOk = false; bool endAddressConversionOk = false; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.hpp index c0768c41..fc280c2c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.hpp @@ -11,6 +11,7 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp" +#include "src/Targets/TargetMemory.hpp" namespace Bloom::Widgets { @@ -28,7 +29,11 @@ namespace Bloom::Widgets Q_OBJECT public: - RegionItem(const MemoryRegion& region, QWidget *parent); + RegionItem( + const MemoryRegion& region, + const Targets::TargetMemoryDescriptor& memoryDescriptor, + QWidget *parent + ); void setSelected(bool selected); [[nodiscard]] QWidget* getFormWidget() const { @@ -48,6 +53,8 @@ namespace Bloom::Widgets protected: static constexpr int NAME_LABEL_MAX_LENGTH = 34; + const Targets::TargetMemoryDescriptor& memoryDescriptor; + QWidget* formWidget = nullptr; TextInput* nameInput = nullptr; QComboBox* addressTypeInput = nullptr; @@ -58,6 +65,14 @@ namespace Bloom::Widgets virtual void initFormInputs(); [[nodiscard]] MemoryRegionAddressType getSelectedAddressType() const; + Targets::TargetMemoryAddressRange convertAbsoluteToRelativeAddressRange( + const Targets::TargetMemoryAddressRange& absoluteAddressRange + ) const; + + Targets::TargetMemoryAddressRange convertRelativeToAbsoluteAddressRange( + const Targets::TargetMemoryAddressRange& relativeAddressRange + ) const; + private: QVBoxLayout* layout = new QVBoxLayout(this); QLabel* nameLabel = new QLabel(this); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp index 19d5806f..d33eff58 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp @@ -20,7 +20,7 @@ using Bloom::Targets::TargetMemoryType; TargetMemoryInspectionPane::TargetMemoryInspectionPane( const TargetMemoryDescriptor& targetMemoryDescriptor, - const TargetMemoryInspectionPaneSettings& settings, + TargetMemoryInspectionPaneSettings& settings, InsightWorker& insightWorker, PanelWidget* parent ): @@ -104,8 +104,8 @@ void TargetMemoryInspectionPane::refreshMemoryValues(std::optionalsettings.excludedMemoryRegions.begin(), this->settings.excludedMemoryRegions.end(), std::inserter(excludedAddressRanges, excludedAddressRanges.begin()), - [] (const ExcludedMemoryRegion& excludedRegion) { - return excludedRegion.getAbsoluteAddressRange(); + [this] (const ExcludedMemoryRegion& excludedRegion) { + return excludedRegion.addressRange; } ); @@ -199,7 +199,7 @@ void TargetMemoryInspectionPane::sanitiseSettings() { this->settings.focusedMemoryRegions.begin(), this->settings.focusedMemoryRegions.end(), [this] (const FocusedMemoryRegion& region) { - return region.memoryDescriptor != this->targetMemoryDescriptor; + return !this->targetMemoryDescriptor.addressRange.contains(region.addressRange); } ), this->settings.focusedMemoryRegions.end() @@ -210,7 +210,7 @@ void TargetMemoryInspectionPane::sanitiseSettings() { this->settings.excludedMemoryRegions.begin(), this->settings.excludedMemoryRegions.end(), [this] (const ExcludedMemoryRegion& region) { - return region.memoryDescriptor != this->targetMemoryDescriptor; + return !this->targetMemoryDescriptor.addressRange.contains(region.addressRange); } ), this->settings.excludedMemoryRegions.end() diff --git a/src/Targets/TargetMemory.hpp b/src/Targets/TargetMemory.hpp index 6e4ad3e6..a49cb3fd 100644 --- a/src/Targets/TargetMemory.hpp +++ b/src/Targets/TargetMemory.hpp @@ -40,6 +40,10 @@ namespace Bloom::Targets [[nodiscard]] bool contains(std::uint32_t address) const { return address >= this->startAddress && address <= this->endAddress; } + + [[nodiscard]] bool contains(const TargetMemoryAddressRange& addressRange) const { + return this->startAddress <= addressRange.startAddress && this->endAddress >= addressRange.endAddress; + } }; struct TargetMemoryDescriptor