mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-01 09:45:25 +00:00
Adding breakpoints and preventing the selection box to be drawn on top of special items
This commit is contained in:
@@ -34,12 +34,14 @@ namespace ComSquare::Debugger
|
|||||||
this->_ui.disassembly->horizontalHeader()->setStretchLastSection(true);
|
this->_ui.disassembly->horizontalHeader()->setStretchLastSection(true);
|
||||||
this->_ui.disassembly->resizeColumnsToContents();
|
this->_ui.disassembly->resizeColumnsToContents();
|
||||||
this->_ui.disassembly->verticalHeader()->setSectionResizeMode (QHeaderView::Fixed);
|
this->_ui.disassembly->verticalHeader()->setSectionResizeMode (QHeaderView::Fixed);
|
||||||
|
this->_ui.disassembly->verticalHeader()->setHighlightSections(false);
|
||||||
this->_ui.disassembly->setItemDelegate(&this->_painter);
|
this->_ui.disassembly->setItemDelegate(&this->_painter);
|
||||||
|
|
||||||
QMainWindow::connect(this->_ui.actionPause, &QAction::triggered, this, &CPUDebug::pause);
|
QMainWindow::connect(this->_ui.actionPause, &QAction::triggered, this, &CPUDebug::pause);
|
||||||
QMainWindow::connect(this->_ui.actionStep, &QAction::triggered, this, &CPUDebug::step);
|
QMainWindow::connect(this->_ui.actionStep, &QAction::triggered, this, &CPUDebug::step);
|
||||||
QMainWindow::connect(this->_ui.actionNext, &QAction::triggered, this, &CPUDebug::next);
|
QMainWindow::connect(this->_ui.actionNext, &QAction::triggered, this, &CPUDebug::next);
|
||||||
QMainWindow::connect(this->_ui.clear, &QPushButton::released, this, &CPUDebug::clearHistory);
|
QMainWindow::connect(this->_ui.clear, &QPushButton::released, this, &CPUDebug::clearHistory);
|
||||||
|
QMainWindow::connect(this->_ui.disassembly->verticalHeader(), &QHeaderView::sectionClicked, this, &CPUDebug::toggleBreakpoint);
|
||||||
this->_window->show();
|
this->_window->show();
|
||||||
this->_updateRegistersPanel();
|
this->_updateRegistersPanel();
|
||||||
}
|
}
|
||||||
@@ -131,6 +133,19 @@ namespace ComSquare::Debugger
|
|||||||
this->_isPaused = false;
|
this->_isPaused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPUDebug::toggleBreakpoint(int logicalIndex)
|
||||||
|
{
|
||||||
|
DisassembledInstruction instruction = this->disassembledInstructions[logicalIndex];
|
||||||
|
auto existing = std::find_if(this->breakpoints.begin(), this->breakpoints.end(), [instruction](Breakpoint &i) {
|
||||||
|
return i.address == instruction.address;
|
||||||
|
});
|
||||||
|
if (existing == this->breakpoints.end())
|
||||||
|
this->breakpoints.push_back({instruction.address, false});
|
||||||
|
else
|
||||||
|
this->breakpoints.erase(existing);
|
||||||
|
this->_ui.disassembly->viewport()->repaint();
|
||||||
|
}
|
||||||
|
|
||||||
void CPUDebug::_updateRegistersPanel()
|
void CPUDebug::_updateRegistersPanel()
|
||||||
{
|
{
|
||||||
if (!this->_registers.p.m)
|
if (!this->_registers.p.m)
|
||||||
@@ -412,11 +427,15 @@ void RowPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, co
|
|||||||
if (breakpoint != this->_cpu.breakpoints.end())
|
if (breakpoint != this->_cpu.breakpoints.end())
|
||||||
isBreakpoint = true;
|
isBreakpoint = true;
|
||||||
|
|
||||||
if (instruction.address == this->_cpu.getPC())
|
QStyleOptionViewItem style = option;
|
||||||
painter->fillRect(option.rect,QColor(Qt::darkGreen));
|
if (instruction.address == this->_cpu.getPC()) {
|
||||||
if (isBreakpoint && !breakpoint->oneTime)
|
painter->fillRect(option.rect, QColor(Qt::darkGreen));
|
||||||
|
style.state &= ~QStyle::State_Selected;
|
||||||
|
} else if (isBreakpoint && !breakpoint->oneTime) {
|
||||||
painter->fillRect(option.rect,QColor(Qt::darkRed));
|
painter->fillRect(option.rect,QColor(Qt::darkRed));
|
||||||
QStyledItemDelegate::paint(painter, option, index);
|
style.state &= ~QStyle::State_Selected;
|
||||||
|
}
|
||||||
|
QStyledItemDelegate::paint(painter, style, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize RowPainter::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const
|
QSize RowPainter::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const
|
||||||
|
|||||||
@@ -159,6 +159,8 @@ namespace ComSquare::Debugger
|
|||||||
void next();
|
void next();
|
||||||
//! @brief Clear the history panel.
|
//! @brief Clear the history panel.
|
||||||
void clearHistory();
|
void clearHistory();
|
||||||
|
//! @brief Called when the user clicks on a section header. It enable/disable a breakpoint for this address.
|
||||||
|
void toggleBreakpoint(int logicalIndex);
|
||||||
//! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
|
//! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
|
||||||
void disableDebugger();
|
void disableDebugger();
|
||||||
//! @brief The list of disassembled instructions to show on the debugger.
|
//! @brief The list of disassembled instructions to show on the debugger.
|
||||||
|
|||||||
Reference in New Issue
Block a user