-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathttdeventswidget.cpp
More file actions
1200 lines (1037 loc) · 39.5 KB
/
Copy pathttdeventswidget.cpp
File metadata and controls
1200 lines (1037 loc) · 39.5 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
/*
Copyright 2020-2026 Vector 35 Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "ttdeventswidget.h"
#include "ttdbookmarkwidget.h"
#include "ui.h"
#include <QGridLayout>
#include <QGroupBox>
#include <QMessageBox>
#include <QApplication>
#include <QHeaderView>
#include <QMenu>
#include <QClipboard>
#include <QCheckBox>
#include <QToolButton>
#include <QPropertyAnimation>
#include <QFrame>
#include <QFileInfo>
#include <map>
static uint64_t PositionSortValue(const TTDPosition& position)
{
return (position.sequence << 32) | (position.step & 0xFFFFFFFF);
}
// TTDEventsColumnVisibilityDialog implementation
TTDEventsColumnVisibilityDialog::TTDEventsColumnVisibilityDialog(QWidget* parent, const QStringList& columnNames, const QList<bool>& visibility)
: QDialog(parent)
{
setWindowTitle("Column Visibility");
setModal(true);
resize(300, 400);
QVBoxLayout* layout = new QVBoxLayout(this);
QLabel* label = new QLabel("Select columns to display:");
layout->addWidget(label);
m_columnList = new QListWidget();
for (int i = 0; i < columnNames.size(); ++i)
{
QListWidgetItem* item = new QListWidgetItem(columnNames[i]);
item->setCheckState(visibility[i] ? Qt::Checked : Qt::Unchecked);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
m_columnList->addItem(item);
}
layout->addWidget(m_columnList);
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults);
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
// Handle restore defaults
connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, [this]() {
// Reset to default visibility (show main columns, hide some detailed ones)
QList<bool> defaultVisibility;
defaultVisibility << true // Index
<< true // Event Type
<< true // Position
<< true // Thread ID
<< false // Thread Unique ID (hidden by default)
<< true // Module Name
<< true // Module Address
<< false // Module Size (hidden by default)
<< true // Exception Type
<< true // Exception Code
<< true; // Exception PC
for (int i = 0; i < m_columnList->count() && i < defaultVisibility.size(); ++i)
{
QListWidgetItem* item = m_columnList->item(i);
item->setCheckState(defaultVisibility[i] ? Qt::Checked : Qt::Unchecked);
}
});
layout->addWidget(buttons);
}
QList<bool> TTDEventsColumnVisibilityDialog::getColumnVisibility() const
{
QList<bool> visibility;
for (int i = 0; i < m_columnList->count(); ++i)
{
QListWidgetItem* item = m_columnList->item(i);
visibility.append(item->checkState() == Qt::Checked);
}
return visibility;
}
// TTDEventsQueryWidget implementation
TTDEventsQueryWidget::TTDEventsQueryWidget(QWidget* parent, BinaryViewRef data, WidgetType type)
: QWidget(parent), m_data(data), m_widgetType(type),
m_threadCreatedCheck(nullptr), m_threadTerminatedCheck(nullptr),
m_moduleLoadedCheck(nullptr), m_moduleUnloadedCheck(nullptr),
m_exceptionCheck(nullptr), m_queryButton(nullptr), m_clearButton(nullptr),
m_resultsTable(nullptr), m_statusLabel(nullptr), m_contextMenuManager(nullptr)
{
m_controller = DebuggerController::GetController(data);
if (!m_controller)
{
// Create a placeholder widget showing no controller available
QVBoxLayout* layout = new QVBoxLayout(this);
QLabel* label = new QLabel("No debugger controller available for TTD Events analysis.");
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
return;
}
setupUI();
setupTable();
setupUIActions();
setupContextMenu();
}
TTDEventsQueryWidget::~TTDEventsQueryWidget()
{
if (m_contextMenuManager)
{
delete m_contextMenuManager;
}
}
void TTDEventsQueryWidget::setupUI()
{
QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0); // Add padding like TTD memory/calls widget
// Only show input controls for AllEvents widget type
if (m_widgetType == AllEvents)
{
// Input controls
QGroupBox* inputGroup = new QGroupBox("Event Type Filters");
QVBoxLayout* inputLayout = new QVBoxLayout(inputGroup);
// Event type checkboxes
m_threadCreatedCheck = new QCheckBox("Thread Created");
m_threadCreatedCheck->setChecked(true);
connect(m_threadCreatedCheck, &QCheckBox::toggled, this, &TTDEventsQueryWidget::onFilterChanged);
inputLayout->addWidget(m_threadCreatedCheck);
m_threadTerminatedCheck = new QCheckBox("Thread Terminated");
m_threadTerminatedCheck->setChecked(true);
connect(m_threadTerminatedCheck, &QCheckBox::toggled, this, &TTDEventsQueryWidget::onFilterChanged);
inputLayout->addWidget(m_threadTerminatedCheck);
m_moduleLoadedCheck = new QCheckBox("Module Loaded");
m_moduleLoadedCheck->setChecked(true);
connect(m_moduleLoadedCheck, &QCheckBox::toggled, this, &TTDEventsQueryWidget::onFilterChanged);
inputLayout->addWidget(m_moduleLoadedCheck);
m_moduleUnloadedCheck = new QCheckBox("Module Unloaded");
m_moduleUnloadedCheck->setChecked(true);
connect(m_moduleUnloadedCheck, &QCheckBox::toggled, this, &TTDEventsQueryWidget::onFilterChanged);
inputLayout->addWidget(m_moduleUnloadedCheck);
m_exceptionCheck = new QCheckBox("Exception");
m_exceptionCheck->setChecked(true);
connect(m_exceptionCheck, &QCheckBox::toggled, this, &TTDEventsQueryWidget::onFilterChanged);
inputLayout->addWidget(m_exceptionCheck);
// Query buttons
QHBoxLayout* buttonLayout = new QHBoxLayout();
m_queryButton = new QPushButton("Query All TTD Events");
m_queryButton->setDefault(true);
connect(m_queryButton, &QPushButton::clicked, this, &TTDEventsQueryWidget::performQuery);
buttonLayout->addWidget(m_queryButton);
m_clearButton = new QPushButton("Clear Results");
connect(m_clearButton, &QPushButton::clicked, this, &TTDEventsQueryWidget::clearResults);
buttonLayout->addWidget(m_clearButton);
buttonLayout->addStretch();
inputLayout->addLayout(buttonLayout);
mainLayout->addWidget(inputGroup);
}
else
{
// For specialized widgets, initialize checkboxes as null pointers
m_threadCreatedCheck = nullptr;
m_threadTerminatedCheck = nullptr;
m_moduleLoadedCheck = nullptr;
m_moduleUnloadedCheck = nullptr;
m_exceptionCheck = nullptr;
m_queryButton = nullptr;
m_clearButton = nullptr;
}
// Results table
m_resultsTable = new QTableWidget();
mainLayout->addWidget(m_resultsTable, 1); // Give table most of the space
// Status label
m_statusLabel = new QLabel("Ready to query TTD events.");
m_statusLabel->setContentsMargins(5, 5, 5, 5); // Add padding around status text
mainLayout->addWidget(m_statusLabel);
// Connect double-click on table
connect(m_resultsTable, &QTableWidget::cellDoubleClicked, this, &TTDEventsQueryWidget::onCellDoubleClicked);
}
void TTDEventsQueryWidget::setupTable()
{
// Configure columns and visibility based on widget type
switch (m_widgetType)
{
case ModuleEvents:
m_columnNames << "Index" << "Position" << "Event Type" << "Name"
<< "Module Address" << "Module Size" << "Module Checksum" << "Module Timestamp" << "Path";
m_columnVisibility << true // Index
<< true // Position
<< true // Event Type
<< true // Name
<< true // Module Address
<< true // Module Size
<< false // Module Checksum (hidden by default)
<< false // Module Timestamp (hidden by default)
<< true; // Path (moved to last column)
break;
case ThreadEvents:
m_columnNames << "Index" << "Position" << "Event Type" << "Thread ID" << "Thread UniqueID"
<< "Lifetime Start" << "Lifetime End" << "Active Start" << "Active End";
m_columnVisibility << true // Index
<< true // Position
<< true // Event Type
<< true // Thread ID
<< true // Thread UniqueID
<< true // Lifetime Start
<< true // Lifetime End
<< true // Active Start
<< true; // Active End
break;
case ExceptionEvents:
m_columnNames << "Index" << "Position" << "Exception Type" << "Program Counter"
<< "Exception Code" << "Exception Flags" << "Record Address";
m_columnVisibility << true // Index
<< true // Position
<< true // Exception Type
<< true // Program Counter
<< true // Exception Code
<< true // Exception Flags
<< true; // Record Address
break;
default: // AllEvents
m_columnNames << "Index" << "Event Type" << "Position" << "Thread ID" << "Thread UniqueID"
<< "Module Name" << "Module Address" << "Module Size" << "Exception Type"
<< "Exception Code" << "Exception PC";
// Default column visibility (show main columns, hide some detailed ones)
m_columnVisibility << true // Index
<< true // Event Type
<< true // Position
<< true // Thread ID
<< false // Thread Unique ID (hidden by default)
<< true // Module Name
<< true // Module Address
<< false // Module Size (hidden by default)
<< true // Exception Type
<< true // Exception Code
<< true; // Exception PC
break;
}
m_resultsTable->setColumnCount(m_columnNames.size());
m_resultsTable->setHorizontalHeaderLabels(m_columnNames);
// Make cells non-editable
m_resultsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
// Hide the row numbers (vertical header) but keep the Index column
m_resultsTable->verticalHeader()->setVisible(false);
// Enable sorting
m_resultsTable->setSortingEnabled(true);
// Set selection behavior
m_resultsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
m_resultsTable->setAlternatingRowColors(true);
// Adjust column widths
QHeaderView* header = m_resultsTable->horizontalHeader();
header->setStretchLastSection(true);
header->setSectionResizeMode(QHeaderView::Interactive);
// Set context menu policy
m_resultsTable->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_resultsTable, &QTableWidget::customContextMenuRequested, this, &TTDEventsQueryWidget::showContextMenu);
// Apply initial column visibility
updateColumnVisibility();
}
void TTDEventsQueryWidget::updateColumnVisibility()
{
for (int i = 0; i < m_columnNames.size() && i < m_columnVisibility.size(); ++i)
{
m_resultsTable->setColumnHidden(i, !m_columnVisibility[i]);
}
}
void TTDEventsQueryWidget::updateStatus(const QString& message)
{
if (m_statusLabel)
{
m_statusLabel->setText(message);
}
}
void TTDEventsQueryWidget::setupUIActions()
{
m_actionHandler.setupActionHandler(this);
m_contextMenuManager = new ContextMenuManager(this);
// Add Copy action with Ctrl+C support
m_menu.addAction("Copy", "Options", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Copy", UIAction([&]() { copy(); }, [&]() { return canCopy(); }));
m_menu.addAction("Copy Row", "Options", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Copy Row", UIAction([&]() { copySelectedRow(); }, [&]() { return canCopy(); }));
m_menu.addAction("Copy Table", "Options", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Copy Table", UIAction([&]() { copyEntireTable(); }, [&]() { return m_resultsTable->rowCount() > 0; }));
m_menu.addAction("Column Visibility...", "Options", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Column Visibility...", UIAction([&]() { showColumnVisibilityDialog(); }));
m_menu.addAction("Reset Columns to Default", "Options", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Reset Columns to Default", UIAction([&]() { resetColumnsToDefault(); }));
// Refresh action to clear and re-query from backend
m_menu.addAction("Refresh", "Options", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Refresh", UIAction([&]() { refreshEvents(); }));
m_menu.addAction("Add TTD Bookmark...", "Bookmark", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Add TTD Bookmark...", UIAction([&]() {
int row = m_resultsTable->currentRow();
if (row < 0)
return;
// Find the Position column
int posCol = -1;
for (int c = 0; c < m_resultsTable->columnCount(); ++c)
{
auto* header = m_resultsTable->horizontalHeaderItem(c);
if (header && header->text().contains("Position", Qt::CaseInsensitive))
{
posCol = c;
break;
}
}
if (posCol < 0)
return;
QTableWidgetItem* posItem = m_resultsTable->item(row, posCol);
if (!posItem)
return;
QString posStr = posItem->text();
TTDBookmarkEditDialog dialog(this, posStr, "", "");
if (dialog.exec() == QDialog::Accepted)
{
QString editedPosStr = dialog.getPosition();
QStringList parts = editedPosStr.split(':');
if (parts.size() == 2)
{
bool ok1, ok2;
uint64_t seq = parts[0].toULongLong(&ok1, 16);
uint64_t stp = parts[1].toULongLong(&ok2, 16);
if (ok1 && ok2)
{
uint64_t addr = 0;
QString addrStr = dialog.getViewAddress();
if (!addrStr.isEmpty())
{
QString clean = addrStr.trimmed();
if (clean.startsWith("0x") || clean.startsWith("0X"))
clean = clean.mid(2);
bool aOk;
addr = clean.toULongLong(&aOk, 16);
if (!aOk)
addr = 0;
}
m_controller->AddTTDBookmark(TTDPosition(seq, stp), dialog.getNote().toStdString(), addr);
}
}
}
}, [&]() { return m_resultsTable && m_resultsTable->currentRow() >= 0; }));
}
void TTDEventsQueryWidget::setupContextMenu()
{
m_resultsTable->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_resultsTable, &QTableWidget::customContextMenuRequested,
this, &TTDEventsQueryWidget::showContextMenu);
}
void TTDEventsQueryWidget::performQuery()
{
if (!m_controller)
{
updateStatus("No debugger controller available.");
return;
}
if (!m_controller->IsConnected())
{
updateStatus("No active debugging session.");
return;
}
if (!m_controller->IsTTD())
{
updateStatus("No a TTD debugging session.");
return;
}
updateStatus("Querying all TTD events...");
// Only disable button if it exists (AllEvents widgets have buttons, specialized don't)
if (m_queryButton)
m_queryButton->setEnabled(false);
try
{
// Get all events and cache them
m_allEvents = m_controller->GetAllTTDEvents();
updateStatus(QString("Query completed. Loaded %1 total events.").arg(m_allEvents.size()));
// Filter and display events based on widget type
if (m_widgetType == AllEvents)
{
filterAndDisplayEvents();
}
else
{
filterAndDisplaySpecializedEvents();
}
}
catch (const std::exception& e)
{
updateStatus(QString("Query failed: %1").arg(e.what()));
QMessageBox::warning(this, "TTD Events Query Error", QString("Failed to query TTD events:\n%1").arg(e.what()));
}
// Only re-enable button if it exists
if (m_queryButton)
m_queryButton->setEnabled(true);
}
void TTDEventsQueryWidget::filterAndDisplayEvents()
{
if (m_allEvents.empty())
{
m_resultsTable->setRowCount(0);
updateStatus("No events to display.");
return;
}
// Filter events based on checkbox states
std::vector<TTDEvent> filteredEvents;
for (const auto& event : m_allEvents)
{
bool shouldInclude = false;
switch (event.type)
{
case TTDEventThreadCreated:
shouldInclude = m_threadCreatedCheck ? m_threadCreatedCheck->isChecked() : false;
break;
case TTDEventThreadTerminated:
shouldInclude = m_threadTerminatedCheck ? m_threadTerminatedCheck->isChecked() : false;
break;
case TTDEventModuleLoaded:
shouldInclude = m_moduleLoadedCheck ? m_moduleLoadedCheck->isChecked() : false;
break;
case TTDEventModuleUnloaded:
shouldInclude = m_moduleUnloadedCheck ? m_moduleUnloadedCheck->isChecked() : false;
break;
case TTDEventException:
shouldInclude = m_exceptionCheck ? m_exceptionCheck->isChecked() : false;
break;
default:
break;
}
if (shouldInclude)
{
filteredEvents.push_back(event);
}
}
// Populate table with filtered results
m_resultsTable->setRowCount((int)filteredEvents.size());
for (int i = 0; i < (int)filteredEvents.size(); ++i)
{
const TTDEvent& event = filteredEvents[i];
// Index
m_resultsTable->setItem(i, IndexColumn, new NumericalTableWidgetItem(QString::number(i + 1), i + 1));
// Event Type
QString eventTypeStr;
switch (event.type)
{
case TTDEventThreadCreated:
eventTypeStr = "ThreadCreated";
break;
case TTDEventThreadTerminated:
eventTypeStr = "ThreadTerminated";
break;
case TTDEventModuleLoaded:
eventTypeStr = "ModuleLoaded";
break;
case TTDEventModuleUnloaded:
eventTypeStr = "ModuleUnloaded";
break;
case TTDEventException:
eventTypeStr = "Exception";
break;
default:
eventTypeStr = "Unknown";
break;
}
m_resultsTable->setItem(i, EventTypeColumn, new QTableWidgetItem(eventTypeStr));
// Position
QString positionStr = QString("%1:%2").arg(event.position.sequence, 0, 16).arg(event.position.step, 0, 16);
m_resultsTable->setItem(i, PositionColumn, new NumericalTableWidgetItem(positionStr, PositionSortValue(event.position)));
// Thread details (if available)
if (event.thread.has_value())
{
m_resultsTable->setItem(i, ThreadIdColumn, new NumericalTableWidgetItem(QString::number(event.thread->id), event.thread->id));
m_resultsTable->setItem(i, ThreadUniqueIdColumn, new NumericalTableWidgetItem(QString::number(event.thread->uniqueId), event.thread->uniqueId));
}
else
{
m_resultsTable->setItem(i, ThreadIdColumn, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, ThreadUniqueIdColumn, new NumericalTableWidgetItem("", 0));
}
// Module details (if available)
if (event.module.has_value())
{
m_resultsTable->setItem(i, ModuleNameColumn, new QTableWidgetItem(QString::fromStdString(event.module->name)));
m_resultsTable->setItem(i, ModuleAddressColumn, new NumericalTableWidgetItem(QString("0x%1").arg(event.module->address, 0, 16), event.module->address));
m_resultsTable->setItem(i, ModuleSizeColumn, new NumericalTableWidgetItem(QString::number(event.module->size), event.module->size));
}
else
{
m_resultsTable->setItem(i, ModuleNameColumn, new QTableWidgetItem(""));
m_resultsTable->setItem(i, ModuleAddressColumn, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, ModuleSizeColumn, new NumericalTableWidgetItem("", 0));
}
// Exception details (if available)
if (event.exception.has_value())
{
QString exceptionTypeStr = (event.exception->type == TTDExceptionHardware) ? "Hardware" : "Software";
m_resultsTable->setItem(i, ExceptionTypeColumn, new QTableWidgetItem(exceptionTypeStr));
m_resultsTable->setItem(i, ExceptionCodeColumn, new NumericalTableWidgetItem(QString("0x%1").arg(event.exception->code, 0, 16), event.exception->code));
m_resultsTable->setItem(i, ExceptionPCColumn, new NumericalTableWidgetItem(QString("0x%1").arg(event.exception->programCounter, 0, 16), event.exception->programCounter));
}
else
{
m_resultsTable->setItem(i, ExceptionTypeColumn, new QTableWidgetItem(""));
m_resultsTable->setItem(i, ExceptionCodeColumn, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, ExceptionPCColumn, new NumericalTableWidgetItem("", 0));
}
}
m_resultsTable->resizeColumnsToContents();
updateStatus(QString("Displaying %1 of %2 events.").arg(filteredEvents.size()).arg(m_allEvents.size()));
}
void TTDEventsQueryWidget::filterAndDisplaySpecializedEvents()
{
if (m_allEvents.empty())
{
m_resultsTable->setRowCount(0);
updateStatus("No events to display.");
return;
}
// Filter events based on widget type
std::vector<TTDEvent> filteredEvents;
for (const auto& event : m_allEvents)
{
bool shouldInclude = false;
switch (m_widgetType)
{
case ModuleEvents:
shouldInclude = (event.type == TTDEventModuleLoaded || event.type == TTDEventModuleUnloaded);
break;
case ThreadEvents:
shouldInclude = (event.type == TTDEventThreadCreated || event.type == TTDEventThreadTerminated);
break;
case ExceptionEvents:
shouldInclude = (event.type == TTDEventException);
break;
default:
shouldInclude = true; // AllEvents
break;
}
if (shouldInclude)
{
filteredEvents.push_back(event);
}
}
// Populate table with filtered results using specialized columns
m_resultsTable->setRowCount((int)filteredEvents.size());
for (int i = 0; i < (int)filteredEvents.size(); ++i)
{
const TTDEvent& event = filteredEvents[i];
int col = 0;
// Index (always first column)
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString::number(i + 1), i + 1));
switch (m_widgetType)
{
case ModuleEvents:
// Position, Event Type, Name (base name), Module Address, Module Size, Module Checksum, Module Timestamp, Path (full path)
{
QString positionStr = QString("%1:%2").arg(event.position.sequence, 0, 16).arg(event.position.step, 0, 16);
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(positionStr, PositionSortValue(event.position)));
QString eventTypeStr = (event.type == TTDEventModuleLoaded) ? "Loaded" : "Unloaded";
m_resultsTable->setItem(i, col++, new QTableWidgetItem(eventTypeStr));
if (event.module.has_value())
{
// Extract base name from full path
QString fullPath = QString::fromStdString(event.module->name);
QString baseName = QFileInfo(fullPath).fileName();
if (baseName.isEmpty())
baseName = fullPath; // fallback to full path if no filename
m_resultsTable->setItem(i, col++, new QTableWidgetItem(baseName));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString("0x%1").arg(event.module->address, 0, 16), event.module->address));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString::number(event.module->size), event.module->size));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString("0x%1").arg(event.module->checksum, 0, 16), event.module->checksum));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString("0x%1").arg(event.module->timestamp, 0, 16), event.module->timestamp));
m_resultsTable->setItem(i, col++, new QTableWidgetItem(fullPath)); // Full path in last column
}
else
{
// Fill empty cells for all module columns
m_resultsTable->setItem(i, col++, new QTableWidgetItem(""));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new QTableWidgetItem(""));
}
}
break;
case ThreadEvents:
// Position, Event Type, Thread ID, Thread UniqueID, Lifetime Start, Lifetime End, Active Start, Active End
{
QString positionStr = QString("%1:%2").arg(event.position.sequence, 0, 16).arg(event.position.step, 0, 16);
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(positionStr, PositionSortValue(event.position)));
QString eventTypeStr = (event.type == TTDEventThreadCreated) ? "Created" : "Terminated";
m_resultsTable->setItem(i, col++, new QTableWidgetItem(eventTypeStr));
if (event.thread.has_value())
{
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString::number(event.thread->id), event.thread->id));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString::number(event.thread->uniqueId), event.thread->uniqueId));
// Lifetime range
QString lifetimeStart = QString("%1:%2").arg(event.thread->lifetimeStart.sequence, 0, 16).arg(event.thread->lifetimeStart.step, 0, 16);
QString lifetimeEnd = QString("%1:%2").arg(event.thread->lifetimeEnd.sequence, 0, 16).arg(event.thread->lifetimeEnd.step, 0, 16);
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(lifetimeStart, PositionSortValue(event.thread->lifetimeStart)));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(lifetimeEnd, PositionSortValue(event.thread->lifetimeEnd)));
// Active time range
QString activeStart = QString("%1:%2").arg(event.thread->activeTimeStart.sequence, 0, 16).arg(event.thread->activeTimeStart.step, 0, 16);
QString activeEnd = QString("%1:%2").arg(event.thread->activeTimeEnd.sequence, 0, 16).arg(event.thread->activeTimeEnd.step, 0, 16);
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(activeStart, PositionSortValue(event.thread->activeTimeStart)));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(activeEnd, PositionSortValue(event.thread->activeTimeEnd)));
}
else
{
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
}
}
break;
case ExceptionEvents:
// Position, Exception Type, Program Counter, Exception Code, Exception Flags, Record Address
{
QString positionStr = QString("%1:%2").arg(event.position.sequence, 0, 16).arg(event.position.step, 0, 16);
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(positionStr, PositionSortValue(event.position)));
if (event.exception.has_value())
{
QString exceptionTypeStr = (event.exception->type == TTDExceptionHardware) ? "Hardware" : "Software";
m_resultsTable->setItem(i, col++, new QTableWidgetItem(exceptionTypeStr));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString("0x%1").arg(event.exception->programCounter, 0, 16), event.exception->programCounter));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString("0x%1").arg(event.exception->code, 0, 16), event.exception->code));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString("0x%1").arg(event.exception->flags, 0, 16), event.exception->flags));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem(QString("0x%1").arg(event.exception->recordAddress, 0, 16), event.exception->recordAddress));
}
else
{
m_resultsTable->setItem(i, col++, new QTableWidgetItem(""));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
m_resultsTable->setItem(i, col++, new NumericalTableWidgetItem("", 0));
}
}
break;
default:
// This shouldn't happen for specialized widgets
break;
}
}
m_resultsTable->resizeColumnsToContents();
updateStatus(QString("Displaying %1 events.").arg(filteredEvents.size()));
}
void TTDEventsQueryWidget::onFilterChanged()
{
// Re-filter and display events when checkbox states change
// Only applies to AllEvents widget type (specialized widgets don't have checkboxes)
if (m_widgetType == AllEvents && !m_allEvents.empty())
{
filterAndDisplayEvents();
}
}
void TTDEventsQueryWidget::clearResults()
{
m_resultsTable->setRowCount(0);
m_allEvents.clear();
updateStatus("Results cleared.");
}
void TTDEventsQueryWidget::refreshEvents()
{
// Clear current contents and re-query from backend
clearResults();
performQuery();
}
void TTDEventsQueryWidget::onCellDoubleClicked(int row, int column)
{
if (!m_controller)
return;
QTableWidgetItem* item = m_resultsTable->item(row, column);
if (!item)
return;
QString cellText = item->text();
// Check if this is a position column - navigate to TTD position
QString columnName = m_resultsTable->horizontalHeaderItem(column) ?
m_resultsTable->horizontalHeaderItem(column)->text() : "";
if (columnName.contains("Position", Qt::CaseInsensitive) || column == PositionColumn)
{
QStringList parts = cellText.split(':');
if (parts.size() == 2)
{
bool ok1, ok2;
uint64_t sequence = parts[0].toULongLong(&ok1, 16);
uint64_t step = parts[1].toULongLong(&ok2, 16);
if (ok1 && ok2)
{
TTDPosition position(sequence, step);
if (m_controller->SetTTDPosition(position))
{
updateStatus(QString("Navigated to position %1:%2").arg(sequence, 0, 16).arg(step, 0, 16));
}
else
{
updateStatus("Failed to navigate to position");
}
}
}
}
// Check if this is an address column - jump to address
else if (columnName.contains("Address", Qt::CaseInsensitive) ||
columnName.contains("PC", Qt::CaseInsensitive) ||
column == ModuleAddressColumn ||
column == ExceptionPCColumn)
{
if (cellText.startsWith("0x"))
{
bool ok;
uint64_t address = cellText.mid(2).toULongLong(&ok, 16);
if (ok)
{
// Jump to address in disassembly view
// Navigate to the address in the disassembly view
ViewFrame* frame = ViewFrame::viewFrameForWidget(this);
if (frame)
{
frame->navigate(m_data, address);
updateStatus(QString("Navigated to address %1").arg(cellText));
}
else
{
updateStatus(QString("Address: %1 (no view frame available)").arg(cellText));
}
}
}
}
}
void TTDEventsQueryWidget::contextMenuEvent(QContextMenuEvent* event)
{
if (m_contextMenuManager)
{
m_contextMenuManager->show(&m_menu, &m_actionHandler);
}
}
void TTDEventsQueryWidget::showContextMenu(const QPoint& position)
{
if (m_contextMenuManager)
{
m_contextMenuManager->show(&m_menu, &m_actionHandler);
}
}
void TTDEventsQueryWidget::showColumnVisibilityDialog()
{
TTDEventsColumnVisibilityDialog dialog(this, m_columnNames, m_columnVisibility);
if (dialog.exec() == QDialog::Accepted)
{
m_columnVisibility = dialog.getColumnVisibility();
updateColumnVisibility();
}
}
void TTDEventsQueryWidget::resetColumnsToDefault()
{
// Reset to default visibility
m_columnVisibility.clear();
m_columnVisibility << true // Index
<< true // Event Type
<< true // Position
<< true // Thread ID
<< false // Thread Unique ID (hidden by default)
<< true // Module Name
<< true // Module Address
<< false // Module Size (hidden by default)
<< true // Exception Type
<< true // Exception Code
<< true; // Exception PC
updateColumnVisibility();
}
bool TTDEventsQueryWidget::canCopy()
{
return m_resultsTable->selectionModel()->hasSelection();
}
void TTDEventsQueryWidget::copy()
{
copySelectedRow();
}
void TTDEventsQueryWidget::copySelectedCell()
{
QItemSelectionModel* selectionModel = m_resultsTable->selectionModel();
if (!selectionModel->hasSelection())
return;
QModelIndexList selected = selectionModel->selectedIndexes();
if (selected.isEmpty())
return;
QTableWidgetItem* item = m_resultsTable->item(selected.first().row(), selected.first().column());
if (item)
{
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(item->text());
}
}
void TTDEventsQueryWidget::copySelectedRow()
{
QItemSelectionModel* selectionModel = m_resultsTable->selectionModel();
if (!selectionModel->hasSelection())
return;
QModelIndexList selected = selectionModel->selectedRows();
if (selected.isEmpty())
return;
QStringList rowData;
int row = selected.first().row();
for (int col = 0; col < m_resultsTable->columnCount(); ++col)
{
if (!m_resultsTable->isColumnHidden(col))
{
QTableWidgetItem* item = m_resultsTable->item(row, col);
rowData << (item ? item->text() : "");
}
}
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(rowData.join('\t'));
}
void TTDEventsQueryWidget::copyEntireTable()
{
QStringList tableData;
// Header row
QStringList headers;
for (int col = 0; col < m_resultsTable->columnCount(); ++col)
{
if (!m_resultsTable->isColumnHidden(col))
{
headers << m_columnNames[col];
}
}
tableData << headers.join('\t');
// Data rows
for (int row = 0; row < m_resultsTable->rowCount(); ++row)
{
QStringList rowData;
for (int col = 0; col < m_resultsTable->columnCount(); ++col)
{
if (!m_resultsTable->isColumnHidden(col))
{
QTableWidgetItem* item = m_resultsTable->item(row, col);
rowData << (item ? item->text() : "");
}
}
tableData << rowData.join('\t');
}
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(tableData.join('\n'));
}
void TTDEventsQueryWidget::performInitialQuery()
{
// For specialized widgets, automatically load and filter events
if (m_widgetType != AllEvents)
{
// First perform the query to get all events
performQuery();
// Then filter based on widget type
filterAndDisplaySpecializedEvents();
}
else
{
// For AllEvents widget, just perform the query
performQuery();
}
}
bool TTDEventsQueryWidget::isUnused() const
{