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+
312327static const char * ComboTypeNames[] = { " read_mem" , " write_mem" , " read_io" , " write_io" };
313328
314329std::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);
0 commit comments