Share breakpoints in editor and simulator
MODIFY
src/codeeditor.cpp
src/codeeditor.cpp
@@ -131,12 +131,18 @@ void CodeEditor::updateTooltip(int line, QString tip) {
}
}
+void CodeEditor::clearBreakpoints() {
+ auto breakpoints = Pipeline::getPipeline()->getBreakpoints();
+ breakpoints->clear();
+}
+
void CodeEditor::updateBreakpoints() {
// called after disassembler text has been set
+ auto breakpoints = Pipeline::getPipeline()->getBreakpoints();
// Remove breakpoints if a breakpoint line has been removed
- while (!m_breakpoints.empty() && *(m_breakpoints.rbegin()) > (blockCount() - 1)) {
- m_breakpoints.erase(std::prev(m_breakpoints.end()));
+ while (!breakpoints->empty() && *(breakpoints->rbegin()) > ((blockCount() - 1) * 4)) { // byte indexed
+ breakpoints->erase(std::prev(breakpoints->end()));
}
}
@@ -245,14 +251,17 @@ void CodeEditor::breakpointAreaPaintEvent(QPaintEvent* event) {
}
painter.fillRect(area, gradient);
+ if (m_breakpointAreaEnabled) {
QTextBlock block = firstVisibleBlock();
- int blockNumber = block.blockNumber();
+ int blockNumber = block.blockNumber() * 4; // byte indexed
int top = (int)blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int)blockBoundingRect(block).height();
+ auto breakpoints = Pipeline::getPipeline()->getBreakpoints();
+
while (block.isValid() && top <= event->rect().bottom()) {
if (block.isVisible() && bottom >= event->rect().top()) {
- if (m_breakpoints.find(blockNumber) != m_breakpoints.end()) {
+ if (breakpoints->find(blockNumber) != breakpoints->end()) {
painter.drawPixmap(m_breakpointArea->padding, top, m_breakpointArea->imageWidth,
m_breakpointArea->imageHeight, m_breakpointArea->m_breakpoint);
}
@@ -261,7 +270,8 @@ void CodeEditor::breakpointAreaPaintEvent(QPaintEvent* event) {
block = block.next();
top = bottom;
bottom = top + (int)blockBoundingRect(block).height();
- ++blockNumber;
+ blockNumber += 4;
+ }
}
}
@@ -297,20 +307,22 @@ void CodeEditor::breakpointClick(QMouseEvent* event, int forceState) {
index--;
}
// Set or unset breakpoint
- int blockNumber = block.blockNumber();
+ // Since we want the simulator as fast as possible, the breakpoints are byte-indexed
+ auto breakpoints = Pipeline::getPipeline()->getBreakpoints();
+ int blockNumber = block.blockNumber() * 4;
if (block.isValid()) {
- auto brkptIter = m_breakpoints.find(blockNumber);
+ auto brkptIter = breakpoints->find(blockNumber);
// Set/unset breakpoint
if (forceState == 1) {
- m_breakpoints.insert(blockNumber);
+ breakpoints->insert(blockNumber);
} else if (forceState == 2) {
- if (brkptIter != m_breakpoints.end())
- m_breakpoints.erase(m_breakpoints.find(blockNumber));
+ if (brkptIter != breakpoints->end())
+ breakpoints->erase(breakpoints->find(blockNumber));
} else {
- if (brkptIter != m_breakpoints.end()) {
- m_breakpoints.erase(brkptIter);
+ if (brkptIter != breakpoints->end()) {
+ breakpoints->erase(brkptIter);
} else {
- m_breakpoints.insert(blockNumber);
+ breakpoints->insert(blockNumber);
}
}
repaint();

MODIFY
src/codeeditor.h
src/codeeditor.h
@@ -25,7 +25,7 @@ public:
void lineNumberAreaPaintEvent(QPaintEvent* event);
void breakpointAreaPaintEvent(QPaintEvent* event);
void breakpointClick(QMouseEvent* event, int forceState = 0);
- void clearBreakpoints() { m_breakpoints.clear(); }
+ void clearBreakpoints();
void updateBreakpoints();
int lineNumberAreaWidth();
void setupSyntaxHighlighter();
@@ -63,7 +63,6 @@ private:
bool m_syntaxChecking = false;
bool m_breakpointAreaEnabled = false;
- std::set<int> m_breakpoints;
QMap<int, QString> m_tooltipForLine;
QFont m_font = font();

MODIFY
src/pipeline.cpp
src/pipeline.cpp
@@ -782,7 +782,6 @@ void Pipeline::reset() {
restart();
m_memory.clear();
m_dataMemory.clear();
- m_breakpoints.clear();
m_textSize = 0;
m_ready = false;
}

MODIFY
src/pipeline.h
src/pipeline.h
@@ -20,6 +20,7 @@ public:
int run();
// Pointers for GUI
+ std::set<uint32_t>* getBreakpoints() { return &m_breakpoints; }
MainMemory* getMemoryPtr() { return &m_memory; }
std::unordered_map<uint32_t, uint8_t>* getDataMemoryPtr() { return &m_dataMemory; }
std::vector<uint32_t>* getRegPtr() { return m_reg.getRegPtr(); }

Share breakpoints in editor and simulator