2021-11-30 16:59:42 -06:00
|
|
|
#include "SeerArrayVisualizerWidget.h"
|
|
|
|
|
#include "SeerUtl.h"
|
|
|
|
|
#include <QtWidgets/QMessageBox>
|
|
|
|
|
#include <QtWidgets/QFileDialog>
|
|
|
|
|
#include <QtGui/QIntValidator>
|
|
|
|
|
#include <QtGui/QIcon>
|
|
|
|
|
#include <QtPrintSupport/QPrinter>
|
|
|
|
|
#include <QtPrintSupport/QPrintDialog>
|
|
|
|
|
#include <QtCore/QRegExp>
|
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
|
|
|
|
SeerArrayVisualizerWidget::SeerArrayVisualizerWidget (QWidget* parent) : QWidget(parent) {
|
|
|
|
|
|
|
|
|
|
// Init variables.
|
|
|
|
|
_variableId = Seer::createID(); // Create two id's for queries.
|
|
|
|
|
_memoryId = Seer::createID();
|
|
|
|
|
|
|
|
|
|
// Set up UI.
|
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
|
|
// Setup the widgets
|
|
|
|
|
setWindowIcon(QIcon(":/seer/resources/seer_64x64.png"));
|
|
|
|
|
setWindowTitle("Seer Array Visualizer");
|
|
|
|
|
|
|
|
|
|
arrayLengthLineEdit->setValidator(new QIntValidator(1, 9999999, this));
|
2022-03-14 18:28:46 -05:00
|
|
|
columnCountSpinBox->setValue(arrayTableWidget->elementsPerLine());
|
2021-11-30 16:59:42 -06:00
|
|
|
|
|
|
|
|
arrayDisplayFormatComboBox->setCurrentIndex(0);
|
2022-03-14 18:28:46 -05:00
|
|
|
handleArrayDisplayFormatComboBox(0);
|
2021-11-30 16:59:42 -06:00
|
|
|
|
|
|
|
|
// Connect things.
|
|
|
|
|
QObject::connect(refreshToolButton, &QToolButton::clicked, this, &SeerArrayVisualizerWidget::handleRefreshButton);
|
|
|
|
|
QObject::connect(arrayLengthLineEdit, &QLineEdit::returnPressed, this, &SeerArrayVisualizerWidget::handleRefreshButton);
|
|
|
|
|
QObject::connect(variableNameLineEdit, &QLineEdit::returnPressed, this, &SeerArrayVisualizerWidget::handleVariableNameLineEdit);
|
|
|
|
|
QObject::connect(arrayDisplayFormatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SeerArrayVisualizerWidget::handleArrayDisplayFormatComboBox);
|
|
|
|
|
QObject::connect(columnCountSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &SeerArrayVisualizerWidget::handleColumnCountSpinBox);
|
|
|
|
|
|
|
|
|
|
// Restore window settings.
|
|
|
|
|
readSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SeerArrayVisualizerWidget::~SeerArrayVisualizerWidget () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerArrayVisualizerWidget::setVariableName (const QString& name) {
|
|
|
|
|
|
|
|
|
|
setWindowTitle("Seer Array Visualizer - '" + name + "'");
|
|
|
|
|
|
|
|
|
|
variableNameLineEdit->setText(name);
|
|
|
|
|
setVariableAddress("");
|
|
|
|
|
|
|
|
|
|
if (variableNameLineEdit->text() == "") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear old contents.
|
|
|
|
|
QByteArray array;
|
|
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
arrayTableWidget->setData(new SeerArrayWidget::DataStorageArray(array));
|
2021-11-30 16:59:42 -06:00
|
|
|
|
|
|
|
|
// Send signal to get variable address.
|
|
|
|
|
emit evaluateVariableExpression(_variableId, variableNameLineEdit->text());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SeerArrayVisualizerWidget::variableName () const {
|
|
|
|
|
return variableNameLineEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerArrayVisualizerWidget::setVariableAddress (const QString& address) {
|
|
|
|
|
|
|
|
|
|
unsigned long offset = 0;
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
|
|
if (address.startsWith("0x")) {
|
|
|
|
|
|
|
|
|
|
offset = address.toULong(&ok, 16);
|
|
|
|
|
|
|
|
|
|
if (ok == true) {
|
|
|
|
|
variableAddressLineEdit->setText(address);
|
|
|
|
|
}else{
|
|
|
|
|
variableAddressLineEdit->setText("not an address");
|
|
|
|
|
offset = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
variableAddressLineEdit->setText("not an address");
|
|
|
|
|
offset = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug() << address << offset << ok;
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
arrayTableWidget->setAddressOffset(offset);
|
2021-11-30 16:59:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SeerArrayVisualizerWidget::variableAddress () const {
|
|
|
|
|
return variableAddressLineEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerArrayVisualizerWidget::handleText (const QString& text) {
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug() << text;
|
2021-11-30 16:59:42 -06:00
|
|
|
|
|
|
|
|
if (text.contains(QRegExp("^([0-9]+)\\^done,value="))) {
|
|
|
|
|
|
|
|
|
|
// 10^done,value="1"
|
|
|
|
|
// 11^done,value="0x7fffffffd538"
|
|
|
|
|
|
|
|
|
|
QString id_text = text.section('^', 0,0);
|
|
|
|
|
|
|
|
|
|
if (id_text.toInt() == _variableId) {
|
|
|
|
|
|
|
|
|
|
QStringList words = Seer::filterEscapes(Seer::parseFirst(text, "value=", '"', '"', false)).split(' ', QString::SkipEmptyParts);
|
|
|
|
|
|
|
|
|
|
setVariableAddress(words.first());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if (text.contains(QRegExp("^([0-9]+)\\^done,memory="))) {
|
|
|
|
|
|
|
|
|
|
// 3^done,memory=[{begin="0x0000000000613e70",offset="0x0000000000000000",end="0x0000000000613e71",contents="00"}]
|
|
|
|
|
// 4^done,memory=[{begin="0x0000000000613e70",offset="0x0000000000000000",end="0x0000000000613ed4",contents="000000000000000000000000"}]
|
|
|
|
|
|
|
|
|
|
QString id_text = text.section('^', 0,0);
|
|
|
|
|
|
|
|
|
|
if (id_text.toInt() == _memoryId) {
|
|
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
qDebug() << text;
|
2021-11-30 16:59:42 -06:00
|
|
|
|
|
|
|
|
QString memory_text = Seer::parseFirst(text, "memory=", '[', ']', false);
|
|
|
|
|
|
|
|
|
|
QStringList range_list = Seer::parse(memory_text, "", '{', '}', false);
|
|
|
|
|
|
|
|
|
|
// Loop through the memory ranges.
|
|
|
|
|
for ( const auto& range_text : range_list ) {
|
|
|
|
|
|
|
|
|
|
QString contents_text = Seer::parseFirst(range_text, "contents=", '"', '"', false);
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug() << contents_text;
|
2021-11-30 16:59:42 -06:00
|
|
|
|
|
|
|
|
// Convert hex string to byte array.
|
|
|
|
|
QByteArray array;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i<contents_text.size(); i += 2) {
|
|
|
|
|
QString num = contents_text.mid(i, 2);
|
|
|
|
|
bool ok = false;
|
|
|
|
|
array.push_back(num.toInt(&ok, 16));
|
2022-02-08 19:24:41 -06:00
|
|
|
Q_ASSERT(ok);
|
2021-11-30 16:59:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Give the byte array to the hex widget.
|
2022-03-14 18:28:46 -05:00
|
|
|
arrayTableWidget->setData(new SeerArrayWidget::DataStorageArray(array));
|
2021-11-30 16:59:42 -06:00
|
|
|
|
|
|
|
|
break; // Take just the first range for now.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if (text.contains(QRegExp("^([0-9]+)\\^error,msg="))) {
|
|
|
|
|
|
|
|
|
|
// 12^error,msg="No symbol \"return\" in current context."
|
|
|
|
|
// 13^error,msg="No symbol \"cout\" in current context."
|
|
|
|
|
// 3^error,msg="Unable to read memory."
|
|
|
|
|
|
|
|
|
|
QString id_text = text.section('^', 0,0);
|
|
|
|
|
|
|
|
|
|
if (id_text.toInt() == _variableId) {
|
|
|
|
|
variableAddressLineEdit->setText( Seer::filterEscapes(Seer::parseFirst(text, "msg=", '"', '"', false)) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id_text.toInt() == _memoryId) {
|
|
|
|
|
// Display the error message.
|
|
|
|
|
QString msg_text = Seer::parseFirst(text, "msg=", false);
|
|
|
|
|
|
|
|
|
|
if (msg_text != "") {
|
|
|
|
|
QMessageBox::warning(this, "Error.", Seer::filterEscapes(msg_text));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
// Ignore anything else.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerArrayVisualizerWidget::handleRefreshButton () {
|
|
|
|
|
|
|
|
|
|
if (variableNameLineEdit->text() == "") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (variableAddressLineEdit->text() == "") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (variableAddressLineEdit->text() == "not an address") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
int bytes = arrayLengthLineEdit->text().toInt() * Seer::typeBytes(arrayDisplayFormatComboBox->currentText());
|
|
|
|
|
|
|
|
|
|
qDebug() << _memoryId << variableAddressLineEdit->text() << arrayLengthLineEdit->text() << arrayDisplayFormatComboBox->currentText() << bytes;
|
|
|
|
|
|
|
|
|
|
emit evaluateMemoryExpression(_memoryId, variableAddressLineEdit->text(), bytes);
|
2021-11-30 16:59:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerArrayVisualizerWidget::handleVariableNameLineEdit () {
|
|
|
|
|
|
|
|
|
|
setVariableName (variableNameLineEdit->text());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerArrayVisualizerWidget::handleArrayDisplayFormatComboBox (int index) {
|
|
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
qDebug() << index;
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
if (index == 0) {
|
|
|
|
|
arrayTableWidget->setArrayMode(SeerArrayWidget::Int16ArrayMode);
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
}else if (index == 1) {
|
|
|
|
|
arrayTableWidget->setArrayMode(SeerArrayWidget::Int32ArrayMode);
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
}else if (index == 2) {
|
|
|
|
|
arrayTableWidget->setArrayMode(SeerArrayWidget::Int64ArrayMode);
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
}else if (index == 3) {
|
|
|
|
|
arrayTableWidget->setArrayMode(SeerArrayWidget::UInt16ArrayMode);
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
}else if (index == 4) {
|
|
|
|
|
arrayTableWidget->setArrayMode(SeerArrayWidget::UInt32ArrayMode);
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
}else if (index == 5) {
|
|
|
|
|
arrayTableWidget->setArrayMode(SeerArrayWidget::UInt64ArrayMode);
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
}else if (index == 6) {
|
|
|
|
|
arrayTableWidget->setArrayMode(SeerArrayWidget::Float32ArrayMode);
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
}else if (index == 7) {
|
|
|
|
|
arrayTableWidget->setArrayMode(SeerArrayWidget::Float64ArrayMode);
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
}else{
|
|
|
|
|
// Do nothing.
|
2021-11-30 16:59:42 -06:00
|
|
|
}
|
2022-03-14 18:28:46 -05:00
|
|
|
}
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
void SeerArrayVisualizerWidget::handleColumnCountSpinBox (int value) {
|
2021-11-30 16:59:42 -06:00
|
|
|
|
2022-03-14 18:28:46 -05:00
|
|
|
arrayTableWidget->setElementsPerLine(value);
|
2021-11-30 16:59:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerArrayVisualizerWidget::writeSettings() {
|
|
|
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
|
|
settings.beginGroup("arrayvisualizerwindow");
|
|
|
|
|
settings.setValue("size", size());
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug() << size();
|
2021-11-30 16:59:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerArrayVisualizerWidget::readSettings() {
|
|
|
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
|
|
settings.beginGroup("arrayvisualizerwindow");
|
|
|
|
|
resize(settings.value("size", QSize(800, 400)).toSize());
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug() << size();
|
2021-11-30 16:59:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerArrayVisualizerWidget::resizeEvent (QResizeEvent* event) {
|
|
|
|
|
|
|
|
|
|
writeSettings();
|
|
|
|
|
|
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|