2003-01-22 Martin Baulig <martin@ximian.com>
[mono.git] / mono / jit / debug.h
1 #ifndef __MONO_JIT_DEBUG_H__
2 #define __MONO_JIT_DEBUG_H__
3
4 #include <glib.h>
5 #include <stdio.h>
6 #include <mono/metadata/debug-helpers.h>
7 #include <mono/metadata/debug-mono-symfile.h>
8 #include <mono/metadata/loader.h>
9 #include <mono/jit/jit.h>
10
11 typedef struct _MonoDebugHandle                 MonoDebugHandle;
12 typedef struct _MonoDebuggerSymbolFileTable     MonoDebuggerSymbolFileTable;
13 typedef struct _MonoDebuggerBreakpointInfo      MonoDebuggerBreakpointInfo;
14
15 typedef struct _MonoDebuggerIOLayer             MonoDebuggerIOLayer;
16
17 typedef enum {
18         MONO_DEBUG_FORMAT_NONE,
19         MONO_DEBUG_FORMAT_STABS,
20         MONO_DEBUG_FORMAT_DWARF2,
21         MONO_DEBUG_FORMAT_MONO
22 } MonoDebugFormat;
23
24 typedef enum {
25         MONO_DEBUGGER_EVENT_TYPE_ADDED,
26         MONO_DEBUGGER_EVENT_METHOD_ADDED,
27         MONO_DEBUGGER_EVENT_BREAKPOINT_TRAMPOLINE,
28         MONO_DEBUGGER_EVENT_THREAD_CREATED
29 } MonoDebuggerEvent;
30
31 /*
32  * Functions we export to the debugger.
33  */
34 struct _MonoDebuggerIOLayer
35 {
36         void (*InitializeCriticalSection) (WapiCriticalSection *section);
37         void (*DeleteCriticalSection) (WapiCriticalSection *section);
38         gboolean (*TryEnterCriticalSection) (WapiCriticalSection *section);
39         void (*EnterCriticalSection) (WapiCriticalSection *section);
40         void (*LeaveCriticalSection) (WapiCriticalSection *section);
41
42         guint32 (*WaitForSingleObject) (gpointer handle, guint32 timeout);
43         guint32 (*SignalObjectAndWait) (gpointer signal_handle, gpointer wait,
44                                         guint32 timeout, gboolean alertable);
45         guint32 (*WaitForMultipleObjects) (guint32 numobjects, gpointer *handles,
46                                            gboolean waitall, guint32 timeout);
47
48         gpointer (*CreateSemaphore) (WapiSecurityAttributes *security,
49                                      gint32 initial, gint32 max,
50                                      const guchar *name);
51         gboolean (*ReleaseSemaphore) (gpointer handle, gint32 count, gint32 *prevcount);
52
53         gpointer (*CreateThread) (WapiSecurityAttributes *security,
54                                   guint32 stacksize, WapiThreadStart start,
55                                   gpointer param, guint32 create, guint32 *tid);
56 };
57
58 extern MonoDebuggerIOLayer mono_debugger_io_layer;
59
60 extern void (*mono_debugger_event_handler) (MonoDebuggerEvent event, gpointer data, gpointer data2);
61
62 extern MonoDebugFormat mono_debug_format;
63
64 MonoDebugHandle* mono_debug_open (MonoAssembly *assembly, MonoDebugFormat format, const char **args);
65
66 void           mono_debug_cleanup (void);
67
68 void           mono_debug_add_method (MonoFlowGraph *cfg);
69
70 void           mono_debug_add_type (MonoClass *klass);
71
72 gchar *        mono_debug_source_location_from_address (MonoMethod *method, guint32 address,
73                                                         guint32 *line_number);
74
75 gint32         mono_debug_il_offset_from_address (MonoMethod *method, gint32 address);
76
77 gint32         mono_debug_address_from_il_offset (MonoMethod *method, gint32 il_offset);
78
79 int            mono_method_has_breakpoint (MonoMethod* method, gboolean use_trampoline);
80
81 int            mono_insert_breakpoint (const gchar *method_name, gboolean include_namespace);
82
83 int            mono_insert_breakpoint_full (MonoMethodDesc *desc, gboolean use_trampoline);
84
85 int            mono_remove_breakpoint (int breakpint_id);
86
87 void           mono_debugger_trampoline_breakpoint_callback (void);
88
89 void           mono_debugger_event (MonoDebuggerEvent event, gpointer data, gpointer data2);
90
91 gpointer       mono_debug_create_notification_function (gpointer *notification_address);
92
93 void           mono_debug_init (void);
94 void           mono_debug_lock (void);
95 void           mono_debug_unlock (void);
96 int            mono_debug_update_symbol_file_table (void);
97
98
99 /* DEBUGGER PUBLIC FUNCTION:
100  *
101  * This is a public function which is supposed to be called from within a debugger
102  * each time the program stops. It's used to recreate the symbol file to tell the
103  * debugger about method addresses and such things. After calling this function,
104  * you must tell your debugger to reload its symbol file.
105  */
106 void           mono_debug_make_symbols (void);
107
108 void           mono_debug_write_symbols (MonoDebugHandle* debug);
109
110 /*
111  * Address of the x86 trampoline code.  This is used by the debugger to check
112  * whether a method is a trampoline.
113  */
114 extern guint8 *mono_generic_trampoline_code;
115
116 /*
117  * Address of a special breakpoint code which is used by the debugger to get a breakpoint
118  * after compiling a method.
119  */
120 extern guint8 *mono_breakpoint_trampoline_code;
121
122 /* This is incremented each time the symbol table is modified.
123  * The debugger looks at this variable and if it has a higher value than its current
124  * copy of the symbol table, it must call debugger_update_symbol_file_table().
125  */
126 extern guint32 mono_debugger_symbol_file_table_generation;
127 extern guint32 mono_debugger_symbol_file_table_modified;
128
129 /* Caution: This variable may be accessed at any time from the debugger;
130  *          it is very important not to modify the memory it is pointing to
131  *          without previously setting this pointer back to NULL.
132  */
133 extern MonoDebuggerSymbolFileTable *mono_debugger_symbol_file_table;
134
135 struct _MonoDebuggerSymbolFileTable {
136         guint64 magic;
137         guint32 version;
138         guint32 total_size;
139         guint32 count;
140         guint32 generation;
141         MonoGlobalSymbolFile *global_symfile;
142         MonoSymbolFile *symfiles [MONO_ZERO_LEN_ARRAY];
143 };
144
145 struct _MonoDebuggerBreakpointInfo {
146         guint32 index;
147         gboolean use_trampoline;
148         MonoMethodDesc *desc;
149 };
150
151 #endif /* __MONO_JIT_DEBUG_H__ */