Skip to content

Commit cccf067

Browse files
authored
Merge pull request #125 from pvmm/master
support labels in BreakpointViewer
2 parents d3d3b4b + 56d9f71 commit cccf067

File tree

4 files changed

+75
-25
lines changed

4 files changed

+75
-25
lines changed

src/BreakpointViewer.cpp

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "BreakpointViewer.h"
22
#include "Convert.h"
33
#include "CommClient.h"
4+
#include "DebugSession.h"
45
#include "OpenMSXConnection.h"
56
#include "ScopedAssign.h"
67
#include "ranges.h"
@@ -17,17 +18,18 @@ enum TableColumns {
1718
ENABLED = 0,
1819
WP_TYPE = 1,
1920
LOCATION = 2,
20-
BP_ADDRESS = 2,
2121
WP_REGION = 2,
2222
T_CONDITION = 3,
2323
SLOT = 4,
2424
SEGMENT = 5,
25-
ID = 6
25+
ID = 6,
26+
BP_ADDRESS = 7,
2627
};
2728

28-
BreakpointViewer::BreakpointViewer(QWidget* parent)
29-
: QTabWidget(parent),
30-
ui(new Ui::BreakpointViewer)
29+
BreakpointViewer::BreakpointViewer(DebugSession& session, QWidget* parent)
30+
: QTabWidget(parent),
31+
ui(new Ui::BreakpointViewer),
32+
debugSession(session)
3133
{
3234
setupUi(this);
3335

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

4143
bpTableWidget->horizontalHeader()->setHighlightSections(false);
42-
bpTableWidget->sortByColumn(BP_ADDRESS, Qt::AscendingOrder);
44+
bpTableWidget->sortByColumn(LOCATION, Qt::AscendingOrder);
4345
bpTableWidget->setColumnHidden(WP_TYPE, true);
4446
bpTableWidget->setColumnHidden(ID, true);
47+
bpTableWidget->setColumnHidden(BP_ADDRESS, true);
4548
bpTableWidget->resizeColumnsToContents();
4649
bpTableWidget->setSortingEnabled(true);
4750
connect(bpTableWidget, &QTableWidget::itemPressed, this, &BreakpointViewer::on_itemPressed);
@@ -254,7 +257,7 @@ void BreakpointViewer::setBreakpointChecked(BreakpointRef::Type type, int row, Q
254257
table->setSortingEnabled(oldValue);
255258
}
256259

257-
void BreakpointViewer::setTextField(BreakpointRef::Type type, int row, int column, const QString& value)
260+
void BreakpointViewer::setTextField(BreakpointRef::Type type, int row, int column, const QString& value, const QString& tooltip)
258261
{
259262
auto sa = ScopedAssign(userMode, false);
260263

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

265268
table->setSortingEnabled(false);
266269
item->setText(value);
270+
item->setToolTip(tooltip);
267271
table->setSortingEnabled(oldValue);
268272
}
269273

@@ -309,13 +313,24 @@ std::optional<uint8_t> BreakpointViewer::parseSegmentField(std::optional<int> in
309313
return {};
310314
}
311315

316+
std::optional<AddressRange> BreakpointViewer::parseSymbolOrValue(const QString& field) const
317+
{
318+
if (Symbol* s = debugSession.symbolTable().getAddressSymbol(field)) {
319+
return AddressRange{uint16_t(s->value())};
320+
}
321+
if (auto address = stringToValue<uint16_t>(field)) {
322+
return AddressRange{*address};
323+
}
324+
return {};
325+
}
326+
312327
static const char* ComboTypeNames[] = { "read_mem", "write_mem", "read_io", "write_io" };
313328

314329
std::optional<AddressRange> BreakpointViewer::parseLocationField(
315330
std::optional<int> index, BreakpointRef::Type type, const QString& field, const QString& comboTxt)
316331
{
317332
if (type == BreakpointRef::BREAKPOINT) {
318-
auto value = stringToValue<uint16_t>(field);
333+
auto value = parseSymbolOrValue(field);
319334
return value ? AddressRange{*value}
320335
: (index ? breakpoints->getBreakpoint(*index).range : std::optional<AddressRange>());
321336
}
@@ -367,27 +382,34 @@ void BreakpointViewer::changeTableItem(BreakpointRef::Type type, QTableWidgetIte
367382
case LOCATION: {
368383
auto* model = table->model();
369384
auto* combo = (QComboBox*) table->indexWidget(model->index(row, WP_TYPE));
370-
int adrLen;
385+
int adrLen;
371386

372387
if (type == BreakpointRef::CONDITION) {
373388
return;
374389
} else if (type == BreakpointRef::WATCHPOINT) {
375390
auto wType = static_cast<Breakpoint::Type>(combo->currentIndex() + 1);
376391
adrLen = (wType == Breakpoint::WATCHPOINT_IOREAD || wType == Breakpoint::WATCHPOINT_IOWRITE)
377-
? 2 : 4;
392+
? 2 : 4;
378393
} else {
379394
adrLen = 4;
380395
}
381396

382397
if (auto range = parseLocationField(index, type, item->text(), combo ? combo->currentText() : "")) {
383398
auto [begin, end] = *range;
384-
setTextField(type, row, LOCATION, QString("%1%2%3")
385-
.arg(hexValue(begin, adrLen))
386-
.arg(end ? ":" : "")
387-
.arg(end ? hexValue(*end, adrLen) : ""));
399+
QString address = QString("%1%2%3")
400+
.arg(hexValue(begin, adrLen))
401+
.arg(end ? ":" : "")
402+
.arg(end ? hexValue(*end, adrLen) : "");
403+
setTextField(type, row, BP_ADDRESS, address);
404+
405+
// Use a symbolic address in the location field if available
406+
QString location = ((type == BreakpointRef::BREAKPOINT) && debugSession.symbolTable().getAddressSymbol(item->text()))
407+
? item->text() : address;
408+
setTextField(type, row, LOCATION, location, location != address ? address : "");
388409
} else {
389410
enabled = false;
390411
setTextField(type, row, LOCATION, "");
412+
setTextField(type, row, BP_ADDRESS, "");
391413
setBreakpointChecked(type, row, Qt::Unchecked);
392414
}
393415
if (!enabled) return;
@@ -706,7 +728,7 @@ int BreakpointViewer::createTableRow(BreakpointRef::Type type, int row)
706728
createComboBox(row);
707729
}
708730

709-
// address
731+
// location
710732
auto* item2 = new QTableWidgetItem();
711733
item2->setTextAlignment(Qt::AlignCenter);
712734
table->setItem(row, LOCATION, item2);
@@ -742,6 +764,14 @@ int BreakpointViewer::createTableRow(BreakpointRef::Type type, int row)
742764
item6->setText("");
743765
table->setItem(row, ID, item6);
744766

767+
// bp_address
768+
if (type == BreakpointRef::BREAKPOINT) {
769+
auto* item7 = new QTableWidgetItem();
770+
item7->setFlags(Qt::NoItemFlags);
771+
item7->setText("");
772+
table->setItem(row, BP_ADDRESS, item7);
773+
}
774+
745775
return row;
746776
}
747777

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

765-
// location
766-
int locLen = (bp.type == Breakpoint::WATCHPOINT_IOREAD
767-
|| bp.type == Breakpoint::WATCHPOINT_IOWRITE) ? 2 : 4;
768-
QString location = QString("%1%2%3").arg(hexValue(bp.range->start, locLen))
769-
.arg(bp.range->end ? ":" : "")
770-
.arg(bp.range->end ? hexValue(*bp.range->end, locLen) : "");
771-
772795
// location
773796
auto* item2 = table->item(row, LOCATION);
797+
QString location;
798+
799+
if (bp.type == Breakpoint::BREAKPOINT) {
800+
if (Symbol* s = debugSession.symbolTable().getAddressSymbol(item2->text())) {
801+
if (s->value() == bp.range->start) {
802+
location = s->text();
803+
}
804+
}
805+
}
806+
if (location.isEmpty()) {
807+
int locLen = (bp.type == Breakpoint::WATCHPOINT_IOREAD
808+
|| bp.type == Breakpoint::WATCHPOINT_IOWRITE) ? 2 : 4;
809+
location = QString("%1%2%3").arg(hexValue(bp.range->start, locLen))
810+
.arg(bp.range->end ? ":" : "")
811+
.arg(bp.range->end ? hexValue(*bp.range->end, locLen) : "");
812+
}
774813
item2->setText(location);
775814

776815
auto* item3 = table->item(row, T_CONDITION);

src/BreakpointViewer.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
class QPaintEvent;
1212
class Breakpoints;
13+
class DebugSession;
1314

1415
struct BreakpointRef {
1516
enum Type { BREAKPOINT, WATCHPOINT, CONDITION, ALL } type;
@@ -24,7 +25,7 @@ class BreakpointViewer : public QTabWidget, private Ui::BreakpointViewer
2425
{
2526
Q_OBJECT
2627
public:
27-
BreakpointViewer(QWidget* parent = nullptr);
28+
BreakpointViewer(DebugSession& session, QWidget* parent = nullptr);
2829
void setBreakpoints(Breakpoints* bps);
2930

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

4445
private:
45-
void setTextField(BreakpointRef::Type type, int row, int column, const QString& value);
46+
void setTextField(BreakpointRef::Type type, int row, int column, const QString& value, const QString& tooltip = {});
47+
48+
std::optional<AddressRange> parseSymbolOrValue(const QString& field) const;
49+
4650
std::optional<AddressRange> parseLocationField(std::optional<int> index,
4751
BreakpointRef::Type type,
4852
const QString& field,
@@ -86,6 +90,8 @@ class BreakpointViewer : public QTabWidget, private Ui::BreakpointViewer
8690

8791
private:
8892
Ui::BreakpointViewer* ui;
93+
DebugSession& debugSession;
94+
8995
QTableWidget* tables[BreakpointRef::ALL];
9096
std::map<QString, BreakpointRef> maps[BreakpointRef::ALL];
9197

src/BreakpointViewer.ui

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@
115115
<string>#</string>
116116
</property>
117117
</column>
118+
<column>
119+
<property name="text">
120+
<string>real_addr</string>
121+
</property>
122+
</column>
118123
</widget>
119124
</item>
120125
<item>

src/DebuggerForm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ void DebuggerForm::createForm()
566566
connect(dw, &DockableWidget::visibilityChanged, this, &DebuggerForm::dockWidgetVisibilityChanged);
567567

568568
// create breakpoints viewer
569-
bpView = new BreakpointViewer(this);
569+
bpView = new BreakpointViewer(session, this);
570570
dw = new DockableWidget(dockMan);
571571
dw->setWidget(bpView);
572572
dw->setTitle(tr("Debug list"));

0 commit comments

Comments
 (0)