Wireshark 5.1.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 <gerald@wireshark.org>
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
44 typedef enum
45 {
47 WSLUA_HIT_COUNT_MODE_FROM = 0,
49 WSLUA_HIT_COUNT_MODE_EVERY = 1,
51 WSLUA_HIT_COUNT_MODE_ONCE = 2,
52 } wslua_hit_count_mode_t;
53
69 typedef struct _wslua_breakpoint_t
70 {
71 char *file_path;
72 int64_t line;
73 bool active;
74 char *condition;
76 int64_t hit_count;
77 wslua_hit_count_mode_t hit_count_mode;
91 int64_t last_fired_us;
92 } wslua_breakpoint_t;
93
98 WS_DLL_PUBLIC void wslua_debugger_init(lua_State *L);
99
104 WS_DLL_PUBLIC bool wslua_debugger_is_enabled(void);
105
110 WS_DLL_PUBLIC void wslua_debugger_set_enabled(bool enabled);
111
121 WS_DLL_PUBLIC void
122 wslua_debugger_set_user_explicitly_disabled(bool user_wants_debugger_stay_off);
123
135 WS_DLL_PUBLIC bool
136 wslua_debugger_get_user_explicitly_disabled(void);
137
149 WS_DLL_PUBLIC bool
150 wslua_debugger_may_auto_enable_for_breakpoints(void);
151
157 typedef void (*wslua_debugger_ui_update_cb_t)(const char *file_path,
158 int64_t line);
159
164 WS_DLL_PUBLIC void
165 wslua_debugger_register_ui_callback(wslua_debugger_ui_update_cb_t cb);
166
170 WS_DLL_PUBLIC void wslua_debugger_continue(void);
171
178 WS_DLL_PUBLIC void wslua_debugger_step_in(void);
179
186 WS_DLL_PUBLIC void wslua_debugger_step_over(void);
187
194 WS_DLL_PUBLIC void wslua_debugger_step_out(void);
195
204 WS_DLL_PUBLIC void wslua_debugger_set_variable_stack_level(int32_t level);
205
211 WS_DLL_PUBLIC void wslua_debugger_run_to_line(const char *file_path,
212 int64_t line);
213
219 WS_DLL_PUBLIC void wslua_debugger_add_breakpoint(const char *file_path,
220 int64_t line);
221
227 WS_DLL_PUBLIC void wslua_debugger_remove_breakpoint(const char *file_path,
228 int64_t line);
229
236 WS_DLL_PUBLIC void
237 wslua_debugger_set_breakpoint_active(const char *file_path, int64_t line,
238 bool active);
239
243 WS_DLL_PUBLIC void wslua_debugger_clear_breakpoints(void);
244
259 WS_DLL_PUBLIC void
260 wslua_debugger_set_breakpoint_condition(const char *file_path, int64_t line,
261 const char *condition);
262
274 WS_DLL_PUBLIC void
275 wslua_debugger_set_breakpoint_hit_count_target(const char *file_path,
276 int64_t line,
277 int64_t target);
278
287 WS_DLL_PUBLIC void
288 wslua_debugger_set_breakpoint_hit_count_mode(const char *file_path,
289 int64_t line,
290 wslua_hit_count_mode_t mode);
291
303 WS_DLL_PUBLIC void
304 wslua_debugger_set_breakpoint_log_message(const char *file_path,
305 int64_t line,
306 const char *message);
307
317 WS_DLL_PUBLIC void
318 wslua_debugger_set_breakpoint_log_also_pause(const char *file_path,
319 int64_t line,
320 bool also_pause);
321
325 WS_DLL_PUBLIC void
326 wslua_debugger_reset_breakpoint_hit_count(const char *file_path,
327 int64_t line);
328
332 WS_DLL_PUBLIC void wslua_debugger_reset_all_breakpoint_hit_counts(void);
333
347 WS_DLL_PUBLIC bool
348 wslua_debugger_check_condition_syntax(const char *expression,
349 char **err_msg);
350
366 WS_DLL_PUBLIC void
367 wslua_debugger_set_breakpoint_condition_error(const char *file_path,
368 int64_t line,
369 const char *err_msg);
370
377 WS_DLL_PUBLIC int32_t
378 wslua_debugger_get_breakpoint_state(const char *file_path, int64_t line);
379
385 WS_DLL_PUBLIC char *wslua_debugger_canonical_path(const char *file_path);
386
390 typedef struct
391 {
392 char *name;
393 char *value;
394 char *type;
397
401 typedef struct
402 {
403 char *source;
404 int64_t line;
405 int64_t linedefined;
410 char *name;
412
419 WS_DLL_PUBLIC wslua_stack_frame_t *
420 wslua_debugger_get_stack(int32_t *frame_count);
421
427 WS_DLL_PUBLIC void wslua_debugger_free_stack(wslua_stack_frame_t *stack,
428 int32_t frame_count);
429
438 WS_DLL_PUBLIC wslua_variable_t *
439 wslua_debugger_get_variables(const char *path, int32_t *variable_count);
440
446 WS_DLL_PUBLIC void wslua_debugger_free_variables(wslua_variable_t *vars,
447 int32_t variable_count);
448
453 WS_DLL_PUBLIC unsigned wslua_debugger_get_breakpoint_count(void);
454
463 WS_DLL_PUBLIC bool wslua_debugger_get_breakpoint(unsigned idx,
464 const char **file_path,
465 int64_t *line,
466 bool *active);
467
477 WS_DLL_PUBLIC bool wslua_debugger_get_breakpoint_extended(
478 unsigned idx, const char **file_path, int64_t *line, bool *active,
479 const char **condition, int64_t *hit_count_target,
480 int64_t *hit_count, bool *condition_error,
481 const char **log_message,
482 wslua_hit_count_mode_t *hit_count_mode,
483 bool *log_also_pause);
484
502 WS_DLL_PUBLIC char *
503 wslua_debugger_get_breakpoint_condition_error_message(unsigned idx);
504
518 WS_DLL_PUBLIC int32_t
519 wslua_debugger_get_breakpoint_state_canonical(const char *canonical_path,
520 int64_t line,
521 bool *has_extras);
522
533 typedef void (*wslua_debugger_log_emit_callback_t)(const char *file_path,
534 int64_t line,
535 const char *message);
536
540 WS_DLL_PUBLIC void wslua_debugger_register_log_emit_callback(
541 wslua_debugger_log_emit_callback_t callback);
542
567 typedef void (*wslua_debugger_breakpoint_state_dirty_callback_t)(void);
568
572 WS_DLL_PUBLIC void wslua_debugger_register_breakpoint_state_dirty_callback(
573 wslua_debugger_breakpoint_state_dirty_callback_t callback);
574
583 WS_DLL_PUBLIC void wslua_debugger_clear_breakpoint_state_dirty(void);
584
591 typedef void (*wslua_debugger_reload_callback_t)(void);
592
604 WS_DLL_PUBLIC void wslua_debugger_register_reload_callback(
605 wslua_debugger_reload_callback_t callback);
606
621 WS_DLL_PUBLIC bool wslua_debugger_notify_reload(void);
622
629 typedef void (*wslua_debugger_post_reload_callback_t)(void);
630
641 WS_DLL_PUBLIC void wslua_debugger_register_post_reload_callback(
642 wslua_debugger_post_reload_callback_t callback);
643
652 WS_DLL_PUBLIC void wslua_debugger_prepare_for_reload_init(void);
653
661 WS_DLL_PUBLIC void wslua_debugger_notify_post_reload(void);
662
678 WS_DLL_PUBLIC char *wslua_debugger_evaluate(const char *expression,
679 char **error_msg);
680
685 WS_DLL_PUBLIC bool wslua_debugger_is_paused(void);
686
695 WS_DLL_PUBLIC void wslua_debugger_forget_lua_thread(lua_State *L);
696
706 typedef void (*wslua_debugger_script_loaded_callback_t)(
707 const char *file_path);
708
717 WS_DLL_PUBLIC void wslua_debugger_register_script_loaded_callback(
718 wslua_debugger_script_loaded_callback_t callback);
719
728 WS_DLL_PUBLIC void
729 wslua_debugger_notify_script_loaded(const char *file_path);
730
737 typedef void (*wslua_debugger_loaded_script_callback_t)(
738 const char *file_path, void *user_data);
739
753 WS_DLL_PUBLIC void wslua_debugger_foreach_loaded_script(
754 wslua_debugger_loaded_script_callback_t callback, void *user_data);
755
765 WS_DLL_PUBLIC void wslua_debugger_set_error_break_enabled(bool enabled);
766
771 WS_DLL_PUBLIC bool wslua_debugger_get_error_break_enabled(void);
772
785 WS_DLL_PUBLIC bool wslua_debugger_capture_runtime_error(lua_State *L,
786 const char *msg);
787
798 WS_DLL_PUBLIC bool wslua_debugger_after_pcall_failure(lua_State *L);
799
811 WS_DLL_PUBLIC const char *wslua_debugger_consume_error_text(void);
812
813 /*
814 * Watch path APIs (below) take @c debugger.mutex when they touch the
815 * paused Lua state. Call them from the same execution context as the Lua
816 * debugger UI (typically the Qt GUI thread), matching
817 * @ref wslua_debugger_get_variables and other variable accessors. Do not
818 * interleave them with code that resumes the debugger or replaces
819 * @c paused_L from another thread.
820 */
821
823#define WSLUA_WATCH_MAX_PATH_SEGMENTS 32
824
835 WS_DLL_PUBLIC bool wslua_debugger_watch_spec_uses_path_resolution(
836 const char *spec);
837
843 WS_DLL_PUBLIC char *wslua_debugger_watch_variable_path_for_spec(
844 const char *spec);
845
856 WS_DLL_PUBLIC char *wslua_debugger_watch_resolved_variable_path_for_spec(
857 const char *spec);
858
870 WS_DLL_PUBLIC bool wslua_debugger_watch_read_root(
871 const char *spec, char **value_out, char **type_out,
872 bool *can_expand_out, char **error_msg);
873
899 WS_DLL_PUBLIC bool wslua_debugger_read_variable_value_full(
900 const char *variable_path, char **value_out, char **error_msg);
901
902 /*
903 * Watch expression APIs (below) evaluate an arbitrary Lua expression
904 * against the paused state. They share the same instruction-count and
905 * call-depth safety hooks as @ref wslua_debugger_evaluate, and run with
906 * a custom @c _ENV that exposes the paused frame's locals, upvalues,
907 * and globals — so a bare identifier in an expression resolves the
908 * same way an unqualified path watch does.
909 *
910 * Use these for any spec that does not validate as a path under
911 * @ref wslua_debugger_watch_spec_uses_path_resolution. Like the path
912 * APIs above, they take @c debugger.mutex when they touch the paused
913 * Lua state and must be called from the same execution context as the
914 * Qt debugger UI (typically the GUI thread).
915 */
916
929 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_read_root(
930 const char *spec, char **value_out, char **type_out,
931 bool *can_expand_out, char **error_msg);
932
946 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_get_variables(
947 const char *spec, const char *subpath,
948 wslua_variable_t **variables_out, int32_t *count_out,
949 char **error_msg);
950
961 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_read_full(
962 const char *spec, const char *subpath, char **value_out,
963 char **error_msg);
964
965#ifdef __cplusplus
966}
967#endif
968
969#endif /* __WSLUA_DEBUGGER_H__ */
Breakpoint structure for in-memory storage.
Definition wslua_debugger.h:70
char * log_message
Definition wslua_debugger.h:85
wslua_hit_count_mode_t hit_count_mode
Definition wslua_debugger.h:77
int64_t hit_count
Definition wslua_debugger.h:76
bool condition_error
Definition wslua_debugger.h:81
char * condition_error_msg
Definition wslua_debugger.h:82
int64_t hit_count_target
Definition wslua_debugger.h:75
bool active
Definition wslua_debugger.h:73
bool log_also_pause
Definition wslua_debugger.h:86
char * condition
Definition wslua_debugger.h:74
char * file_path
Definition wslua_debugger.h:71
int64_t last_fired_us
Definition wslua_debugger.h:91
int64_t line
Definition wslua_debugger.h:72
Stack frame structure.
Definition wslua_debugger.h:402
int64_t linedefined
Definition wslua_debugger.h:405
char * source
Definition wslua_debugger.h:403
int64_t line
Definition wslua_debugger.h:404
char * name
Definition wslua_debugger.h:410
Variable structure for inspection.
Definition wslua_debugger.h:391
char * value
Definition wslua_debugger.h:393
char * name
Definition wslua_debugger.h:392
char * type
Definition wslua_debugger.h:394
bool can_expand
Definition wslua_debugger.h:395