RetrieveMemorySnapshots insight worker task
This commit is contained in:
@@ -33,6 +33,7 @@ target_sources(
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/GetTargetDescriptor.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/GetTargetDescriptor.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ConstructHexViewerByteItems.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ConstructHexViewerByteItems.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/CaptureMemorySnapshot.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/CaptureMemorySnapshot.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp
|
||||||
|
|
||||||
# Error dialogue window
|
# Error dialogue window
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp
|
||||||
|
|||||||
58
src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp
Normal file
58
src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include "RetrieveMemorySnapshots.hpp"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
|
#include "src/Helpers/Paths.hpp"
|
||||||
|
#include "src/Helpers/EnumToStringMappings.hpp"
|
||||||
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
|
namespace Bloom
|
||||||
|
{
|
||||||
|
using TargetController::TargetControllerConsole;
|
||||||
|
|
||||||
|
RetrieveMemorySnapshots::RetrieveMemorySnapshots(Targets::TargetMemoryType memoryType)
|
||||||
|
: memoryType(memoryType)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void RetrieveMemorySnapshots::run(TargetControllerConsole& targetControllerConsole) {
|
||||||
|
emit this->memorySnapshotsRetrieved(this->getSnapshots(this->memoryType));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<MemorySnapshot> RetrieveMemorySnapshots::getSnapshots(Targets::TargetMemoryType memoryType) {
|
||||||
|
auto snapshotDir = QDir(QString::fromStdString(Paths::projectSettingsDirPath())
|
||||||
|
+ "/memory_snapshots/" + EnumToStringMappings::targetMemoryTypes.at(memoryType));
|
||||||
|
|
||||||
|
if (!snapshotDir.exists()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto snapshots = std::vector<MemorySnapshot>();
|
||||||
|
|
||||||
|
const auto snapshotFileEntries = snapshotDir.entryInfoList(QStringList("*.json"), QDir::Files);
|
||||||
|
for (const auto& snapshotFileEntry : snapshotFileEntries) {
|
||||||
|
auto snapshotFile = QFile(snapshotFileEntry.absoluteFilePath());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!snapshotFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
throw Exceptions::Exception("Failed to open snapshot file");
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshots.emplace_back(QJsonDocument::fromJson(snapshotFile.readAll()).object());
|
||||||
|
|
||||||
|
} catch (const Exceptions::Exception& exception) {
|
||||||
|
Logger::error(
|
||||||
|
"Failed to load snapshot " + snapshotFileEntry.absoluteFilePath().toStdString() + " - "
|
||||||
|
+ exception.getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshotFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return snapshots;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.hpp
Normal file
30
src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.hpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "InsightWorkerTask.hpp"
|
||||||
|
|
||||||
|
#include "src/Targets/TargetMemory.hpp"
|
||||||
|
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp"
|
||||||
|
|
||||||
|
namespace Bloom
|
||||||
|
{
|
||||||
|
class RetrieveMemorySnapshots: public InsightWorkerTask
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
RetrieveMemorySnapshots(Targets::TargetMemoryType memoryType);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void memorySnapshotsRetrieved(std::vector<MemorySnapshot> snapshots);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void run(TargetController::TargetControllerConsole& targetControllerConsole) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Targets::TargetMemoryType memoryType;
|
||||||
|
|
||||||
|
std::vector<MemorySnapshot> getSnapshots(Targets::TargetMemoryType memoryType);
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user