2009-03-03 Zoltan Varga <vargaz@gmail.com>
[mono-debugger.git] / mono / mini / debug-mini.c
blob2b12382e5cdb7472073e05a3b43e718457f5063c
1 /*
2 * debug-mini.c: Mini-specific debugging stuff.
4 * Author:
5 * Martin Baulig (martin@ximian.com)
7 * (C) 2003 Ximian, Inc.
8 */
10 #include "mini.h"
11 #include "jit.h"
12 #include "config.h"
13 #include <mono/metadata/verify.h>
14 #include <mono/metadata/mono-config.h>
15 #include <mono/metadata/mono-debug.h>
16 #include <mono/metadata/appdomain.h>
17 #include <mono/metadata/threads-types.h>
19 #define _IN_THE_MONO_DEBUGGER
20 #include <mono/metadata/mono-debug-debugger.h>
21 #include "debug-mini.h"
23 #ifdef HAVE_VALGRIND_H
24 #include <valgrind/valgrind.h>
25 #endif
27 #ifdef MONO_DEBUGGER_SUPPORTED
28 #include <libgc/include/libgc-mono-debugger.h>
29 #endif
31 typedef struct {
32 guint32 index;
33 MonoMethodDesc *desc;
34 } MiniDebugBreakpointInfo;
36 typedef struct
38 MonoDebugMethodJitInfo *jit;
39 GArray *line_numbers;
40 guint32 has_line_numbers;
41 guint32 breakpoint_id;
42 } MiniDebugMethodInfo;
44 struct _MonoDebuggerThreadInfo {
45 guint64 tid;
46 guint64 lmf_addr;
47 guint64 end_stack;
49 guint64 extended_notifications;
51 /* Next pointer. */
52 MonoDebuggerThreadInfo *next;
55 * The stack bounds are only used when reading a core file.
57 guint64 stack_start;
58 guint64 signal_stack_start;
59 guint32 stack_size;
60 guint32 signal_stack_size;
63 * The debugger doesn't access anything beyond this point.
65 MonoJitTlsData *jit_tls;
66 MonoThread *thread;
69 MonoDebuggerThreadInfo *mono_debugger_thread_table = NULL;
71 static inline void
72 record_line_number (MiniDebugMethodInfo *info, guint32 address, guint32 offset)
74 MonoDebugLineNumberEntry lne;
76 lne.native_offset = address;
77 lne.il_offset = offset;
79 g_array_append_val (info->line_numbers, lne);
83 void
84 mono_debug_init_method (MonoCompile *cfg, MonoBasicBlock *start_block, guint32 breakpoint_id)
86 MiniDebugMethodInfo *info;
88 if (mono_debug_format == MONO_DEBUG_FORMAT_NONE)
89 return;
91 info = g_new0 (MiniDebugMethodInfo, 1);
92 info->breakpoint_id = breakpoint_id;
94 cfg->debug_info = info;
97 void
98 mono_debug_open_method (MonoCompile *cfg)
100 MiniDebugMethodInfo *info;
101 MonoDebugMethodJitInfo *jit;
102 MonoMethodHeader *header;
104 info = (MiniDebugMethodInfo *) cfg->debug_info;
105 if (!info)
106 return;
108 mono_class_init (cfg->method->klass);
110 header = mono_method_get_header (cfg->method);
111 g_assert (header);
113 info->jit = jit = g_new0 (MonoDebugMethodJitInfo, 1);
114 info->line_numbers = g_array_new (FALSE, TRUE, sizeof (MonoDebugLineNumberEntry));
115 jit->num_locals = header->num_locals;
116 jit->locals = g_new0 (MonoDebugVarInfo, jit->num_locals);
119 static void
120 write_variable (MonoInst *inst, MonoDebugVarInfo *var)
122 var->type = inst->inst_vtype;
124 if (inst->opcode == OP_REGVAR)
125 var->index = inst->dreg | MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER;
126 else if (inst->flags & MONO_INST_IS_DEAD)
127 var->index = MONO_DEBUG_VAR_ADDRESS_MODE_DEAD;
128 else {
129 /* the debug interface needs fixing to allow 0(%base) address */
130 var->index = inst->inst_basereg | MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET;
131 var->offset = inst->inst_offset;
136 * mono_debug_add_vg_method:
138 * Register symbol information for the method with valgrind
140 static void
141 mono_debug_add_vg_method (MonoMethod *method, MonoDebugMethodJitInfo *jit)
143 #ifdef VALGRIND_ADD_LINE_INFO
144 MonoMethodHeader *header;
145 MonoDebugMethodInfo *minfo;
146 int i;
147 char *filename = NULL;
148 guint32 address, line_number;
149 const char *full_name;
150 guint32 *addresses;
151 guint32 *lines;
153 if (!RUNNING_ON_VALGRIND)
154 return;
156 header = mono_method_get_header (method);
158 full_name = mono_method_full_name (method, TRUE);
160 addresses = g_new0 (guint32, header->code_size + 1);
161 lines = g_new0 (guint32, header->code_size + 1);
164 * Very simple code to convert the addr->offset mappings that mono has
165 * into [addr-addr] ->line number mappings.
168 minfo = mono_debug_lookup_method (method);
169 if (minfo) {
170 /* Create offset->line number mapping */
171 for (i = 0; i < header->code_size; ++i) {
172 MonoDebugSourceLocation *location;
174 location = mono_debug_symfile_lookup_location (minfo, i);
175 if (!location)
176 continue;
178 lines [i] = location.row;
179 if (!filename)
180 filename = location.source_file;
182 mono_debug_free_source_location (location);
186 /* Create address->offset mapping */
187 for (i = 0; i < jit->num_line_numbers; ++i) {
188 MonoDebugLineNumberEntry *lne = jit->line_numbers [i];
190 g_assert (lne->offset <= header->code_size);
192 if ((addresses [lne->offset] == 0) || (lne->address < addresses [lne->offset]))
193 addresses [lne->offset] = lne->address;
195 /* Fill out missing addresses */
196 address = 0;
197 for (i = 0; i < header->code_size; ++i) {
198 if (addresses [i] == 0)
199 addresses [i] = address;
200 else
201 address = addresses [i];
204 address = 0;
205 line_number = 0;
206 i = 0;
207 while (i < header->code_size) {
208 if (lines [i] == line_number)
209 i ++;
210 else {
211 if (line_number > 0) {
212 //g_assert (addresses [i] - 1 >= address);
214 if (addresses [i] - 1 >= address) {
215 VALGRIND_ADD_LINE_INFO (jit->code_start + address, jit->code_start + addresses [i] - 1, filename, line_number);
216 //printf ("[%d-%d] -> %d.\n", address, addresses [i] - 1, line_number);
219 address = addresses [i];
220 line_number = lines [i];
224 if (line_number > 0) {
225 VALGRIND_ADD_LINE_INFO (jit->code_start + address, jit->code_start + jit->code_size - 1, filename, line_number);
226 //printf ("[%d-%d] -> %d.\n", address, jit->code_size - 1, line_number);
229 VALGRIND_ADD_SYMBOL (jit->code_start, jit->code_size, full_name);
231 g_free (addresses);
232 g_free (lines);
233 #endif /* VALGRIND_ADD_LINE_INFO */
236 void
237 mono_debug_close_method (MonoCompile *cfg)
239 MiniDebugMethodInfo *info;
240 MonoDebugMethodJitInfo *jit;
241 MonoMethodHeader *header;
242 MonoMethodSignature *sig;
243 MonoDebugMethodAddress *debug_info;
244 MonoMethod *method;
245 int i;
247 info = (MiniDebugMethodInfo *) cfg->debug_info;
248 if (!info || !info->jit) {
249 if (info)
250 g_free (info);
251 return;
254 method = cfg->method;
255 header = mono_method_get_header (method);
256 sig = mono_method_signature (method);
258 jit = info->jit;
259 jit->code_start = cfg->native_code;
260 jit->epilogue_begin = cfg->epilog_begin;
261 jit->code_size = cfg->code_len;
263 if (jit->epilogue_begin)
264 record_line_number (info, jit->epilogue_begin, header->code_size);
266 jit->num_params = sig->param_count;
267 jit->params = g_new0 (MonoDebugVarInfo, jit->num_params);
269 for (i = 0; i < jit->num_locals; i++)
270 write_variable (cfg->locals [i], &jit->locals [i]);
272 if (sig->hasthis) {
273 jit->this_var = g_new0 (MonoDebugVarInfo, 1);
274 write_variable (cfg->args [0], jit->this_var);
277 for (i = 0; i < jit->num_params; i++)
278 write_variable (cfg->args [i + sig->hasthis], &jit->params [i]);
280 jit->num_line_numbers = info->line_numbers->len;
281 jit->line_numbers = g_new0 (MonoDebugLineNumberEntry, jit->num_line_numbers);
283 for (i = 0; i < jit->num_line_numbers; i++)
284 jit->line_numbers [i] = g_array_index (info->line_numbers, MonoDebugLineNumberEntry, i);
286 debug_info = mono_debug_add_method (method, jit, cfg->domain);
288 mono_debug_add_vg_method (method, jit);
290 if (info->breakpoint_id)
291 mono_debugger_breakpoint_callback (method, info->breakpoint_id);
293 mono_debugger_check_breakpoints (method, debug_info);
295 mono_debug_free_method_jit_info (jit);
296 g_array_free (info->line_numbers, TRUE);
297 g_free (info);
300 void
301 mono_debug_record_line_number (MonoCompile *cfg, MonoInst *ins, guint32 address)
303 MiniDebugMethodInfo *info;
304 MonoMethodHeader *header;
305 guint32 offset;
307 info = (MiniDebugMethodInfo *) cfg->debug_info;
308 if (!info || !info->jit || !ins->cil_code)
309 return;
311 header = mono_method_get_header (cfg->method);
312 g_assert (header);
314 if ((ins->cil_code < header->code) ||
315 (ins->cil_code > header->code + header->code_size))
316 return;
318 offset = ins->cil_code - header->code;
319 if (!info->has_line_numbers) {
320 info->jit->prologue_end = address;
321 info->has_line_numbers = TRUE;
324 record_line_number (info, address, offset);
327 void
328 mono_debug_open_block (MonoCompile *cfg, MonoBasicBlock *bb, guint32 address)
330 MiniDebugMethodInfo *info;
331 MonoMethodHeader *header;
332 guint32 offset;
334 info = (MiniDebugMethodInfo *) cfg->debug_info;
335 if (!info || !info->jit || !bb->cil_code)
336 return;
338 header = mono_method_get_header (cfg->method);
339 g_assert (header);
341 if ((bb->cil_code < header->code) ||
342 (bb->cil_code > header->code + header->code_size))
343 return;
345 offset = bb->cil_code - header->code;
346 if (!info->has_line_numbers) {
347 info->jit->prologue_end = address;
348 info->has_line_numbers = TRUE;
351 record_line_number (info, address, offset);
354 static inline void
355 encode_value (gint32 value, guint8 *buf, guint8 **endbuf)
357 guint8 *p = buf;
359 //printf ("ENCODE: %d 0x%x.\n", value, value);
362 * Same encoding as the one used in the metadata, extended to handle values
363 * greater than 0x1fffffff.
365 if ((value >= 0) && (value <= 127))
366 *p++ = value;
367 else if ((value >= 0) && (value <= 16383)) {
368 p [0] = 0x80 | (value >> 8);
369 p [1] = value & 0xff;
370 p += 2;
371 } else if ((value >= 0) && (value <= 0x1fffffff)) {
372 p [0] = (value >> 24) | 0xc0;
373 p [1] = (value >> 16) & 0xff;
374 p [2] = (value >> 8) & 0xff;
375 p [3] = value & 0xff;
376 p += 4;
378 else {
379 p [0] = 0xff;
380 p [1] = (value >> 24) & 0xff;
381 p [2] = (value >> 16) & 0xff;
382 p [3] = (value >> 8) & 0xff;
383 p [4] = value & 0xff;
384 p += 5;
386 if (endbuf)
387 *endbuf = p;
390 static inline gint32
391 decode_value (guint8 *ptr, guint8 **rptr)
393 guint8 b = *ptr;
394 gint32 len;
396 if ((b & 0x80) == 0){
397 len = b;
398 ++ptr;
399 } else if ((b & 0x40) == 0){
400 len = ((b & 0x3f) << 8 | ptr [1]);
401 ptr += 2;
402 } else if (b != 0xff) {
403 len = ((b & 0x1f) << 24) |
404 (ptr [1] << 16) |
405 (ptr [2] << 8) |
406 ptr [3];
407 ptr += 4;
409 else {
410 len = (ptr [1] << 24) | (ptr [2] << 16) | (ptr [3] << 8) | ptr [4];
411 ptr += 5;
413 if (rptr)
414 *rptr = ptr;
416 //printf ("DECODE: %d.\n", len);
417 return len;
420 static void
421 serialize_variable (MonoDebugVarInfo *var, guint8 *p, guint8 **endbuf)
423 guint32 flags = var->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS;
425 encode_value (var->index, p, &p);
427 switch (flags) {
428 case MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER:
429 break;
430 case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET:
431 encode_value (var->offset, p, &p);
432 break;
433 case MONO_DEBUG_VAR_ADDRESS_MODE_DEAD:
434 break;
435 default:
436 g_assert_not_reached ();
438 *endbuf = p;
441 void
442 mono_debug_serialize_debug_info (MonoCompile *cfg, guint8 **out_buf, guint32 *buf_len)
444 MonoDebugMethodJitInfo *jit;
445 guint32 size, prev_offset, prev_native_offset;
446 guint8 *buf, *p;
447 int i;
449 /* Can't use cfg->debug_info as it is freed by close_method () */
450 jit = mono_debug_find_method (cfg->method, mono_domain_get ());
451 if (!jit) {
452 *buf_len = 0;
453 return;
456 size = ((jit->num_params + jit->num_locals + 1) * 10) + (jit->num_line_numbers * 10) + 64;
457 p = buf = g_malloc (size);
458 encode_value (jit->epilogue_begin, p, &p);
459 encode_value (jit->prologue_end, p, &p);
460 encode_value (jit->code_size, p, &p);
462 for (i = 0; i < jit->num_params; ++i)
463 serialize_variable (&jit->params [i], p, &p);
465 if (mono_method_signature (cfg->method)->hasthis)
466 serialize_variable (jit->this_var, p, &p);
468 for (i = 0; i < jit->num_locals; i++)
469 serialize_variable (&jit->locals [i], p, &p);
471 encode_value (jit->num_line_numbers, p, &p);
473 prev_offset = 0;
474 prev_native_offset = 0;
475 for (i = 0; i < jit->num_line_numbers; ++i) {
476 /* Sometimes, the offset values are not in increasing order */
477 MonoDebugLineNumberEntry *lne = &jit->line_numbers [i];
478 encode_value (lne->il_offset - prev_offset, p, &p);
479 encode_value (lne->native_offset - prev_native_offset, p, &p);
480 prev_offset = lne->il_offset;
481 prev_native_offset = lne->native_offset;
484 g_assert (p - buf < size);
486 *out_buf = buf;
487 *buf_len = p - buf;
490 static void
491 deserialize_variable (MonoDebugVarInfo *var, guint8 *p, guint8 **endbuf)
493 guint32 flags;
495 var->index = decode_value (p, &p);
497 flags = var->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS;
499 switch (flags) {
500 case MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER:
501 break;
502 case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET:
503 var->offset = decode_value (p, &p);
504 break;
505 case MONO_DEBUG_VAR_ADDRESS_MODE_DEAD:
506 break;
507 default:
508 g_assert_not_reached ();
510 *endbuf = p;
513 static MonoDebugMethodJitInfo *
514 deserialize_debug_info (MonoMethod *method, guint8 *code_start, guint8 *buf, guint32 buf_len)
516 MonoMethodHeader *header;
517 gint32 offset, native_offset, prev_offset, prev_native_offset;
518 MonoDebugMethodJitInfo *jit;
519 guint8 *p;
520 int i;
522 header = mono_method_get_header (method);
523 g_assert (header);
525 jit = g_new0 (MonoDebugMethodJitInfo, 1);
526 jit->code_start = code_start;
527 jit->num_locals = header->num_locals;
528 jit->locals = g_new0 (MonoDebugVarInfo, jit->num_locals);
529 jit->num_params = mono_method_signature (method)->param_count;
530 jit->params = g_new0 (MonoDebugVarInfo, jit->num_params);
532 p = buf;
533 jit->epilogue_begin = decode_value (p, &p);
534 jit->prologue_end = decode_value (p, &p);
535 jit->code_size = decode_value (p, &p);
537 for (i = 0; i < jit->num_params; ++i)
538 deserialize_variable (&jit->params [i], p, &p);
540 if (mono_method_signature (method)->hasthis) {
541 jit->this_var = g_new0 (MonoDebugVarInfo, 1);
542 deserialize_variable (jit->this_var, p, &p);
545 for (i = 0; i < jit->num_locals; i++)
546 deserialize_variable (&jit->locals [i], p, &p);
548 jit->num_line_numbers = decode_value (p, &p);
549 jit->line_numbers = g_new0 (MonoDebugLineNumberEntry, jit->num_line_numbers);
551 prev_offset = 0;
552 prev_native_offset = 0;
553 for (i = 0; i < jit->num_line_numbers; ++i) {
554 MonoDebugLineNumberEntry *lne = &jit->line_numbers [i];
556 offset = prev_offset + decode_value (p, &p);
557 native_offset = prev_native_offset + decode_value (p, &p);
559 lne->native_offset = native_offset;
560 lne->il_offset = offset;
562 prev_offset = offset;
563 prev_native_offset = native_offset;
566 return jit;
569 void
570 mono_debug_add_aot_method (MonoDomain *domain, MonoMethod *method, guint8 *code_start,
571 guint8 *debug_info, guint32 debug_info_len)
573 MonoDebugMethodJitInfo *jit;
575 if (mono_debug_format == MONO_DEBUG_FORMAT_NONE)
576 return;
578 if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
579 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) ||
580 (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
581 (method->flags & METHOD_ATTRIBUTE_ABSTRACT) ||
582 (method->wrapper_type != MONO_WRAPPER_NONE))
583 return;
585 if (debug_info_len == 0)
586 return;
588 jit = deserialize_debug_info (method, code_start, debug_info, debug_info_len);
590 mono_debug_add_method (method, jit, domain);
592 mono_debug_add_vg_method (method, jit);
594 mono_debug_free_method_jit_info (jit);
597 void
598 mono_debug_add_icall_wrapper (MonoMethod *method, MonoJitICallInfo* callinfo)
600 if (mono_debug_format == MONO_DEBUG_FORMAT_NONE)
601 return;
603 // mono_debug_add_wrapper (method, callinfo->wrapper, callinfo->func);
606 static void
607 print_var_info (MonoDebugVarInfo *info, int idx, const char *name, const char *type)
609 switch (info->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS) {
610 case MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER:
611 g_print ("%s %s (%d) in register %s\n", type, name, idx, mono_arch_regname (info->index & (~MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS)));
612 break;
613 case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET:
614 g_print ("%s %s (%d) in memory: base register %s + %d\n", type, name, idx, mono_arch_regname (info->index & (~MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS)), info->offset);
615 break;
616 case MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS:
617 default:
618 g_assert_not_reached ();
623 * mono_debug_print_locals:
625 * Prints to stdout the information about the local variables in
626 * a method (if @only_arguments is false) or about the arguments.
627 * The information includes the storage info (where the variable
628 * lives, in a register or in memory).
629 * The method is found by looking up what method has been emitted at
630 * the instruction address @ip.
631 * This is for use inside a debugger.
633 void
634 mono_debug_print_vars (gpointer ip, gboolean only_arguments)
636 MonoDomain *domain = mono_domain_get ();
637 MonoJitInfo *ji = mono_jit_info_table_find (domain, ip);
638 MonoDebugMethodJitInfo *jit;
639 int i;
641 if (!ji)
642 return;
644 jit = mono_debug_find_method (mono_jit_info_get_method (ji), domain);
645 if (!jit)
646 return;
648 if (only_arguments) {
649 char **names;
650 names = g_new (char *, jit->num_params);
651 mono_method_get_param_names (mono_jit_info_get_method (ji), (const char **) names);
652 if (jit->this_var)
653 print_var_info (jit->this_var, 0, "this", "Arg");
654 for (i = 0; i < jit->num_params; ++i) {
655 print_var_info (&jit->params [i], i, names [i]? names [i]: "unknown name", "Arg");
657 g_free (names);
658 } else {
659 for (i = 0; i < jit->num_locals; ++i) {
660 print_var_info (&jit->locals [i], i, "", "Local");
663 mono_debug_free_method_jit_info (jit);
667 * The old Debugger breakpoint interface.
669 * This interface is used to insert breakpoints on methods which are not yet JITed.
670 * The debugging code keeps a list of all such breakpoints and automatically inserts the
671 * breakpoint when the method is JITed.
674 static GPtrArray *breakpoints = NULL;
677 mono_debugger_insert_breakpoint_full (MonoMethodDesc *desc)
679 static int last_breakpoint_id = 0;
680 MiniDebugBreakpointInfo *info;
682 info = g_new0 (MiniDebugBreakpointInfo, 1);
683 info->desc = desc;
684 info->index = ++last_breakpoint_id;
686 if (!breakpoints)
687 breakpoints = g_ptr_array_new ();
689 g_ptr_array_add (breakpoints, info);
691 return info->index;
695 mono_debugger_remove_breakpoint (int breakpoint_id)
697 int i;
699 if (!breakpoints)
700 return 0;
702 for (i = 0; i < breakpoints->len; i++) {
703 MiniDebugBreakpointInfo *info = g_ptr_array_index (breakpoints, i);
705 if (info->index != breakpoint_id)
706 continue;
708 mono_method_desc_free (info->desc);
709 g_ptr_array_remove (breakpoints, info);
710 g_free (info);
711 return 1;
714 return 0;
718 mono_debugger_insert_breakpoint (const gchar *method_name, gboolean include_namespace)
720 MonoMethodDesc *desc;
722 desc = mono_method_desc_new (method_name, include_namespace);
723 if (!desc)
724 return 0;
726 return mono_debugger_insert_breakpoint_full (desc);
730 mono_debugger_method_has_breakpoint (MonoMethod *method)
732 int i;
734 if (!breakpoints || (method->wrapper_type != MONO_WRAPPER_NONE))
735 return 0;
737 for (i = 0; i < breakpoints->len; i++) {
738 MiniDebugBreakpointInfo *info = g_ptr_array_index (breakpoints, i);
740 if (!mono_method_desc_full_match (info->desc, method))
741 continue;
743 return info->index;
746 return 0;
749 void
750 mono_debugger_breakpoint_callback (MonoMethod *method, guint32 index)
752 mono_debugger_event (MONO_DEBUGGER_EVENT_JIT_BREAKPOINT, (guint64) (gsize) method, index);
755 void
756 mono_debugger_thread_created (gsize tid, MonoThread *thread, MonoJitTlsData *jit_tls)
758 #ifdef MONO_DEBUGGER_SUPPORTED
759 size_t stsize = 0;
760 guint8 *staddr = NULL;
761 MonoDebuggerThreadInfo *info;
763 if (mono_debug_format == MONO_DEBUG_FORMAT_NONE)
764 return;
766 mono_debugger_lock ();
768 mono_thread_get_stack_bounds (&staddr, &stsize);
770 info = g_new0 (MonoDebuggerThreadInfo, 1);
771 info->tid = tid;
772 info->thread = thread;
773 info->stack_start = (guint64) (gsize) staddr;
774 info->signal_stack_start = (guint64) (gsize) jit_tls->signal_stack;
775 info->stack_size = stsize;
776 info->signal_stack_size = jit_tls->signal_stack_size;
777 info->end_stack = (guint64) (gsize) GC_mono_debugger_get_stack_ptr ();
778 info->lmf_addr = (guint64) (gsize) mono_get_lmf_addr ();
779 info->jit_tls = jit_tls;
781 info->next = mono_debugger_thread_table;
782 mono_debugger_thread_table = info;
784 mono_debugger_event (MONO_DEBUGGER_EVENT_THREAD_CREATED,
785 tid, (guint64) (gsize) info);
787 mono_debugger_unlock ();
788 #endif /* MONO_DEBUGGER_SUPPORTED */
791 void
792 mono_debugger_thread_cleanup (MonoJitTlsData *jit_tls)
794 #ifdef MONO_DEBUGGER_SUPPORTED
795 MonoDebuggerThreadInfo **ptr;
797 if (mono_debug_format == MONO_DEBUG_FORMAT_NONE)
798 return;
800 mono_debugger_lock ();
802 for (ptr = &mono_debugger_thread_table; *ptr; ptr = &(*ptr)->next) {
803 MonoDebuggerThreadInfo *info = *ptr;
805 if (info->jit_tls != jit_tls)
806 continue;
808 mono_debugger_event (MONO_DEBUGGER_EVENT_THREAD_CLEANUP,
809 info->tid, (guint64) (gsize) info);
811 *ptr = info->next;
812 g_free (info);
813 break;
816 mono_debugger_unlock ();
817 #endif
820 void
821 mono_debugger_extended_notification (MonoDebuggerEvent event, guint64 data, guint64 arg)
823 #ifdef MONO_DEBUGGER_SUPPORTED
824 MonoDebuggerThreadInfo **ptr;
825 MonoThread *thread = mono_thread_current ();
827 if (!mono_debug_using_mono_debugger ())
828 return;
830 mono_debugger_lock ();
832 for (ptr = &mono_debugger_thread_table; *ptr; ptr = &(*ptr)->next) {
833 MonoDebuggerThreadInfo *info = *ptr;
835 if (info->thread != thread)
836 continue;
838 if ((info->extended_notifications & (int) event) == 0)
839 continue;
841 mono_debugger_event (event, data, arg);
844 mono_debugger_unlock ();
845 #endif
848 void
849 mono_debugger_trampoline_compiled (MonoMethod *method, const guint8 *code)
851 mono_debugger_extended_notification (MONO_DEBUGGER_EVENT_TRAMPOLINE,
852 (guint64) (gsize) method, (guint64) (gsize) code);