Moved memory region JSON conversion to individual constructors/member functions
This commit is contained in:
@@ -75,6 +75,9 @@ target_sources(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/AnnotationItem.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ValueAnnotationItem.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.cpp
|
||||
|
||||
# Memory region manager window
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "ExcludedMemoryRegion.hpp"
|
||||
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
|
||||
namespace Bloom
|
||||
{
|
||||
ExcludedMemoryRegion::ExcludedMemoryRegion(
|
||||
const QString& name,
|
||||
Targets::TargetMemoryType memoryType,
|
||||
const Targets::TargetMemoryAddressRange& addressRange
|
||||
)
|
||||
: MemoryRegion(name, memoryType, MemoryRegionType::EXCLUDED, addressRange)
|
||||
{}
|
||||
|
||||
ExcludedMemoryRegion::ExcludedMemoryRegion(const QJsonObject& jsonObject)
|
||||
: MemoryRegion(jsonObject)
|
||||
{
|
||||
if (this->type != MemoryRegionType::EXCLUDED) {
|
||||
throw Exceptions::Exception("Invalid memory region type");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,12 @@ namespace Bloom
|
||||
class ExcludedMemoryRegion: public MemoryRegion
|
||||
{
|
||||
public:
|
||||
explicit ExcludedMemoryRegion(
|
||||
ExcludedMemoryRegion(
|
||||
const QString& name,
|
||||
Targets::TargetMemoryType memoryType,
|
||||
const Targets::TargetMemoryAddressRange& addressRange
|
||||
): MemoryRegion(name, MemoryRegionType::EXCLUDED, addressRange) {};
|
||||
);
|
||||
|
||||
ExcludedMemoryRegion(const QJsonObject& jsonObject);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "FocusedMemoryRegion.hpp"
|
||||
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
|
||||
namespace Bloom
|
||||
{
|
||||
FocusedMemoryRegion::FocusedMemoryRegion(
|
||||
const QString& name,
|
||||
Targets::TargetMemoryType memoryType,
|
||||
const Targets::TargetMemoryAddressRange& addressRange
|
||||
)
|
||||
: MemoryRegion(name, memoryType, MemoryRegionType::FOCUSED, addressRange)
|
||||
{}
|
||||
|
||||
FocusedMemoryRegion::FocusedMemoryRegion(const QJsonObject& jsonObject)
|
||||
: MemoryRegion(jsonObject)
|
||||
{
|
||||
if (this->type != MemoryRegionType::FOCUSED) {
|
||||
throw Exceptions::Exception("Invalid memory region type");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,12 @@ namespace Bloom
|
||||
MemoryRegionDataType dataType = MemoryRegionDataType::UNKNOWN;
|
||||
Targets::TargetMemoryEndianness endianness = Targets::TargetMemoryEndianness::LITTLE;
|
||||
|
||||
explicit FocusedMemoryRegion(
|
||||
FocusedMemoryRegion(
|
||||
const QString& name,
|
||||
Targets::TargetMemoryType memoryType,
|
||||
const Targets::TargetMemoryAddressRange& addressRange
|
||||
): MemoryRegion(name, MemoryRegionType::FOCUSED, addressRange) {};
|
||||
);
|
||||
|
||||
FocusedMemoryRegion(const QJsonObject& jsonObject);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "MemoryRegion.hpp"
|
||||
|
||||
#include "src/Helpers/EnumToStringMappings.hpp"
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
|
||||
namespace Bloom
|
||||
{
|
||||
MemoryRegion::MemoryRegion(
|
||||
const QString& name,
|
||||
Targets::TargetMemoryType memoryType,
|
||||
MemoryRegionType type,
|
||||
const Targets::TargetMemoryAddressRange& addressRange
|
||||
)
|
||||
: name(name)
|
||||
, memoryType(memoryType)
|
||||
, type(type)
|
||||
, addressRange(addressRange)
|
||||
{}
|
||||
|
||||
MemoryRegion::MemoryRegion(const QJsonObject& jsonObject) {
|
||||
using Exceptions::Exception;
|
||||
|
||||
if (
|
||||
!jsonObject.contains("name")
|
||||
|| !jsonObject.contains("memoryType")
|
||||
|| !jsonObject.contains("type")
|
||||
|| !jsonObject.contains("createdTimestamp")
|
||||
|| !jsonObject.contains("addressInputType")
|
||||
|| !jsonObject.contains("addressRange")
|
||||
) {
|
||||
throw Exception("Missing data");
|
||||
}
|
||||
|
||||
const auto addressRangeObj = jsonObject.find("addressRange")->toObject();
|
||||
if (
|
||||
!addressRangeObj.contains("startAddress")
|
||||
|| !addressRangeObj.contains("endAddress")
|
||||
) {
|
||||
throw Exception("Missing address range data");
|
||||
}
|
||||
|
||||
this->name = jsonObject.find("name")->toString();
|
||||
this->memoryType = EnumToStringMappings::targetMemoryTypes.at(jsonObject.find("memoryType")->toString());
|
||||
this->type = MemoryRegion::memoryRegionTypesByName.at(jsonObject.find("type")->toString());
|
||||
this->createdDate.setSecsSinceEpoch(jsonObject.find("createdTimestamp")->toInteger());
|
||||
this->addressRangeInputType = MemoryRegion::addressTypesByName.at(jsonObject.find("addressInputType")->toString());
|
||||
|
||||
this->addressRange = {
|
||||
static_cast<std::uint32_t>(addressRangeObj.find("startAddress")->toInteger()),
|
||||
static_cast<std::uint32_t>(addressRangeObj.find("endAddress")->toInteger()),
|
||||
};
|
||||
}
|
||||
|
||||
QJsonObject MemoryRegion::toJson() const {
|
||||
return QJsonObject({
|
||||
{"name", this->name},
|
||||
{"memoryType", EnumToStringMappings::targetMemoryTypes.at(this->memoryType)},
|
||||
{"type", MemoryRegion::memoryRegionTypesByName.at(this->type)},
|
||||
{"createdTimestamp", this->createdDate.toSecsSinceEpoch()},
|
||||
{"addressInputType", MemoryRegion::addressTypesByName.at(this->addressRangeInputType)},
|
||||
{"addressRange", QJsonObject({
|
||||
{"startAddress", static_cast<qint64>(this->addressRange.startAddress)},
|
||||
{"endAddress", static_cast<qint64>(this->addressRange.endAddress)},
|
||||
})},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,12 @@
|
||||
#include <cstdint>
|
||||
#include <atomic>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
#include <utility>
|
||||
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
#include "src/Helpers/DateTime.hpp"
|
||||
#include "src/Helpers/BiMap.hpp"
|
||||
#include "AddressType.hpp"
|
||||
|
||||
namespace Bloom
|
||||
@@ -28,6 +30,7 @@ namespace Bloom
|
||||
public:
|
||||
QString name;
|
||||
QDateTime createdDate = DateTime::currentDateTime();
|
||||
Targets::TargetMemoryType memoryType;
|
||||
MemoryRegionType type;
|
||||
|
||||
/**
|
||||
@@ -50,10 +53,15 @@ namespace Bloom
|
||||
Targets::TargetMemoryAddressRange addressRange;
|
||||
|
||||
MemoryRegion(
|
||||
QString name,
|
||||
const QString& name,
|
||||
Targets::TargetMemoryType memoryType,
|
||||
MemoryRegionType type,
|
||||
const Targets::TargetMemoryAddressRange& addressRange
|
||||
): name(std::move(name)), type(type), addressRange(addressRange) {};
|
||||
);
|
||||
|
||||
MemoryRegion(const QJsonObject& jsonObject);
|
||||
|
||||
virtual QJsonObject toJson() const;
|
||||
|
||||
virtual ~MemoryRegion() = default;
|
||||
|
||||
@@ -66,5 +74,16 @@ namespace Bloom
|
||||
[[nodiscard]] bool intersectsWith(const MemoryRegion& other) const {
|
||||
return this->addressRange.intersectsWith(other.addressRange);
|
||||
}
|
||||
|
||||
private:
|
||||
static const inline BiMap<MemoryRegionType, QString> memoryRegionTypesByName = {
|
||||
{MemoryRegionType::EXCLUDED, "excluded"},
|
||||
{MemoryRegionType::FOCUSED, "focused"},
|
||||
};
|
||||
|
||||
static const inline BiMap<AddressType, QString> addressTypesByName = {
|
||||
{AddressType::ABSOLUTE, "absolute"},
|
||||
{AddressType::RELATIVE, "relative"},
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -249,6 +249,7 @@ namespace Bloom::Widgets
|
||||
|
||||
auto* region = this->addFocusedRegion(FocusedMemoryRegion(
|
||||
"Untitled Region",
|
||||
this->memoryDescriptor.type,
|
||||
TargetMemoryAddressRange(
|
||||
this->memoryDescriptor.addressRange.startAddress,
|
||||
this->memoryDescriptor.addressRange.startAddress + 10
|
||||
@@ -263,6 +264,7 @@ namespace Bloom::Widgets
|
||||
|
||||
auto* region = this->addExcludedRegion(ExcludedMemoryRegion(
|
||||
"Untitled Region",
|
||||
this->memoryDescriptor.type,
|
||||
TargetMemoryAddressRange(
|
||||
this->memoryDescriptor.addressRange.startAddress,
|
||||
this->memoryDescriptor.addressRange.startAddress + 10
|
||||
|
||||
Reference in New Issue
Block a user