[System] Fixes UdpClient.Receive with IPv6 endpoint
[mono.git] / mono / mini / debug-mini.c
1 /*
2  * debug-mini.c: Mini-specific debugging stuff.
3  *
4  * Author:
5  *   Martin Baulig (martin@ximian.com)
6  *
7  * (C) 2003 Ximian, Inc.
8  */
9
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>
18
19 #include <mono/metadata/mono-debug-debugger.h>
20
21 #include <mono/utils/valgrind.h>
22
23 typedef struct {
24         guint32 index;
25         MonoMethodDesc *desc;
26 } MiniDebugBreakpointInfo;
27
28 typedef struct
29 {
30         MonoDebugMethodJitInfo *jit;
31         GArray *line_numbers;
32         guint32 has_line_numbers;
33         guint32 breakpoint_id;
34 } MiniDebugMethodInfo;
35
36 static inline void
37 record_line_number (MiniDebugMethodInfo *info, guint32 address, guint32 offset)
38 {
39         MonoDebugLineNumberEntry lne;
40
41         lne.native_offset = address;
42         lne.il_offset = offset;
43
44         g_array_append_val (info->line_numbers, lne);
45 }
46
47
48 void
49 mono_debug_init_method (MonoCompile *cfg, MonoBasicBlock *start_block, guint32 breakpoint_id)
50 {
51         MiniDebugMethodInfo *info;
52
53         if (!mono_debug_enabled ())
54                 return;
55
56         info = g_new0 (MiniDebugMethodInfo, 1);
57         info->breakpoint_id = breakpoint_id;
58
59         cfg->debug_info = info;
60 }
61
62 void
63 mono_debug_open_method (MonoCompile *cfg)
64 {
65         MiniDebugMethodInfo *info;
66         MonoDebugMethodJitInfo *jit;
67         MonoMethodHeader *header;
68
69         info = (MiniDebugMethodInfo *) cfg->debug_info;
70         if (!info)
71                 return;
72
73         mono_class_init (cfg->method->klass);
74
75         header = cfg->header;
76         g_assert (header);
77         
78         info->jit = jit = g_new0 (MonoDebugMethodJitInfo, 1);
79         info->line_numbers = g_array_new (FALSE, TRUE, sizeof (MonoDebugLineNumberEntry));
80         jit->num_locals = header->num_locals;
81         jit->locals = g_new0 (MonoDebugVarInfo, jit->num_locals);
82 }
83
84 static void
85 write_variable (MonoInst *inst, MonoDebugVarInfo *var)
86 {
87         var->type = inst->inst_vtype;
88
89         if (inst->opcode == OP_REGVAR)
90                 var->index = inst->dreg | MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER;
91         else if (inst->flags & MONO_INST_IS_DEAD)
92                 var->index = MONO_DEBUG_VAR_ADDRESS_MODE_DEAD;
93         else if (inst->opcode == OP_REGOFFSET) {
94                 /* the debug interface needs fixing to allow 0(%base) address */
95                 var->index = inst->inst_basereg | MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET;
96                 var->offset = inst->inst_offset;
97         } else if (inst->opcode == OP_GSHAREDVT_ARG_REGOFFSET) {
98                 var->index = inst->inst_basereg | MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET_INDIR;
99                 var->offset = inst->inst_offset;
100         } else if (inst->opcode == OP_GSHAREDVT_LOCAL) {
101                 var->index = inst->inst_imm | MONO_DEBUG_VAR_ADDRESS_MODE_GSHAREDVT_LOCAL;
102         } else if (inst->opcode == OP_VTARG_ADDR) {
103                 MonoInst *vtaddr;
104
105                 vtaddr = inst->inst_left;
106                 g_assert (vtaddr->opcode == OP_REGOFFSET);
107                 var->offset = vtaddr->inst_offset;
108                 var->index  = vtaddr->inst_basereg | MONO_DEBUG_VAR_ADDRESS_MODE_VTADDR;
109         } else {
110                 g_assert_not_reached ();
111         }
112 }
113
114 /*
115  * mono_debug_add_vg_method:
116  *
117  *  Register symbol information for the method with valgrind
118  */
119 static void 
120 mono_debug_add_vg_method (MonoMethod *method, MonoDebugMethodJitInfo *jit)
121 {
122 #ifdef VALGRIND_ADD_LINE_INFO
123         MonoMethodHeader *header;
124         MonoDebugMethodInfo *minfo;
125         int i;
126         char *filename = NULL;
127         guint32 address, line_number;
128         const char *full_name;
129         guint32 *addresses;
130         guint32 *lines;
131
132         if (!RUNNING_ON_VALGRIND)
133                 return;
134
135         header = mono_method_get_header (method);
136
137         full_name = mono_method_full_name (method, TRUE);
138
139         addresses = g_new0 (guint32, header->code_size + 1);
140         lines = g_new0 (guint32, header->code_size + 1);
141
142         /* 
143          * Very simple code to convert the addr->offset mappings that mono has
144          * into [addr-addr] ->line number mappings.
145          */
146
147         minfo = mono_debug_lookup_method (method);
148         if (minfo) {
149                 /* Create offset->line number mapping */
150                 for (i = 0; i < header->code_size; ++i) {
151                         MonoDebugSourceLocation *location;
152
153                         location = mono_debug_symfile_lookup_location (minfo, i);
154                         if (!location)
155                                 continue;
156
157                         lines [i] = location.row;
158                         if (!filename)
159                                 filename = location.source_file;
160
161                         mono_debug_free_source_location (location);
162                 }
163         }
164
165         /* Create address->offset mapping */
166         for (i = 0; i < jit->num_line_numbers; ++i) {
167                 MonoDebugLineNumberEntry *lne = jit->line_numbers [i];
168
169                 g_assert (lne->offset <= header->code_size);
170
171                 if ((addresses [lne->offset] == 0) || (lne->address < addresses [lne->offset]))
172                         addresses [lne->offset] = lne->address;
173         }
174         /* Fill out missing addresses */
175         address = 0;
176         for (i = 0; i < header->code_size; ++i) {
177                 if (addresses [i] == 0)
178                         addresses [i] = address;
179                 else
180                         address = addresses [i];
181         }
182         
183         address = 0;
184         line_number = 0;
185         i = 0;
186         while (i < header->code_size) {
187                 if (lines [i] == line_number)
188                         i ++;
189                 else {
190                         if (line_number > 0) {
191                                 //g_assert (addresses [i] - 1 >= address);
192                                 
193                                 if (addresses [i] - 1 >= address) {
194                                         VALGRIND_ADD_LINE_INFO (jit->code_start + address, jit->code_start + addresses [i] - 1, filename, line_number);
195                                         //printf ("[%d-%d] -> %d.\n", address, addresses [i] - 1, line_number);
196                                 }
197                         }
198                         address = addresses [i];
199                         line_number = lines [i];
200                 }
201         }
202
203         if (line_number > 0) {
204                 VALGRIND_ADD_LINE_INFO (jit->code_start + address, jit->code_start + jit->code_size - 1, filename, line_number);
205                 //printf ("[%d-%d] -> %d.\n", address, jit->code_size - 1, line_number);
206         }
207
208         VALGRIND_ADD_SYMBOL (jit->code_start, jit->code_size, full_name);
209
210         g_free (addresses);
211         g_free (lines);
212         mono_metadata_free_mh (header);
213 #endif /* VALGRIND_ADD_LINE_INFO */
214 }
215
216 void
217 mono_debug_close_method (MonoCompile *cfg)
218 {
219         MiniDebugMethodInfo *info;
220         MonoDebugMethodJitInfo *jit;
221         MonoMethodHeader *header;
222         MonoMethodSignature *sig;
223         MonoMethod *method;
224         int i;
225
226         info = (MiniDebugMethodInfo *) cfg->debug_info;
227         if (!info || !info->jit) {
228                 if (info)
229                         g_free (info);
230                 return;
231         }
232
233         method = cfg->method;
234         header = cfg->header;
235         sig = mono_method_signature (method);
236
237         jit = info->jit;
238         jit->code_start = cfg->native_code;
239         jit->epilogue_begin = cfg->epilog_begin;
240         jit->code_size = cfg->code_len;
241
242         if (jit->epilogue_begin)
243                    record_line_number (info, jit->epilogue_begin, header->code_size);
244
245         jit->num_params = sig->param_count;
246         jit->params = g_new0 (MonoDebugVarInfo, jit->num_params);
247
248         for (i = 0; i < jit->num_locals; i++)
249                 write_variable (cfg->locals [i], &jit->locals [i]);
250
251         if (sig->hasthis) {
252                 jit->this_var = g_new0 (MonoDebugVarInfo, 1);
253                 write_variable (cfg->args [0], jit->this_var);
254         }
255
256         for (i = 0; i < jit->num_params; i++)
257                 write_variable (cfg->args [i + sig->hasthis], &jit->params [i]);
258
259         if (cfg->gsharedvt_info_var) {
260                 jit->gsharedvt_info_var = g_new0 (MonoDebugVarInfo, 1);
261                 jit->gsharedvt_locals_var = g_new0 (MonoDebugVarInfo, 1);
262                 write_variable (cfg->gsharedvt_info_var, jit->gsharedvt_info_var);
263                 write_variable (cfg->gsharedvt_locals_var, jit->gsharedvt_locals_var);
264         }
265
266         jit->num_line_numbers = info->line_numbers->len;
267         jit->line_numbers = g_new0 (MonoDebugLineNumberEntry, jit->num_line_numbers);
268
269         for (i = 0; i < jit->num_line_numbers; i++)
270                 jit->line_numbers [i] = g_array_index (info->line_numbers, MonoDebugLineNumberEntry, i);
271
272         mono_debug_add_method (cfg->method_to_register, jit, cfg->domain);
273
274         mono_debug_add_vg_method (method, jit);
275
276         mono_debug_free_method_jit_info (jit);
277         mono_debug_free_method (cfg);
278 }
279
280 void
281 mono_debug_free_method (MonoCompile *cfg)
282 {
283         MiniDebugMethodInfo *info;
284
285         info = (MiniDebugMethodInfo *) cfg->debug_info;
286         if (info) {
287                 if (info->line_numbers)
288                         g_array_free (info->line_numbers, TRUE);
289                 g_free (info);
290                 cfg->debug_info = NULL; 
291         }
292 }
293
294 void
295 mono_debug_record_line_number (MonoCompile *cfg, MonoInst *ins, guint32 address)
296 {
297         MiniDebugMethodInfo *info;
298         MonoMethodHeader *header;
299         guint32 offset;
300
301         info = (MiniDebugMethodInfo *) cfg->debug_info;
302         if (!info || !info->jit || !ins->cil_code)
303                 return;
304
305         header = cfg->header;
306         g_assert (header);
307
308         if ((ins->cil_code < header->code) ||
309             (ins->cil_code > header->code + header->code_size))
310                 return;
311
312         offset = ins->cil_code - header->code;
313         if (!info->has_line_numbers) {
314                 info->jit->prologue_end = address;
315                 info->has_line_numbers = TRUE;
316         }
317
318         record_line_number (info, address, offset);
319 }
320
321 void
322 mono_debug_open_block (MonoCompile *cfg, MonoBasicBlock *bb, guint32 address)
323 {
324         MiniDebugMethodInfo *info;
325         MonoMethodHeader *header;
326         guint32 offset;
327
328         info = (MiniDebugMethodInfo *) cfg->debug_info;
329         if (!info || !info->jit || !bb->cil_code)
330                 return;
331
332         header = cfg->header;
333         g_assert (header);
334
335         if ((bb->cil_code < header->code) ||
336             (bb->cil_code > header->code + header->code_size))
337                 return;
338
339         offset = bb->cil_code - header->code;
340         if (!info->has_line_numbers) {
341                 info->jit->prologue_end = address;
342                 info->has_line_numbers = TRUE;
343         }
344
345         record_line_number (info, address, offset);
346 }
347
348 static inline void
349 encode_value (gint32 value, guint8 *buf, guint8 **endbuf)
350 {
351         guint8 *p = buf;
352
353         //printf ("ENCODE: %d 0x%x.\n", value, value);
354
355         /* 
356          * Same encoding as the one used in the metadata, extended to handle values
357          * greater than 0x1fffffff.
358          */
359         if ((value >= 0) && (value <= 127))
360                 *p++ = value;
361         else if ((value >= 0) && (value <= 16383)) {
362                 p [0] = 0x80 | (value >> 8);
363                 p [1] = value & 0xff;
364                 p += 2;
365         } else if ((value >= 0) && (value <= 0x1fffffff)) {
366                 p [0] = (value >> 24) | 0xc0;
367                 p [1] = (value >> 16) & 0xff;
368                 p [2] = (value >> 8) & 0xff;
369                 p [3] = value & 0xff;
370                 p += 4;
371         }
372         else {
373                 p [0] = 0xff;
374                 p [1] = (value >> 24) & 0xff;
375                 p [2] = (value >> 16) & 0xff;
376                 p [3] = (value >> 8) & 0xff;
377                 p [4] = value & 0xff;
378                 p += 5;
379         }
380         if (endbuf)
381                 *endbuf = p;
382 }
383
384 static inline gint32
385 decode_value (guint8 *ptr, guint8 **rptr)
386 {
387         guint8 b = *ptr;
388         gint32 len;
389         
390         if ((b & 0x80) == 0){
391                 len = b;
392                 ++ptr;
393         } else if ((b & 0x40) == 0){
394                 len = ((b & 0x3f) << 8 | ptr [1]);
395                 ptr += 2;
396         } else if (b != 0xff) {
397                 len = ((b & 0x1f) << 24) |
398                         (ptr [1] << 16) |
399                         (ptr [2] << 8) |
400                         ptr [3];
401                 ptr += 4;
402         }
403         else {
404                 len = (ptr [1] << 24) | (ptr [2] << 16) | (ptr [3] << 8) | ptr [4];
405                 ptr += 5;
406         }
407         if (rptr)
408                 *rptr = ptr;
409
410         //printf ("DECODE: %d.\n", len);
411         return len;
412 }
413
414 static void
415 serialize_variable (MonoDebugVarInfo *var, guint8 *p, guint8 **endbuf)
416 {
417         guint32 flags = var->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS;
418
419         encode_value (var->index, p, &p);
420
421         switch (flags) {
422         case MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER:
423                 break;
424         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET:
425         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET_INDIR:
426         case MONO_DEBUG_VAR_ADDRESS_MODE_VTADDR:
427                 encode_value (var->offset, p, &p);
428                 break;
429         case MONO_DEBUG_VAR_ADDRESS_MODE_GSHAREDVT_LOCAL:
430         case MONO_DEBUG_VAR_ADDRESS_MODE_DEAD:
431                 break;
432         default:
433                 g_assert_not_reached ();
434         }
435         *endbuf = p;
436 }
437
438 void
439 mono_debug_serialize_debug_info (MonoCompile *cfg, guint8 **out_buf, guint32 *buf_len)
440 {
441         MonoDebugMethodJitInfo *jit;
442         guint32 size, prev_offset, prev_native_offset;
443         guint8 *buf, *p;
444         int i;
445
446         /* Can't use cfg->debug_info as it is freed by close_method () */
447         jit = mono_debug_find_method (cfg->method, mono_domain_get ());
448         if (!jit) {
449                 *buf_len = 0;
450                 return;
451         }
452
453         size = ((jit->num_params + jit->num_locals + 1) * 10) + (jit->num_line_numbers * 10) + 64;
454         p = buf = g_malloc (size);
455         encode_value (jit->epilogue_begin, p, &p);
456         encode_value (jit->prologue_end, p, &p);
457         encode_value (jit->code_size, p, &p);
458
459         for (i = 0; i < jit->num_params; ++i)
460                 serialize_variable (&jit->params [i], p, &p);
461
462         if (mono_method_signature (cfg->method)->hasthis)
463                 serialize_variable (jit->this_var, p, &p);
464
465         for (i = 0; i < jit->num_locals; i++)
466                 serialize_variable (&jit->locals [i], p, &p);
467
468         if (jit->gsharedvt_info_var) {
469                 encode_value (1, p, &p);
470                 serialize_variable (jit->gsharedvt_info_var, p, &p);
471                 serialize_variable (jit->gsharedvt_locals_var, p, &p);
472         } else {
473                 encode_value (0, p, &p);
474         }
475
476         encode_value (jit->num_line_numbers, p, &p);
477
478         prev_offset = 0;
479         prev_native_offset = 0;
480         for (i = 0; i < jit->num_line_numbers; ++i) {
481                 /* Sometimes, the offset values are not in increasing order */
482                 MonoDebugLineNumberEntry *lne = &jit->line_numbers [i];
483                 encode_value (lne->il_offset - prev_offset, p, &p);
484                 encode_value (lne->native_offset - prev_native_offset, p, &p);
485                 prev_offset = lne->il_offset;
486                 prev_native_offset = lne->native_offset;
487         }
488
489         g_assert (p - buf < size);
490
491         *out_buf = buf;
492         *buf_len = p - buf;
493 }
494
495 static void
496 deserialize_variable (MonoDebugVarInfo *var, guint8 *p, guint8 **endbuf)
497 {
498         guint32 flags;
499
500         var->index = decode_value (p, &p);
501
502         flags = var->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS;
503
504         switch (flags) {
505         case MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER:
506                 break;
507         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET:
508         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET_INDIR:
509         case MONO_DEBUG_VAR_ADDRESS_MODE_VTADDR:
510                 var->offset = decode_value (p, &p);
511                 break;
512         case MONO_DEBUG_VAR_ADDRESS_MODE_GSHAREDVT_LOCAL:
513         case MONO_DEBUG_VAR_ADDRESS_MODE_DEAD:
514                 break;
515         default:
516                 g_assert_not_reached ();
517         }
518         *endbuf = p;
519 }
520
521 static MonoDebugMethodJitInfo *
522 deserialize_debug_info (MonoMethod *method, guint8 *code_start, guint8 *buf, guint32 buf_len)
523 {
524         MonoMethodHeader *header;
525         gint32 offset, native_offset, prev_offset, prev_native_offset;
526         MonoDebugMethodJitInfo *jit;
527         guint8 *p;
528         int i;
529
530         header = mono_method_get_header (method);
531         g_assert (header);
532
533         jit = g_new0 (MonoDebugMethodJitInfo, 1);
534         jit->code_start = code_start;
535         jit->num_locals = header->num_locals;
536         jit->locals = g_new0 (MonoDebugVarInfo, jit->num_locals);
537         jit->num_params = mono_method_signature (method)->param_count;
538         jit->params = g_new0 (MonoDebugVarInfo, jit->num_params);
539
540         p = buf;
541         jit->epilogue_begin = decode_value (p, &p);
542         jit->prologue_end = decode_value (p, &p);
543         jit->code_size = decode_value (p, &p);
544
545         for (i = 0; i < jit->num_params; ++i)
546                 deserialize_variable (&jit->params [i], p, &p);
547
548         if (mono_method_signature (method)->hasthis) {
549                 jit->this_var = g_new0 (MonoDebugVarInfo, 1);
550                 deserialize_variable (jit->this_var, p, &p);
551         }
552
553         for (i = 0; i < jit->num_locals; i++)
554                 deserialize_variable (&jit->locals [i], p, &p);
555
556         if (decode_value (p, &p)) {
557                 jit->gsharedvt_info_var = g_new0 (MonoDebugVarInfo, 1);
558                 jit->gsharedvt_locals_var = g_new0 (MonoDebugVarInfo, 1);
559                 deserialize_variable (jit->gsharedvt_info_var, p, &p);
560                 deserialize_variable (jit->gsharedvt_locals_var, p, &p);
561         }
562
563         jit->num_line_numbers = decode_value (p, &p);
564         jit->line_numbers = g_new0 (MonoDebugLineNumberEntry, jit->num_line_numbers);
565
566         prev_offset = 0;
567         prev_native_offset = 0;
568         for (i = 0; i < jit->num_line_numbers; ++i) {
569                 MonoDebugLineNumberEntry *lne = &jit->line_numbers [i];
570
571                 offset = prev_offset + decode_value (p, &p);
572                 native_offset = prev_native_offset + decode_value (p, &p);
573
574                 lne->native_offset = native_offset;
575                 lne->il_offset = offset;
576
577                 prev_offset = offset;
578                 prev_native_offset = native_offset;
579         }
580
581         mono_metadata_free_mh (header);
582         return jit;
583 }
584
585 void
586 mono_debug_add_aot_method (MonoDomain *domain, MonoMethod *method, guint8 *code_start, 
587                            guint8 *debug_info, guint32 debug_info_len)
588 {
589         MonoDebugMethodJitInfo *jit;
590
591         if (!mono_debug_enabled ())
592                 return;
593
594         if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
595             (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) ||
596             (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
597             (method->flags & METHOD_ATTRIBUTE_ABSTRACT) ||
598             (method->wrapper_type != MONO_WRAPPER_NONE))
599                 return;
600
601         if (debug_info_len == 0)
602                 return;
603
604         jit = deserialize_debug_info (method, code_start, debug_info, debug_info_len);
605
606         mono_debug_add_method (method, jit, domain);
607
608         mono_debug_add_vg_method (method, jit);
609
610         mono_debug_free_method_jit_info (jit);
611 }
612
613 static void
614 print_var_info (MonoDebugVarInfo *info, int idx, const char *name, const char *type)
615 {
616         switch (info->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS) {
617         case MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER:
618                 g_print ("%s %s (%d) in register %s\n", type, name, idx, mono_arch_regname (info->index & (~MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS)));
619                 break;
620         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET:
621                 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);
622                 break;
623         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET_INDIR:
624                 g_print ("%s %s (%d) in indir memory: base register %s + %d\n", type, name, idx, mono_arch_regname (info->index & (~MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS)), info->offset);
625                 break;
626         case MONO_DEBUG_VAR_ADDRESS_MODE_GSHAREDVT_LOCAL:
627                 g_print ("%s %s (%d) gsharedvt local.\n", type, name, idx);
628                 break;
629         case MONO_DEBUG_VAR_ADDRESS_MODE_VTADDR:
630                 g_print ("%s %s (%d) vt address: base register %s + %d\n", type, name, idx, mono_arch_regname (info->index & (~MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS)), info->offset);
631                 break;
632         case MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS:
633         default:
634                 g_assert_not_reached ();
635         }
636 }
637
638 /**
639  * mono_debug_print_locals:
640  *
641  * Prints to stdout the information about the local variables in
642  * a method (if @only_arguments is false) or about the arguments.
643  * The information includes the storage info (where the variable 
644  * lives, in a register or in memory).
645  * The method is found by looking up what method has been emitted at
646  * the instruction address @ip.
647  * This is for use inside a debugger.
648  */
649 void
650 mono_debug_print_vars (gpointer ip, gboolean only_arguments)
651 {
652         MonoDomain *domain = mono_domain_get ();
653         MonoJitInfo *ji = mono_jit_info_table_find (domain, ip);
654         MonoDebugMethodJitInfo *jit;
655         int i;
656
657         if (!ji)
658                 return;
659
660         jit = mono_debug_find_method (jinfo_get_method (ji), domain);
661         if (!jit)
662                 return;
663
664         if (only_arguments) {
665                 char **names;
666                 names = g_new (char *, jit->num_params);
667                 mono_method_get_param_names (jinfo_get_method (ji), (const char **) names);
668                 if (jit->this_var)
669                         print_var_info (jit->this_var, 0, "this", "Arg");
670                 for (i = 0; i < jit->num_params; ++i) {
671                         print_var_info (&jit->params [i], i, names [i]? names [i]: "unknown name", "Arg");
672                 }
673                 g_free (names);
674         } else {
675                 for (i = 0; i < jit->num_locals; ++i) {
676                         print_var_info (&jit->locals [i], i, "", "Local");
677                 }
678         }
679         mono_debug_free_method_jit_info (jit);
680 }
681
682 /*
683  * The old Debugger breakpoint interface.
684  *
685  * This interface is used to insert breakpoints on methods which are not yet JITed.
686  * The debugging code keeps a list of all such breakpoints and automatically inserts the
687  * breakpoint when the method is JITed.
688  */
689
690 static GPtrArray *breakpoints;
691
692 static int
693 mono_debugger_insert_breakpoint_full (MonoMethodDesc *desc)
694 {
695         static int last_breakpoint_id = 0;
696         MiniDebugBreakpointInfo *info;
697
698         info = g_new0 (MiniDebugBreakpointInfo, 1);
699         info->desc = desc;
700         info->index = ++last_breakpoint_id;
701
702         if (!breakpoints)
703                 breakpoints = g_ptr_array_new ();
704
705         g_ptr_array_add (breakpoints, info);
706
707         return info->index;
708 }
709
710 /*FIXME This is part of the public API by accident, remove it from there when possible. */
711 int
712 mono_debugger_insert_breakpoint (const gchar *method_name, gboolean include_namespace)
713 {
714         MonoMethodDesc *desc;
715
716         desc = mono_method_desc_new (method_name, include_namespace);
717         if (!desc)
718                 return 0;
719
720         return mono_debugger_insert_breakpoint_full (desc);
721 }
722
723 /*FIXME This is part of the public API by accident, remove it from there when possible. */
724 int
725 mono_debugger_method_has_breakpoint (MonoMethod *method)
726 {
727         int i;
728
729         if (!breakpoints)
730                 return 0;
731
732         for (i = 0; i < breakpoints->len; i++) {
733                 MiniDebugBreakpointInfo *info = g_ptr_array_index (breakpoints, i);
734
735                 if (!mono_method_desc_full_match (info->desc, method))
736                         continue;
737
738                 return info->index;
739         }
740
741         return 0;
742 }