From 561f2587701285f952feb84dd93a5237cc4746c9 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 7 Dec 2020 20:12:34 -0500 Subject: [PATCH 1/3] Qt debugger breakpoint highlight bug fixes. --- src/drivers/Qt/ConsoleDebugger.cpp | 37 ++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index 84ba6eb3..fbb266c5 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -54,6 +54,8 @@ debuggerBookmarkManager_t dbgBmMgr; static std::list dbgWinList; static void DeleteBreak(int sel); +static bool waitingAtBp = false; +static int lastBpIdx = 0; //---------------------------------------------------------------------------- ConsoleDebugger::ConsoleDebugger(QWidget *parent) : QDialog( parent, Qt::Window ) @@ -72,6 +74,7 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent) float fontCharWidth; QTreeWidgetItem * item; int opt, useNativeMenuBar; + fceuDecIntValidtor *validator; font.setFamily("Courier New"); font.setStyle( QFont::StyleNormal ); @@ -487,17 +490,19 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent) hbox->addWidget( instrExdVal, 1, Qt::AlignLeft ); hbox2->addLayout( vbox ); + validator = new fceuDecIntValidtor( 0, 0x3FFFFFFF, this ); cpuCycExdVal->setFont( font ); cpuCycExdVal->setMaxLength( 16 ); - cpuCycExdVal->setInputMask( ">9000000000000000;" ); + cpuCycExdVal->setValidator( validator ); cpuCycExdVal->setAlignment(Qt::AlignLeft); cpuCycExdVal->setMaximumWidth( 18 * fontCharWidth ); cpuCycExdVal->setCursorPosition(0); connect( cpuCycExdVal, SIGNAL(textEdited(const QString &)), this, SLOT(cpuCycleThresChanged(const QString &))); + validator = new fceuDecIntValidtor( 0, 0x3FFFFFFF, this ); instrExdVal->setFont( font ); instrExdVal->setMaxLength( 16 ); - instrExdVal->setInputMask( ">9000000000000000;" ); + instrExdVal->setValidator( validator ); instrExdVal->setAlignment(Qt::AlignLeft); instrExdVal->setMaximumWidth( 18 * fontCharWidth ); instrExdVal->setCursorPosition(0); @@ -2548,6 +2553,24 @@ void ConsoleDebugger::updatePeriodic(void) emuStatLbl->setStyleSheet("background-color: green; color: white;"); } + if ( waitingAtBp && (lastBpIdx == BREAK_TYPE_CYCLES_EXCEED) ) + { + cpuCyclesLbl1->setStyleSheet("background-color: blue; color: white;"); + } + else + { + cpuCyclesLbl1->setStyleSheet(NULL); + } + + if ( waitingAtBp && (lastBpIdx == BREAK_TYPE_INSTRUCTIONS_EXCEED) ) + { + cpuInstrsLbl1->setStyleSheet("background-color: blue; color: white;"); + } + else + { + cpuInstrsLbl1->setStyleSheet(NULL); + } + if ( bpTree->topLevelItemCount() != numWPs ) { printf("Breakpoint Tree Update\n"); @@ -2583,6 +2606,7 @@ void ConsoleDebugger::breakPointNotify( int bpNum ) if ( item != NULL ) { item->setSelected(true); + bpTree->setCurrentItem( item ); } bpTree->viewport()->update(); } @@ -2591,11 +2615,11 @@ void ConsoleDebugger::breakPointNotify( int bpNum ) { if (bpNum == BREAK_TYPE_CYCLES_EXCEED) { - // TODO + // Label Coloring done in periodic update } else if (bpNum == BREAK_TYPE_INSTRUCTIONS_EXCEED) { - // TODO + // Label Coloring done in periodic update } } @@ -2622,6 +2646,9 @@ void FCEUD_DebugBreakpoint( int bpNum ) { return; } + lastBpIdx = bpNum; + waitingAtBp = true; + printf("Breakpoint Hit: %i \n", bpNum ); fceuWrapperUnLock(); @@ -2654,6 +2681,8 @@ void FCEUD_DebugBreakpoint( int bpNum ) ResetDebugStatisticsDeltaCounters(); fceuWrapperLock(); + + waitingAtBp = false; } //---------------------------------------------------------------------------- bool debuggerWindowIsOpen(void) From fbf8fe6eb5e2c4970d433193f809c843ad54c7ce Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 7 Dec 2020 22:04:36 -0500 Subject: [PATCH 2/3] Added logic to allow for copy/paste of trace logger viewport to/from clipboard. --- src/drivers/Qt/TraceLogger.cpp | 268 ++++++++++++++++++++++++++++++++- src/drivers/Qt/TraceLogger.h | 24 ++- 2 files changed, 287 insertions(+), 5 deletions(-) diff --git a/src/drivers/Qt/TraceLogger.cpp b/src/drivers/Qt/TraceLogger.cpp index f96b88bd..13e75662 100644 --- a/src/drivers/Qt/TraceLogger.cpp +++ b/src/drivers/Qt/TraceLogger.cpp @@ -1,12 +1,14 @@ // TraceLogger.cpp // #include +#include #include #include #include #include #include +#include #include "../../types.h" #include "../../fceu.h" @@ -243,6 +245,7 @@ TraceLoggerDialog_t::TraceLoggerDialog_t(QWidget *parent) setLayout( mainLayout ); traceViewCounter = 0; + recbufHeadLp = recBufHead; updateTimer = new QTimer( this ); @@ -320,6 +323,12 @@ void TraceLoggerDialog_t::updatePeriodic(void) if ( traceViewCounter > 20 ) { + if ( recBufHead != recbufHeadLp ) + { + traceView->highlightClear(); + } + recbufHeadLp = recBufHead; + if ( traceViewDrawEnable ) { traceView->update(); @@ -654,7 +663,7 @@ static int convToXchar( int i ) return c; } //---------------------------------------------------- -int traceRecord_t::convToText( char *txt ) +int traceRecord_t::convToText( char *txt, int *len ) { int i=0, j=0; char stmp[128]; @@ -848,6 +857,11 @@ int traceRecord_t::convToText( char *txt ) txt[i] = 0; + if ( len ) + { + *len = i; + } + return 0; } //---------------------------------------------------- @@ -1089,6 +1103,7 @@ QTraceLogView::QTraceLogView(QWidget *parent) } this->setPalette(pal); + this->setMouseTracking(true); calcFontData(); @@ -1096,6 +1111,12 @@ QTraceLogView::QTraceLogView(QWidget *parent) hbar = NULL; wheelPixelCounter = 0; + mouseLeftBtnDown = false; + txtHlgtStartChar = -1; + txtHlgtStartLine = -1; + txtHlgtEndChar = -1; + txtHlgtEndLine = -1; + captureHighLightText = false; } //---------------------------------------------------- QTraceLogView::~QTraceLogView(void) @@ -1126,6 +1147,159 @@ void QTraceLogView::setScrollBars( QScrollBar *h, QScrollBar *v ) hbar = h; vbar = v; } //---------------------------------------------------- +void QTraceLogView::highlightClear(void) +{ + txtHlgtEndLine = txtHlgtStartLine = txtHlgtAnchorLine; + txtHlgtEndChar = txtHlgtStartChar = txtHlgtAnchorChar; +} +//---------------------------------------------------- +QPoint QTraceLogView::convPixToCursor( QPoint p ) +{ + QPoint c(0,0); + + if ( p.x() < 0 ) + { + c.setX(0); + } + else + { + float x = (float)p.x() / pxCharWidth; + + c.setX( (int)x ); + } + + if ( p.y() < 0 ) + { + c.setY( 0 ); + } + else + { + float ly = ( (float)pxLineLead / (float)pxLineSpacing ); + float py = ( (float)p.y() ) / (float)pxLineSpacing; + float ry = fmod( py, 1.0 ); + + if ( ry < ly ) + { + c.setY( ((int)py) - 1 ); + } + else + { + c.setY( (int)py ); + } + } + return c; +} +//---------------------------------------------------------------------------- +bool QTraceLogView::textIsHighlighted(void) +{ + bool set = false; + + if ( txtHlgtStartLine == txtHlgtEndLine ) + { + set = (txtHlgtStartChar != txtHlgtEndChar); + } + else + { + set = true; + } + return set; +} +//---------------------------------------------------------------------------- +void QTraceLogView::setHighlightEndCoord( int x, int y ) +{ + + if ( txtHlgtAnchorLine < y ) + { + txtHlgtStartLine = txtHlgtAnchorLine; + txtHlgtStartChar = txtHlgtAnchorChar; + txtHlgtEndLine = y; + txtHlgtEndChar = x; + } + else if ( txtHlgtAnchorLine > y ) + { + txtHlgtStartLine = y; + txtHlgtStartChar = x; + txtHlgtEndLine = txtHlgtAnchorLine; + txtHlgtEndChar = txtHlgtAnchorChar; + } + else + { + txtHlgtStartLine = txtHlgtAnchorLine; + txtHlgtEndLine = txtHlgtAnchorLine; + + if ( txtHlgtAnchorChar < x ) + { + txtHlgtStartChar = txtHlgtAnchorChar; + txtHlgtEndChar = x; + } + else if ( txtHlgtAnchorChar > x ) + { + txtHlgtStartChar = x; + txtHlgtEndChar = txtHlgtAnchorChar; + } + else + { + txtHlgtStartChar = txtHlgtAnchorChar; + txtHlgtEndChar = txtHlgtAnchorChar; + } + } + return; +} +//---------------------------------------------------------------------------- +void QTraceLogView::loadClipboard( const char *txt ) +{ + QClipboard *clipboard = QGuiApplication::clipboard(); + + clipboard->setText( tr(txt), QClipboard::Clipboard ); + + if ( clipboard->supportsSelection() ) + { + clipboard->setText( tr(txt), QClipboard::Selection ); + } +} +//---------------------------------------------------- +void QTraceLogView::mouseMoveEvent(QMouseEvent * event) +{ + QPoint c = convPixToCursor( event->pos() ); + + if ( mouseLeftBtnDown ) + { + //printf("Left Button Move: (%i,%i)\n", c.x(), c.y() ); + setHighlightEndCoord( c.x(), c.y() ); + } +} +//---------------------------------------------------- +void QTraceLogView::mouseReleaseEvent(QMouseEvent * event) +{ + QPoint c = convPixToCursor( event->pos() ); + + if ( event->button() == Qt::LeftButton ) + { + //printf("Left Button Release: (%i,%i)\n", c.x(), c.y() ); + mouseLeftBtnDown = false; + setHighlightEndCoord( c.x(), c.y() ); + + captureHighLightText = true; + } +} +//---------------------------------------------------- +void QTraceLogView::mousePressEvent(QMouseEvent * event) +{ + QPoint c = convPixToCursor( event->pos() ); + + //printf("Line: %i,%i\n", c.x(), c.y() ); + + if ( event->button() == Qt::LeftButton ) + { + //printf("Left Button Pressed: (%i,%i)\n", c.x(), c.y() ); + mouseLeftBtnDown = true; + txtHlgtAnchorChar = c.x(); + txtHlgtAnchorLine = c.y(); + + setHighlightEndCoord( c.x(), c.y() ); + } +} +//---------------------------------------------------- void QTraceLogView::wheelEvent(QWheelEvent *event) { int lineOffset; @@ -1199,12 +1373,28 @@ void QTraceLogView::resizeEvent(QResizeEvent *event) } //---------------------------------------------------- +void QTraceLogView::drawText( QPainter *painter, int x, int y, const char *txt, int maxChars ) +{ + int i=0; + char c[2]; + + c[0] = 0; c[1] = 0; + + while ( (txt[i] != 0) && (i < maxChars) ) + { + c[0] = txt[i]; + painter->drawText( x, y, tr(c) ); + i++; x += pxCharWidth; + } +} +//---------------------------------------------------- void QTraceLogView::paintEvent(QPaintEvent *event) { - int x,y, v, ofs, row, start, end, nrow; + int x,y, v, ofs, row, start, end, nrow, lineLen; QPainter painter(this); char line[256]; traceRecord_t rec[64]; + QColor hlgtFG("white"), hlgtBG("blue"); painter.setFont(font); viewWidth = event->rect().width(); @@ -1241,6 +1431,11 @@ void QTraceLogView::paintEvent(QPaintEvent *event) start = (start + 1) % recBufMax; } + if ( captureHighLightText ) + { + hlgtText.clear(); + } + pxLineXScroll = (int)(0.010f * (float)hbar->value() * (float)(pxLineWidth - viewWidth) ); x = -pxLineXScroll; @@ -1248,15 +1443,80 @@ void QTraceLogView::paintEvent(QPaintEvent *event) for (row=0; row= txtHlgtStartLine) && (l <= txtHlgtEndLine) ) + { + int ax, hlgtXs, hlgtXe, hlgtXd; + + if ( l == txtHlgtStartLine ) + { + hlgtXs = txtHlgtStartChar; + } + else + { + hlgtXs = 0; + } + + if ( l == txtHlgtEndLine ) + { + hlgtXe = txtHlgtEndChar; + } + else + { + hlgtXe = (viewWidth / pxCharWidth) + 1; + } + hlgtXd = (hlgtXe - hlgtXs); + + ax = x + (hlgtXs * pxCharWidth); + + painter.fillRect( ax, y - pxLineSpacing + pxLineLead, hlgtXd * pxCharWidth, pxLineSpacing, hlgtBG ); + + if ( hlgtXs < lineLen ) + { + painter.setPen( hlgtFG ); + + drawText( &painter, ax, y, &line[hlgtXs], hlgtXd ); + + painter.setPen( this->palette().color(QPalette::WindowText)); + + for (int i=0; i #include #include +#include struct traceRecord_t { @@ -47,7 +48,7 @@ struct traceRecord_t int appendAsmText( const char *txt ); - int convToText( char *line ); + int convToText( char *line, int *len = 0 ); }; class QTraceLogView : public QWidget @@ -59,12 +60,21 @@ class QTraceLogView : public QWidget ~QTraceLogView(void); void setScrollBars( QScrollBar *h, QScrollBar *v ); + void highlightClear(void); protected: void paintEvent(QPaintEvent *event); void resizeEvent(QResizeEvent *event); void wheelEvent(QWheelEvent *event); + void mousePressEvent(QMouseEvent * event); + void mouseReleaseEvent(QMouseEvent * event); + void mouseMoveEvent(QMouseEvent * event); void calcFontData(void); + QPoint convPixToCursor( QPoint p ); + bool textIsHighlighted(void); + void setHighlightEndCoord( int x, int y ); + void loadClipboard( const char *txt ); + void drawText( QPainter *painter, int x, int y, const char *txt, int maxChars = 256 ); protected: QFont font; @@ -82,6 +92,17 @@ class QTraceLogView : public QWidget int viewWidth; int viewHeight; int wheelPixelCounter; + int txtHlgtAnchorChar; + int txtHlgtAnchorLine; + int txtHlgtStartChar; + int txtHlgtStartLine; + int txtHlgtEndChar; + int txtHlgtEndLine; + + bool mouseLeftBtnDown; + bool captureHighLightText; + + std::string hlgtText; }; class TraceLoggerDialog_t : public QDialog @@ -121,6 +142,7 @@ class TraceLoggerDialog_t : public QDialog QScrollBar *vbar; int traceViewCounter; + int recbufHeadLp; void closeEvent(QCloseEvent *bar); From accc476623b6296cfd932acbbb8d40b3e45b9b76 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 7 Dec 2020 22:34:05 -0500 Subject: [PATCH 3/3] Cleaned up a couple cppcheck warnings in Qt GUI. --- src/drivers/Qt/ConsoleDebugger.cpp | 12 +++++++----- src/drivers/Qt/MsgLogViewer.cpp | 5 +++++ src/drivers/Qt/TraceLogger.cpp | 2 ++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index fbb266c5..4f5b7f02 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -3104,11 +3104,13 @@ QAsmView::QAsmView(QWidget *parent) maxLineOffset = 0; ctxMenuAddr = -1; - mouseLeftBtnDown = false; - txtHlgtStartChar = -1; - txtHlgtStartLine = -1; - txtHlgtEndChar = -1; - txtHlgtEndLine = -1; + mouseLeftBtnDown = false; + txtHlgtAnchorLine = -1; + txtHlgtAnchorChar = -1; + txtHlgtStartChar = -1; + txtHlgtStartLine = -1; + txtHlgtEndChar = -1; + txtHlgtEndLine = -1; pcLinePlacement = 0; pcLineOffset = 0; diff --git a/src/drivers/Qt/MsgLogViewer.cpp b/src/drivers/Qt/MsgLogViewer.cpp index 3d29209a..dc2addad 100644 --- a/src/drivers/Qt/MsgLogViewer.cpp +++ b/src/drivers/Qt/MsgLogViewer.cpp @@ -38,6 +38,11 @@ class msgLogBuf_t maxLines = MSG_LOG_MAX_LINES; totalLines = 0; head = tail = 0; + + for (int i=0; i