[wasm] Improve virtualenv installation script (#18470)
[mono-project.git] / mono / mini / debugger-engine.h
blobbd9fd62ab7770887fc6e037f3450eba94d9afe88
1 /**
2 * \file
3 */
5 #ifndef __MONO_DEBUGGER_ENGINE_H__
6 #define __MONO_DEBUGGER_ENGINE_H__
8 #include "mini.h"
9 #include <mono/metadata/seq-points-data.h>
10 #include <mono/mini/debugger-state-machine.h>
13 FIXME:
14 - Move EventKind back to debugger-agent.c as it contains sdb wire protocol constants.
15 This is complicated because EventRequest has an event_kind field.
19 typedef enum {
20 EVENT_KIND_VM_START = 0,
21 EVENT_KIND_VM_DEATH = 1,
22 EVENT_KIND_THREAD_START = 2,
23 EVENT_KIND_THREAD_DEATH = 3,
24 EVENT_KIND_APPDOMAIN_CREATE = 4,
25 EVENT_KIND_APPDOMAIN_UNLOAD = 5,
26 EVENT_KIND_METHOD_ENTRY = 6,
27 EVENT_KIND_METHOD_EXIT = 7,
28 EVENT_KIND_ASSEMBLY_LOAD = 8,
29 EVENT_KIND_ASSEMBLY_UNLOAD = 9,
30 EVENT_KIND_BREAKPOINT = 10,
31 EVENT_KIND_STEP = 11,
32 EVENT_KIND_TYPE_LOAD = 12,
33 EVENT_KIND_EXCEPTION = 13,
34 EVENT_KIND_KEEPALIVE = 14,
35 EVENT_KIND_USER_BREAK = 15,
36 EVENT_KIND_USER_LOG = 16,
37 EVENT_KIND_CRASH = 17
38 } EventKind;
40 typedef enum {
41 MOD_KIND_COUNT = 1,
42 MOD_KIND_THREAD_ONLY = 3,
43 MOD_KIND_LOCATION_ONLY = 7,
44 MOD_KIND_EXCEPTION_ONLY = 8,
45 MOD_KIND_STEP = 10,
46 MOD_KIND_ASSEMBLY_ONLY = 11,
47 MOD_KIND_SOURCE_FILE_ONLY = 12,
48 MOD_KIND_TYPE_NAME_ONLY = 13,
49 MOD_KIND_NONE = 14
50 } ModifierKind;
52 typedef enum {
53 STEP_DEPTH_INTO = 0,
54 STEP_DEPTH_OVER = 1,
55 STEP_DEPTH_OUT = 2
56 } StepDepth;
58 typedef enum {
59 STEP_SIZE_MIN = 0,
60 STEP_SIZE_LINE = 1
61 } StepSize;
63 typedef enum {
64 STEP_FILTER_NONE = 0,
65 STEP_FILTER_STATIC_CTOR = 1,
66 STEP_FILTER_DEBUGGER_HIDDEN = 2,
67 STEP_FILTER_DEBUGGER_STEP_THROUGH = 4,
68 STEP_FILTER_DEBUGGER_NON_USER_CODE = 8
69 } StepFilter;
71 typedef struct {
72 ModifierKind kind;
73 union {
74 int count; /* For kind == MOD_KIND_COUNT */
75 MonoInternalThread *thread; /* For kind == MOD_KIND_THREAD_ONLY */
76 MonoClass *exc_class; /* For kind == MONO_KIND_EXCEPTION_ONLY */
77 MonoAssembly **assemblies; /* For kind == MONO_KIND_ASSEMBLY_ONLY */
78 GHashTable *source_files; /* For kind == MONO_KIND_SOURCE_FILE_ONLY */
79 GHashTable *type_names; /* For kind == MONO_KIND_TYPE_NAME_ONLY */
80 StepFilter filter; /* For kind == MOD_KIND_STEP */
81 } data;
82 gboolean caught, uncaught, subclasses, not_filtered_feature, everything_else; /* For kind == MOD_KIND_EXCEPTION_ONLY */
83 } Modifier;
85 typedef struct{
86 int id;
87 int event_kind;
88 int suspend_policy;
89 int nmodifiers;
90 gpointer info;
91 Modifier modifiers [MONO_ZERO_LEN_ARRAY];
92 } EventRequest;
95 * Describes a single step request.
97 typedef struct {
98 EventRequest *req;
99 MonoInternalThread *thread;
100 StepDepth depth;
101 StepSize size;
102 StepFilter filter;
103 gpointer last_sp;
104 gpointer start_sp;
105 MonoMethod *start_method;
106 MonoMethod *last_method;
107 int last_line;
108 /* Whenever single stepping is performed using start/stop_single_stepping () */
109 gboolean global;
110 /* The list of breakpoints used to implement step-over */
111 GSList *bps;
112 /* The number of frames at the start of a step-over */
113 int nframes;
114 /* If set, don't stop in methods that are not part of user assemblies */
115 MonoAssembly** user_assemblies;
116 /* Used to distinguish stepping breakpoint hits in parallel tasks executions */
117 int async_id;
118 /* Used to know if we are in process of async step-out and distishing from exception breakpoints */
119 MonoMethod* async_stepout_method;
120 int refcount;
121 } SingleStepReq;
125 * Contains information about an inserted breakpoint.
127 typedef struct {
128 long il_offset, native_offset;
129 guint8 *ip;
130 MonoJitInfo *ji;
131 MonoDomain *domain;
132 } BreakpointInstance;
135 * Contains generic information about a breakpoint.
137 typedef struct {
139 * The method where the breakpoint is placed. Can be NULL in which case it
140 * is inserted into every method. This is used to implement method entry/
141 * exit events. Can be a generic method definition, in which case the
142 * breakpoint is inserted into every instance.
144 MonoMethod *method;
145 long il_offset;
146 EventRequest *req;
148 * A list of BreakpointInstance structures describing where the breakpoint
149 * was inserted. There could be more than one because of
150 * generics/appdomains/method entry/exit.
152 GPtrArray *children;
153 } MonoBreakpoint;
155 typedef struct {
156 MonoJitInfo *ji;
157 MonoDomain *domain;
158 MonoMethod *method;
159 guint32 native_offset;
160 } DbgEngineStackFrame;
162 typedef struct {
164 * Method where to start single stepping
166 MonoMethod *method;
169 * If ctx is set, tls must belong to the same thread.
171 MonoContext *ctx;
172 void *tls;
175 * Stopped at a throw site
177 gboolean step_to_catch;
180 * Sequence point to start from.
182 SeqPoint sp;
183 MonoSeqPointInfo *info;
186 * Frame data, will be freed at the end of ss_start if provided
188 DbgEngineStackFrame **frames;
189 int nframes;
190 } SingleStepArgs;
193 * OBJECT IDS
197 * Represents an object accessible by the debugger client.
199 typedef struct {
200 /* Unique id used in the wire protocol to refer to objects */
201 int id;
203 * A weakref gc handle pointing to the object. The gc handle is used to
204 * detect if the object was garbage collected.
206 guint32 handle;
207 } ObjRef;
210 void mono_debugger_free_objref (gpointer value);
212 typedef int DbgEngineErrorCode;
213 #define DE_ERR_NONE 0
214 // WARNING WARNING WARNING
215 // Error codes MUST match those of sdb for now
216 #define DE_ERR_NOT_IMPLEMENTED 100
218 MonoGHashTable *
219 mono_debugger_get_thread_states (void);
221 gboolean
222 mono_debugger_is_disconnected (void);
224 gsize
225 mono_debugger_tls_thread_id (DebuggerTlsData *debuggerTlsData);
227 void
228 mono_debugger_set_thread_state (DebuggerTlsData *ref, MonoDebuggerThreadState expected, MonoDebuggerThreadState set);
230 MonoDebuggerThreadState
231 mono_debugger_get_thread_state (DebuggerTlsData *ref);
233 typedef struct {
234 MonoContext *(*tls_get_restore_state) (void *tls);
235 gboolean (*try_process_suspend) (void *tls, MonoContext *ctx);
236 gboolean (*begin_breakpoint_processing) (void *tls, MonoContext *ctx, MonoJitInfo *ji, gboolean from_signal);
237 void (*begin_single_step_processing) (MonoContext *ctx, gboolean from_signal);
239 void (*ss_discard_frame_context) (void *tls);
240 void (*ss_calculate_framecount) (void *tls, MonoContext *ctx, gboolean force_use_ctx, DbgEngineStackFrame ***frames, int *nframes);
241 gboolean (*ensure_jit) (DbgEngineStackFrame *frame);
242 int (*ensure_runtime_is_suspended) (void);
244 int (*get_this_async_id) (DbgEngineStackFrame *frame);
246 void* (*create_breakpoint_events) (GPtrArray *ss_reqs, GPtrArray *bp_reqs, MonoJitInfo *ji, EventKind kind);
247 void (*process_breakpoint_events) (void *_evts, MonoMethod *method, MonoContext *ctx, int il_offset);
249 gboolean (*set_set_notification_for_wait_completion_flag) (DbgEngineStackFrame *f);
250 MonoMethod* (*get_notify_debugger_of_wait_completion_method)(void);
252 int (*ss_create_init_args) (SingleStepReq *ss_req, SingleStepArgs *args);
253 void (*ss_args_destroy) (SingleStepArgs *ss_args);
254 } DebuggerEngineCallbacks;
257 void mono_de_init (DebuggerEngineCallbacks *cbs);
258 void mono_de_cleanup (void);
259 void mono_de_set_log_level (int level, FILE *file);
261 //locking - we expose the lock object from the debugging engine to ensure we keep the same locking semantics of sdb.
262 void mono_de_lock (void);
263 void mono_de_unlock (void);
265 // domain handling
266 void mono_de_foreach_domain (GHFunc func, gpointer user_data);
267 void mono_de_domain_add (MonoDomain *domain);
268 void mono_de_domain_remove (MonoDomain *domain);
270 //breakpoints
271 void mono_de_clear_breakpoint (MonoBreakpoint *bp);
272 MonoBreakpoint* mono_de_set_breakpoint (MonoMethod *method, long il_offset, EventRequest *req, MonoError *error);
273 void mono_de_collect_breakpoints_by_sp (SeqPoint *sp, MonoJitInfo *ji, GPtrArray *ss_reqs, GPtrArray *bp_reqs);
274 void mono_de_clear_breakpoints_for_domain (MonoDomain *domain);
275 void mono_de_add_pending_breakpoints (MonoMethod *method, MonoJitInfo *ji);
276 void mono_de_clear_all_breakpoints (void);
277 MonoBreakpoint * mono_de_get_breakpoint_by_id (int id);
279 //single stepping
280 void mono_de_start_single_stepping (void);
281 void mono_de_stop_single_stepping (void);
283 void mono_de_process_breakpoint (void *tls, gboolean from_signal);
284 void mono_de_process_single_step (void *tls, gboolean from_signal);
285 DbgEngineErrorCode mono_de_ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilter filter, EventRequest *req);
286 void mono_de_cancel_ss (void);
288 #endif