Wireshark 5.1.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
15
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{
70class LuaDebuggerDialog;
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
209 static LuaDebuggerDialog *instance(QWidget *parent = nullptr);
210
218
233 static bool handleMainCloseIfPaused(QCloseEvent *event);
234
240 void handlePause(const char *file_path, int64_t line);
241
248 void reject() override;
249
256 void addWatchFromSpec(const QString &watchSpec);
257
265
272 LuaDebuggerStackController &stackController() { return stackController_; }
273
281 bool isDebuggerPaused() const { return debuggerPaused; }
282
291 {
292 return changeHighlight_.changeHighlightAllowed(stackController_.selectionLevel());
293 }
294
302 void applyChangedVisuals(QStandardItem *valueCell, bool changed)
303 {
304 changeHighlight_.applyChangedVisuals(this, valueCell, changed);
305 }
306
312 QKeySequence addWatchShortcut() const;
313
321
322 LuaDebuggerVariablesController &variablesController() { return variablesController_; }
324 LuaDebuggerCodeTabsController &codeTabsController() { return codeTabsController_; }
326 LuaDebuggerFilesController &filesController() { return filesController_; }
328 LuaDebuggerWatchController &watchController() { return watchController_; }
330 LuaDebuggerBreakpointsController &breakpointsController() { return breakpointsController_; }
332 LuaDebuggerPauseController &pauseController() { return pauseController_; }
334 LuaDebuggerLuaReloadCoordinator &reloadCoordinator() { return reloadCoordinator_; }
336 LuaDebuggerEvalController &evalController() { return evalController_; }
338 LuaDebuggerFontPolicy &fontPolicy() { return fontPolicy_; }
340
346 QString pausedFile() const { return pausedFile_; }
347
353 qlonglong pausedLine() const { return pausedLine_; }
354
361 QCheckBox *enabledToggle() { return enabledCheckBox; }
362
370 QString normalizedFilePath(const QString &file_path) const;
371
376
380 void updateWidgets();
381
386
392
398
403
408
413 void scheduleErrorFrameHide(int delayMs);
414
419
424
428 void clearPausedStateUi();
429
436 void setSaveActionEnabled(bool enabled);
437
448
449 public slots:
456 void onCodeViewContextMenu(const QPoint &pos);
457
463 void handleEscapeKey();
464
473 void runToCurrentLineInPausedEditor(LuaDebuggerCodeView *codeView, qint32 line);
474
475 protected:
480 void closeEvent(QCloseEvent *event) override;
481
486 void showEvent(QShowEvent *event) override;
487
493 bool event(QEvent *event) override;
494
501 bool eventFilter(QObject *obj, QEvent *event) override;
502
507 void childEvent(QChildEvent *event) override;
508
509 private slots:
511 void onContinue();
512
514 void onStepOver();
515
517 void onStepIn();
518
520 void onStepOut();
521
523 void onRunToLine();
524
526 void onAddWatch();
527
532 void onDebuggerToggled(bool checked);
533
535 void onOpenFile();
536
541 void onMonospaceFontUpdated(const QFont &font);
542
544 void onMainAppInitialized();
545
547 void onPreferencesChanged();
548
550 void onColorsChanged();
551
562 void drainPendingLogs();
563
578 void drainBreakpointStateUpdates();
579
581 void onEditorFind();
582
584 void onEditorGoToLine();
585
591 void onVariablesCurrentItemChanged(const QModelIndex &current, const QModelIndex &previous);
592
598 void onWatchCurrentItemChanged(const QModelIndex &current, const QModelIndex &previous);
599
610 void updateLeftPanelStretch();
611
612 private:
614 Ui::LuaDebuggerDialog *ui;
616 LuaDebuggerVariablesController variablesController_;
618 LuaDebuggerStackController stackController_;
620 LuaDebuggerEvalController evalController_;
622 LuaDebuggerBreakpointsController breakpointsController_;
624 LuaDebuggerFilesController filesController_;
626 LuaDebuggerWatchController watchController_;
628 LuaDebuggerCodeTabsController codeTabsController_;
630 LuaDebuggerPauseController pauseController_;
632 LuaDebuggerLuaReloadCoordinator reloadCoordinator_;
634 LuaDebuggerFontPolicy fontPolicy_;
636 LuaDebuggerKeyRouter keyRouter_;
638 static LuaDebuggerDialog *_instance;
639
641 void wireFilesPanel();
643 void wireStackPanel();
645 void wireVariablesPanel();
647 void wireWatchPanel();
649 void wireBreakpointsPanel();
651 void wireEvaluatePanel();
653 void wireCodeTabs();
654
660 CollapsibleSection *createVariablesSection(QWidget *parent);
661
667 CollapsibleSection *createWatchSection(QWidget *parent);
668
674 CollapsibleSection *createStackSection(QWidget *parent);
675
681 CollapsibleSection *createBreakpointsSection(QWidget *parent);
682
688 CollapsibleSection *createFilesSection(QWidget *parent);
689
695 CollapsibleSection *createEvaluateSection(QWidget *parent);
696
698 void resetStackForPauseEntry();
700 void clearStackPanel();
701
703 QCheckBox *enabledCheckBox;
704
711 bool debuggerPaused;
712
713 // Collapsible sections (created programmatically)
715 CollapsibleSection *variablesSection;
717 CollapsibleSection *watchSection;
719 CollapsibleSection *stackSection;
721 CollapsibleSection *breakpointsSection;
723 CollapsibleSection *filesSection;
725 CollapsibleSection *evalSection;
726
727 // Tree views and item models (created programmatically)
729 QTreeView *variablesTree;
731 QStandardItemModel *variablesModel;
733 QTreeView *watchTree;
735 QStandardItemModel *watchModel;
737 QTreeView *stackTree;
739 QStandardItemModel *stackModel;
741 QTreeView *fileTree;
743 QStandardItemModel *fileModel;
745 QTreeView *breakpointsTree;
747 QStandardItemModel *breakpointsModel;
748
749 // Eval panel widgets (created programmatically)
751 QPlainTextEdit *evalInputEdit;
753 QPlainTextEdit *evalOutputEdit;
755 QPushButton *evalButton;
757 QPushButton *evalClearButton;
758
766 QSplitter *evalSplitter_ = nullptr;
767
769 QToolButton *breakpointHeaderToggleButton_ = nullptr;
771 QToolButton *breakpointHeaderRemoveButton_ = nullptr;
773 QToolButton *breakpointHeaderRemoveAllButton_ = nullptr;
775 QToolButton *breakpointHeaderBreakOnErrorButton_ = nullptr;
782 QToolButton *breakpointHeaderEditButton_ = nullptr;
783
785 QAction *actionRemoveAllBreakpoints_ = nullptr;
786
792 void showAccordionFrame(AccordionFrame *frame, bool toggle = false);
793
798 void installDescendantShortcutFilters();
799
801 void syncDebuggerToggleWithCore();
802
807 enum class DebuggerUiStatus
808 {
810 Paused,
812 DisabledLiveCapture,
814 DisabledPreferences,
816 Disabled,
818 Running
819 };
820
825 DebuggerUiStatus currentDebuggerUiStatus() const;
826
828 void updateEnabledCheckboxIcon();
829
831 void updateStatusLabel();
832
834 void applyCodeViewThemes();
835
837 void updateStyleSheets();
838
842 void resumeDebuggerAndExitLoop();
843
853 void endPauseFreeze();
854
859 void runDebuggerStep(void (*step_fn)(void));
860
862 void createCollapsibleSections();
863
864 // ---- Qt-based JSON settings persistence (like import_hexdump) ----
865
867 LuaDebuggerSettingsStore settingsStore_;
868
870 bool luaDebuggerJsonSaved_{false};
871
875 void saveSettingsFile();
876
878 void applyDialogSettings();
879
881 void storeDialogSettings();
882
888 QStandardItem *findVariablesItemByPath(const QString &path) const;
889
895 QStandardItem *findWatchRootForVariablePath(const QString &path) const;
896
903 static void expandAncestorsOf(QTreeView *tree, QStandardItemModel *model, QStandardItem *item);
904
906 bool syncWatchVariablesSelection_ = false;
907
909 LuaDebuggerChangeHighlightTracker changeHighlight_;
910
926 QString pausedFile_;
927
932 qlonglong pausedLine_ = 0;
933
935 int errorFrameHideEpoch_ = 0;
936
938 void refreshChangedValueBrushes() { changeHighlight_.refreshChangedValueBrushes(watchTree, this); }
939
941 void snapshotBaselinesOnPauseEntry() { changeHighlight_.snapshotBaselinesOnPauseEntry(); }
942
944 void clearAllChangeBaselines() { changeHighlight_.clearAllChangeBaselines(); }
945
947 void pruneChangeBaselinesToLiveWatchSpecs() { changeHighlight_.pruneChangeBaselinesToLiveWatchSpecs(watchModel); }
948
950 void updatePauseEntryFrameIdentity() { changeHighlight_.updatePauseEntryFrameIdentity(); }
951};
952
953#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
GeometryStateDialog(QWidget *parent, Qt::WindowFlags f=Qt::Window)
Constructs a new GeometryStateDialog with the specified parent and window flags.
Definition geometry_state_dialog.h:91
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:895
Owns the script tab strip and the documents inside it.
Definition lua_debugger_code_editor.h:463
Editable code editor supporting gutter breakpoints and highlighting.
Definition lua_debugger_code_editor.h:84
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:330
void refreshDebuggerStateUi()
Refresh checkbox sync + all debugger state chrome/widgets.
Definition lua_debugger_dialog.cpp:1498
LuaDebuggerLuaReloadCoordinator & reloadCoordinator()
Gets the Lua reload coordinator.
Definition lua_debugger_dialog.h:334
LuaDebuggerEvalController & evalController()
Gets the evaluation controller.
Definition lua_debugger_dialog.h:336
void syncVariablesTreeToCurrentWatch()
Select the Variables row matching the current Watch row, or clear the Variables selection when no mat...
Definition lua_debugger_watch.cpp:1982
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:454
void childEvent(QChildEvent *event) override
Handle child widget events.
Definition lua_debugger_dialog.cpp:1076
static LuaDebuggerDialog * instanceIfExists()
Like instance but never creates the dialog; returns nullptr when no instance exists yet....
Definition lua_debugger_dialog.cpp:449
void updateWidgets()
Update all widgets based on the current debugger state.
Definition lua_debugger_dialog.cpp:1664
void handleEscapeKey()
Escape: hide inline find/go accordions if shown, else close dialog. Invoked from the script editor be...
Definition lua_debugger_dialog.cpp:1047
bool changeHighlightAllowed() const
Combined "is the change-highlight cue allowed for paint this pass?" gate. Reads the tracker policy wi...
Definition lua_debugger_dialog.h:290
void handlePause(const char *file_path, int64_t line)
React to the debugger pausing execution at a breakpoint.
Definition lua_debugger_dialog.cpp:674
QString pausedFile() const
Source file path (normalized) of the line the debugger is paused on; empty when not paused....
Definition lua_debugger_dialog.h:346
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:281
bool tearDownPauseLoopForReload()
Tear down an active pause loop because the Lua engine is about to be reloaded under us....
Definition lua_debugger_dialog.cpp:1651
LuaDebuggerChangeHighlightTracker & changeHighlight()
Borrowed reference to the change-highlight tracker. Used by controllers that compute "changed since l...
Definition lua_debugger_dialog.h:264
void ensureDebuggerEnabledForActiveBreakpoints()
Enable the debugger if any active breakpoint requires it.
Definition lua_debugger_dialog.cpp:1680
void updateLuaEditorAuxFrames()
Point find / goto bars at the active code tab.
Definition lua_debugger_dialog.cpp:1155
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:1646
void clearPausedStateUi()
Remove paused-state UI artifacts like stacks and highlights.
Definition lua_debugger_dialog.cpp:1434
QCheckBox * enabledToggle()
Borrowed reference to the toggle that mirrors the core's enable/disable state; the reload coordinator...
Definition lua_debugger_dialog.h:361
LuaDebuggerFontPolicy & fontPolicy()
Gets the font policy.
Definition lua_debugger_dialog.h:338
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:1242
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:637
bool event(QEvent *event) override
Handle general events.
Definition lua_debugger_dialog.cpp:1015
bool eventFilter(QObject *obj, QEvent *event) override
Filter events for child objects to intercept shortcuts.
Definition lua_debugger_dialog.cpp:1092
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:2042
static LuaDebuggerDialog * instance(QWidget *parent=nullptr)
Retrieve the singleton instance, creating it if needed.
Definition lua_debugger_dialog.cpp:660
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:2047
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:1405
LuaDebuggerCodeTabsController & codeTabsController()
Gets the code tabs controller.
Definition lua_debugger_dialog.h:324
LuaDebuggerVariablesController & variablesController()
Gets the variables controller.
Definition lua_debugger_dialog.h:322
void updateContinueActionState()
Enable or disable the Continue action based on debugger state.
Definition lua_debugger_dialog.cpp:1634
void showEvent(QShowEvent *event) override
Handle widget show events.
Definition lua_debugger_dialog.cpp:1032
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:1757
LuaDebuggerStackController & stackController()
Borrowed reference to the stack controller. Used by Watch / Variables / Eval to read the currently in...
Definition lua_debugger_dialog.h:272
void reject() override
Close from Esc or programmatic reject(); queues close() so closeEvent() runs (unsaved-scripts prompt ...
Definition lua_debugger_dialog.cpp:942
LuaDebuggerDialog(QWidget *parent=nullptr)
Construct the dialog and initialize all child widgets.
Definition lua_debugger_dialog.cpp:459
LuaDebuggerPauseController & pauseController()
Gets the pause controller.
Definition lua_debugger_dialog.h:332
void cancelErrorFrameHide()
Cancel any pending delayed hide token.
Definition lua_debugger_dialog.cpp:1200
LuaDebuggerWatchController & watchController()
Gets the watch controller.
Definition lua_debugger_dialog.h:328
qlonglong pausedLine() const
Line number of the pause; zero when the debugger is not paused. Paired with pausedFile.
Definition lua_debugger_dialog.h:353
void closeEvent(QCloseEvent *event) override
Flush state and resume execution when the dialog closes.
Definition lua_debugger_dialog.cpp:952
void scheduleErrorFrameHide(int delayMs)
Schedule a delayed hide to avoid hide/show flicker on rapid re-pauses.
Definition lua_debugger_dialog.cpp:1205
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:302
void updatePausedErrorFrame()
Populate/hide the inline error frame for paused break-on-error states.
Definition lua_debugger_dialog.cpp:1162
LuaDebuggerFilesController & filesController()
Gets the files controller.
Definition lua_debugger_dialog.h:326
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:362
Centralised keyboard-shortcut dispatcher for the Lua debugger dialog's eventFilter().
Definition lua_debugger_utils.h:827
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:1963
bool takeDeferredReload()
If reloadDeferred_ was set, clear it and return true.
Definition lua_debugger_dialog.cpp:1919
void handlePreReload()
Handles actions required before a Lua plugin reload.
Definition lua_debugger_dialog.cpp:1929
LuaDebuggerLuaReloadCoordinator(LuaDebuggerDialog *host)
Constructs a LuaDebuggerLuaReloadCoordinator.
Definition lua_debugger_dialog.cpp:1915
void onReloadLuaPluginsRequested()
Slot triggered when a request to reload Lua plugins is made.
Definition lua_debugger_dialog.cpp:2046
Owns the nested pause QEventLoop pointer and the application-wide freeze (disabled top-levels,...
Definition lua_debugger_pause.h:40
Stack trace panel: column layout, rebuild from the engine, selection → variables frame,...
Definition lua_debugger_stack.h:41
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:1839
bool handleMainCloseIfPaused(QCloseEvent *event)
Decide whether to defer a main-window close while the Lua debugger needs to arbitrate.
Definition lua_debugger_dialog.cpp:1851
void cancelPendingClose()
Cancel any pending deferred main close.
Definition lua_debugger_dialog.cpp:1908
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:1903
void deliverDeferredMainCloseIfPending()
Re-deliver a previously deferred main-window close, if any. Idempotent.
Definition lua_debugger_dialog.cpp:1880
Opaque handle representing an active or pending capture session.
Definition capture_session.h:156