Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gui/qt/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,7 @@ HexWidget *MainWindow::gotoMemAddrNoRaise(uint32_t address) {
const int offset = static_cast<int>(address - edit->getBase());
if (offset < edit->getSize()) {
edit->setOffset(offset);
edit->setHighlight(static_cast<int>(address));
memWidget = edit;
didGoto = true;
break;
Expand All @@ -2037,6 +2038,8 @@ HexWidget *MainWindow::gotoMemAddrNoRaise(uint32_t address) {
}
if (memWidget != Q_NULLPTR && !didGoto) {
memGoto(memWidget, address);
} else if (memWidget != Q_NULLPTR) {
memWidget->setHighlight(static_cast<int>(address));
}
return memWidget;
}
Expand Down
73 changes: 66 additions & 7 deletions gui/qt/debugger/hexwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ void HexWidget::setOffset(int offset) {
}

void HexWidget::setCursorOffset(int offset, bool selection) {
setCursorOffset(offset, selection, true);
}

void HexWidget::setHighlight(const int address) {
const int normalized = address < 0 ? -1 : address;
if (m_highlightedAddr == normalized) {
return;
}
m_highlightedAddr = normalized;
viewport()->update();
}

void HexWidget::setCursorOffset(int offset, bool selection, bool clearHighlight) {
if (offset > m_size * 2) {
offset = m_size * 2;
}
Expand All @@ -141,6 +154,10 @@ void HexWidget::setCursorOffset(int offset, bool selection) {
resetSelection();
}

if (clearHighlight) {
m_highlightedAddr = -1;
}

m_cursorOffset = offset;
adjust();
showCursor();
Expand Down Expand Up @@ -254,18 +271,19 @@ void HexWidget::setSelection(int addr) {
addr = 0;
}

if (m_selectStart == -1) {
m_selectStart = addr;
m_selectEnd = addr;
m_selectLen = 0;
if (m_selectAnchor == -1) {
m_selectAnchor = addr;
}
if (addr > m_selectStart) {

if (addr >= m_selectAnchor) {
m_selectStart = m_selectAnchor;
m_selectEnd = addr;
m_selectLen = addr - m_selectStart + 1;
} else {
m_selectStart = addr;
m_selectLen = m_selectEnd - addr + 1;
m_selectEnd = m_selectAnchor;
}

m_selectLen = (m_selectStart == -1 || m_selectEnd == -1) ? 0 : (m_selectEnd - m_selectStart + 1);
}

void HexWidget::undo() {
Expand Down Expand Up @@ -310,12 +328,27 @@ void HexWidget::paintEvent(QPaintEvent *event) {
const QColor &cSelected = pal.color(QPalette::Highlight);
const QColor cModified = QColor(Qt::blue).lighter(160);
const QColor cBoth = QColor(Qt::green).lighter(160);
const bool darkMode = isRunningInDarkMode();
const QColor boxBorder = darkMode ? QColor(0xdb, 0xdb, 0xdb) : QColor(0x66, 0x66, 0x66);
QColor boxFill = darkMode ? QColor(0x55, 0x55, 0x55) : QColor(0xd0, 0xd0, 0xd0);
boxFill.setAlpha(140);
const int xOffset = horizontalScrollBar()->value();
const int xAddr = m_addrLoc - xOffset;

painter.setRenderHint(QPainter::Antialiasing);
painter.fillRect(region, cBg);

const auto drawHighlightBox = [&](const QRect &rect) {
if (!rect.isValid() || rect.isNull()) {
return;
}
painter.save();
painter.setPen(QPen(boxBorder, 1));
painter.setBrush(boxFill);
painter.drawRoundedRect(rect.adjusted(0, 0, -1, -1), 2, 2);
painter.restore();
};

painter.setPen(Qt::gray);
painter.drawLine(m_dataLine - xOffset, region.top(), m_dataLine - xOffset, height());
if (m_asciiArea) {
Expand All @@ -338,6 +371,22 @@ void HexWidget::paintEvent(QPaintEvent *event) {
uint8_t flags = debug.addr[addr + m_base];
bool selected = addr >= m_selectStart && addr <= m_selectEnd;
bool modified = !m_modified.isEmpty() && m_modified[addr];
const bool highlighted = m_highlightedAddr >= 0 && (m_base + addr) == m_highlightedAddr;
const int xDataStart = xData;
const int xAsciiStart = xAscii;
QRect dataHighlightRect;
QRect asciiHighlightRect;

if (highlighted) {
if (!col) {
dataHighlightRect.setRect(xDataStart, y - m_charHeight + m_margin, 2 * m_charWidth + 3, m_charHeight);
} else {
dataHighlightRect.setRect(xDataStart - m_charWidth, y - m_charHeight + m_margin, 3 * m_charWidth + 3, m_charHeight);
}
if (m_asciiArea) {
asciiHighlightRect.setRect(xAsciiStart, y - m_charHeight + m_margin, m_charWidth + 1, m_charHeight);
}
}

QFont font = painter.font();
const QFont fontorig = painter.font();
Expand Down Expand Up @@ -367,6 +416,10 @@ void HexWidget::paintEvent(QPaintEvent *event) {
painter.fillRect(r, modified ? selected ? cBoth : cModified : cSelected);
}

if (highlighted) {
drawHighlightBox(dataHighlightRect);
}

QString hex = int2hex(data, 2);
if ((flags & DBG_MASK_READ) && (flags & DBG_MASK_WRITE)) {
painter.setPen(Qt::darkGreen);
Expand All @@ -391,6 +444,9 @@ void HexWidget::paintEvent(QPaintEvent *event) {
r.setRect(xAscii, y - m_charHeight + m_margin, m_charWidth, m_charHeight);
painter.fillRect(r, modified ? selected ? cBoth : cModified : cSelected);
}
if (highlighted) {
drawHighlightBox(asciiHighlightRect);
}
painter.drawText(xAscii, y, QChar(ch));
xAscii += m_charWidth;
}
Expand Down Expand Up @@ -421,6 +477,9 @@ void HexWidget::mousePressEvent(QMouseEvent *event) {
int addr = getPosition(event->pos());
if (addr >= 0) {
setCursorOffset(addr, true);
m_selectAnchor = addr / 2;
m_selectStart = m_selectEnd = -1;
m_selectLen = 0;
}
}

Expand Down
6 changes: 5 additions & 1 deletion gui/qt/debugger/hexwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class HexWidget : public QAbstractScrollArea {
void setBytesPerLine(int bytes) { m_bytesPerLine = bytes; adjust(); }
void setAsciiArea(bool area) { m_asciiArea = area; adjust(); }
void setCursorOffset(int address, bool selection = true);
void setHighlight(int address);
void setScrollable(bool state) { m_scrollable = state; adjust(); }
void setFont(const QFont &font) { QAbstractScrollArea::setFont(font); adjust(); }
void setOffset(int addr);
Expand Down Expand Up @@ -52,11 +53,12 @@ private slots:
void scroll(int value);

private:
void setCursorOffset(int offset, bool selection, bool clearHighlight);
void redo();
void undo();
void showCursor();
void setSelection(int addr);
void resetSelection() { m_selectStart = m_selectEnd = -1; }
void resetSelection() { m_selectStart = m_selectEnd = -1; m_selectLen = 0; m_selectAnchor = -1; }
bool isSelected() const { return m_selectStart != -1; }
void setSelected(char n) { overwrite(m_selectStart * 2, QByteArray(m_selectLen, n)); }
void overwrite(int pos, char c);
Expand Down Expand Up @@ -98,11 +100,13 @@ private slots:
int m_selectStart;
int m_selectEnd;
int m_selectLen;
int m_selectAnchor = -1;

bool m_scrollable = false; // fetch bytes from memory on scroll
bool m_asciiArea = true; // show character representations
bool m_scrolled = false; // scrolled while focused
bool m_asciiEdit = false; // editing from the ascii side
int m_highlightedAddr = -1; // Address to highlight with a box

QStack<stack_entry_t> m_stack;
};
Expand Down
1 change: 1 addition & 0 deletions gui/qt/memorywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void MainWindow::memGoto(HexWidget *edit, uint32_t address) {
edit->setBase(static_cast<int>(address));
edit->setOffset(0);
memUpdateEdit(edit, true);
edit->setHighlight(static_cast<int>(address));
}

void MainWindow::memGotoEdit(HexWidget *edit) {
Expand Down
Loading