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
83 changes: 61 additions & 22 deletions src/BreakpointViewer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "BreakpointViewer.h"
#include "Convert.h"
#include "CommClient.h"
#include "DebugSession.h"
#include "OpenMSXConnection.h"
#include "ScopedAssign.h"
#include "ranges.h"
Expand All @@ -17,17 +18,18 @@ enum TableColumns {
ENABLED = 0,
WP_TYPE = 1,
LOCATION = 2,
BP_ADDRESS = 2,
WP_REGION = 2,
T_CONDITION = 3,
SLOT = 4,
SEGMENT = 5,
ID = 6
ID = 6,
BP_ADDRESS = 7,
};

BreakpointViewer::BreakpointViewer(QWidget* parent)
: QTabWidget(parent),
ui(new Ui::BreakpointViewer)
BreakpointViewer::BreakpointViewer(DebugSession& session, QWidget* parent)
: QTabWidget(parent),
ui(new Ui::BreakpointViewer),
debugSession(session)
{
setupUi(this);

Expand All @@ -39,9 +41,10 @@ BreakpointViewer::BreakpointViewer(QWidget* parent)
connect(btnRemoveCn, &QPushButton::clicked, this, &BreakpointViewer::on_btnRemoveCn_clicked);

bpTableWidget->horizontalHeader()->setHighlightSections(false);
bpTableWidget->sortByColumn(BP_ADDRESS, Qt::AscendingOrder);
bpTableWidget->sortByColumn(LOCATION, Qt::AscendingOrder);
bpTableWidget->setColumnHidden(WP_TYPE, true);
bpTableWidget->setColumnHidden(ID, true);
bpTableWidget->setColumnHidden(BP_ADDRESS, true);
bpTableWidget->resizeColumnsToContents();
bpTableWidget->setSortingEnabled(true);
connect(bpTableWidget, &QTableWidget::itemPressed, this, &BreakpointViewer::on_itemPressed);
Expand Down Expand Up @@ -254,7 +257,7 @@ void BreakpointViewer::setBreakpointChecked(BreakpointRef::Type type, int row, Q
table->setSortingEnabled(oldValue);
}

void BreakpointViewer::setTextField(BreakpointRef::Type type, int row, int column, const QString& value)
void BreakpointViewer::setTextField(BreakpointRef::Type type, int row, int column, const QString& value, const QString& tooltip)
{
auto sa = ScopedAssign(userMode, false);

Expand All @@ -264,6 +267,7 @@ void BreakpointViewer::setTextField(BreakpointRef::Type type, int row, int colum

table->setSortingEnabled(false);
item->setText(value);
item->setToolTip(tooltip);
table->setSortingEnabled(oldValue);
}

Expand Down Expand Up @@ -309,13 +313,24 @@ std::optional<uint8_t> BreakpointViewer::parseSegmentField(std::optional<int> in
return {};
}

std::optional<AddressRange> BreakpointViewer::parseSymbolOrValue(const QString& field) const
{
if (Symbol* s = debugSession.symbolTable().getAddressSymbol(field)) {
return AddressRange{uint16_t(s->value())};
}
if (auto address = stringToValue<uint16_t>(field)) {
return AddressRange{*address};
}
return {};
}

static const char* ComboTypeNames[] = { "read_mem", "write_mem", "read_io", "write_io" };

std::optional<AddressRange> BreakpointViewer::parseLocationField(
std::optional<int> index, BreakpointRef::Type type, const QString& field, const QString& comboTxt)
{
if (type == BreakpointRef::BREAKPOINT) {
auto value = stringToValue<uint16_t>(field);
auto value = parseSymbolOrValue(field);
return value ? AddressRange{*value}
: (index ? breakpoints->getBreakpoint(*index).range : std::optional<AddressRange>());
}
Expand Down Expand Up @@ -367,27 +382,34 @@ void BreakpointViewer::changeTableItem(BreakpointRef::Type type, QTableWidgetIte
case LOCATION: {
auto* model = table->model();
auto* combo = (QComboBox*) table->indexWidget(model->index(row, WP_TYPE));
int adrLen;
int adrLen;

if (type == BreakpointRef::CONDITION) {
return;
} else if (type == BreakpointRef::WATCHPOINT) {
auto wType = static_cast<Breakpoint::Type>(combo->currentIndex() + 1);
adrLen = (wType == Breakpoint::WATCHPOINT_IOREAD || wType == Breakpoint::WATCHPOINT_IOWRITE)
? 2 : 4;
? 2 : 4;
} else {
adrLen = 4;
}

if (auto range = parseLocationField(index, type, item->text(), combo ? combo->currentText() : "")) {
auto [begin, end] = *range;
setTextField(type, row, LOCATION, QString("%1%2%3")
.arg(hexValue(begin, adrLen))
.arg(end ? ":" : "")
.arg(end ? hexValue(*end, adrLen) : ""));
QString address = QString("%1%2%3")
.arg(hexValue(begin, adrLen))
.arg(end ? ":" : "")
.arg(end ? hexValue(*end, adrLen) : "");
setTextField(type, row, BP_ADDRESS, address);

// Use a symbolic address in the location field if available
QString location = ((type == BreakpointRef::BREAKPOINT) && debugSession.symbolTable().getAddressSymbol(item->text()))
? item->text() : address;
setTextField(type, row, LOCATION, location, location != address ? address : "");
} else {
enabled = false;
setTextField(type, row, LOCATION, "");
setTextField(type, row, BP_ADDRESS, "");
setBreakpointChecked(type, row, Qt::Unchecked);
}
if (!enabled) return;
Expand Down Expand Up @@ -706,7 +728,7 @@ int BreakpointViewer::createTableRow(BreakpointRef::Type type, int row)
createComboBox(row);
}

// address
// location
auto* item2 = new QTableWidgetItem();
item2->setTextAlignment(Qt::AlignCenter);
table->setItem(row, LOCATION, item2);
Expand Down Expand Up @@ -742,6 +764,14 @@ int BreakpointViewer::createTableRow(BreakpointRef::Type type, int row)
item6->setText("");
table->setItem(row, ID, item6);

// bp_address
if (type == BreakpointRef::BREAKPOINT) {
auto* item7 = new QTableWidgetItem();
item7->setFlags(Qt::NoItemFlags);
item7->setText("");
table->setItem(row, BP_ADDRESS, item7);
}

return row;
}

Expand All @@ -762,15 +792,24 @@ void BreakpointViewer::fillTableRow(int index, BreakpointRef::Type type, int row
combo->setCurrentIndex(static_cast<int>(bp.type) - 1);
}

// location
int locLen = (bp.type == Breakpoint::WATCHPOINT_IOREAD
|| bp.type == Breakpoint::WATCHPOINT_IOWRITE) ? 2 : 4;
QString location = QString("%1%2%3").arg(hexValue(bp.range->start, locLen))
.arg(bp.range->end ? ":" : "")
.arg(bp.range->end ? hexValue(*bp.range->end, locLen) : "");

// location
auto* item2 = table->item(row, LOCATION);
QString location;

if (bp.type == Breakpoint::BREAKPOINT) {
if (Symbol* s = debugSession.symbolTable().getAddressSymbol(item2->text())) {
if (s->value() == bp.range->start) {
location = s->text();
}
}
}
if (location.isEmpty()) {
int locLen = (bp.type == Breakpoint::WATCHPOINT_IOREAD
|| bp.type == Breakpoint::WATCHPOINT_IOWRITE) ? 2 : 4;
location = QString("%1%2%3").arg(hexValue(bp.range->start, locLen))
.arg(bp.range->end ? ":" : "")
.arg(bp.range->end ? hexValue(*bp.range->end, locLen) : "");
}
item2->setText(location);

auto* item3 = table->item(row, T_CONDITION);
Expand Down
10 changes: 8 additions & 2 deletions src/BreakpointViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class QPaintEvent;
class Breakpoints;
class DebugSession;

struct BreakpointRef {
enum Type { BREAKPOINT, WATCHPOINT, CONDITION, ALL } type;
Expand All @@ -24,7 +25,7 @@ class BreakpointViewer : public QTabWidget, private Ui::BreakpointViewer
{
Q_OBJECT
public:
BreakpointViewer(QWidget* parent = nullptr);
BreakpointViewer(DebugSession& session, QWidget* parent = nullptr);
void setBreakpoints(Breakpoints* bps);

void on_btnAddBp_clicked();
Expand All @@ -42,7 +43,10 @@ class BreakpointViewer : public QTabWidget, private Ui::BreakpointViewer
void contentsUpdated(bool merge);

private:
void setTextField(BreakpointRef::Type type, int row, int column, const QString& value);
void setTextField(BreakpointRef::Type type, int row, int column, const QString& value, const QString& tooltip = {});

std::optional<AddressRange> parseSymbolOrValue(const QString& field) const;

std::optional<AddressRange> parseLocationField(std::optional<int> index,
BreakpointRef::Type type,
const QString& field,
Expand Down Expand Up @@ -86,6 +90,8 @@ class BreakpointViewer : public QTabWidget, private Ui::BreakpointViewer

private:
Ui::BreakpointViewer* ui;
DebugSession& debugSession;

QTableWidget* tables[BreakpointRef::ALL];
std::map<QString, BreakpointRef> maps[BreakpointRef::ALL];

Expand Down
5 changes: 5 additions & 0 deletions src/BreakpointViewer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
<string>#</string>
</property>
</column>
<column>
<property name="text">
<string>real_addr</string>
</property>
</column>
</widget>
</item>
<item>
Expand Down
2 changes: 1 addition & 1 deletion src/DebuggerForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ void DebuggerForm::createForm()
connect(dw, &DockableWidget::visibilityChanged, this, &DebuggerForm::dockWidgetVisibilityChanged);

// create breakpoints viewer
bpView = new BreakpointViewer(this);
bpView = new BreakpointViewer(session, this);
dw = new DockableWidget(dockMan);
dw->setWidget(bpView);
dw->setTitle(tr("Debug list"));
Expand Down