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 <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
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
145 WS_DLL_PUBLIC bool
146 wslua_debugger_get_user_explicitly_disabled(void);
147
159 WS_DLL_PUBLIC bool
160 wslua_debugger_may_auto_enable_for_breakpoints(void);
161
167 typedef void (*wslua_debugger_ui_update_cb_t)(const char *file_path,
168 int64_t line);
169
174 WS_DLL_PUBLIC void
175 wslua_debugger_register_ui_callback(wslua_debugger_ui_update_cb_t cb);
176
180 WS_DLL_PUBLIC void wslua_debugger_continue(void);
181
188 WS_DLL_PUBLIC void wslua_debugger_step_in(void);
189
196 WS_DLL_PUBLIC void wslua_debugger_step_over(void);
197
204 WS_DLL_PUBLIC void wslua_debugger_step_out(void);
205
214 WS_DLL_PUBLIC void wslua_debugger_set_variable_stack_level(int32_t level);
215
221 WS_DLL_PUBLIC void wslua_debugger_run_to_line(const char *file_path,
222 int64_t line);
223
229 WS_DLL_PUBLIC void wslua_debugger_add_breakpoint(const char *file_path,
230 int64_t line);
231
237 WS_DLL_PUBLIC void wslua_debugger_remove_breakpoint(const char *file_path,
238 int64_t line);
239
246 WS_DLL_PUBLIC void
247 wslua_debugger_set_breakpoint_active(const char *file_path, int64_t line,
248 bool active);
249
253 WS_DLL_PUBLIC void wslua_debugger_clear_breakpoints(void);
254
269 WS_DLL_PUBLIC void
270 wslua_debugger_set_breakpoint_condition(const char *file_path, int64_t line,
271 const char *condition);
272
284 WS_DLL_PUBLIC void
285 wslua_debugger_set_breakpoint_hit_count_target(const char *file_path,
286 int64_t line,
287 int64_t target);
288
297 WS_DLL_PUBLIC void
298 wslua_debugger_set_breakpoint_hit_count_mode(const char *file_path,
299 int64_t line,
300 wslua_hit_count_mode_t mode);
301
313 WS_DLL_PUBLIC void
314 wslua_debugger_set_breakpoint_log_message(const char *file_path,
315 int64_t line,
316 const char *message);
317
327 WS_DLL_PUBLIC void
328 wslua_debugger_set_breakpoint_log_also_pause(const char *file_path,
329 int64_t line,
330 bool also_pause);
331
335 WS_DLL_PUBLIC void
336 wslua_debugger_reset_breakpoint_hit_count(const char *file_path,
337 int64_t line);
338
342 WS_DLL_PUBLIC void wslua_debugger_reset_all_breakpoint_hit_counts(void);
343
357 WS_DLL_PUBLIC bool
358 wslua_debugger_check_condition_syntax(const char *expression,
359 char **err_msg);
360
376 WS_DLL_PUBLIC void
377 wslua_debugger_set_breakpoint_condition_error(const char *file_path,
378 int64_t line,
379 const char *err_msg);
380
387 WS_DLL_PUBLIC int32_t
388 wslua_debugger_get_breakpoint_state(const char *file_path, int64_t line);
389
395 WS_DLL_PUBLIC char *wslua_debugger_canonical_path(const char *file_path);
396
400 typedef struct
401 {
402 char *name;
403 char *value;
404 char *type;
407
411 typedef struct
412 {
413 char *source;
414 int64_t line;
415 int64_t linedefined;
420 char *name;
422
429 WS_DLL_PUBLIC wslua_stack_frame_t *
430 wslua_debugger_get_stack(int32_t *frame_count);
431
437 WS_DLL_PUBLIC void wslua_debugger_free_stack(wslua_stack_frame_t *stack,
438 int32_t frame_count);
439
448 WS_DLL_PUBLIC wslua_variable_t *
449 wslua_debugger_get_variables(const char *path, int32_t *variable_count);
450
456 WS_DLL_PUBLIC void wslua_debugger_free_variables(wslua_variable_t *vars,
457 int32_t variable_count);
458
463 WS_DLL_PUBLIC unsigned wslua_debugger_get_breakpoint_count(void);
464
473 WS_DLL_PUBLIC bool wslua_debugger_get_breakpoint(unsigned idx,
474 const char **file_path,
475 int64_t *line,
476 bool *active);
477
487 WS_DLL_PUBLIC bool wslua_debugger_get_breakpoint_extended(
488 unsigned idx, const char **file_path, int64_t *line, bool *active,
489 const char **condition, int64_t *hit_count_target,
490 int64_t *hit_count, bool *condition_error,
491 const char **log_message,
492 wslua_hit_count_mode_t *hit_count_mode,
493 bool *log_also_pause);
494
512 WS_DLL_PUBLIC char *
513 wslua_debugger_get_breakpoint_condition_error_message(unsigned idx);
514
528 WS_DLL_PUBLIC int32_t
529 wslua_debugger_get_breakpoint_state_canonical(const char *canonical_path,
530 int64_t line,
531 bool *has_extras);
532
543 typedef void (*wslua_debugger_log_emit_callback_t)(const char *file_path,
544 int64_t line,
545 const char *message);
546
550 WS_DLL_PUBLIC void wslua_debugger_register_log_emit_callback(
551 wslua_debugger_log_emit_callback_t callback);
552
577 typedef void (*wslua_debugger_breakpoint_state_dirty_callback_t)(void);
578
582 WS_DLL_PUBLIC void wslua_debugger_register_breakpoint_state_dirty_callback(
583 wslua_debugger_breakpoint_state_dirty_callback_t callback);
584
593 WS_DLL_PUBLIC void wslua_debugger_clear_breakpoint_state_dirty(void);
594
601 typedef void (*wslua_debugger_reload_callback_t)(void);
602
614 WS_DLL_PUBLIC void wslua_debugger_register_reload_callback(
615 wslua_debugger_reload_callback_t callback);
616
631 WS_DLL_PUBLIC bool wslua_debugger_notify_reload(void);
632
639 typedef void (*wslua_debugger_post_reload_callback_t)(void);
640
651 WS_DLL_PUBLIC void wslua_debugger_register_post_reload_callback(
652 wslua_debugger_post_reload_callback_t callback);
653
662 WS_DLL_PUBLIC void wslua_debugger_prepare_for_reload_init(void);
663
671 WS_DLL_PUBLIC void wslua_debugger_notify_post_reload(void);
672
688 WS_DLL_PUBLIC char *wslua_debugger_evaluate(const char *expression,
689 char **error_msg);
690
695 WS_DLL_PUBLIC bool wslua_debugger_is_paused(void);
696
705 WS_DLL_PUBLIC void wslua_debugger_forget_lua_thread(lua_State *L);
706
716 typedef void (*wslua_debugger_script_loaded_callback_t)(
717 const char *file_path);
718
727 WS_DLL_PUBLIC void wslua_debugger_register_script_loaded_callback(
728 wslua_debugger_script_loaded_callback_t callback);
729
738 WS_DLL_PUBLIC void
739 wslua_debugger_notify_script_loaded(const char *file_path);
740
747 typedef void (*wslua_debugger_loaded_script_callback_t)(
748 const char *file_path, void *user_data);
749
763 WS_DLL_PUBLIC void wslua_debugger_foreach_loaded_script(
764 wslua_debugger_loaded_script_callback_t callback, void *user_data);
765
775 WS_DLL_PUBLIC void wslua_debugger_set_error_break_enabled(bool enabled);
776
781 WS_DLL_PUBLIC bool wslua_debugger_get_error_break_enabled(void);
782
795 WS_DLL_PUBLIC bool wslua_debugger_capture_runtime_error(lua_State *L,
796 const char *msg);
797
808 WS_DLL_PUBLIC bool wslua_debugger_after_pcall_failure(lua_State *L);
809
821 WS_DLL_PUBLIC const char *wslua_debugger_consume_error_text(void);
822
823 /*
824 * Watch path APIs (below) take @c debugger.mutex when they touch the
825 * paused Lua state. Call them from the same execution context as the Lua
826 * debugger UI (typically the Qt GUI thread), matching
827 * @ref wslua_debugger_get_variables and other variable accessors. Do not
828 * interleave them with code that resumes the debugger or replaces
829 * @c paused_L from another thread.
830 */
831
833#define WSLUA_WATCH_MAX_PATH_SEGMENTS 32
834
845 WS_DLL_PUBLIC bool wslua_debugger_watch_spec_uses_path_resolution(
846 const char *spec);
847
853 WS_DLL_PUBLIC char *wslua_debugger_watch_variable_path_for_spec(
854 const char *spec);
855
866 WS_DLL_PUBLIC char *wslua_debugger_watch_resolved_variable_path_for_spec(
867 const char *spec);
868
880 WS_DLL_PUBLIC bool wslua_debugger_watch_read_root(
881 const char *spec, char **value_out, char **type_out,
882 bool *can_expand_out, char **error_msg);
883
909 WS_DLL_PUBLIC bool wslua_debugger_read_variable_value_full(
910 const char *variable_path, char **value_out, char **error_msg);
911
912 /*
913 * Watch expression APIs (below) evaluate an arbitrary Lua expression
914 * against the paused state. They share the same instruction-count and
915 * call-depth safety hooks as @ref wslua_debugger_evaluate, and run with
916 * a custom @c _ENV that exposes the paused frame's locals, upvalues,
917 * and globals — so a bare identifier in an expression resolves the
918 * same way an unqualified path watch does.
919 *
920 * Use these for any spec that does not validate as a path under
921 * @ref wslua_debugger_watch_spec_uses_path_resolution. Like the path
922 * APIs above, they take @c debugger.mutex when they touch the paused
923 * Lua state and must be called from the same execution context as the
924 * Qt debugger UI (typically the GUI thread).
925 */
926
939 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_read_root(
940 const char *spec, char **value_out, char **type_out,
941 bool *can_expand_out, char **error_msg);
942
956 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_get_variables(
957 const char *spec, const char *subpath,
958 wslua_variable_t **variables_out, int32_t *count_out,
959 char **error_msg);
960
971 WS_DLL_PUBLIC bool wslua_debugger_watch_expr_read_full(
972 const char *spec, const char *subpath, char **value_out,
973 char **error_msg);
974
975#ifdef __cplusplus
976}
977#endif
978
979#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:412
int64_t linedefined
Definition wslua_debugger.h:415
char * source
Definition wslua_debugger.h:413
int64_t line
Definition wslua_debugger.h:414
char * name
Definition wslua_debugger.h:420
Variable structure for inspection.
Definition wslua_debugger.h:401
char * value
Definition wslua_debugger.h:403
char * name
Definition wslua_debugger.h:402
char * type
Definition wslua_debugger.h:404
bool can_expand
Definition wslua_debugger.h:405