Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
lua_debugger_dialog.h
Go to the documentation of this file.
1/* lua_debugger_dialog.h
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
16#ifndef LUA_DEBUGGER_DIALOG_H
17#define LUA_DEBUGGER_DIALOG_H
18
19#include <QBrush>
20#include <QCheckBox>
21#include <QComboBox>
22#include <QFont>
23#include <QHash>
24#include <QIcon>
25#include <QKeySequence>
26#include <QList>
27#include <QModelIndex>
28#include <QObject>
29#include <QPair>
30#include <QPlainTextEdit>
31#include <QPointer>
32#include <QPushButton>
33#include <QSet>
34#include <QString>
35#include <QStringList>
36#include <QStandardItem>
37#include <QStandardItemModel>
38#include <QTreeView>
39#include <QVariantMap>
40#include <QVector>
41
42#include "epan/wslua/wslua_debugger.h"
47#include "lua_debugger_files.h"
48#include "lua_debugger_pause.h"
50#include "lua_debugger_stack.h"
51#include "lua_debugger_utils.h"
53#include "lua_debugger_watch.h"
54
55class QToolButton;
56
57struct _capture_session;
58
59class AccordionFrame;
61class QAction;
62class QEvent;
63class QChildEvent;
64class QCloseEvent;
65class QShowEvent;
66class QSplitter;
67
68namespace Ui
69{
71}
72
75
81class LuaDebuggerLuaReloadCoordinator : public QObject
82{
83 Q_OBJECT
84
85 public:
91
95 void handlePreReload();
96
100 void handlePostReload();
101
106 bool takeDeferredReload();
107
108 public slots:
113
114 private:
118 void enterReloadUiStateIfEnabled();
119
123 void exitReloadUiState();
124
128 void reloadAllScriptFilesFromDisk();
129
130 LuaDebuggerDialog *host_ = nullptr;
131 bool reloadDeferred_ = false;
132 bool reloadUiActive_ = false;
133 bool reloadUiRequestWasEnabled_ = false;
134};
135
155{
156
165bool handleMainCloseIfPaused(QCloseEvent *event);
166
172
178void markQuitRequested();
179
181void cancelPendingClose();
182
183} // namespace LuaDebuggerMainClosePolicy
184
189{
190 Q_OBJECT
191
192 public:
197 explicit LuaDebuggerDialog(QWidget *parent = nullptr);
198
203
208 static int32_t currentTheme();
209
215 static LuaDebuggerDialog *instance(QWidget *parent = nullptr);
216
224
239 static bool handleMainCloseIfPaused(QCloseEvent *event);
240
246 void handlePause(const char *file_path, int64_t line);
247
254 void reject() override;
255
262 void addWatchFromSpec(const QString &watchSpec);
263
271
278 LuaDebuggerStackController &stackController() { return stackController_; }
279
287 bool isDebuggerPaused() const { return debuggerPaused; }
288
297 {
298 return changeHighlight_.changeHighlightAllowed(stackController_.selectionLevel());
299 }
300
308 void applyChangedVisuals(QStandardItem *valueCell, bool changed)
309 {
310 changeHighlight_.applyChangedVisuals(this, valueCell, changed);
311 }
312
318 QKeySequence addWatchShortcut() const;
319
327
328 LuaDebuggerVariablesController &variablesController() { return variablesController_; }
330 LuaDebuggerCodeTabsController &codeTabsController() { return codeTabsController_; }
332 LuaDebuggerFilesController &filesController() { return filesController_; }
334 LuaDebuggerWatchController &watchController() { return watchController_; }
336 LuaDebuggerBreakpointsController &breakpointsController() { return breakpointsController_; }
338 LuaDebuggerPauseController &pauseController() { return pauseController_; }
340 LuaDebuggerLuaReloadCoordinator &reloadCoordinator() { return reloadCoordinator_; }
342 LuaDebuggerEvalController &evalController() { return evalController_; }
344 LuaDebuggerFontPolicy &fontPolicy() { return fontPolicy_; }
346
352 QString pausedFile() const { return pausedFile_; }
353
359 qlonglong pausedLine() const { return pausedLine_; }
360
367 QCheckBox *enabledToggle() { return enabledCheckBox; }
368
376 QString normalizedFilePath(const QString &file_path) const;
377
382
386 void updateWidgets();
387
392
398
404
409
414
419 void scheduleErrorFrameHide(int delayMs);
420
425
430
434 void clearPausedStateUi();
435
442 void setSaveActionEnabled(bool enabled);
443
454
455 public slots:
462 void onCodeViewContextMenu(const QPoint &pos);
463
469 void handleEscapeKey();
470
479 void runToCurrentLineInPausedEditor(LuaDebuggerCodeView *codeView, qint32 line);
480
481 protected:
486 void closeEvent(QCloseEvent *event) override;
487
492 void showEvent(QShowEvent *event) override;
493
499 bool event(QEvent *event) override;
500
507 bool eventFilter(QObject *obj, QEvent *event) override;
508
513 void childEvent(QChildEvent *event) override;
514
515 private slots:
517 void onContinue();
518
520 void onStepOver();
521
523 void onStepIn();
524
526 void onStepOut();
527
529 void onRunToLine();
530
532 void onAddWatch();
533
538 void onDebuggerToggled(bool checked);
539
541 void onOpenFile();
542
547 void onMonospaceFontUpdated(const QFont &font);
548
550 void onMainAppInitialized();
551
553 void onPreferencesChanged();
554
556 void onColorsChanged();
557
568 void drainPendingLogs();
569
584 void drainBreakpointStateUpdates();
585
590 void onThemeChanged(int idx);
591
593 void onEditorFind();
594
596 void onEditorGoToLine();
597
603 void onVariablesCurrentItemChanged(const QModelIndex &current, const QModelIndex &previous);
604
610 void onWatchCurrentItemChanged(const QModelIndex &current, const QModelIndex &previous);
611
622 void updateLeftPanelStretch();
623
624 private:
626 Ui::LuaDebuggerDialog *ui;
628 LuaDebuggerVariablesController variablesController_;
630 LuaDebuggerStackController stackController_;
632 LuaDebuggerEvalController evalController_;
634 LuaDebuggerBreakpointsController breakpointsController_;
636 LuaDebuggerFilesController filesController_;
638 LuaDebuggerWatchController watchController_;
640 LuaDebuggerCodeTabsController codeTabsController_;
642 LuaDebuggerPauseController pauseController_;
644 LuaDebuggerLuaReloadCoordinator reloadCoordinator_;
646 LuaDebuggerFontPolicy fontPolicy_;
648 LuaDebuggerKeyRouter keyRouter_;
650 static LuaDebuggerDialog *_instance;
652 static int32_t currentTheme_;
653
655 void wireFilesPanel();
657 void wireStackPanel();
659 void wireVariablesPanel();
661 void wireWatchPanel();
663 void wireBreakpointsPanel();
665 void wireEvaluatePanel();
667 void wireCodeTabs();
668
674 CollapsibleSection *createVariablesSection(QWidget *parent);
675
681 CollapsibleSection *createWatchSection(QWidget *parent);
682
688 CollapsibleSection *createStackSection(QWidget *parent);
689
695 CollapsibleSection *createBreakpointsSection(QWidget *parent);
696
702 CollapsibleSection *createFilesSection(QWidget *parent);
703
709 CollapsibleSection *createEvaluateSection(QWidget *parent);
710
712 void resetStackForPauseEntry();
714 void clearStackPanel();
715
717 QCheckBox *enabledCheckBox;
718
725 bool debuggerPaused;
726
727 // Collapsible sections (created programmatically)
729 CollapsibleSection *variablesSection;
731 CollapsibleSection *watchSection;
733 CollapsibleSection *stackSection;
735 CollapsibleSection *breakpointsSection;
737 CollapsibleSection *filesSection;
739 CollapsibleSection *evalSection;
741 CollapsibleSection *settingsSection;
742
743 // Tree views and item models (created programmatically)
745 QTreeView *variablesTree;
747 QStandardItemModel *variablesModel;
749 QTreeView *watchTree;
751 QStandardItemModel *watchModel;
753 QTreeView *stackTree;
755 QStandardItemModel *stackModel;
757 QTreeView *fileTree;
759 QStandardItemModel *fileModel;
761 QTreeView *breakpointsTree;
763 QStandardItemModel *breakpointsModel;
764
765 // Eval panel widgets (created programmatically)
767 QPlainTextEdit *evalInputEdit;
769 QPlainTextEdit *evalOutputEdit;
771 QPushButton *evalButton;
773 QPushButton *evalClearButton;
774
782 QSplitter *evalSplitter_ = nullptr;
783
784 // Settings panel widgets (created programmatically)
786 QComboBox *themeComboBox;
787
789 QToolButton *breakpointHeaderToggleButton_ = nullptr;
791 QToolButton *breakpointHeaderRemoveButton_ = nullptr;
793 QToolButton *breakpointHeaderRemoveAllButton_ = nullptr;
795 QToolButton *breakpointHeaderBreakOnErrorButton_ = nullptr;
802 QToolButton *breakpointHeaderEditButton_ = nullptr;
803
805 QAction *actionRemoveAllBreakpoints_ = nullptr;
806
812 void showAccordionFrame(AccordionFrame *frame, bool toggle = false);
813
818 void installDescendantShortcutFilters();
819
821 void syncDebuggerToggleWithCore();
822
827 enum class DebuggerUiStatus
828 {
830 Paused,
832 DisabledLiveCapture,
834 Disabled,
836 Running
837 };
838
843 DebuggerUiStatus currentDebuggerUiStatus() const;
844
846 void updateEnabledCheckboxIcon();
847
849 void updateStatusLabel();
850
852 void applyCodeViewThemes();
853
855 void updateStyleSheets();
856
860 void resumeDebuggerAndExitLoop();
861
871 void endPauseFreeze();
872
877 void runDebuggerStep(void (*step_fn)(void));
878
880 void createCollapsibleSections();
881
882 // ---- Qt-based JSON settings persistence (like import_hexdump) ----
883
885 LuaDebuggerSettingsStore settingsStore_;
886
888 bool luaDebuggerJsonSaved_{false};
889
893 void saveSettingsFile();
894
896 void applyDialogSettings();
897
899 void storeDialogSettings();
900
906 QStandardItem *findVariablesItemByPath(const QString &path) const;
907
913 QStandardItem *findWatchRootForVariablePath(const QString &path) const;
914
921 static void expandAncestorsOf(QTreeView *tree, QStandardItemModel *model, QStandardItem *item);
922
924 bool syncWatchVariablesSelection_ = false;
925
927 LuaDebuggerChangeHighlightTracker changeHighlight_;
928
944 QString pausedFile_;
945
950 qlonglong pausedLine_ = 0;
951
953 int errorFrameHideEpoch_ = 0;
954
956 void refreshChangedValueBrushes() { changeHighlight_.refreshChangedValueBrushes(watchTree, this); }
957
959 void snapshotBaselinesOnPauseEntry() { changeHighlight_.snapshotBaselinesOnPauseEntry(); }
960
962 void clearAllChangeBaselines() { changeHighlight_.clearAllChangeBaselines(); }
963
965 void pruneChangeBaselinesToLiveWatchSpecs() { changeHighlight_.pruneChangeBaselinesToLiveWatchSpecs(watchModel); }
966
968 void updatePauseEntryFrameIdentity() { changeHighlight_.updatePauseEntryFrameIdentity(); }
969};
970
971#endif // LUA_DEBUGGER_DIALOG_H
A QFrame that shows and hides itself with a slide animation.
Definition accordion_frame.h:21
A collapsible section widget for use in a QSplitter.
Definition collapsible_section.h:31
A dialog that remembers its geometry and splitter state.
Definition geometry_state_dialog.h:20
Owns the breakpoints panel: tree wiring, model rebuild from the engine, inline edit dispatch,...
Definition lua_debugger_breakpoints.h:349
"Value changed since last pause" highlighter for the Watch and Variables trees.
Definition lua_debugger_utils.h:989
bool changeHighlightAllowed(int stackSelectionLevel) const
Checks if change highlighting is allowed for a given stack level.
Definition lua_debugger_utils.cpp:1523
void snapshotBaselinesOnPauseEntry()
Snapshots the current values to baseline on a new pause entry.
Definition lua_debugger_utils.cpp:1283
void clearAllChangeBaselines()
Clears all change baselines for watches and variables.
Definition lua_debugger_utils.cpp:1364
void pruneChangeBaselinesToLiveWatchSpecs(QStandardItemModel *watchModel)
Prunes baselines to keep only those present in the live watch specs.
Definition lua_debugger_utils.cpp:1480
void refreshChangedValueBrushes(QTreeView *watchTree, QWidget *paletteFallback)
Refreshes the brushes used for changed values based on the application palette.
Definition lua_debugger_utils.cpp:1259
void applyChangedVisuals(QObject *timerOwner, QStandardItem *anchor, bool changed)
Stamp the anchor row with the change visuals; isPauseEntryRefresh_ is consulted internally so callers...
Definition lua_debugger_utils.cpp:1318
void updatePauseEntryFrameIdentity()
Updates the identity of the current frame on pause entry.
Definition lua_debugger_utils.cpp:1297
Owns the script tab strip and the documents inside it.
Definition lua_debugger_code_editor.h:515
Editable code editor supporting gutter breakpoints and highlighting.
Definition lua_debugger_code_editor.h:136
Top-level dialog hosting the Lua debugger UI components.
Definition lua_debugger_dialog.h:189
LuaDebuggerBreakpointsController & breakpointsController()
Gets the breakpoints controller.
Definition lua_debugger_dialog.h:336
void refreshDebuggerStateUi()
Refresh checkbox sync + all debugger state chrome/widgets.
Definition lua_debugger_dialog.cpp:1492
static int32_t currentTheme()
Get the current theme setting.
Definition lua_debugger_dialog.cpp:428
LuaDebuggerLuaReloadCoordinator & reloadCoordinator()
Gets the Lua reload coordinator.
Definition lua_debugger_dialog.h:340
LuaDebuggerEvalController & evalController()
Gets the evaluation controller.
Definition lua_debugger_dialog.h:342
void syncVariablesTreeToCurrentWatch()
Select the Variables row matching the current Watch row, or clear the Variables selection when no mat...
Definition lua_debugger_watch.cpp:1988
static bool handleMainCloseIfPaused(QCloseEvent *event)
If the debugger is paused or owns unsaved scripts, defer the supplied main-window close event so the ...
Definition lua_debugger_dialog.cpp:423
void childEvent(QChildEvent *event) override
Handle child widget events.
Definition lua_debugger_dialog.cpp:1046
static LuaDebuggerDialog * instanceIfExists()
Like instance but never creates the dialog; returns nullptr when no instance exists yet....
Definition lua_debugger_dialog.cpp:418
void updateWidgets()
Update all widgets based on the current debugger state.
Definition lua_debugger_dialog.cpp:1648
void handleEscapeKey()
Escape: hide inline find/go accordions if shown, else close dialog. Invoked from the script editor be...
Definition lua_debugger_dialog.cpp:1017
bool changeHighlightAllowed() const
Combined "is the change-highlight cue allowed for paint this pass?" gate. Reads the tracker policy w...
Definition lua_debugger_dialog.h:296
void handlePause(const char *file_path, int64_t line)
React to the debugger pausing execution at a breakpoint.
Definition lua_debugger_dialog.cpp:644
QString pausedFile() const
Source file path (normalized) of the line the debugger is paused on; empty when not paused....
Definition lua_debugger_dialog.h:352
bool isDebuggerPaused() const
True while the dialog is in a pause-entry / nested event-loop UI. Mirrors the C side's wslua_debugger...
Definition lua_debugger_dialog.h:287
bool tearDownPauseLoopForReload()
Tear down an active pause loop because the Lua engine is about to be reloaded under us....
Definition lua_debugger_dialog.cpp:1635
LuaDebuggerChangeHighlightTracker & changeHighlight()
Borrowed reference to the change-highlight tracker. Used by controllers that compute "changed since l...
Definition lua_debugger_dialog.h:270
void ensureDebuggerEnabledForActiveBreakpoints()
Enable the debugger if any active breakpoint requires it.
Definition lua_debugger_dialog.cpp:1664
void updateLuaEditorAuxFrames()
Point find / goto bars at the active code tab.
Definition lua_debugger_dialog.cpp:1125
void setSaveActionEnabled(bool enabled)
Toggle the toolbar Save Script action's enabled state. Surfaced as a typed setter so the code-tabs co...
Definition lua_debugger_dialog.cpp:1630
void clearPausedStateUi()
Remove paused-state UI artifacts like stacks and highlights.
Definition lua_debugger_dialog.cpp:1428
QCheckBox * enabledToggle()
Borrowed reference to the toggle that mirrors the core's enable/disable state; the reload coordinator...
Definition lua_debugger_dialog.h:367
LuaDebuggerFontPolicy & fontPolicy()
Gets the font policy.
Definition lua_debugger_dialog.h:344
void onCodeViewContextMenu(const QPoint &pos)
Build and show the editor context menu (right-click in a code tab). Routed through Qt's signal/slot m...
Definition lua_debugger_dialog.cpp:1212
void refreshVariablesForCurrentStackFrame()
Rebuild the variables tree after the stack frame for inspection changed.
Definition lua_debugger_variables.cpp:405
~LuaDebuggerDialog()
Destroy the dialog and disconnect debugger callbacks.
Definition lua_debugger_dialog.cpp:607
bool event(QEvent *event) override
Handle general events.
Definition lua_debugger_dialog.cpp:985
bool eventFilter(QObject *obj, QEvent *event) override
Filter events for child objects to intercept shortcuts.
Definition lua_debugger_dialog.cpp:1062
void addWatchFromSpec(const QString &watchSpec)
Add a watch from an expression/path spec without opening the inline editor. Convenience used by the e...
Definition lua_debugger_watch.cpp:2048
static LuaDebuggerDialog * instance(QWidget *parent=nullptr)
Retrieve the singleton instance, creating it if needed.
Definition lua_debugger_dialog.cpp:630
QKeySequence addWatchShortcut() const
Shortcut bound to the Add Watch toolbar action. Watch / Variables context menus mirror it on their "A...
Definition lua_debugger_watch.cpp:2053
QString normalizedFilePath(const QString &file_path) const
Normalize a path by trimming prefixes and resolving symbolic components. Public so controllers and th...
Definition lua_debugger_dialog.cpp:1399
LuaDebuggerCodeTabsController & codeTabsController()
Gets the code tabs controller.
Definition lua_debugger_dialog.h:330
LuaDebuggerVariablesController & variablesController()
Gets the variables controller.
Definition lua_debugger_dialog.h:328
void updateContinueActionState()
Enable or disable the Continue action based on debugger state.
Definition lua_debugger_dialog.cpp:1618
void showEvent(QShowEvent *event) override
Handle widget show events.
Definition lua_debugger_dialog.cpp:1002
void runToCurrentLineInPausedEditor(LuaDebuggerCodeView *codeView, qint32 line)
Run-to-line dispatch from the focused paused editor. Public so LuaDebuggerKeyRouter can fire it from ...
Definition lua_debugger_dialog.cpp:1740
LuaDebuggerStackController & stackController()
Borrowed reference to the stack controller. Used by Watch / Variables / Eval to read the currently in...
Definition lua_debugger_dialog.h:278
void reject() override
Close from Esc or programmatic reject(); queues close() so closeEvent() runs (unsaved-scripts prompt ...
Definition lua_debugger_dialog.cpp:912
LuaDebuggerPauseController & pauseController()
Gets the pause controller.
Definition lua_debugger_dialog.h:338
void cancelErrorFrameHide()
Cancel any pending delayed hide token.
Definition lua_debugger_dialog.cpp:1170
LuaDebuggerWatchController & watchController()
Gets the watch controller.
Definition lua_debugger_dialog.h:334
qlonglong pausedLine() const
Line number of the pause; zero when the debugger is not paused. Paired with pausedFile.
Definition lua_debugger_dialog.h:359
void closeEvent(QCloseEvent *event) override
Flush state and resume execution when the dialog closes.
Definition lua_debugger_dialog.cpp:922
void scheduleErrorFrameHide(int delayMs)
Schedule a delayed hide to avoid hide/show flicker on rapid re-pauses.
Definition lua_debugger_dialog.cpp:1175
void applyChangedVisuals(QStandardItem *valueCell, bool changed)
Stamp valueCell with the change-highlight visuals; the dialog supplies itself as the timer owner so t...
Definition lua_debugger_dialog.h:308
void updatePausedErrorFrame()
Populate/hide the inline error frame for paused break-on-error states.
Definition lua_debugger_dialog.cpp:1132
LuaDebuggerFilesController & filesController()
Gets the files controller.
Definition lua_debugger_dialog.h:332
Manages the debugger's eval panel: enabling/disabling controls based on pause state,...
Definition lua_debugger_evaluate.h:30
Files panel: plugin/script indexing, hierarchical entries, open / reveal / copy gestures,...
Definition lua_debugger_files.h:36
Owns the dialog's font story end-to-end.
Definition lua_debugger_code_editor.h:414
Centralised keyboard-shortcut dispatcher for the Lua debugger dialog's eventFilter().
Definition lua_debugger_utils.h:921
Coordinates Lua plugin reload: pre/post core callbacks, deferred reload after pause,...
Definition lua_debugger_dialog.h:82
void handlePostReload()
Handles actions required after a Lua plugin reload.
Definition lua_debugger_dialog.cpp:1941
bool takeDeferredReload()
If reloadDeferred_ was set, clear it and return true.
Definition lua_debugger_dialog.cpp:1897
void handlePreReload()
Handles actions required before a Lua plugin reload.
Definition lua_debugger_dialog.cpp:1907
void onReloadLuaPluginsRequested()
Slot triggered when a request to reload Lua plugins is made.
Definition lua_debugger_dialog.cpp:2024
Owns the nested pause QEventLoop pointer and the application-wide freeze (disabled top-levels,...
Definition lua_debugger_pause.h:40
In-memory Lua debugger UI settings backed by lua_debugger.json (global personal config,...
Definition lua_debugger_settings.h:26
Stack trace panel: column layout, rebuild from the engine, selection → variables frame,...
Definition lua_debugger_stack.h:41
int selectionLevel() const
Stack frame index whose locals/upvalues currently drive the Variables and Watch panels (0 = topmost /...
Definition lua_debugger_stack.h:71
Variables panel: column sizing, expansion persistence, lazy child fill on expand, context menu,...
Definition lua_debugger_variables.h:45
Watch panel: column layout, expand/collapse tracking + lazy fill, runtime expansion-state map,...
Definition lua_debugger_watch.h:330
Pause-aware arbitration for main-window close while the Lua debugger is involved.
Definition lua_debugger_dialog.cpp:1817
bool handleMainCloseIfPaused(QCloseEvent *event)
Decide whether to defer a main-window close while the Lua debugger needs to arbitrate.
Definition lua_debugger_dialog.cpp:1829
void cancelPendingClose()
Cancel any pending deferred main close.
Definition lua_debugger_dialog.cpp:1886
void markQuitRequested()
Record a debugger-initiated quit (Ctrl+Q from the debugger window) so that the main window will be cl...
Definition lua_debugger_dialog.cpp:1881
void deliverDeferredMainCloseIfPending()
Re-deliver a previously deferred main-window close, if any. Idempotent.
Definition lua_debugger_dialog.cpp:1858
Opaque handle representing an active or pending capture session.
Definition capture_session.h:142