Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
wslua_debugger.h
1/* wslua_debugger.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
10#ifndef __WSLUA_DEBUGGER_H__
11#define __WSLUA_DEBUGGER_H__
12
13#include "ws_symbol_export.h"
14#include <glib.h>
15#include <stdbool.h>
16
17typedef struct lua_State lua_State;
18
19#ifdef __cplusplus
20extern "C"
21{
22#endif
23
27 typedef enum
28 {
29 WSLUA_DEBUGGER_OFF,
30 WSLUA_DEBUGGER_RUNNING,
32 WSLUA_DEBUGGER_PAUSED
33 } wslua_debugger_state_t;
34
38 typedef enum
39 {
40 WSLUA_DEBUGGER_THEME_AUTO = 0,
41 WSLUA_DEBUGGER_THEME_DARK = 1,
42 WSLUA_DEBUGGER_THEME_LIGHT = 2
43 } wslua_debugger_theme_t;
44
54 typedef enum
55 {
57 WSLUA_HIT_COUNT_MODE_FROM = 0,
59 WSLUA_HIT_COUNT_MODE_EVERY = 1,
61 WSLUA_HIT_COUNT_MODE_ONCE = 2,
62 } wslua_hit_count_mode_t;
63
79 typedef struct _wslua_breakpoint_t
80 {
81 char *file_path;
82 int64_t line;
83 bool active;
84 char *condition;
86 int64_t hit_count;
87 wslua_hit_count_mode_t hit_count_mode;
103
108 WS_DLL_PUBLIC void wslua_debugger_init(lua_State *L);
109
114 WS_DLL_PUBLIC bool wslua_debugger_is_enabled(void);
115
120 WS_DLL_PUBLIC void wslua_debugger_set_enabled(bool enabled);
121
131 WS_DLL_PUBLIC void
132 wslua_debugger_set_user_explicitly_disabled(bool user_wants_debugger_stay_off);
133
140 WS_DLL_PUBLIC bool
141 wslua_debugger_may_auto_enable_for_breakpoints(void);
142
148 WS_DLL_PUBLIC void wslua_debugger_renounce_restore_after_reload(void);
149
155 typedef void (*wslua_debugger_ui_update_cb_t)(const char *file_path,
156 int64_t line);
157
162 WS_DLL_PUBLIC void
163 wslua_debugger_register_ui_callback(wslua_debugger_ui_update_cb_t cb);
164
168 WS_DLL_PUBLIC void wslua_debugger_continue(void);
169
176 WS_DLL_PUBLIC void wslua_debugger_step_in(void);
177
184 WS_DLL_PUBLIC void wslua_debugger_step_over(void);
185
192 WS_DLL_PUBLIC void wslua_debugger_step_out(void);
193
202 WS_DLL_PUBLIC void wslua_debugger_set_variable_stack_level(int32_t level);
203
208 WS_DLL_PUBLIC int32_t wslua_debugger_get_variable_stack_level(void);
209
218 WS_DLL_PUBLIC int32_t wslua_debugger_find_stack_level_for_watch_spec(
219 const char *spec);
220
226 WS_DLL_PUBLIC void wslua_debugger_run_to_line(const char *file_path,
227 int64_t line);
228
234 WS_DLL_PUBLIC void wslua_debugger_add_breakpoint(const char *file_path,
235 int64_t line);
236
242 WS_DLL_PUBLIC void wslua_debugger_remove_breakpoint(const char *file_path,
243 int64_t line);
244
251 WS_DLL_PUBLIC void
252 wslua_debugger_set_breakpoint_active(const char *file_path, int64_t line,
253 bool active);
254
258 WS_DLL_PUBLIC void wslua_debugger_clear_breakpoints(void);
259
274 WS_DLL_PUBLIC void
275 wslua_debugger_set_breakpoint_condition(const char *file_path, int64_t line,
276 const char *condition);
277
289 WS_DLL_PUBLIC void
290 wslua_debugger_set_breakpoint_hit_count_target(const char *file_path,
291 int64_t line,
292 int64_t target);
293
302 WS_DLL_PUBLIC void
303 wslua_debugger_set_breakpoint_hit_count_mode(const char *file_path,
304 int64_t line,
305 wslua_hit_count_mode_t mode);
306
318 WS_DLL_PUBLIC void
319 wslua_debugger_set_breakpoint_log_message(const char *file_path,
320 int64_t line,
321 const char *message);
322
332 WS_DLL_PUBLIC void
333 wslua_debugger_set_breakpoint_log_also_pause(const char *file_path,
334 int64_t line,
335 bool also_pause);
336
340 WS_DLL_PUBLIC void
341 wslua_debugger_reset_breakpoint_hit_count(const char *file_path,
342 int64_t line);
343
347 WS_DLL_PUBLIC void wslua_debugger_reset_all_breakpoint_hit_counts(void);
348
362 WS_DLL_PUBLIC bool
363 wslua_debugger_check_condition_syntax(const char *expression,
364 char **err_msg);
365
381 WS_DLL_PUBLIC void
382 wslua_debugger_set_breakpoint_condition_error(const char *file_path,
383 int64_t line,
384 const char *err_msg);
385
392 WS_DLL_PUBLIC int32_t
393 wslua_debugger_get_breakpoint_state(const char *file_path, int64_t line);
394
406 WS_DLL_PUBLIC int32_t
407 wslua_debugger_get_breakpoint_state_canonical(
408 const char *canonical_path, int64_t line);
409
415 WS_DLL_PUBLIC char *wslua_debugger_canonical_path(const char *file_path);
416
420 typedef struct
421 {
422 char *name;
423 char *value;
424 char *type;
427
431 typedef struct
432 {
433 char *source;
434 int64_t line;
435 int64_t linedefined;
440 char *name;
442
449 WS_DLL_PUBLIC wslua_stack_frame_t *
450 wslua_debugger_get_stack(int32_t *frame_count);
451
457 WS_DLL_PUBLIC void wslua_debugger_free_stack(wslua_stack_frame_t *stack,
458 int32_t frame_count);
459
468 WS_DLL_PUBLIC wslua_variable_t *
469 wslua_debugger_get_variables(const char *path, int32_t *variable_count);
470
476 WS_DLL_PUBLIC void wslua_debugger_free_variables(wslua_variable_t *vars,
477 int32_t variable_count);
478
483 WS_DLL_PUBLIC unsigned wslua_debugger_get_breakpoint_count(void);
484
493 WS_DLL_PUBLIC bool wslua_debugger_get_breakpoint(unsigned idx,
494 const char **file_path,
495 int64_t *line,
496 bool *active);
497
507 WS_DLL_PUBLIC bool wslua_debugger_get_breakpoint_extended(
508 unsigned idx, const char **file_path, int64_t *line, bool *active,
509 const char **condition, int64_t *hit_count_target,
510 int64_t *hit_count, bool *condition_error,
511 const char **log_message,
512 wslua_hit_count_mode_t *hit_count_mode,
513 bool *log_also_pause);
514
532 WS_DLL_PUBLIC char *
533 wslua_debugger_get_breakpoint_condition_error_message(unsigned idx);
534
548 WS_DLL_PUBLIC int32_t
549 wslua_debugger_get_breakpoint_state_canonical_ex(const char *canonical_path,
550 int64_t line,
551 bool *has_extras);
552
563 typedef void (*wslua_debugger_log_emit_callback_t)(const char *file_path,
564 int64_t line,
565 const char *message);
566
570 WS_DLL_PUBLIC void wslua_debugger_register_log_emit_callback(
571 wslua_debugger_log_emit_callback_t callback);
572
579 typedef void (*wslua_debugger_reload_callback_t)(void);
580
592 WS_DLL_PUBLIC void wslua_debugger_register_reload_callback(
593 wslua_debugger_reload_callback_t callback);
594
609 WS_DLL_PUBLIC bool wslua_debugger_notify_reload(void);
610
617 typedef void (*wslua_debugger_post_reload_callback_t)(void);
618
629 WS_DLL_PUBLIC void wslua_debugger_register_post_reload_callback(
630 wslua_debugger_post_reload_callback_t callback);
631
639 WS_DLL_PUBLIC void wslua_debugger_notify_post_reload(void);
640
647 WS_DLL_PUBLIC void wslua_debugger_restore_after_reload(void);
648
664 WS_DLL_PUBLIC char *wslua_debugger_evaluate(const char *expression,
665 char **error_msg);
666
671 WS_DLL_PUBLIC bool wslua_debugger_is_paused(void);
672
682 typedef void (*wslua_debugger_script_loaded_callback_t)(
683 const char *file_path);
684
693 WS_DLL_PUBLIC void wslua_debugger_register_script_loaded_callback(
694 wslua_debugger_script_loaded_callback_t callback);
695
704 WS_DLL_PUBLIC void
705 wslua_debugger_notify_script_loaded(const char *file_path);
706
713 typedef void (*wslua_debugger_loaded_script_callback_t)(
714 const char *file_path, void *user_data);
715
729 WS_DLL_PUBLIC void wslua_debugger_foreach_loaded_script(
730 wslua_debugger_loaded_script_callback_t callback, void *user_data);
731
732 /*
733 * Watch path APIs (below) take @c debugger.mutex when they touch the
734 * paused Lua state. Call them from the same execution context as the Lua
735 * debugger UI (typically the Qt GUI thread), matching
736 * @ref wslua_debugger_get_variables and other variable accessors. Do not
737 * interleave them with code that resumes the debugger or replaces
738 * @c paused_L from another thread.
739 */
740
742#define WSLUA_WATCH_MAX_PATH_SEGMENTS 32
743
754 WS_DLL_PUBLIC bool wslua_debugger_watch_spec_uses_path_resolution(
755 const char *spec);
756
762 WS_DLL_PUBLIC char *wslua_debugger_watch_variable_path_for_spec(
763 const char *spec);
764
775 WS_DLL_PUBLIC char *wslua_debugger_watch_resolved_variable_path_for_spec(
776 const char *spec);
777
789 WS_DLL_PUBLIC bool wslua_debugger_watch_read_root(
790 const char *spec, char **value_out, char **type_out,
791 bool *can_expand_out, char **error_msg);
792
818 WS_DLL_PUBLIC bool wslua_debugger_read_variable_value_full(
819 const char *variable_path, char **value_out, char **error_msg);
820
821 /*
822 * Watch expression APIs (below) evaluate an arbitrary Lua expression
823 * against the paused state. They share the same instruction-count and
824 * call-depth safety hooks as @ref wslua_debugger_evaluate, and run with
825 * a custom @c _ENV that exposes the paused frame's locals, upvalues,
826 * and globals — so a bare identifier in an expression resolves the
827 * same way an unqualified path watch does.
828 *
829 * Use these for any spec that does not validate as a path under
830 * @ref wslua_debugger_watch_spec_uses_path_resolution. Like the path
831 * APIs above, they take @c debugger.mutex when they touch the paused
832 * Lua state and must be called from the same execution context as the
833 * Qt debugger UI (typically the GUI thread).
834 */
835
848 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_read_root(
849 const char *spec, char **value_out, char **type_out,
850 bool *can_expand_out, char **error_msg);
851
863 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_read_subpath(
864 const char *spec, const char *subpath, char **value_out,
865 char **type_out, bool *can_expand_out, char **error_msg);
866
880 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_get_variables(
881 const char *spec, const char *subpath,
882 wslua_variable_t **variables_out, int32_t *count_out,
883 char **error_msg);
884
895 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_read_full(
896 const char *spec, const char *subpath, char **value_out,
897 char **error_msg);
898
899#ifdef __cplusplus
900}
901#endif
902
903#endif /* __WSLUA_DEBUGGER_H__ */
Breakpoint structure for in-memory storage.
Definition wslua_debugger.h:80
char * log_message
Definition wslua_debugger.h:95
wslua_hit_count_mode_t hit_count_mode
Definition wslua_debugger.h:87
int64_t hit_count
Definition wslua_debugger.h:86
bool condition_error
Definition wslua_debugger.h:91
char * condition_error_msg
Definition wslua_debugger.h:92
int64_t hit_count_target
Definition wslua_debugger.h:85
bool active
Definition wslua_debugger.h:83
bool log_also_pause
Definition wslua_debugger.h:96
char * condition
Definition wslua_debugger.h:84
char * file_path
Definition wslua_debugger.h:81
int64_t last_fired_us
Definition wslua_debugger.h:101
int64_t line
Definition wslua_debugger.h:82
Stack frame structure.
Definition wslua_debugger.h:432
int64_t linedefined
Definition wslua_debugger.h:435
char * source
Definition wslua_debugger.h:433
int64_t line
Definition wslua_debugger.h:434
char * name
Definition wslua_debugger.h:440
Variable structure for inspection.
Definition wslua_debugger.h:421
char * value
Definition wslua_debugger.h:423
char * name
Definition wslua_debugger.h:422
char * type
Definition wslua_debugger.h:424
bool can_expand
Definition wslua_debugger.h:425