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 <[email protected]>
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:
87
88 void handlePreReload();
89 void handlePostReload();
90
91 bool reloadUiActive() const { return reloadUiActive_; }
92
94 bool takeDeferredReload();
95
96 public slots:
97 void onReloadLuaPluginsRequested();
98
99 private:
100 void enterReloadUiStateIfEnabled();
101 void exitReloadUiState();
102 void reloadAllScriptFilesFromDisk();
103
104 LuaDebuggerDialog *host_ = nullptr;
105 bool reloadDeferred_ = false;
106 bool reloadUiActive_ = false;
107 bool reloadUiSavedCheckboxChecked_ = false;
108 bool reloadUiSavedCheckboxEnabled_ = true;
109 bool reloadUiRequestWasEnabled_ = false;
110};
111
131{
132
141bool handleMainCloseIfPaused(QCloseEvent *event);
142
148
154void markQuitRequested();
155
157void cancelPendingClose();
158
159} // namespace LuaDebuggerMainClosePolicy
160
165{
166 Q_OBJECT
167
168 public:
173 explicit LuaDebuggerDialog(QWidget *parent = nullptr);
178
183 static int32_t currentTheme();
184
190 static LuaDebuggerDialog *instance(QWidget *parent = nullptr);
191
198
212 static bool handleMainCloseIfPaused(QCloseEvent *event);
213
219 void handlePause(const char *file_path, int64_t line);
220
227 void reject() override;
228
232 void addWatchFromSpec(const QString &watchSpec);
233
238
242 LuaDebuggerStackController &stackController() { return stackController_; }
243
248 bool isDebuggerPaused() const { return debuggerPaused; }
249
255 {
256 return changeHighlight_.changeHighlightAllowed(stackController_.selectionLevel());
257 }
258
262 void applyChangedVisuals(QStandardItem *valueCell, bool changed)
263 {
264 changeHighlight_.applyChangedVisuals(this, valueCell, changed);
265 }
266
269 QKeySequence addWatchShortcut() const;
270
278 LuaDebuggerVariablesController &variablesController() { return variablesController_; }
279 LuaDebuggerCodeTabsController &codeTabsController() { return codeTabsController_; }
280 LuaDebuggerFilesController &filesController() { return filesController_; }
281 LuaDebuggerWatchController &watchController() { return watchController_; }
282 LuaDebuggerBreakpointsController &breakpointsController() { return breakpointsController_; }
283 LuaDebuggerPauseController &pauseController() { return pauseController_; }
284 LuaDebuggerLuaReloadCoordinator &reloadCoordinator() { return reloadCoordinator_; }
285 LuaDebuggerEvalController &evalController() { return evalController_; }
286 LuaDebuggerFontPolicy &fontPolicy() { return fontPolicy_; }
288
291 QString pausedFile() const { return pausedFile_; }
294 qlonglong pausedLine() const { return pausedLine_; }
295
299 QCheckBox *enabledToggle() { return enabledCheckBox; }
300
304 QString normalizedFilePath(const QString &file_path) const;
305
308
310 void updateWidgets();
311
314
318
322
325
328
330 void clearPausedStateUi();
331
335 void setSaveActionEnabled(bool enabled);
336
344
345 public slots:
349 void onCodeViewContextMenu(const QPoint &pos);
350
351
357 void handleEscapeKey();
358
363 void runToCurrentLineInPausedEditor(LuaDebuggerCodeView *codeView, qint32 line);
364
365 protected:
370 void closeEvent(QCloseEvent *event) override;
371 void showEvent(QShowEvent *event) override;
372 bool event(QEvent *event) override;
373 bool eventFilter(QObject *obj, QEvent *event) override;
374 void childEvent(QChildEvent *event) override;
375
376 private slots:
378 void onContinue();
380 void onStepOver();
382 void onStepIn();
384 void onStepOut();
386 void onRunToLine();
388 void onAddWatch();
391 void onDebuggerToggled(bool checked);
393 void onOpenFile();
395 void onMonospaceFontUpdated(const QFont &font);
397 void onMainAppInitialized();
399 void onPreferencesChanged();
401 void onColorsChanged();
412 void drainPendingLogs();
414 void onThemeChanged(int idx);
416 void onEditorFind();
418 void onEditorGoToLine();
420 void onVariablesCurrentItemChanged(const QModelIndex &current, const QModelIndex &previous);
422 void onWatchCurrentItemChanged(const QModelIndex &current, const QModelIndex &previous);
433 void updateLeftPanelStretch();
434
435 private:
436 Ui::LuaDebuggerDialog *ui;
437 LuaDebuggerVariablesController variablesController_;
438 LuaDebuggerStackController stackController_;
439 LuaDebuggerEvalController evalController_;
440 LuaDebuggerBreakpointsController breakpointsController_;
441 LuaDebuggerFilesController filesController_;
442 LuaDebuggerWatchController watchController_;
443 LuaDebuggerCodeTabsController codeTabsController_;
444 LuaDebuggerPauseController pauseController_;
445 LuaDebuggerLuaReloadCoordinator reloadCoordinator_;
447 LuaDebuggerFontPolicy fontPolicy_;
449 LuaDebuggerKeyRouter keyRouter_;
450 static LuaDebuggerDialog *_instance;
451 static int32_t currentTheme_;
452
453 void wireFilesPanel();
454 void wireStackPanel();
455 void wireVariablesPanel();
456 void wireWatchPanel();
457 void wireBreakpointsPanel();
458 void wireEvaluatePanel();
459 void wireCodeTabs();
460
462 CollapsibleSection *createVariablesSection(QWidget *parent);
464 CollapsibleSection *createWatchSection(QWidget *parent);
466 CollapsibleSection *createStackSection(QWidget *parent);
468 CollapsibleSection *createBreakpointsSection(QWidget *parent);
470 CollapsibleSection *createFilesSection(QWidget *parent);
472 CollapsibleSection *createEvaluateSection(QWidget *parent);
473
474 void resetStackForPauseEntry();
475 void clearStackPanel();
476
477 QCheckBox *enabledCheckBox;
478 /* True when this dialog is in a pause entry / nested event-loop UI
479 * (Continue/step, freeze, chrome). The C side reports an actual
480 * breakpoint with wslua_debugger_is_paused(); the two are usually
481 * aligned but are updated on different call paths. */
482 bool debuggerPaused;
483
484 // Collapsible sections (created programmatically)
485 CollapsibleSection *variablesSection;
486 CollapsibleSection *watchSection;
487 CollapsibleSection *stackSection;
488 CollapsibleSection *breakpointsSection;
489 CollapsibleSection *filesSection;
490 CollapsibleSection *evalSection;
491 CollapsibleSection *settingsSection;
492
493 // Tree views and item models (created programmatically)
494 QTreeView *variablesTree;
495 QStandardItemModel *variablesModel;
496 QTreeView *watchTree;
497 QStandardItemModel *watchModel;
498 QTreeView *stackTree;
499 QStandardItemModel *stackModel;
500 QTreeView *fileTree;
501 QStandardItemModel *fileModel;
502 QTreeView *breakpointsTree;
503 QStandardItemModel *breakpointsModel;
504
505 // Eval panel widgets (created programmatically)
506 QPlainTextEdit *evalInputEdit;
507 QPlainTextEdit *evalOutputEdit;
508 QPushButton *evalButton;
509 QPushButton *evalClearButton;
517 QSplitter *evalSplitter_ = nullptr;
518
519 // Settings panel widgets (created programmatically)
520 QComboBox *themeComboBox;
522 QToolButton *breakpointHeaderToggleButton_ = nullptr;
524 QToolButton *breakpointHeaderRemoveButton_ = nullptr;
525 QToolButton *breakpointHeaderRemoveAllButton_ = nullptr;
532 QToolButton *breakpointHeaderEditButton_ = nullptr;
534 QAction *actionRemoveAllBreakpoints_ = nullptr;
535
537 void showAccordionFrame(AccordionFrame *frame, bool toggle = false);
541 void installDescendantShortcutFilters();
543 void syncDebuggerToggleWithCore();
546 enum class DebuggerUiStatus
547 {
548 Paused,
549 DisabledLiveCapture,
550 Disabled,
551 Running
552 };
553 DebuggerUiStatus currentDebuggerUiStatus() const;
555 void updateEnabledCheckboxIcon();
557 void updateStatusLabel();
559 void applyCodeViewThemes();
561 void updateStyleSheets();
564 void resumeDebuggerAndExitLoop();
574 void endPauseFreeze();
579 void runDebuggerStep(void (*step_fn)(void));
581 void createCollapsibleSections();
582
583 // ---- Qt-based JSON settings persistence (like import_hexdump) ----
585 LuaDebuggerSettingsStore settingsStore_;
587 bool luaDebuggerJsonSaved_{false};
590 void saveSettingsFile();
592 void applyDialogSettings();
594 void storeDialogSettings();
595
596 QStandardItem *findVariablesItemByPath(const QString &path) const;
597 QStandardItem *findWatchRootForVariablePath(const QString &path) const;
598 static void expandAncestorsOf(QTreeView *tree, QStandardItemModel *model, QStandardItem *item);
599
600 bool syncWatchVariablesSelection_ = false;
601
603 LuaDebuggerChangeHighlightTracker changeHighlight_;
604
620 QString pausedFile_;
623 qlonglong pausedLine_ = 0;
624
625 void refreshChangedValueBrushes() { changeHighlight_.refreshChangedValueBrushes(watchTree, this); }
626
627 void snapshotBaselinesOnPauseEntry() { changeHighlight_.snapshotBaselinesOnPauseEntry(); }
628
629 void clearAllChangeBaselines() { changeHighlight_.clearAllChangeBaselines(); }
630
631 void pruneChangeBaselinesToLiveWatchSpecs() { changeHighlight_.pruneChangeBaselinesToLiveWatchSpecs(watchModel); }
632
633 void updatePauseEntryFrameIdentity() { changeHighlight_.updatePauseEntryFrameIdentity(); }
634};
635
636#endif // LUA_DEBUGGER_DIALOG_H
Definition accordion_frame.h:18
A collapsible section widget for use in a QSplitter.
Definition collapsible_section.h:31
Definition geometry_state_dialog.h:17
Owns the breakpoints panel: tree wiring, model rebuild from the engine, inline edit dispatch,...
Definition lua_debugger_breakpoints.h:265
"Value changed since last pause" highlighter for the Watch and Variables trees.
Definition lua_debugger_utils.h:534
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:1246
Owns the script tab strip and the documents inside it.
Definition lua_debugger_code_editor.h:370
Editable code editor supporting gutter breakpoints and highlighting.
Definition lua_debugger_code_editor.h:127
Top-level dialog hosting the Lua debugger UI components.
Definition lua_debugger_dialog.h:165
void refreshDebuggerStateUi()
Refresh checkbox sync + all debugger state chrome/widgets.
Definition lua_debugger_dialog.cpp:1398
static int32_t currentTheme()
Get the current theme setting.
Definition lua_debugger_dialog.cpp:407
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:402
static LuaDebuggerDialog * instanceIfExists()
Like instance but never creates the dialog; returns nullptr when no instance exists yet....
Definition lua_debugger_dialog.cpp:397
void updateWidgets()
Update all widgets based on the current debugger state.
Definition lua_debugger_dialog.cpp:1558
void handleEscapeKey()
Escape: hide inline find/go accordions if shown, else close dialog. Invoked from the script editor be...
Definition lua_debugger_dialog.cpp:988
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:254
void handlePause(const char *file_path, int64_t line)
React to the debugger pausing execution at a breakpoint.
Definition lua_debugger_dialog.cpp:622
QString pausedFile() const
Source file path (normalized) of the line the debugger is paused on; empty when not paused....
Definition lua_debugger_dialog.h:291
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:248
bool tearDownPauseLoopForReload()
Tear down an active pause loop because the Lua engine is about to be reloaded under us....
Definition lua_debugger_dialog.cpp:1545
LuaDebuggerChangeHighlightTracker & changeHighlight()
Borrowed reference to the change-highlight tracker. Used by controllers that compute "changed since l...
Definition lua_debugger_dialog.h:237
void ensureDebuggerEnabledForActiveBreakpoints()
Enable the debugger if any active breakpoint requires it.
Definition lua_debugger_dialog.cpp:1574
void updateLuaEditorAuxFrames()
Point find / goto bars at the active code tab.
Definition lua_debugger_dialog.cpp:1096
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:1540
void clearPausedStateUi()
Remove paused-state UI artifacts like stacks and highlights.
Definition lua_debugger_dialog.cpp:1331
QCheckBox * enabledToggle()
Borrowed reference to the toggle that mirrors the core's enable/disable state; the reload coordinator...
Definition lua_debugger_dialog.h:299
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:1115
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:585
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:2067
static LuaDebuggerDialog * instance(QWidget *parent=nullptr)
Retrieve the singleton instance, creating it if needed.
Definition lua_debugger_dialog.cpp:608
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:2072
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:1302
void updateContinueActionState()
Enable or disable the Continue action based on debugger state.
Definition lua_debugger_dialog.cpp:1528
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:1648
LuaDebuggerStackController & stackController()
Borrowed reference to the stack controller. Used by Watch / Variables / Eval to read the currently in...
Definition lua_debugger_dialog.h:242
void reject() override
Close from Esc or programmatic reject(); queues close() so closeEvent() runs (unsaved-scripts prompt ...
Definition lua_debugger_dialog.cpp:888
qlonglong pausedLine() const
Line number of the pause; zero when the debugger is not paused. Paired with pausedFile.
Definition lua_debugger_dialog.h:294
void closeEvent(QCloseEvent *event) override
Flush state and resume execution when the dialog closes.
Definition lua_debugger_dialog.cpp:898
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:262
Evaluate panel: enable/disable by pause state, run expressions, clear I/O, and append batched logpoin...
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:300
Centralised keyboard-shortcut dispatcher for the Lua debugger dialog's eventFilter().
Definition lua_debugger_utils.h:470
Coordinates Lua plugin reload: pre/post core callbacks, deferred reload after pause,...
Definition lua_debugger_dialog.h:82
bool takeDeferredReload()
If reloadDeferred_ was set, clear it and return true.
Definition lua_debugger_dialog.cpp:1784
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:57
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:217
Pause-aware arbitration for main-window close while the Lua debugger is involved.
Definition lua_debugger_dialog.cpp:1704
bool handleMainCloseIfPaused(QCloseEvent *event)
Decide whether to defer a main-window close while the Lua debugger needs to arbitrate.
Definition lua_debugger_dialog.cpp:1716
void cancelPendingClose()
Cancel any pending deferred main close.
Definition lua_debugger_dialog.cpp:1773
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:1768
void deliverDeferredMainCloseIfPending()
Re-deliver a previously deferred main-window close, if any. Idempotent.
Definition lua_debugger_dialog.cpp:1745
Definition capture_session.h:136