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+ REAL_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 (REAL_ADDRESS, true );
4548 bpTableWidget->resizeColumnsToContents ();
4649 bpTableWidget->setSortingEnabled (true );
4750 connect (bpTableWidget, &QTableWidget::itemPressed, this , &BreakpointViewer::on_itemPressed);
@@ -51,6 +54,7 @@ BreakpointViewer::BreakpointViewer(QWidget* parent)
5154
5255 wpTableWidget->horizontalHeader ()->setHighlightSections (false );
5356 wpTableWidget->setColumnHidden (ID, true );
57+ wpTableWidget->setColumnHidden (REAL_ADDRESS, true );
5458 wpTableWidget->sortByColumn (WP_REGION, Qt::AscendingOrder);
5559 wpTableWidget->resizeColumnsToContents ();
5660 wpTableWidget->setSortingEnabled (true );
@@ -254,7 +258,7 @@ void BreakpointViewer::setBreakpointChecked(BreakpointRef::Type type, int row, Q
254258 table->setSortingEnabled (oldValue);
255259}
256260
257- void BreakpointViewer::setTextField (BreakpointRef::Type type, int row, int column, const QString& value)
261+ void BreakpointViewer::setTextField (BreakpointRef::Type type, int row, int column, const QString& value, const QString& tooltip )
258262{
259263 auto sa = ScopedAssign (userMode, false );
260264
@@ -264,6 +268,7 @@ void BreakpointViewer::setTextField(BreakpointRef::Type type, int row, int colum
264268
265269 table->setSortingEnabled (false );
266270 item->setText (value);
271+ item->setToolTip (tooltip);
267272 table->setSortingEnabled (oldValue);
268273}
269274
@@ -309,13 +314,24 @@ std::optional<uint8_t> BreakpointViewer::parseSegmentField(std::optional<int> in
309314 return {};
310315}
311316
317+ std::optional<AddressRange> BreakpointViewer::parseSymbolOrValue (const QString& field) const
318+ {
319+ if (Symbol* s = debugSession.symbolTable ().getAddressSymbol (field)) {
320+ return AddressRange{uint16_t (s->value ())};
321+ }
322+ if (auto address = stringToValue<uint16_t >(field)) {
323+ return AddressRange{*address};
324+ }
325+ return {};
326+ }
327+
312328static const char * ComboTypeNames[] = { " read_mem" , " write_mem" , " read_io" , " write_io" };
313329
314330std::optional<AddressRange> BreakpointViewer::parseLocationField (
315331 std::optional<int > index, BreakpointRef::Type type, const QString& field, const QString& comboTxt)
316332{
317333 if (type == BreakpointRef::BREAKPOINT) {
318- auto value = stringToValue< uint16_t > (field);
334+ auto value = parseSymbolOrValue (field);
319335 return value ? AddressRange{*value}
320336 : (index ? breakpoints->getBreakpoint (*index).range : std::optional<AddressRange>());
321337 }
@@ -367,27 +383,32 @@ void BreakpointViewer::changeTableItem(BreakpointRef::Type type, QTableWidgetIte
367383 case LOCATION: {
368384 auto * model = table->model ();
369385 auto * combo = (QComboBox*) table->indexWidget (model->index (row, WP_TYPE));
370- int adrLen;
386+ int adrLen;
371387
372388 if (type == BreakpointRef::CONDITION) {
373389 return ;
374390 } else if (type == BreakpointRef::WATCHPOINT) {
375391 auto wType = static_cast <Breakpoint::Type>(combo->currentIndex () + 1 );
376392 adrLen = (wType == Breakpoint::WATCHPOINT_IOREAD || wType == Breakpoint::WATCHPOINT_IOWRITE)
377- ? 2 : 4 ;
393+ ? 2 : 4 ;
378394 } else {
379395 adrLen = 4 ;
380396 }
381397
382398 if (auto range = parseLocationField (index, type, item->text (), combo ? combo->currentText () : " " )) {
383399 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) : " " ));
400+ QString address = QString (" %1%2%3" )
401+ .arg (hexValue (begin, adrLen))
402+ .arg (end ? " :" : " " )
403+ .arg (end ? hexValue (*end, adrLen) : " " );
404+ // Use a symbolic address in the location field if available
405+ QString location = debugSession.symbolTable ().getAddressSymbol (item->text ()) ? item->text () : address;
406+ setTextField (type, row, LOCATION, location, location != address ? address : " " );
407+ setTextField (type, row, REAL_ADDRESS, address);
388408 } else {
389409 enabled = false ;
390410 setTextField (type, row, LOCATION, " " );
411+ setTextField (type, row, REAL_ADDRESS, " " );
391412 setBreakpointChecked (type, row, Qt::Unchecked);
392413 }
393414 if (!enabled) return ;
@@ -706,7 +727,7 @@ int BreakpointViewer::createTableRow(BreakpointRef::Type type, int row)
706727 createComboBox (row);
707728 }
708729
709- // address
730+ // location
710731 auto * item2 = new QTableWidgetItem ();
711732 item2->setTextAlignment (Qt::AlignCenter);
712733 table->setItem (row, LOCATION, item2);
@@ -742,6 +763,12 @@ int BreakpointViewer::createTableRow(BreakpointRef::Type type, int row)
742763 item6->setText (" " );
743764 table->setItem (row, ID, item6);
744765
766+ // real_address
767+ auto * item7 = new QTableWidgetItem ();
768+ item7->setFlags (Qt::NoItemFlags);
769+ item7->setText (" " );
770+ table->setItem (row, REAL_ADDRESS, item7);
771+
745772 return row;
746773}
747774
@@ -762,15 +789,24 @@ void BreakpointViewer::fillTableRow(int index, BreakpointRef::Type type, int row
762789 combo->setCurrentIndex (static_cast <int >(bp.type ) - 1 );
763790 }
764791
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-
772792 // location
773793 auto * item2 = table->item (row, LOCATION);
794+ QString location;
795+
796+ if (bp.type == Breakpoint::BREAKPOINT) {
797+ if (Symbol* s = debugSession.symbolTable ().getAddressSymbol (item2->text ())) {
798+ if (s->value () == bp.range ->start ) {
799+ location = s->text ();
800+ }
801+ }
802+ }
803+ if (location.isEmpty ()) {
804+ int locLen = (bp.type == Breakpoint::WATCHPOINT_IOREAD
805+ || bp.type == Breakpoint::WATCHPOINT_IOWRITE) ? 2 : 4 ;
806+ location = QString (" %1%2%3" ).arg (hexValue (bp.range ->start , locLen))
807+ .arg (bp.range ->end ? " :" : " " )
808+ .arg (bp.range ->end ? hexValue (*bp.range ->end , locLen) : " " );
809+ }
774810 item2->setText (location);
775811
776812 auto * item3 = table->item (row, T_CONDITION);
@@ -817,6 +853,27 @@ std::optional<Breakpoint> BreakpointViewer::parseTableRow(BreakpointRef::Type ty
817853 return bp;
818854}
819855
856+
857+ void BreakpointViewer::onSymbolTableChanged ()
858+ {
859+ for (int row = 0 ; row < bpTableWidget->rowCount (); ++row) {
860+ auto * item = bpTableWidget->item (row, REAL_ADDRESS);
861+
862+ // scan tooltip validity
863+ if (!item->text ().isEmpty ()) {
864+ Symbol* s = debugSession.symbolTable ().getAddressSymbol (item->text ());
865+ auto address = stringToValue<uint16_t >(item->text ());
866+ assert (address);
867+
868+ if (!s || *address != s->value ()) {
869+ setTextField (BreakpointRef::BREAKPOINT, row, LOCATION, item->text ());
870+ setTextField (BreakpointRef::BREAKPOINT, row, REAL_ADDRESS, " " );
871+ }
872+ }
873+ }
874+ }
875+
876+
820877void BreakpointViewer::onAddBtnClicked (BreakpointRef::Type type)
821878{
822879 auto sa = ScopedAssign (userMode, false );
0 commit comments