Memory snapshot data structure
This commit is contained in:
@@ -79,6 +79,7 @@ target_sources(
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.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/FocusedMemoryRegion.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.cpp
|
||||||
|
|
||||||
# Memory region manager window
|
# Memory region manager window
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
#include "MemorySnapshot.hpp"
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include "src/Helpers/EnumToStringMappings.hpp"
|
||||||
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
|
||||||
|
namespace Bloom
|
||||||
|
{
|
||||||
|
MemorySnapshot::MemorySnapshot(
|
||||||
|
const QString& name,
|
||||||
|
const QString& description,
|
||||||
|
Targets::TargetMemoryType memoryType,
|
||||||
|
const Targets::TargetMemoryBuffer& data,
|
||||||
|
Targets::TargetProgramCounter programCounter,
|
||||||
|
const std::vector<FocusedMemoryRegion>& focusedRegions,
|
||||||
|
const std::vector<ExcludedMemoryRegion>& excludedRegions
|
||||||
|
)
|
||||||
|
: name(name)
|
||||||
|
, description(description)
|
||||||
|
, memoryType(memoryType)
|
||||||
|
, data(data)
|
||||||
|
, programCounter(programCounter)
|
||||||
|
, focusedRegions(focusedRegions)
|
||||||
|
, excludedRegions(excludedRegions)
|
||||||
|
{}
|
||||||
|
|
||||||
|
MemorySnapshot::MemorySnapshot(const QJsonObject& jsonObject) {
|
||||||
|
using Exceptions::Exception;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!jsonObject.contains("id")
|
||||||
|
|| !jsonObject.contains("name")
|
||||||
|
|| !jsonObject.contains("description")
|
||||||
|
|| !jsonObject.contains("memoryType")
|
||||||
|
|| !jsonObject.contains("hexData")
|
||||||
|
|| !jsonObject.contains("programCounter")
|
||||||
|
|| !jsonObject.contains("createdTimestamp")
|
||||||
|
|| !jsonObject.contains("focusedRegions")
|
||||||
|
|| !jsonObject.contains("excludedRegions")
|
||||||
|
) {
|
||||||
|
throw Exception("Missing data");
|
||||||
|
}
|
||||||
|
|
||||||
|
this->id = jsonObject.find("id")->toString();
|
||||||
|
this->name = jsonObject.find("name")->toString();
|
||||||
|
this->description = jsonObject.find("description")->toString();
|
||||||
|
this->memoryType = EnumToStringMappings::targetMemoryTypes.at(jsonObject.find("memoryType")->toString());
|
||||||
|
this->programCounter = static_cast<Targets::TargetProgramCounter>(jsonObject.find("programCounter")->toInteger());
|
||||||
|
this->createdDate.setSecsSinceEpoch(jsonObject.find("createdTimestamp")->toInteger());
|
||||||
|
|
||||||
|
const auto hexData = QByteArray::fromHex(jsonObject.find("hexData")->toString().toUtf8());
|
||||||
|
this->data = Targets::TargetMemoryBuffer(hexData.begin(), hexData.end());
|
||||||
|
|
||||||
|
// TODO: Memory regions
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject MemorySnapshot::toJson() const {
|
||||||
|
auto focusedRegions = QJsonArray();
|
||||||
|
for (const auto& focusedRegion : this->focusedRegions) {
|
||||||
|
focusedRegions.push_back(focusedRegion.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto excludedRegions = QJsonArray();
|
||||||
|
for (const auto& excludedRegion : this->excludedRegions) {
|
||||||
|
excludedRegions.push_back(excludedRegion.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
return QJsonObject({
|
||||||
|
{"id", this->id},
|
||||||
|
{"name", this->name},
|
||||||
|
{"description", this->description},
|
||||||
|
{"memoryType", EnumToStringMappings::targetMemoryTypes.at(this->memoryType)},
|
||||||
|
{"hexData", QString(QByteArray(
|
||||||
|
reinterpret_cast<const char*>(this->data.data()),
|
||||||
|
static_cast<qsizetype>(this->data.size())
|
||||||
|
).toHex())},
|
||||||
|
{"programCounter", static_cast<qint64>(this->programCounter)},
|
||||||
|
{"createdTimestamp", this->createdDate.toSecsSinceEpoch()},
|
||||||
|
{"focusedRegions", focusedRegions},
|
||||||
|
{"excludedRegions", excludedRegions},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MemorySnapshot::isCompatible(const Targets::TargetMemoryDescriptor& memoryDescriptor) const {
|
||||||
|
if (this->memoryType != memoryDescriptor.type) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->data.size() != memoryDescriptor.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <QString>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
#include <QUuid>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "src/Targets/TargetMemory.hpp"
|
||||||
|
#include "src/Helpers/DateTime.hpp"
|
||||||
|
|
||||||
|
#include "FocusedMemoryRegion.hpp"
|
||||||
|
#include "ExcludedMemoryRegion.hpp"
|
||||||
|
|
||||||
|
namespace Bloom
|
||||||
|
{
|
||||||
|
struct MemorySnapshot
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString id = QUuid::createUuid().toString(QUuid::StringFormat::WithoutBraces);
|
||||||
|
QString name;
|
||||||
|
QString description;
|
||||||
|
Targets::TargetMemoryType memoryType;
|
||||||
|
Targets::TargetMemoryBuffer data;
|
||||||
|
Targets::TargetProgramCounter programCounter;
|
||||||
|
QDateTime createdDate = DateTime::currentDateTime();
|
||||||
|
|
||||||
|
std::vector<FocusedMemoryRegion> focusedRegions;
|
||||||
|
std::vector<ExcludedMemoryRegion> excludedRegions;
|
||||||
|
|
||||||
|
MemorySnapshot(
|
||||||
|
const QString& name,
|
||||||
|
const QString& description,
|
||||||
|
Targets::TargetMemoryType memoryType,
|
||||||
|
const Targets::TargetMemoryBuffer& data,
|
||||||
|
Targets::TargetProgramCounter programCounter,
|
||||||
|
const std::vector<FocusedMemoryRegion>& focusedRegions,
|
||||||
|
const std::vector<ExcludedMemoryRegion>& excludedRegions
|
||||||
|
);
|
||||||
|
|
||||||
|
MemorySnapshot(const QJsonObject& jsonObject);
|
||||||
|
|
||||||
|
QJsonObject toJson() const;
|
||||||
|
|
||||||
|
bool isCompatible(const Targets::TargetMemoryDescriptor& memoryDescriptor) const;
|
||||||
|
|
||||||
|
virtual ~MemorySnapshot() = default;
|
||||||
|
|
||||||
|
MemorySnapshot(const MemorySnapshot& other) = default;
|
||||||
|
MemorySnapshot(MemorySnapshot&& other) = default;
|
||||||
|
|
||||||
|
MemorySnapshot& operator = (const MemorySnapshot& other) = default;
|
||||||
|
MemorySnapshot& operator = (MemorySnapshot&& other) = default;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user