-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathDebuggerForm.cpp
More file actions
1688 lines (1484 loc) · 53.7 KB
/
DebuggerForm.cpp
File metadata and controls
1688 lines (1484 loc) · 53.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "DebuggerForm.h"
#include "BitMapViewer.h"
#include "TileViewer.h"
#include "SpriteViewer.h"
#include "DockableWidget.h"
#include "DisasmViewer.h"
#include "MainMemoryViewer.h"
#include "CPURegsViewer.h"
#include "FlagsViewer.h"
#include "StackViewer.h"
#include "SlotViewer.h"
#include "BreakpointViewer.h"
#include "CommClient.h"
#include "ConnectDialog.h"
#include "SymbolManager.h"
#include "PreferencesDialog.h"
#include "BreakpointDialog.h"
#include "CommandDialog.h"
#include "GotoDialog.h"
#include "DebuggableViewer.h"
#include "VDPRegViewer.h"
#include "VDPStatusRegViewer.h"
#include "VDPCommandRegViewer.h"
#include "Settings.h"
#include "Version.h"
#include <QAction>
#include <QMessageBox>
#include <QMenu>
#include <QMenuBar>
#include <QToolBar>
#include <QStatusBar>
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QString>
#include <QStringList>
#include <QSplitter>
#include <QPixmap>
#include <QFileDialog>
#include <QCloseEvent>
#include <iostream>
class QueryPauseHandler : public SimpleCommand
{
public:
QueryPauseHandler(DebuggerForm& form_)
: SimpleCommand("set pause")
, form(form_)
{
}
void replyOk(const QString& message) override
{
// old openmsx versions returned 'on','false'
// new versions return 'true','false'
// so check for 'false'
bool checked = message.trimmed() != "false";
form.systemPauseAction->setChecked(checked);
delete this;
}
private:
DebuggerForm& form;
};
class QueryBreakedHandler : public SimpleCommand
{
public:
QueryBreakedHandler(DebuggerForm& form_)
: SimpleCommand("debug breaked")
, form(form_)
{
}
void replyOk(const QString& message) override
{
form.finalizeConnection(message.trimmed() == "1");
delete this;
}
private:
DebuggerForm& form;
};
class CPURegRequest : public ReadDebugBlockCommand
{
public:
CPURegRequest(DebuggerForm& form_)
: ReadDebugBlockCommand("{CPU regs}", 0, 28, buf)
, form(form_)
{
}
void replyOk(const QString& message) override
{
copyData(message);
form.regsView->setData(buf);
delete this;
}
private:
DebuggerForm& form;
uint8_t buf[28];
};
class ListDebuggablesHandler : public SimpleCommand
{
public:
ListDebuggablesHandler(DebuggerForm& form_)
: SimpleCommand("debug list")
, form(form_)
{
}
void replyOk(const QString& message) override
{
form.setDebuggables(message);
delete this;
}
private:
DebuggerForm& form;
};
class DebuggableSizeHandler : public SimpleCommand
{
public:
DebuggableSizeHandler(const QString& debuggable_, DebuggerForm& form_)
: SimpleCommand(QString("debug size %1").arg(debuggable_))
, debuggable(debuggable_)
, form(form_)
{
}
void replyOk(const QString& message) override
{
form.setDebuggableSize(debuggable, message.toInt());
delete this;
}
private:
QString debuggable;
DebuggerForm& form;
};
int DebuggerForm::counter = 0;
DebuggerForm::DebuggerForm(QWidget* parent)
: QMainWindow(parent)
, comm(CommClient::instance())
{
VDPRegView = nullptr;
VDPStatusRegView = nullptr;
VDPCommandRegView = nullptr;
createActions();
createMenus();
createToolbars();
createStatusbar();
createForm();
recentFiles = Settings::get().value("MainWindow/RecentFiles").toStringList();
updateRecentFiles();
connect(&session.symbolTable(), &SymbolTable::symbolFileChanged, this, &DebuggerForm::symbolFileChanged);
}
void DebuggerForm::createActions()
{
fileNewSessionAction = new QAction(tr("&New Session"), this);
fileNewSessionAction->setStatusTip(tr("Clear the current session."));
fileOpenSessionAction = new QAction(tr("&Open Session ..."), this);
fileOpenSessionAction->setShortcut(tr("Ctrl+O"));
fileOpenSessionAction->setStatusTip(tr("Clear the current session."));
fileSaveSessionAction = new QAction(tr("&Save Session"), this);
fileSaveSessionAction->setShortcut(tr("Ctrl+S"));
fileSaveSessionAction->setStatusTip(tr("Save the the current debug session"));
fileSaveSessionAsAction = new QAction(tr("Save Session &As"), this);
fileSaveSessionAsAction->setStatusTip(tr("Save the debug session in a selected file"));
fileQuitAction = new QAction(tr("&Quit"), this);
fileQuitAction->setShortcut(tr("Ctrl+Q"));
fileQuitAction->setStatusTip(tr("Quit the openMSX debugger"));
for (auto& rfa : recentFileActions) {
rfa = new QAction(this);
connect(rfa, &QAction::triggered, this, &DebuggerForm::fileRecentOpen);
}
copyCodeViewAction = new QAction(tr("Copy code view"));
copyCodeViewAction->setStatusTip(tr("Copy contents of Code View to the Clipboard"));
copyCodeViewAction->setEnabled(false);
systemConnectAction = new QAction(tr("&Connect"), this);
systemConnectAction->setShortcut(tr("Ctrl+C"));
systemConnectAction->setStatusTip(tr("Connect to openMSX"));
systemConnectAction->setIcon(QIcon(":/icons/connect.png"));
systemDisconnectAction = new QAction(tr("&Disconnect"), this);
systemDisconnectAction->setShortcut(tr(""));
systemDisconnectAction->setStatusTip(tr("Disconnect from openMSX"));
systemDisconnectAction->setIcon(QIcon(":/icons/disconnect.png"));
systemDisconnectAction->setEnabled(false);
systemPauseAction = new QAction(tr("&Pause emulator"), this);
systemPauseAction->setShortcut(Qt::Key_Pause);
systemPauseAction->setStatusTip(tr("Pause the emulation"));
systemPauseAction->setIcon(QIcon(":/icons/pause.png"));
systemPauseAction->setCheckable(true);
systemPauseAction->setEnabled(false);
systemRebootAction = new QAction(tr("&Reboot emulator"), this);
systemRebootAction->setStatusTip(tr("Reboot the emulation and start if needed"));
systemRebootAction->setEnabled(false);
systemSymbolManagerAction = new QAction(tr("&Symbol manager ..."), this);
systemSymbolManagerAction->setStatusTip(tr("Start the symbol manager"));
systemSymbolManagerAction->setIcon(QIcon(":/icons/symmanager.png"));
systemPreferencesAction = new QAction(tr("Pre&ferences ..."), this);
systemPreferencesAction->setStatusTip(tr("Set the global debugger preferences"));
searchGotoAction = new QAction(tr("&Goto ..."), this);
searchGotoAction->setStatusTip(tr("Jump to a specific address or label in the disassembly view"));
searchGotoAction->setShortcut(tr("Ctrl+G"));
viewRegistersAction = new QAction(tr("CPU &Registers"), this);
viewRegistersAction->setStatusTip(tr("Toggle the cpu registers display"));
viewRegistersAction->setCheckable(true);
viewBreakpointsAction = new QAction(tr("Debug &List"), this);
viewBreakpointsAction->setStatusTip(tr("Toggle the breakpoints/watchpoints display"));
viewBreakpointsAction->setCheckable(true);
viewFlagsAction = new QAction(tr("CPU &Flags"), this);
viewFlagsAction->setStatusTip(tr("Toggle the cpu flags display"));
viewFlagsAction->setCheckable(true);
viewStackAction = new QAction(tr("Stack"), this);
viewStackAction->setStatusTip(tr("Toggle the stack display"));
viewStackAction->setCheckable(true);
viewSlotsAction = new QAction(tr("Slots"), this);
viewSlotsAction->setStatusTip(tr("Toggle the slots display"));
viewSlotsAction->setCheckable(true);
viewMemoryAction = new QAction(tr("Memory"), this);
viewMemoryAction->setStatusTip(tr("Toggle the main memory display"));
viewMemoryAction->setCheckable(true);
viewDebuggableViewerAction = new QAction(tr("Add debuggable viewer"), this);
viewDebuggableViewerAction->setStatusTip(tr("Add a hex viewer for debuggables"));
viewVDPStatusRegsAction = new QAction(tr("Status Registers"), this);
viewVDPStatusRegsAction->setStatusTip(tr("The VDP status registers interpreted"));
viewVDPStatusRegsAction->setCheckable(true);
viewVDPCommandRegsAction = new QAction(tr("Command Registers"), this);
viewVDPCommandRegsAction->setStatusTip(tr("Interact with the VDP command registers"));
viewVDPCommandRegsAction->setCheckable(true);
viewVDPRegsAction = new QAction(tr("Registers"), this);
viewVDPRegsAction->setStatusTip(tr("Interact with the VDP registers"));
viewVDPRegsAction->setCheckable(true);
viewBitMappedAction = new QAction(tr("Bitmapped VRAM"), this);
viewBitMappedAction->setStatusTip(tr("Decode VRAM as screen 5/6/7/8 image"));
//viewBitMappedAction->setCheckable(true);
viewCharMappedAction = new QAction(tr("Tiles in VRAM"), this);
viewCharMappedAction->setStatusTip(tr("Decode VRAM as MSX1 screen tiles"));
viewSpritesAction = new QAction(tr("Sprites in VRAM"), this);
viewSpritesAction->setStatusTip(tr("Decode sprites tiles"));
executeBreakAction = new QAction(tr("Break"), this);
executeBreakAction->setShortcut(tr("CRTL+B"));
executeBreakAction->setStatusTip(tr("Halt the execution and enter debug mode"));
executeBreakAction->setIcon(QIcon(":/icons/break.png"));
executeBreakAction->setEnabled(false);
connect(this, &DebuggerForm::runStateEntered, [this]{ executeBreakAction->setEnabled(true); });
connect(this, &DebuggerForm::breakStateEntered, [this]{ executeBreakAction->setEnabled(false); });
executeRunAction = new QAction(tr("Run"), this);
executeRunAction->setShortcut(tr("F9"));
executeRunAction->setStatusTip(tr("Leave debug mode and resume execution"));
executeRunAction->setIcon(QIcon(":/icons/run.png"));
executeRunAction->setEnabled(false);
connect(this, &DebuggerForm::runStateEntered, [this]{ executeRunAction->setEnabled(false); });
connect(this, &DebuggerForm::breakStateEntered, [this]{ executeRunAction->setEnabled(true); });
executeStepAction = new QAction(tr("Step into"), this);
executeStepAction->setShortcut(tr("F7"));
executeStepAction->setStatusTip(tr("Execute a single instruction"));
executeStepAction->setIcon(QIcon(":/icons/stepinto.png"));
executeStepAction->setEnabled(false);
connect(this, &DebuggerForm::runStateEntered, [this]{ executeStepAction->setEnabled(false); });
connect(this, &DebuggerForm::breakStateEntered, [this]{ executeStepAction->setEnabled(true); });
executeStepOverAction = new QAction(tr("Step over"), this);
executeStepOverAction->setShortcut(tr("F8"));
executeStepOverAction->setStatusTip(tr("Execute the next instruction including any called subroutines"));
executeStepOverAction->setIcon(QIcon(":/icons/stepover.png"));
executeStepOverAction->setEnabled(false);
connect(this, &DebuggerForm::runStateEntered, [this]{ executeStepOverAction->setEnabled(false); });
connect(this, &DebuggerForm::breakStateEntered, [this]{ executeStepOverAction->setEnabled(true); });
executeStepOutAction = new QAction(tr("Step out"), this);
executeStepOutAction->setShortcut(tr("F11"));
executeStepOutAction->setStatusTip(tr("Resume execution until the current routine has finished"));
executeStepOutAction->setIcon(QIcon(":/icons/stepout.png"));
executeStepOutAction->setEnabled(false);
connect(this, &DebuggerForm::runStateEntered, [this]{ executeStepOutAction->setEnabled(false); });
connect(this, &DebuggerForm::breakStateEntered, [this]{ executeStepOutAction->setEnabled(true); });
executeStepBackAction = new QAction(tr("Step back"), this);
executeStepBackAction->setShortcut(tr("F12"));
executeStepBackAction->setStatusTip(tr("Reverse the last instruction"));
executeStepBackAction->setIcon(QIcon(":/icons/stepback.png"));
executeStepBackAction->setEnabled(false);
connect(this, &DebuggerForm::runStateEntered, [this]{ executeStepBackAction->setEnabled(false); });
connect(this, &DebuggerForm::breakStateEntered, [this]{ executeStepBackAction->setEnabled(true); });
executeRunToAction = new QAction(tr("Run to"), this);
executeRunToAction->setShortcut(tr("F4"));
executeRunToAction->setStatusTip(tr("Resume execution until the selected line is reached"));
executeRunToAction->setIcon(QIcon(":/icons/runto.png"));
executeRunToAction->setEnabled(false);
connect(this, &DebuggerForm::runStateEntered, [this]{ executeRunToAction->setEnabled(false); });
connect(this, &DebuggerForm::breakStateEntered, [this]{ executeRunToAction->setEnabled(true); });
breakpointToggleAction = new QAction(tr("Toggle"), this);
breakpointToggleAction->setShortcut(tr("F5"));
breakpointToggleAction->setStatusTip(tr("Toggle breakpoint on/off at cursor"));
breakpointToggleAction->setIcon(QIcon(":/icons/break.png"));
breakpointToggleAction->setEnabled(false);
commandAction = new QAction(tr("Manage command buttons..."), this);
commandAction->setStatusTip(tr("Add new Tcl-scripted command button"));
commandAction->setEnabled(false);
breakpointAddAction = new QAction(tr("Add ..."), this);
breakpointAddAction->setShortcut(tr("CTRL+B"));
breakpointAddAction->setStatusTip(tr("Add a breakpoint at a location"));
breakpointAddAction->setEnabled(false);
helpAboutAction = new QAction(tr("&About"), this);
helpAboutAction->setStatusTip(tr("Show the application information"));
connect(fileNewSessionAction, &QAction::triggered, this, &DebuggerForm::fileNewSession);
connect(fileOpenSessionAction, &QAction::triggered, this, &DebuggerForm::fileOpenSession);
connect(fileSaveSessionAction, &QAction::triggered, this, &DebuggerForm::fileSaveSession);
connect(fileSaveSessionAsAction, &QAction::triggered, this, &DebuggerForm::fileSaveSessionAs);
connect(fileQuitAction, &QAction::triggered, this, &DebuggerForm::close);
connect(copyCodeViewAction, &QAction::triggered, this, &DebuggerForm::copyCodeView);
connect(systemConnectAction, &QAction::triggered, this, &DebuggerForm::systemConnect);
connect(systemDisconnectAction, &QAction::triggered, this, &DebuggerForm::systemDisconnect);
connect(systemPauseAction, &QAction::triggered, this, &DebuggerForm::systemPause);
connect(systemRebootAction, &QAction::triggered, this, &DebuggerForm::systemReboot);
connect(systemSymbolManagerAction, &QAction::triggered, this, &DebuggerForm::systemSymbolManager);
connect(systemPreferencesAction, &QAction::triggered, this, &DebuggerForm::systemPreferences);
connect(searchGotoAction, &QAction::triggered, this, &DebuggerForm::searchGoto);
connect(viewRegistersAction, &QAction::triggered, this, &DebuggerForm::toggleRegisterDisplay);
connect(viewBreakpointsAction, &QAction::triggered, this, &DebuggerForm::toggleBreakpointsDisplay);
connect(viewFlagsAction, &QAction::triggered, this, &DebuggerForm::toggleFlagsDisplay);
connect(viewStackAction, &QAction::triggered, this, &DebuggerForm::toggleStackDisplay);
connect(viewSlotsAction, &QAction::triggered, this, &DebuggerForm::toggleSlotsDisplay);
connect(viewMemoryAction, &QAction::triggered, this, &DebuggerForm::toggleMemoryDisplay);
connect(viewDebuggableViewerAction, &QAction::triggered, this, &DebuggerForm::addDebuggableViewer);
connect(viewBitMappedAction, &QAction::triggered, this, &DebuggerForm::toggleBitMappedDisplay);
connect(viewCharMappedAction, &QAction::triggered, this, &DebuggerForm::toggleCharMappedDisplay);
connect(viewSpritesAction, &QAction::triggered, this, &DebuggerForm::toggleSpritesDisplay);
connect(viewVDPRegsAction, &QAction::triggered, this, &DebuggerForm::toggleVDPRegsDisplay);
connect(viewVDPCommandRegsAction, &QAction::triggered, this, &DebuggerForm::toggleVDPCommandRegsDisplay);
connect(viewVDPStatusRegsAction, &QAction::triggered, this, &DebuggerForm::toggleVDPStatusRegsDisplay);
connect(executeBreakAction, &QAction::triggered, this, &DebuggerForm::executeBreak);
connect(executeRunAction, &QAction::triggered, this, &DebuggerForm::executeRun);
connect(executeStepAction, &QAction::triggered, this, &DebuggerForm::executeStep);
connect(executeStepOverAction, &QAction::triggered, this, &DebuggerForm::executeStepOver);
connect(executeRunToAction, &QAction::triggered, this, &DebuggerForm::executeRunTo);
connect(executeStepOutAction, &QAction::triggered, this, &DebuggerForm::executeStepOut);
connect(executeStepBackAction, &QAction::triggered, this, &DebuggerForm::executeStepBack);
connect(breakpointToggleAction, &QAction::triggered, this, &DebuggerForm::toggleBreakpoint);
connect(breakpointAddAction, &QAction::triggered, this, &DebuggerForm::addBreakpoint);
connect(commandAction, &QAction::triggered, this, &DebuggerForm::manageCommandButtons);
connect(helpAboutAction, &QAction::triggered, this, &DebuggerForm::showAbout);
}
void DebuggerForm::createMenus()
{
// create file menu
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(fileNewSessionAction);
fileMenu->addAction(fileOpenSessionAction);
fileMenu->addAction(fileSaveSessionAction);
fileMenu->addAction(fileSaveSessionAsAction);
recentFileSeparator = fileMenu->addSeparator();
for (auto* rfa : recentFileActions)
fileMenu->addAction(rfa);
fileMenu->addSeparator();
fileMenu->addAction(fileQuitAction);
// create edit menu
editMenu = menuBar()->addMenu(tr("&Edit"));
editMenu->addAction(copyCodeViewAction);
// create system menu
systemMenu = menuBar()->addMenu(tr("&System"));
systemMenu->addAction(systemConnectAction);
systemMenu->addAction(systemDisconnectAction);
systemMenu->addSeparator();
systemMenu->addAction(systemPauseAction);
systemMenu->addSeparator();
systemMenu->addAction(systemRebootAction);
systemMenu->addSeparator();
systemMenu->addAction(systemSymbolManagerAction);
systemMenu->addSeparator();
systemMenu->addAction(systemPreferencesAction);
// create system menu
searchMenu = menuBar()->addMenu(tr("Se&arch"));
searchMenu->addAction(searchGotoAction);
// create view menu
viewMenu = menuBar()->addMenu(tr("&View"));
viewMenu->addAction(viewRegistersAction);
viewMenu->addAction(viewFlagsAction);
viewMenu->addAction(viewStackAction);
viewMenu->addAction(viewSlotsAction);
viewMenu->addAction(viewMemoryAction);
viewMenu->addAction(viewBreakpointsAction);
viewVDPDialogsMenu = viewMenu->addMenu("VDP");
viewMenu->addSeparator();
viewFloatingWidgetsMenu = viewMenu->addMenu("Floating widgets:");
viewMenu->addAction(viewDebuggableViewerAction);
connect(viewMenu, &QMenu::aboutToShow, this, &DebuggerForm::updateViewMenu);
// create VDP dialogs menu
viewVDPDialogsMenu->addAction(viewVDPRegsAction);
viewVDPDialogsMenu->addAction(viewVDPCommandRegsAction);
viewVDPDialogsMenu->addAction(viewVDPStatusRegsAction);
viewVDPDialogsMenu->addAction(viewBitMappedAction);
viewVDPDialogsMenu->addAction(viewCharMappedAction);
viewVDPDialogsMenu->addAction(viewSpritesAction);
connect(viewVDPDialogsMenu, &QMenu::aboutToShow, this, &DebuggerForm::updateVDPViewMenu);
// create Debuggable Viewers menu (so the user can focus an existing one)
connect(viewFloatingWidgetsMenu, &QMenu::aboutToShow, this, &DebuggerForm::updateViewFloatingWidgetsMenu);
// create execute menu
executeMenu = menuBar()->addMenu(tr("&Execute"));
executeMenu->addAction(executeBreakAction);
executeMenu->addAction(executeRunAction);
executeMenu->addSeparator();
executeMenu->addAction(executeStepAction);
executeMenu->addAction(executeStepOverAction);
executeMenu->addAction(executeStepOutAction);
executeMenu->addAction(executeStepBackAction);
executeMenu->addAction(executeRunToAction);
// create breakpoint menu
breakpointMenu = menuBar()->addMenu(tr("&Breakpoint"));
breakpointMenu->addAction(breakpointToggleAction);
breakpointMenu->addAction(breakpointAddAction);
// create command menu
commandMenu = menuBar()->addMenu("&Commands");
commandMenu->addAction(commandAction);
// create help menu
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(helpAboutAction);
}
void DebuggerForm::createToolbars()
{
// create debug toolbar
systemToolbar = addToolBar(tr("System"));
systemToolbar->addAction(systemConnectAction);
systemToolbar->addAction(systemDisconnectAction);
systemToolbar->addSeparator();
systemToolbar->addAction(systemPauseAction);
systemToolbar->addSeparator();
systemToolbar->addAction(systemSymbolManagerAction);
// create debug toolbar
executeToolbar = addToolBar(tr("Execution"));
executeToolbar->addAction(executeBreakAction);
executeToolbar->addAction(executeRunAction);
executeToolbar->addSeparator();
executeToolbar->addAction(executeStepAction);
executeToolbar->addAction(executeStepOverAction);
executeToolbar->addAction(executeStepOutAction);
executeToolbar->addAction(executeStepBackAction);
executeToolbar->addAction(executeRunToAction);
// create customised toolbar
userToolbar = addToolBar(tr("User defined"));
userToolbar->setEnabled(false);
connect(&comm, &CommClient::connectionReady, userToolbar, [this]{ userToolbar->setEnabled(true); });
connect(&comm, &CommClient::connectionTerminated, userToolbar, [this]{ userToolbar->setEnabled(false); });
updateCustomActions();
}
void DebuggerForm::updateCustomActions()
{
userToolbar->clear();
for (const auto& command : commands) {
auto* action = new QAction(command.name, this);
action->setStatusTip(command.description);
action->setIcon(QIcon(command.icon.isEmpty() ? ":/icons/gear.png" : command.icon));
connect(action, &QAction::triggered, [this, command]{ comm.sendCommand(new SimpleCommand(command.source)); });
userToolbar->addAction(action);
}
}
void DebuggerForm::createStatusbar()
{
// create the statusbar
statusBar()->showMessage("No emulation running.");
}
void DebuggerForm::createForm()
{
updateWindowTitle();
mainArea = std::make_unique<DockableWidgetArea>();
dockMan.addDockArea(mainArea.get());
setCentralWidget(mainArea.get());
// Create main widgets and append them to the list first
auto* dw = new DockableWidget(dockMan);
// create the disasm viewer widget
disasmView = new DisasmViewer();
dw->setWidget(disasmView);
dw->setTitle(tr("Code view"));
dw->setId("CODEVIEW");
dw->setFloating(false);
dw->setDestroyable(false);
dw->setMovable(false);
dw->setClosable(false);
connect(dw, &DockableWidget::visibilityChanged, this, &DebuggerForm::dockWidgetVisibilityChanged);
// create the memory view widget
mainMemoryView = new MainMemoryViewer();
dw = new DockableWidget(dockMan);
dw->setWidget(mainMemoryView);
dw->setTitle(tr("Main memory"));
dw->setId("MEMORY");
dw->setFloating(false);
dw->setDestroyable(false);
dw->setMovable(true);
dw->setClosable(true);
connect(dw, &DockableWidget::visibilityChanged, this, &DebuggerForm::dockWidgetVisibilityChanged);
// create register viewer
regsView = new CPURegsViewer();
dw = new DockableWidget(dockMan);
dw->setWidget(regsView);
dw->setTitle(tr("CPU registers"));
dw->setId("REGISTERS");
dw->setFloating(false);
dw->setDestroyable(false);
dw->setMovable(true);
dw->setClosable(true);
connect(dw, &DockableWidget::visibilityChanged, this, &DebuggerForm::dockWidgetVisibilityChanged);
// create flags viewer
flagsView = new FlagsViewer();
dw = new DockableWidget(dockMan);
dw->setWidget(flagsView);
dw->setTitle(tr("Flags"));
dw->setId("FLAGS");
dw->setFloating(false);
dw->setDestroyable(false);
dw->setMovable(true);
dw->setClosable(true);
connect(dw, &DockableWidget::visibilityChanged, this, &DebuggerForm::dockWidgetVisibilityChanged);
// create stack viewer
stackView = new StackViewer();
dw = new DockableWidget(dockMan);
dw->setWidget(stackView);
dw->setTitle(tr("Stack"));
dw->setId("STACK");
dw->setFloating(false);
dw->setDestroyable(false);
dw->setMovable(true);
dw->setClosable(true);
connect(dw, &DockableWidget::visibilityChanged, this, &DebuggerForm::dockWidgetVisibilityChanged);
// create slot viewer
slotView = new SlotViewer();
dw = new DockableWidget(dockMan);
dw->setWidget(slotView);
dw->setTitle(tr("Memory layout"));
dw->setId("SLOTS");
dw->setFloating(false);
dw->setDestroyable(false);
dw->setMovable(true);
dw->setClosable(true);
connect(dw, &DockableWidget::visibilityChanged, this, &DebuggerForm::dockWidgetVisibilityChanged);
// create breakpoints viewer
bpView = new BreakpointViewer(session, this);
dw = new DockableWidget(dockMan);
dw->setWidget(bpView);
dw->setTitle(tr("Debug list"));
dw->setId("DEBUG");
dw->setFloating(false);
dw->setDestroyable(false);
dw->setMovable(true);
dw->setClosable(true);
connect(dw, &DockableWidget::visibilityChanged, this, &DebuggerForm::dockWidgetVisibilityChanged);
// restore layout
restoreGeometry(Settings::get().value("Layout/WindowGeometry", saveGeometry()).toByteArray());
QStringList list = Settings::get().value("Layout/WidgetLayout").toStringList();
// defaults needed?
if (list.empty() || !list.at(0).startsWith("CODEVIEW ")) {
list.clear();
list.append("CODEVIEW D V R 0 -1 -1");
list.append("REGISTERS D V R 0 -1 -1");
list.append("FLAGS D V R 0 -1 -1");
int regW = dockMan.findDockableWidget("REGISTERS")->sizeHint().width();
int regH = dockMan.findDockableWidget("REGISTERS")->sizeHint().height();
list.append(QString("SLOTS D V R 0 -1 %1").arg(regH));
int codeW = dockMan.findDockableWidget("CODEVIEW")->sizeHint().width();
int codeH = dockMan.findDockableWidget("CODEVIEW")->sizeHint().height();
int flagW = dockMan.findDockableWidget("FLAGS")->sizeHint().width();
int slotW = dockMan.findDockableWidget("SLOTS")->sizeHint().width();
list.append(QString("STACK D V R 0 -1 %1").arg(codeH));
list.append(QString("MEMORY D V B %1 %2 %3").arg(codeW)
.arg(regW + flagW + slotW)
.arg(codeH - regH));
int stackW = dockMan.findDockableWidget("STACK")->sizeHint().width();
list.append(QString("DEBUG D V B %1 %2 -1").arg(codeW)
.arg(regW + flagW + slotW + stackW));
}
// restore commands
restoreCommands(Settings::get().value("Commands/Tcl", saveCommands()).toByteArray());
updateCustomActions();
// add widgets
for (int i = 0; i < list.size(); ++i) {
QStringList s = list.at(i).split(" ", Qt::SplitBehaviorFlags::SkipEmptyParts);
// get widget
if ((dw = dockMan.findDockableWidget(s.at(0)))) {
if (s.at(1) == "D") {
// dock widget
DockableWidgetLayout::DockSide side;
if (s.at(3) == "T") {
side = DockableWidgetLayout::TOP;
} else if (s.at(3) == "L") {
side = DockableWidgetLayout::LEFT;
} else if (s.at(3) == "R") {
side = DockableWidgetLayout::RIGHT;
} else {
side = DockableWidgetLayout::BOTTOM;
}
dockMan.insertWidget(dw, 0, side, s.at(4).toInt(),
s.at(5).toInt(), s.at(6).toInt());
if (s.at(2) == "H") dw->hide();
} else if (s.at(1) == "F") {
// float widget
dw->setFloating(true, s.at(2) == "V");
dw->resize(s.at(5).toInt(), s.at(6).toInt());
dw->move (s.at(3).toInt(), s.at(4).toInt());
}
}
}
// disable all widgets
connectionClosed();
// Disasm viewer
connect(disasmView, &DisasmViewer::breakpointToggled, this, &DebuggerForm::toggleBreakpointAddress);
connect(this, &DebuggerForm::connected, disasmView, &DisasmViewer::refresh);
connect(this, &DebuggerForm::symbolsChanged, disasmView, &DisasmViewer::refresh);
connect(this, &DebuggerForm::settingsChanged, disasmView, &DisasmViewer::updateLayout);
connect(this, &DebuggerForm::breakStateEntered, disasmView, &DisasmViewer::refresh);
// Main memory viewer
connect(this, &DebuggerForm::connected, mainMemoryView, &MainMemoryViewer::refresh);
connect(this, &DebuggerForm::breakStateEntered, mainMemoryView, &MainMemoryViewer::refresh);
// Slot viewer
connect(this, &DebuggerForm::connected, slotView, &SlotViewer::refresh);
connect(this, &DebuggerForm::breakStateEntered, slotView, &SlotViewer::refresh);
// Received status update back from widget after breakStateEntered/connected
connect(slotView, &SlotViewer::slotsUpdated, this, &DebuggerForm::onSlotsUpdated);
// Breakpoint viewer
connect(this, &DebuggerForm::breakpointsUpdated, bpView, &BreakpointViewer::refresh);
connect(this, &DebuggerForm::runStateEntered, bpView, &BreakpointViewer::setRunState);
connect(this, &DebuggerForm::breakStateEntered, bpView, &BreakpointViewer::setBreakState);
// CPU regs viewer
// Hook up the register viewer with the main memory viewer
connect(regsView, &CPURegsViewer::registerChanged, mainMemoryView, &MainMemoryViewer::registerChanged);
connect(regsView, &CPURegsViewer::flagsChanged, flagsView, &FlagsViewer::setFlags);
connect(regsView, &CPURegsViewer::spChanged, stackView, &StackViewer::setStackPointer);
// Received status update back from widgets after update
connect(regsView, &CPURegsViewer::pcChanged, this, &DebuggerForm::onPCChanged);
connect(&comm, &CommClient::connectionReady, this, &DebuggerForm::initConnection);
connect(&comm, &CommClient::updateParsed, this, &DebuggerForm::handleUpdate);
connect(&comm, &CommClient::connectionTerminated, this, &DebuggerForm::connectionClosed);
// init main memory
session.breakpoints().setMemoryLayout(&memLayout);
disasmView->setMemory(mainMemory);
disasmView->setBreakpoints(&session.breakpoints());
disasmView->setMemoryLayout(&memLayout);
disasmView->setSymbolTable(&session.symbolTable());
mainMemoryView->setRegsView(regsView);
mainMemoryView->setSymbolTable(&session.symbolTable());
mainMemoryView->setDebuggable("memory", 0x10000);
stackView->setData(mainMemory, 0x10000);
slotView->setMemoryLayout(&memLayout);
bpView->setBreakpoints(&session.breakpoints());
}
void DebuggerForm::closeEvent(QCloseEvent* e)
{
// handle unsaved session
fileNewSession();
// cancel if session is still modified
if (session.isModified()) {
e->ignore();
return;
}
// store commands
Settings::get().setValue("Commands/Tcl", saveCommands());
// store layout
Settings::get().setValue("Layout/WindowGeometry", saveGeometry());
QStringList layoutList;
// fill layout list with docked widgets
dockMan.getConfig(0, layoutList);
// append floating widgets
for (auto* widget : dockMan.managedWidgets()) {
if (widget->isFloating()) {
QString s("%1 F %2 %3 %4 %5 %6");
s = s.arg(widget->id());
if (widget->isHidden()) {
s = s.arg("H");
} else {
s = s.arg("V");
}
s = s.arg(widget->x()).arg(widget->y())
.arg(widget->width()).arg(widget->height());
layoutList.append(s);
}
widget->hide();
}
Settings::get().setValue("Layout/WidgetLayout", layoutList);
QMainWindow::closeEvent(e);
}
void DebuggerForm::updateRecentFiles()
{
// store settings
Settings::get().setValue("MainWindow/RecentFiles", recentFiles);
// update actions
for (int i = 0; i < MaxRecentFiles; i++)
if (i < recentFiles.size()) {
recentFileActions[i]->setVisible(true);
QString text = QString("&%1 %2").arg(i + 1).arg(QFileInfo(recentFiles[i]).fileName());
recentFileActions[i]->setText(text);
recentFileActions[i]->setData(recentFiles[i]);
} else {
recentFileActions[i]->setVisible(false);
}
// show separator only when recent files exist
recentFileSeparator->setVisible(!recentFiles.empty());
}
void DebuggerForm::addRecentFile(const QString& file)
{
recentFiles.removeAll(file);
recentFiles.prepend(file);
while (recentFiles.size() > MaxRecentFiles)
recentFiles.removeLast();
updateRecentFiles();
}
void DebuggerForm::removeRecentFile(const QString& file)
{
recentFiles.removeAll(file);
updateRecentFiles();
}
void DebuggerForm::updateWindowTitle()
{
QString title = "openMSX debugger [%1%2]";
if (session.existsAsFile()) {
title = title.arg(session.filename());
} else {
title = title.arg("unnamed session");
}
if (session.isModified()) {
title = title.arg('*');
} else {
title = title.arg("");
}
setWindowTitle(title);
}
void DebuggerForm::initConnection()
{
copyCodeViewAction->setEnabled(true);
systemConnectAction->setEnabled(false);
systemDisconnectAction->setEnabled(true);
comm.sendCommand(new QueryPauseHandler(*this));
comm.sendCommand(new QueryBreakedHandler(*this));
comm.sendCommand(new SimpleCommand("openmsx_update enable status"));
auto* command = new Command("openmsx_update enable debug",
[=](const QString& /*message*/) {},
[=](const QString& /*error*/) {
// force reload if debug is disabled
connect(bpView, &BreakpointViewer::contentsUpdated, this, [this]{ reloadBreakpoints(false); });
});
comm.sendCommand(command);
comm.sendCommand(new ListDebuggablesHandler(*this));
// define 'debug_bin2hex' proc for internal use
comm.sendCommand(new SimpleCommand(
"proc debug_bin2hex { input } {\n"
" set result \"\"\n"
" foreach i [split $input {}] {\n"
" append result [format %02X [scan $i %c]] \"\"\n"
" }\n"
" return $result\n"
"}\n"));
// define 'debug_hex2bin' proc for internal use
comm.sendCommand(new SimpleCommand(
"proc debug_hex2bin { input } {\n"
" set result \"\"\n"
" foreach {h l} [split $input {}] {\n"
" append result [binary format H2 $h$l] \"\"\n"
" }\n"
" return $result\n"
"}\n"));
// define 'debug_memmapper' proc for internal use
comm.sendCommand(new SimpleCommand(
"proc debug_memmapper { } {\n"
" set result \"\"\n"
" for { set page 0 } { $page < 4 } { incr page } {\n"
" set tmp [get_selected_slot $page]\n"
" append result [lindex $tmp 0] [lindex $tmp 1] \"\\n\"\n"
" if { [lsearch [debug list] \"MapperIO\"] != -1} {\n"
" append result [debug read \"MapperIO\" $page] \"\\n\"\n"
" } else {\n"
" append result \"0\\n\"\n"
" }\n"
" }\n"
" for { set ps 0 } { $ps < 4 } { incr ps } {\n"
" if [machine_info issubslotted $ps] {\n"
" append result \"1\\n\"\n"
" for { set ss 0 } { $ss < 4 } { incr ss } {\n"
" append result [get_mapper_size $ps $ss] \"\\n\"\n"
" }\n"
" } else {\n"
" append result \"0\\n\"\n"
" append result [get_mapper_size $ps 0] \"\\n\"\n"
" }\n"
" }\n"
" for { set page 0 } { $page < 4 } { incr page } {\n"
" set tmp [get_selected_slot $page]\n"
" set ss [lindex $tmp 1]\n"
" if { $ss == \"X\" } { set ss 0 }\n"
" set device_list [machine_info slot [lindex $tmp 0] $ss $page]\n"
" set name \"[lindex $device_list 0] romblocks\"\n"
" if { [lsearch [debug list] $name] != -1} {\n"
" append result \"[debug read $name [expr {$page * 0x4000}] ]\\n\"\n"
" append result \"[debug read $name [expr {$page * 0x4000 + 0x2000}] ]\\n\"\n"
" } else {\n"
" append result \"X\\nX\\n\"\n"
" }\n"
" }\n"
" return $result\n"
"}\n"));
// define 'debug_list_all_breaks' proc for internal use
comm.sendCommand(new SimpleCommand(
"proc debug_list_all_breaks { } {\n"
" set result [debug list_bp]\n"
" append result [debug list_watchpoints]\n"
" append result [debug list_conditions]\n"
" return $result\n"
"}\n"));
// define 'debug_check_debuggables' proc for internal use
comm.sendCommand(new SimpleCommand(
"proc debug_check_debuggables { debuggables } {\n"
" set all_debuggables [debug list]\n"
" lmap x $debuggables {expr {[lsearch $all_debuggables $x] >= 0}}\n"
"}\n"));
}
void DebuggerForm::connectionClosed()
{
systemPauseAction->setEnabled(false);
systemRebootAction->setEnabled(false);
executeBreakAction->setEnabled(false);
executeRunAction->setEnabled(false);
executeStepAction->setEnabled(false);
executeStepOverAction->setEnabled(false);
executeStepOutAction->setEnabled(false);
executeStepBackAction->setEnabled(false);
executeRunToAction->setEnabled(false);
copyCodeViewAction->setEnabled(false);
systemDisconnectAction->setEnabled(false);
systemConnectAction->setEnabled(true);
breakpointToggleAction->setEnabled(false);
breakpointAddAction->setEnabled(false);
commandAction->setEnabled(false);
for (auto* w : dockMan.managedWidgets()) {
w->widget()->setEnabled(false);
}
}
void DebuggerForm::finalizeConnection(bool halted)
{
systemPauseAction->setEnabled(true);
systemRebootAction->setEnabled(true);
breakpointToggleAction->setEnabled(true);
breakpointAddAction->setEnabled(true);
commandAction->setEnabled(true);
// merge breakpoints on connect
mergeBreakpoints = true;
if (halted) {
breakOccured();
} else {
setRunMode();
updateData();
}
emit connected();
for (auto* w : dockMan.managedWidgets()) {
w->widget()->setEnabled(true);
}
}
void DebuggerForm::handleUpdate(const QString& type, const QString& name,
const QString& message)
{
if (type == "debug") {
// TODO: read only new breakpoint
reloadBreakpoints(false);
} else if (type == "status") {
if (name == "cpu") {
// running state by default.
if (message == "suspended") {
breakOccured();
} else if (message == "running") {
emit runStateEntered();
updateData();
}
} else if (name == "paused") {
pauseStatusChanged(message == "true");
}
}
}
void DebuggerForm::pauseStatusChanged(bool isPaused)
{
systemPauseAction->setChecked(isPaused);
}
void DebuggerForm::breakOccured()
{
emit breakStateEntered();
updateData();
}
void DebuggerForm::updateData()
{
reloadBreakpoints(mergeBreakpoints);
// only merge the first time after connect
mergeBreakpoints = false;