Hex viewer is now debugger and manages the debug logs

With printf gone the emulator runs much faster too.
This commit is contained in:
meepingsnesroms
2018-05-01 17:44:09 -07:00
parent ae7b6681d2
commit c70f4fe041
8 changed files with 127 additions and 131 deletions

View File

@@ -60,9 +60,9 @@ SOURCES += \
src/sed1376.c \
src/silkscreen.c \
src/trapNumToName.c \
hexviewer.cpp \
fileaccess.cpp \
src/ads7846.c
src/ads7846.c \
debugviewer.cpp
HEADERS += \
src/bps/crc32.h \
@@ -85,17 +85,17 @@ HEADERS += \
mainwindow.h \
touchscreen.h \
src/sed1376RegisterNames.h \
hexviewer.h \
src/hardwareRegistersTiming.c.h \
src/sed1376Accessors.c.h \
src/hardwareRegistersAccessors.c.h \
fileaccess.h \
src/endianness.h \
src/ads7846.h
src/ads7846.h \
debugviewer.h
FORMS += \
mainwindow.ui \
hexviewer.ui
debugviewer.ui
CONFIG += mobility
MOBILITY =

View File

@@ -1,5 +1,5 @@
#include "hexviewer.h"
#include "ui_hexviewer.h"
#include "debugviewer.h"
#include "ui_debugviewer.h"
#include <QString>
#include <QDir>
@@ -39,25 +39,25 @@ int64_t getEmulatorMemorySafe(uint32_t address, uint8_t size){
}
HexViewer::HexViewer(QWidget *parent) :
DebugViewer::DebugViewer(QWidget *parent) :
QDialog(parent),
ui(new Ui::HexViewer){
ui(new Ui::DebugViewer){
ui->setupUi(this);
bitsPerEntry = 8;
hexRadioButtonHandler();
debugRadioButtonHandler();
#if !defined(EMU_DEBUG) || !defined(EMU_CUSTOM_DEBUG_LOG_HANDLER)
ui->hexPrintDebugLogs->hide();
ui->hexEraseDebugLogs->hide();
ui->debugPrintDebugLogs->hide();
ui->debugEraseDebugLogs->hide();
#endif
}
HexViewer::~HexViewer(){
DebugViewer::~DebugViewer(){
delete ui;
}
int64_t HexViewer::numberFromString(QString str, bool negativeAllowed){
int64_t DebugViewer::numberFromString(QString str, bool negativeAllowed){
int64_t value;
bool validNumber;
@@ -76,7 +76,7 @@ int64_t HexViewer::numberFromString(QString str, bool negativeAllowed){
return value;
}
QString HexViewer::stringFromNumber(int64_t number, bool hex, uint32_t forcedZeros){
QString DebugViewer::stringFromNumber(int64_t number, bool hex, uint32_t forcedZeros){
if(hex){
QString hexString;
hexString += QString::number(number, 16).toUpper();
@@ -88,35 +88,35 @@ QString HexViewer::stringFromNumber(int64_t number, bool hex, uint32_t forcedZer
return QString::number(number, 10);
}
void HexViewer::hexRadioButtonHandler(){
void DebugViewer::debugRadioButtonHandler(){
switch(bitsPerEntry){
case 8:
ui->hex8Bit->setDown(true);
ui->hex16Bit->setDown(false);
ui->hex32Bit->setDown(false);
ui->debug8Bit->setDown(true);
ui->debug16Bit->setDown(false);
ui->debug32Bit->setDown(false);
break;
case 16:
ui->hex8Bit->setDown(false);
ui->hex16Bit->setDown(true);
ui->hex32Bit->setDown(false);
ui->debug8Bit->setDown(false);
ui->debug16Bit->setDown(true);
ui->debug32Bit->setDown(false);
break;
case 32:
ui->hex8Bit->setDown(false);
ui->hex16Bit->setDown(false);
ui->hex32Bit->setDown(true);
ui->debug8Bit->setDown(false);
ui->debug16Bit->setDown(false);
ui->debug32Bit->setDown(true);
break;
}
}
void HexViewer::on_hexUpdate_clicked(){
int64_t address = numberFromString(ui->hexAddress->text(), false/*negative allowed*/);
int64_t length = numberFromString(ui->hexLength->text(), false/*negative allowed*/);
void DebugViewer::on_debugGetHexValues_clicked(){
int64_t address = numberFromString(ui->debugAddress->text(), false/*negative allowed*/);
int64_t length = numberFromString(ui->debugLength->text(), false/*negative allowed*/);
uint8_t bits = bitsPerEntry;
ui->hexValueList->clear();
ui->debugValueList->clear();
if(address != INVALID_NUMBER && length != INVALID_NUMBER && length != 0 && address + bits / 8 * length - 1 <= 0xFFFFFFFF){
for(int64_t count = 0; count < length; count++){
@@ -128,85 +128,81 @@ void HexViewer::on_hexUpdate_clicked(){
value += stringFromNumber(data, true, bits / 8 * 2);
else
value += "Unsafe Access";
ui->hexValueList->addItem(value);
ui->debugValueList->addItem(value);
address += bits / 8;
}
}
else{
ui->hexValueList->addItem("Invalid Parameters");
ui->debugValueList->addItem("Invalid Parameters");
}
}
void HexViewer::on_hex8Bit_clicked(){
void DebugViewer::on_debug8Bit_clicked(){
bitsPerEntry = 8;
hexRadioButtonHandler();
debugRadioButtonHandler();
}
void HexViewer::on_hex16Bit_clicked(){
void DebugViewer::on_debug16Bit_clicked(){
bitsPerEntry = 16;
hexRadioButtonHandler();
debugRadioButtonHandler();
}
void HexViewer::on_hex32Bit_clicked(){
void DebugViewer::on_debug32Bit_clicked(){
bitsPerEntry = 32;
hexRadioButtonHandler();
debugRadioButtonHandler();
}
void HexViewer::on_hexDump_clicked(){
int64_t address = numberFromString(ui->hexAddress->text(), false/*negative allowed*/);
int64_t length = numberFromString(ui->hexLength->text(), false/*negative allowed*/);
uint8_t bits = bitsPerEntry;
QString fileName = ui->hexFilePath->text();
void DebugViewer::on_debugDump_clicked(){
QString fileOut;
QString fileName = ui->debugFilePath->text();
QString filePath = settings.value("resourceDirectory", "").toString() + "/hexDumps";
QDir location = filePath;
if(!location.exists())
location.mkpath(".");
if(validFilePath(filePath + "/" + fileName) && address != INVALID_NUMBER && length != INVALID_NUMBER && length != 0 && address + bits / 8 * length - 1 <= 0xFFFFFFFF){
length *= bits / 8;
uint8_t* dumpBuffer = new uint8_t[length];
for(int64_t count = 0; count < length; count++)
dumpBuffer[count] = getEmulatorMemorySafe(address + count, 8);
setFileBuffer(filePath + "/" + fileName, dumpBuffer, length);
delete[] dumpBuffer;
for(uint64_t index = 0; index < ui->debugValueList->count(); index++){
fileOut += ui->debugValueList->item(index)->text();
fileOut += '\n';
}
setFileBuffer(filePath + "/" + fileName, (uint8_t*)fileOut.data(), fileOut.length() * sizeof(QChar));
}
void HexViewer::on_hexShowRegisters_clicked(){
ui->hexValueList->clear();
void DebugViewer::on_debugShowRegisters_clicked(){
ui->debugValueList->clear();
for(uint8_t aRegs = M68K_REG_A0; aRegs <= M68K_REG_A7; aRegs++)
ui->hexValueList->addItem("A" + stringFromNumber(aRegs - M68K_REG_A0, false, 0) + ":" + stringFromNumber(m68k_get_reg(NULL, (m68k_register_t)aRegs), true, 8));
ui->debugValueList->addItem("A" + stringFromNumber(aRegs - M68K_REG_A0, false, 0) + ":" + stringFromNumber(m68k_get_reg(NULL, (m68k_register_t)aRegs), true, 8));
for(uint8_t dRegs = M68K_REG_D0; dRegs <= M68K_REG_D7; dRegs++)
ui->hexValueList->addItem("D" + stringFromNumber(dRegs - M68K_REG_D0, false, 0) + ":" + stringFromNumber(m68k_get_reg(NULL, (m68k_register_t)dRegs), true, 8));
ui->hexValueList->addItem("SP:" + stringFromNumber(m68k_get_reg(NULL, M68K_REG_SP), true, 8));
ui->hexValueList->addItem("PC:" + stringFromNumber(m68k_get_reg(NULL, M68K_REG_PC), true, 8));
ui->hexValueList->addItem("SR:" + stringFromNumber(m68k_get_reg(NULL, M68K_REG_SR), true, 4));
ui->debugValueList->addItem("D" + stringFromNumber(dRegs - M68K_REG_D0, false, 0) + ":" + stringFromNumber(m68k_get_reg(NULL, (m68k_register_t)dRegs), true, 8));
ui->debugValueList->addItem("SP:" + stringFromNumber(m68k_get_reg(NULL, M68K_REG_SP), true, 8));
ui->debugValueList->addItem("PC:" + stringFromNumber(m68k_get_reg(NULL, M68K_REG_PC), true, 8));
ui->debugValueList->addItem("SR:" + stringFromNumber(m68k_get_reg(NULL, M68K_REG_SR), true, 4));
}
void HexViewer::on_hexPrintDebugLogs_clicked(){
void DebugViewer::on_debugPrintDebugLogs_clicked(){
#if defined(EMU_DEBUG) && defined(EMU_CUSTOM_DEBUG_LOG_HANDLER)
int64_t length = numberFromString(ui->hexLength->text(), true/*negative allowed*/);
int64_t length = numberFromString(ui->debugLength->text(), true/*negative allowed*/);
ui->hexValueList->clear();
ui->debugValueList->clear();
if(length != INVALID_NUMBER && qAbs(length) < debugStrings.size()){
if(length < 0){
for(uint64_t stringNum = debugStrings.size() + length; stringNum < debugStrings.size(); stringNum++)
ui->hexValueList->addItem(QString::fromStdString(debugStrings[stringNum] + "(printed " + std::to_string(duplicateCallCount[stringNum]) + " times)"));
ui->debugValueList->addItem(QString::fromStdString(debugStrings[stringNum] + "(printed " + std::to_string(duplicateCallCount[stringNum]) + " times)"));
}
else{
for(uint64_t stringNum = 0; stringNum < length; stringNum++)
ui->hexValueList->addItem(QString::fromStdString(debugStrings[stringNum] + "(printed " + std::to_string(duplicateCallCount[stringNum]) + " times)"));
ui->debugValueList->addItem(QString::fromStdString(debugStrings[stringNum] + "(printed " + std::to_string(duplicateCallCount[stringNum]) + " times)"));
}
}
else{
for(uint64_t stringNum = 0; stringNum < debugStrings.size(); stringNum++)
ui->hexValueList->addItem(QString::fromStdString(debugStrings[stringNum] + "(printed " + std::to_string(duplicateCallCount[stringNum]) + " times)"));
ui->debugValueList->addItem(QString::fromStdString(debugStrings[stringNum] + "(printed " + std::to_string(duplicateCallCount[stringNum]) + " times)"));
}
#endif
}
void HexViewer::on_hexEraseDebugLogs_clicked(){
void DebugViewer::on_debugEraseDebugLogs_clicked(){
#if defined(EMU_DEBUG) && defined(EMU_CUSTOM_DEBUG_LOG_HANDLER)
debugStrings.clear();
duplicateCallCount.clear();

View File

@@ -0,0 +1,38 @@
#pragma once
#include <QDialog>
#include <QString>
namespace Ui {
class DebugViewer;
}
class DebugViewer : public QDialog
{
Q_OBJECT
public:
explicit DebugViewer(QWidget *parent = 0);
~DebugViewer();
private slots:
int64_t numberFromString(QString str, bool negativeAllowed);
QString stringFromNumber(int64_t number, bool hex, uint32_t forcedZeros = 0);
void debugRadioButtonHandler();
void on_debugGetHexValues_clicked();
void on_debug8Bit_clicked();
void on_debug16Bit_clicked();
void on_debug32Bit_clicked();
void on_debugDump_clicked();
void on_debugShowRegisters_clicked();
void on_debugPrintDebugLogs_clicked();
void on_debugEraseDebugLogs_clicked();
private:
uint8_t bitsPerEntry;
Ui::DebugViewer *ui;
};

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HexViewer</class>
<widget class="QDialog" name="HexViewer">
<class>DebugViewer</class>
<widget class="QDialog" name="DebugViewer">
<property name="geometry">
<rect>
<x>0</x>
@@ -17,7 +17,7 @@
</sizepolicy>
</property>
<property name="windowTitle">
<string>Hex Viewer</string>
<string>Debugger</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
@@ -47,7 +47,7 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QPushButton" name="hexUpdate">
<widget class="QPushButton" name="debugGetHexValues">
<property name="geometry">
<rect>
<x>420</x>
@@ -57,10 +57,10 @@
</rect>
</property>
<property name="text">
<string>Update</string>
<string>Get Hex Values</string>
</property>
</widget>
<widget class="QLineEdit" name="hexAddress">
<widget class="QLineEdit" name="debugAddress">
<property name="geometry">
<rect>
<x>430</x>
@@ -83,7 +83,7 @@
<string>Address</string>
</property>
</widget>
<widget class="QRadioButton" name="hex8Bit">
<widget class="QRadioButton" name="debug8Bit">
<property name="geometry">
<rect>
<x>420</x>
@@ -96,7 +96,7 @@
<string>8bit</string>
</property>
</widget>
<widget class="QRadioButton" name="hex16Bit">
<widget class="QRadioButton" name="debug16Bit">
<property name="geometry">
<rect>
<x>480</x>
@@ -109,7 +109,7 @@
<string>16bit</string>
</property>
</widget>
<widget class="QRadioButton" name="hex32Bit">
<widget class="QRadioButton" name="debug32Bit">
<property name="geometry">
<rect>
<x>540</x>
@@ -122,7 +122,7 @@
<string>32bit</string>
</property>
</widget>
<widget class="QLineEdit" name="hexLength">
<widget class="QLineEdit" name="debugLength">
<property name="geometry">
<rect>
<x>430</x>
@@ -145,7 +145,7 @@
<string>Length</string>
</property>
</widget>
<widget class="QListWidget" name="hexValueList">
<widget class="QListWidget" name="debugValueList">
<property name="geometry">
<rect>
<x>10</x>
@@ -155,20 +155,20 @@
</rect>
</property>
</widget>
<widget class="QPushButton" name="hexDump">
<widget class="QPushButton" name="debugDump">
<property name="geometry">
<rect>
<x>420</x>
<y>190</y>
<y>310</y>
<width>201</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Dump</string>
<string>Dump To File</string>
</property>
</widget>
<widget class="QLineEdit" name="hexFilePath">
<widget class="QLineEdit" name="debugFilePath">
<property name="geometry">
<rect>
<x>432</x>
@@ -191,7 +191,7 @@
<string>File Path</string>
</property>
</widget>
<widget class="QPushButton" name="hexShowRegisters">
<widget class="QPushButton" name="debugShowRegisters">
<property name="geometry">
<rect>
<x>420</x>
@@ -204,7 +204,7 @@
<string>Show Registers</string>
</property>
</widget>
<widget class="QPushButton" name="hexPrintDebugLogs">
<widget class="QPushButton" name="debugPrintDebugLogs">
<property name="geometry">
<rect>
<x>420</x>
@@ -217,7 +217,7 @@
<string>Print Debug Logs</string>
</property>
</widget>
<widget class="QPushButton" name="hexEraseDebugLogs">
<widget class="QPushButton" name="debugEraseDebugLogs">
<property name="geometry">
<rect>
<x>420</x>
@@ -239,7 +239,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>HexViewer</receiver>
<receiver>DebugViewer</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@@ -255,7 +255,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>HexViewer</receiver>
<receiver>DebugViewer</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

View File

@@ -1,38 +0,0 @@
#pragma once
#include <QDialog>
#include <QString>
namespace Ui {
class HexViewer;
}
class HexViewer : public QDialog
{
Q_OBJECT
public:
explicit HexViewer(QWidget *parent = 0);
~HexViewer();
private slots:
int64_t numberFromString(QString str, bool negativeAllowed);
QString stringFromNumber(int64_t number, bool hex, uint32_t forcedZeros = 0);
void hexRadioButtonHandler();
void on_hexUpdate_clicked();
void on_hex8Bit_clicked();
void on_hex16Bit_clicked();
void on_hex32Bit_clicked();
void on_hexDump_clicked();
void on_hexShowRegisters_clicked();
void on_hexPrintDebugLogs_clicked();
void on_hexEraseDebugLogs_clicked();
private:
uint8_t bitsPerEntry;
Ui::HexViewer *ui;
};

View File

@@ -18,7 +18,7 @@
#include <atomic>
#include <stdint.h>
#include "hexviewer.h"
#include "debugviewer.h"
#include "fileaccess.h"
#include "src/emulator.h"
@@ -30,7 +30,7 @@ QSettings settings;
static QImage video;
static QTimer* refreshDisplay;
static HexViewer* emuStateBrowser;
static DebugViewer* emuDebugger;
static std::thread emuThread;
static std::atomic<bool> emuThreadJoin;
static std::atomic<bool> emuOn;
@@ -121,7 +121,7 @@ MainWindow::MainWindow(QWidget* parent) :
ui(new Ui::MainWindow){
ui->setupUi(this);
emuStateBrowser = new HexViewer(this);
emuDebugger = new DebugViewer(this);
refreshDisplay = new QTimer(this);
ui->calender->installEventFilter(this);
@@ -139,7 +139,7 @@ MainWindow::MainWindow(QWidget* parent) :
ui->screenshot->installEventFilter(this);
ui->ctrlBtn->installEventFilter(this);
ui->hexViewer->installEventFilter(this);
ui->debugger->installEventFilter(this);
ui->ctrlBtn->setIcon(QIcon(":/buttons/images/play.png"));
@@ -163,7 +163,7 @@ MainWindow::MainWindow(QWidget* parent) :
emuDoubleBuffer = NULL;
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
ui->hexViewer->hide();
ui->debugger->hide();
#endif
#if defined(EMU_DEBUG) && defined(EMU_CUSTOM_DEBUG_LOG_HANDLER)
@@ -360,7 +360,7 @@ void MainWindow::on_ctrlBtn_clicked(){
}
}
void MainWindow::on_hexViewer_clicked(){
void MainWindow::on_debugger_clicked(){
if(emuInited){
if(emuOn){
emuOn = false;
@@ -369,10 +369,10 @@ void MainWindow::on_hexViewer_clicked(){
waitForEmuPaused();
emuStateBrowser->exec();
emuDebugger->exec();
}
else{
popupInformationDialog("Cant open hex viewer, emulator not running.");
popupInformationDialog("Cant open debugger, emulator not running.");
}
}

View File

@@ -56,7 +56,7 @@ private slots:
void on_ctrlBtn_clicked();
void on_hexViewer_clicked();
void on_debugger_clicked();
void on_screenshot_clicked();

View File

@@ -263,7 +263,7 @@
</widget>
</item>
<item row="0" column="7">
<widget class="QPushButton" name="hexViewer">
<widget class="QPushButton" name="debugger">
<property name="enabled">
<bool>true</bool>
</property>