From 8ba8d65fe6c4d12b7c0ab57cdc641fcf09cc86d6 Mon Sep 17 00:00:00 2001 From: Ernie Pasveer Date: Mon, 25 Dec 2023 13:51:25 -0600 Subject: [PATCH] Final changes for register profiles. --- CHANGELOG.md | 1 + src/SeerMemoryVisualizerWidget.cpp | 3 +- src/SeerRegisterProfileDialog.cpp | 144 ++++++++++++++++++ src/SeerRegisterProfileDialog.h | 2 + .../help/VariableRegisterInfoBrowser.md | 6 + 5 files changed, 155 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f866e97..b5deaf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Fixed long tooltips text by restricting them to 100 characters. (#189) The text in the various viewing dialogs is still the full length. The 100 limit probably needs to be configurable. +* Added register profiles to show only interesting/relevant registers. ## [2.3] - 2023-11-19 * In the margins of the source windows, allow CTRL+DoubleClick to do a quick RunToLine or RunToAddress. diff --git a/src/SeerMemoryVisualizerWidget.cpp b/src/SeerMemoryVisualizerWidget.cpp index 9d4f9b3..48f3f94 100644 --- a/src/SeerMemoryVisualizerWidget.cpp +++ b/src/SeerMemoryVisualizerWidget.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include SeerMemoryVisualizerWidget::SeerMemoryVisualizerWidget (QWidget* parent) : QWidget(parent) { @@ -376,7 +377,7 @@ void SeerMemoryVisualizerWidget::handlePrintButton () { void SeerMemoryVisualizerWidget::handleSaveButton () { - QFileDialog dialog(this, "Seer visualizer file", "./", "Logs (*.log);;Text files (*.txt);;All files (*.*)"); + QFileDialog dialog(this, "Seer Visualizer File", "./", "Logs (*.log);;Text files (*.txt);;All files (*.*)"); dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.setFileMode(QFileDialog::AnyFile); dialog.setDefaultSuffix("log"); diff --git a/src/SeerRegisterProfileDialog.cpp b/src/SeerRegisterProfileDialog.cpp index 7100a17..8d011a3 100644 --- a/src/SeerRegisterProfileDialog.cpp +++ b/src/SeerRegisterProfileDialog.cpp @@ -1,6 +1,7 @@ #include "SeerRegisterProfileDialog.h" #include "SeerRegisterTreeWidgetItem.h" #include +#include #include #include #include @@ -29,6 +30,8 @@ SeerRegisterProfileDialog::SeerRegisterProfileDialog (QWidget* parent) : QDialog // Connect things. QObject::connect(enablePushButton, &QPushButton::clicked, this, &SeerRegisterProfileDialog::handleEnableSelected); QObject::connect(disablePushButton, &QPushButton::clicked, this, &SeerRegisterProfileDialog::handleDisableSelected); + QObject::connect(importPushButton, &QPushButton::clicked, this, &SeerRegisterProfileDialog::handleImportFile); + QObject::connect(exportPushButton, &QPushButton::clicked, this, &SeerRegisterProfileDialog::handleExportFile); // Restore window settings. readSettings(); @@ -136,6 +139,147 @@ void SeerRegisterProfileDialog::handleDisableSelected () { } } +void SeerRegisterProfileDialog::handleImportFile () { + + // + // Get the name of the file to import. + // + QFileDialog dialog(this, "Seer Register Profile File", "./", "Text files (*.txt);;All files (*.*)"); + dialog.setAcceptMode(QFileDialog::AcceptOpen); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setDefaultSuffix("txt"); + dialog.selectFile("registerprofile.txt"); + + if (dialog.exec() != QDialog::Accepted) { + return; + } + + QStringList files = dialog.selectedFiles(); + + if (files.size() == 0) { + return; + } + + if (files.size() > 1) { + QMessageBox::critical(this, tr("Error"), tr("Select only 1 file.")); + return; + } + + // + // Open the file and read from it. + // A simple format of: + // + // + QFile file(files[0]); + + if (file.open(QIODevice::ReadOnly)) { + + QStringList registerNames; + QVector registerEnabled; + QTextStream stream(&file); + + while (stream.atEnd() == false) { + + QString line = stream.readLine(); + + QStringList words = line.split(QRegularExpression("\\s+")); + + // Ignore empty lines. + if (words.count() == 0) { + continue; + } + + // Ignore null lines. + if (words.count() == 1 && words[0] == "") { + continue; + } + + // There should be only two words on each line. + if (words.count() != 2) { + QMessageBox::critical(this, tr("Error"), tr("Can't load register profile file.\nEncountered a line not the form of:\n\n ")); + return; + } + + // The second word must be 'enabled' or 'disabled'. + if (words[1] != "enabled" && words[1] != "disabled") { + QMessageBox::critical(this, tr("Error"), tr("Can't load register profile file.\nEncountered a line not the form of:\n\n ")); + return; + } + + registerNames.push_back(words[0]); + registerEnabled.push_back(words[1] == "enabled" ? true : false); + } + + // Populate the list with the imported values. + setRegisters (registerNames, registerEnabled); + + QMessageBox::information(this, "Seer", "Loaded."); + + }else{ + + QMessageBox::critical(this, tr("Error"), tr("Can't open register profile file.")); + return; + } + +} + +void SeerRegisterProfileDialog::handleExportFile () { + + // + // Get the name of the file to export. + // + QFileDialog dialog(this, "Seer Register Profile File", "./", "Text files (*.txt);;All files (*.*)"); + dialog.setAcceptMode(QFileDialog::AcceptSave); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setDefaultSuffix("txt"); + dialog.selectFile("registerprofile.txt"); + + if (dialog.exec() != QDialog::Accepted) { + return; + } + + QStringList files = dialog.selectedFiles(); + + if (files.size() == 0) { + return; + } + + if (files.size() > 1) { + QMessageBox::critical(this, tr("Error"), tr("Select only 1 file.")); + return; + } + + // + // Create the file and write to it. + // A simple format of: + // + // + QFile file(files[0]); + + if (file.open(QIODevice::ReadWrite)) { + + QTextStream stream(&file); + + QStringList names = registerNames(); + QVector enabled = registerEnabled(); + + for (int i=0; i