From 80b86f92574556e5ddc4be5a3bdd9a1445dac223 Mon Sep 17 00:00:00 2001 From: Sidharth Anil Date: Sun, 18 Feb 2024 21:02:56 -0600 Subject: [PATCH 1/5] Add functionality to set saved trace reg val as current --- src/gui/Src/Tracer/TraceRegisters.cpp | 50 +++++++++++++++++++++++++++ src/gui/Src/Tracer/TraceRegisters.h | 2 ++ 2 files changed, 52 insertions(+) diff --git a/src/gui/Src/Tracer/TraceRegisters.cpp b/src/gui/Src/Tracer/TraceRegisters.cpp index def39eb6..0c53bae2 100644 --- a/src/gui/Src/Tracer/TraceRegisters.cpp +++ b/src/gui/Src/Tracer/TraceRegisters.cpp @@ -4,12 +4,16 @@ #include "EditFloatRegister.h" #include "StringUtil.h" #include "MiscUtil.h" +#include TraceRegisters::TraceRegisters(QWidget* parent) : RegistersView(parent) { wCM_CopySIMDRegister = setupAction(DIcon("copy"), tr("Copy floating point value")); connect(wCM_CopySIMDRegister, SIGNAL(triggered()), this, SLOT(onCopySIMDRegister())); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(displayCustomContextMenuSlot(QPoint))); + + wCM_SetRegister = setupAction(tr("Set Register value")); + connect(wCM_SetRegister, SIGNAL(triggered()), this, SLOT(onSetRegister())); } void TraceRegisters::setRegisters(REGDUMP* registers) @@ -64,6 +68,8 @@ void TraceRegisters::displayCustomContextMenuSlot(QPoint pos) menu.addAction(mDisplayMMX); } + menu.addAction(wCM_SetRegister); + menu.exec(this->mapToGlobal(pos)); } else // Right-click on empty space @@ -101,6 +107,50 @@ void TraceRegisters::onCopySIMDRegister() showCopyFloatRegister(64, this, tr("View MMX register"), registerValue(&mRegDumpStruct, mSelected)); } +void TraceRegisters::onSetRegister() +{ + // map x87st0 to x87r0 + REGISTER_NAME reg = mSelected; + QString regName; + duint value = *((duint*)registerValue(&mRegDumpStruct, mSelected)); + if(reg >= x87st0 && reg <= x87st7) + regName = QString().sprintf("st%d", reg - x87st0); + else + // map "cax" to "eax" or "rax" + regName = mRegisterMapping.constFind(reg).value(); + + // flags need to '_' infront + if(mFlags.contains(reg)) + { + regName = "_" + regName; + value = (int)(* (bool*) registerValue(&mRegDumpStruct, mSelected)); + } + + + // tell everything the compiler + if(mFPU.contains(reg)) + { + regName = "_" + regName; + value = (duint)registerValue(&mRegDumpStruct, mSelected); + } + + if(mTAGWORD.contains(reg) || reg == MxCsr_RC || reg == x87CW_RC || reg == x87CW_PC || reg == x87SW_TOP) + { + value = (* ((const unsigned short*)registerValue(&mRegDumpStruct, mSelected))); + } + + // we change the value (so highlight it) + mRegisterUpdates.insert(reg); + + qDebug() << "This is the value " << value; + qDebug() << "This is the string " << regName.toUtf8().constData(); + + DbgValToString(regName.toUtf8().constData(), value); + + // force repaint + emit refresh(); +} + void TraceRegisters::mouseDoubleClickEvent(QMouseEvent* event) { if(!isActive || event->button() != Qt::LeftButton) diff --git a/src/gui/Src/Tracer/TraceRegisters.h b/src/gui/Src/Tracer/TraceRegisters.h index 4889f761..9365fcaf 100644 --- a/src/gui/Src/Tracer/TraceRegisters.h +++ b/src/gui/Src/Tracer/TraceRegisters.h @@ -14,10 +14,12 @@ public: public slots: virtual void displayCustomContextMenuSlot(QPoint pos); void onCopySIMDRegister(); + void onSetRegister(); protected: virtual void mouseDoubleClickEvent(QMouseEvent* event); private: QAction* wCM_CopySIMDRegister; + QAction* wCM_SetRegister; }; From 01dae0666d5320441028e0c082530b826afc4356 Mon Sep 17 00:00:00 2001 From: Sidharth Anil Date: Mon, 19 Feb 2024 00:45:55 -0600 Subject: [PATCH 2/5] Add action to context menu appropriately --- src/gui/Src/Tracer/TraceRegisters.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gui/Src/Tracer/TraceRegisters.cpp b/src/gui/Src/Tracer/TraceRegisters.cpp index 0c53bae2..6306c6c6 100644 --- a/src/gui/Src/Tracer/TraceRegisters.cpp +++ b/src/gui/Src/Tracer/TraceRegisters.cpp @@ -68,7 +68,13 @@ void TraceRegisters::displayCustomContextMenuSlot(QPoint pos) menu.addAction(mDisplayMMX); } - menu.addAction(wCM_SetRegister); + if((!mNoChange.contains(mSelected)) || + mSelected == LastError || + mSelected == LastStatus || + mSelected == CIP) + { + menu.addAction(wCM_SetRegister); + } menu.exec(this->mapToGlobal(pos)); } @@ -140,7 +146,7 @@ void TraceRegisters::onSetRegister() } // we change the value (so highlight it) - mRegisterUpdates.insert(reg); + // mRegisterUpdates.insert(reg); qDebug() << "This is the value " << value; qDebug() << "This is the string " << regName.toUtf8().constData(); @@ -148,7 +154,7 @@ void TraceRegisters::onSetRegister() DbgValToString(regName.toUtf8().constData(), value); // force repaint - emit refresh(); + // emit refresh(); } void TraceRegisters::mouseDoubleClickEvent(QMouseEvent* event) From f0ad95732cf58979832b29d0f88f2203759f52cd Mon Sep 17 00:00:00 2001 From: Sidharth Anil Date: Mon, 19 Feb 2024 14:23:16 -0600 Subject: [PATCH 3/5] Bug fixes and code improvement --- src/gui/Src/Tracer/TraceRegisters.cpp | 39 ++++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/gui/Src/Tracer/TraceRegisters.cpp b/src/gui/Src/Tracer/TraceRegisters.cpp index 6306c6c6..4c1a1fbc 100644 --- a/src/gui/Src/Tracer/TraceRegisters.cpp +++ b/src/gui/Src/Tracer/TraceRegisters.cpp @@ -118,7 +118,8 @@ void TraceRegisters::onSetRegister() // map x87st0 to x87r0 REGISTER_NAME reg = mSelected; QString regName; - duint value = *((duint*)registerValue(&mRegDumpStruct, mSelected)); + // duint value = *((duint*)registerValue(&mRegDumpStruct, mSelected)); + duint value; if(reg >= x87st0 && reg <= x87st7) regName = QString().sprintf("st%d", reg - x87st0); else @@ -129,25 +130,37 @@ void TraceRegisters::onSetRegister() if(mFlags.contains(reg)) { regName = "_" + regName; - value = (int)(* (bool*) registerValue(&mRegDumpStruct, mSelected)); + // value = (int)(* (bool*) registerValue(&mRegDumpStruct, mSelected)); } - - - // tell everything the compiler if(mFPU.contains(reg)) - { regName = "_" + regName; - value = (duint)registerValue(&mRegDumpStruct, mSelected); - } - - if(mTAGWORD.contains(reg) || reg == MxCsr_RC || reg == x87CW_RC || reg == x87CW_PC || reg == x87SW_TOP) - { - value = (* ((const unsigned short*)registerValue(&mRegDumpStruct, mSelected))); - } + // else if(mFPUXMM.contains(reg) || mFPUYMM.contains(reg) || mFPUMMX.contains(reg)) + // { + // regName = "_" + regName; + //// value = (duint)((const char *)registerValue(&mRegDumpStruct, mSelected)); + // } + // else if(mFPUx87.contains(reg) || mFPU.contains(reg)) + // { + // value = (* ((const unsigned short*)registerValue(&mRegDumpStruct, mSelected))); + // } // we change the value (so highlight it) // mRegisterUpdates.insert(reg); + if(mUINTDISPLAY.contains(reg) || reg == LastError || reg == LastStatus) + value = *((const duint*)registerValue(&mRegDumpStruct, mSelected)); + else if(mBOOLDISPLAY.contains(reg)) + value = (duint)(*(const bool*)registerValue(&mRegDumpStruct, mSelected)); + else if(mUSHORTDISPLAY.contains(reg) || mFIELDVALUE.contains(reg)) + value = (duint)(*(const unsigned short*)registerValue(&mRegDumpStruct, mSelected)); + else if(mDWORDDISPLAY.contains(reg)) + value = (duint)(*(const DWORD*)registerValue(&mRegDumpStruct, mSelected)); + else if(mFPUXMM.contains(reg) || mFPUYMM.contains(reg) || mFPUMMX.contains(reg) || mFPUx87_80BITSDISPLAY.contains(reg)) + value = (duint)((const char*)registerValue(&mRegDumpStruct, mSelected)); + else + qDebug() << "What do I do with " << reg; + + qDebug() << "Trace Registers"; qDebug() << "This is the value " << value; qDebug() << "This is the string " << regName.toUtf8().constData(); From e2271e303a9e2fc32a0784031a73afb96b099e3b Mon Sep 17 00:00:00 2001 From: Sidharth Anil Date: Mon, 19 Feb 2024 14:35:43 -0600 Subject: [PATCH 4/5] Cleaning up code --- src/gui/Src/Tracer/TraceRegisters.cpp | 39 +++++++-------------------- src/gui/Src/Tracer/TraceRegisters.h | 4 +-- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/gui/Src/Tracer/TraceRegisters.cpp b/src/gui/Src/Tracer/TraceRegisters.cpp index 4c1a1fbc..3373cd5e 100644 --- a/src/gui/Src/Tracer/TraceRegisters.cpp +++ b/src/gui/Src/Tracer/TraceRegisters.cpp @@ -4,7 +4,6 @@ #include "EditFloatRegister.h" #include "StringUtil.h" #include "MiscUtil.h" -#include TraceRegisters::TraceRegisters(QWidget* parent) : RegistersView(parent) { @@ -12,8 +11,8 @@ TraceRegisters::TraceRegisters(QWidget* parent) : RegistersView(parent) connect(wCM_CopySIMDRegister, SIGNAL(triggered()), this, SLOT(onCopySIMDRegister())); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(displayCustomContextMenuSlot(QPoint))); - wCM_SetRegister = setupAction(tr("Set Register value")); - connect(wCM_SetRegister, SIGNAL(triggered()), this, SLOT(onSetRegister())); + wCM_SetCurrentRegister = setupAction(tr("Set as current value")); + connect(wCM_SetCurrentRegister, SIGNAL(triggered()), this, SLOT(onSetCurrentRegister())); } void TraceRegisters::setRegisters(REGDUMP* registers) @@ -73,7 +72,7 @@ void TraceRegisters::displayCustomContextMenuSlot(QPoint pos) mSelected == LastStatus || mSelected == CIP) { - menu.addAction(wCM_SetRegister); + menu.addAction(wCM_SetCurrentRegister); } menu.exec(this->mapToGlobal(pos)); @@ -113,12 +112,11 @@ void TraceRegisters::onCopySIMDRegister() showCopyFloatRegister(64, this, tr("View MMX register"), registerValue(&mRegDumpStruct, mSelected)); } -void TraceRegisters::onSetRegister() +void TraceRegisters::onSetCurrentRegister() { // map x87st0 to x87r0 REGISTER_NAME reg = mSelected; QString regName; - // duint value = *((duint*)registerValue(&mRegDumpStruct, mSelected)); duint value; if(reg >= x87st0 && reg <= x87st7) regName = QString().sprintf("st%d", reg - x87st0); @@ -126,28 +124,15 @@ void TraceRegisters::onSetRegister() // map "cax" to "eax" or "rax" regName = mRegisterMapping.constFind(reg).value(); - // flags need to '_' infront + // flags and MFPU need to '_' infront if(mFlags.contains(reg)) - { regName = "_" + regName; - // value = (int)(* (bool*) registerValue(&mRegDumpStruct, mSelected)); - } + \ + if(mFPU.contains(reg)) regName = "_" + regName; - // else if(mFPUXMM.contains(reg) || mFPUYMM.contains(reg) || mFPUMMX.contains(reg)) - // { - // regName = "_" + regName; - //// value = (duint)((const char *)registerValue(&mRegDumpStruct, mSelected)); - // } - // else if(mFPUx87.contains(reg) || mFPU.contains(reg)) - // { - // value = (* ((const unsigned short*)registerValue(&mRegDumpStruct, mSelected))); - // } - // we change the value (so highlight it) - // mRegisterUpdates.insert(reg); - - if(mUINTDISPLAY.contains(reg) || reg == LastError || reg == LastStatus) + if(mUINTDISPLAY.contains(reg)) value = *((const duint*)registerValue(&mRegDumpStruct, mSelected)); else if(mBOOLDISPLAY.contains(reg)) value = (duint)(*(const bool*)registerValue(&mRegDumpStruct, mSelected)); @@ -158,16 +143,10 @@ void TraceRegisters::onSetRegister() else if(mFPUXMM.contains(reg) || mFPUYMM.contains(reg) || mFPUMMX.contains(reg) || mFPUx87_80BITSDISPLAY.contains(reg)) value = (duint)((const char*)registerValue(&mRegDumpStruct, mSelected)); else - qDebug() << "What do I do with " << reg; - - qDebug() << "Trace Registers"; - qDebug() << "This is the value " << value; - qDebug() << "This is the string " << regName.toUtf8().constData(); + value = *((const duint*)registerValue(&mRegDumpStruct, mSelected)); DbgValToString(regName.toUtf8().constData(), value); - // force repaint - // emit refresh(); } void TraceRegisters::mouseDoubleClickEvent(QMouseEvent* event) diff --git a/src/gui/Src/Tracer/TraceRegisters.h b/src/gui/Src/Tracer/TraceRegisters.h index 9365fcaf..6f36ac24 100644 --- a/src/gui/Src/Tracer/TraceRegisters.h +++ b/src/gui/Src/Tracer/TraceRegisters.h @@ -14,12 +14,12 @@ public: public slots: virtual void displayCustomContextMenuSlot(QPoint pos); void onCopySIMDRegister(); - void onSetRegister(); + void onSetCurrentRegister(); protected: virtual void mouseDoubleClickEvent(QMouseEvent* event); private: QAction* wCM_CopySIMDRegister; - QAction* wCM_SetRegister; + QAction* wCM_SetCurrentRegister; }; From dca1d28eb6313a17bc6d0438a6151d60e4ff210e Mon Sep 17 00:00:00 2001 From: Sidharth Anil <44941778+sid-38@users.noreply.github.com> Date: Mon, 19 Feb 2024 20:00:42 -0600 Subject: [PATCH 5/5] Update TraceRegisters.cpp - Minor refactoring --- src/gui/Src/Tracer/TraceRegisters.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/gui/Src/Tracer/TraceRegisters.cpp b/src/gui/Src/Tracer/TraceRegisters.cpp index 3373cd5e..3e252abc 100644 --- a/src/gui/Src/Tracer/TraceRegisters.cpp +++ b/src/gui/Src/Tracer/TraceRegisters.cpp @@ -125,11 +125,7 @@ void TraceRegisters::onSetCurrentRegister() regName = mRegisterMapping.constFind(reg).value(); // flags and MFPU need to '_' infront - if(mFlags.contains(reg)) - regName = "_" + regName; - \ - - if(mFPU.contains(reg)) + if(mFlags.contains(reg) || mFPU.contains(reg)) regName = "_" + regName; if(mUINTDISPLAY.contains(reg))