Merge pull request #1156 from felfert/master
[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         MonoDebugMethodAddress *debug_info;
224         MonoMethod *method;
225         int i;
226
227         info = (MiniDebugMethodInfo *) cfg->debug_info;
228         if (!info || !info->jit) {
229                 if (info)
230                         g_free (info);
231                 return;
232         }
233
234         method = cfg->method;
235         header = cfg->header;
236         sig = mono_method_signature (method);
237
238         jit = info->jit;
239         jit->code_start = cfg->native_code;
240         jit->epilogue_begin = cfg->epilog_begin;
241         jit->code_size = cfg->code_len;
242
243         if (jit->epilogue_begin)
244                    record_line_number (info, jit->epilogue_begin, header->code_size);
245
246         jit->num_params = sig->param_count;
247         jit->params = g_new0 (MonoDebugVarInfo, jit->num_params);
248
249         for (i = 0; i < jit->num_locals; i++)
250                 write_variable (cfg->locals [i], &jit->locals [i]);
251
252         if (sig->hasthis) {
253                 jit->this_var = g_new0 (MonoDebugVarInfo, 1);
254                 write_variable (cfg->args [0], jit->this_var);
255         }
256
257         for (i = 0; i < jit->num_params; i++)
258                 write_variable (cfg->args [i + sig->hasthis], &jit->params [i]);
259
260         if (cfg->gsharedvt_info_var) {
261                 jit->gsharedvt_info_var = g_new0 (MonoDebugVarInfo, 1);
262                 jit->gsharedvt_locals_var = g_new0 (MonoDebugVarInfo, 1);
263                 write_variable (cfg->gsharedvt_info_var, jit->gsharedvt_info_var);
264                 write_variable (cfg->gsharedvt_locals_var, jit->gsharedvt_locals_var);
265         }
266
267         jit->num_line_numbers = info->line_numbers->len;
268         jit->line_numbers = g_new0 (MonoDebugLineNumberEntry, jit->num_line_numbers);
269
270         for (i = 0; i < jit->num_line_numbers; i++)
271                 jit->line_numbers [i] = g_array_index (info->line_numbers, MonoDebugLineNumberEntry, i);
272
273         debug_info = mono_debug_add_method (cfg->method_to_register, jit, cfg->domain);
274
275         mono_debug_add_vg_method (method, jit);
276
277         mono_debug_free_method_jit_info (jit);
278         mono_debug_free_method (cfg);
279 }
280
281 void
282 mono_debug_free_method (MonoCompile *cfg)
283 {
284         MiniDebugMethodInfo *info;
285
286         info = (MiniDebugMethodInfo *) cfg->debug_info;
287         if (info) {
288                 if (info->line_numbers)
289                         g_array_free (info->line_numbers, TRUE);
290                 g_free (info);
291                 cfg->debug_info = NULL; 
292         }
293 }
294
295 void
296 mono_debug_record_line_number (MonoCompile *cfg, MonoInst *ins, guint32 address)
297 {
298         MiniDebugMethodInfo *info;
299         MonoMethodHeader *header;
300         guint32 offset;
301
302         info = (MiniDebugMethodInfo *) cfg->debug_info;
303         if (!info || !info->jit || !ins->cil_code)
304                 return;
305
306         header = cfg->header;
307         g_assert (header);
308
309         if ((ins->cil_code < header->code) ||
310             (ins->cil_code > header->code + header->code_size))
311                 return;
312
313         offset = ins->cil_code - header->code;
314         if (!info->has_line_numbers) {
315                 info->jit->prologue_end = address;
316                 info->has_line_numbers = TRUE;
317         }
318
319         record_line_number (info, address, offset);
320 }
321
322 void
323 mono_debug_open_block (MonoCompile *cfg, MonoBasicBlock *bb, guint32 address)
324 {
325         MiniDebugMethodInfo *info;
326         MonoMethodHeader *header;
327         guint32 offset;
328
329         info = (MiniDebugMethodInfo *) cfg->debug_info;
330         if (!info || !info->jit || !bb->cil_code)
331                 return;
332
333         header = cfg->header;
334         g_assert (header);
335
336         if ((bb->cil_code < header->code) ||
337             (bb->cil_code > header->code + header->code_size))
338                 return;
339
340         offset = bb->cil_code - header->code;
341         if (!info->has_line_numbers) {
342                 info->jit->prologue_end = address;
343                 info->has_line_numbers = TRUE;
344         }
345
346         record_line_number (info, address, offset);
347 }
348
349 static inline void
350 encode_value (gint32 value, guint8 *buf, guint8 **endbuf)
351 {
352         guint8 *p = buf;
353
354         //printf ("ENCODE: %d 0x%x.\n", value, value);
355
356         /* 
357          * Same encoding as the one used in the metadata, extended to handle values
358          * greater than 0x1fffffff.
359          */
360         if ((value >= 0) && (value <= 127))
361                 *p++ = value;
362         else if ((value >= 0) && (value <= 16383)) {
363                 p [0] = 0x80 | (value >> 8);
364                 p [1] = value & 0xff;
365                 p += 2;
366         } else if ((value >= 0) && (value <= 0x1fffffff)) {
367                 p [0] = (value >> 24) | 0xc0;
368                 p [1] = (value >> 16) & 0xff;
369                 p [2] = (value >> 8) & 0xff;
370                 p [3] = value & 0xff;
371                 p += 4;
372         }
373         else {
374                 p [0] = 0xff;
375                 p [1] = (value >> 24) & 0xff;
376                 p [2] = (value >> 16) & 0xff;
377                 p [3] = (value >> 8) & 0xff;
378                 p [4] = value & 0xff;
379                 p += 5;
380         }
381         if (endbuf)
382                 *endbuf = p;
383 }
384
385 static inline gint32
386 decode_value (guint8 *ptr, guint8 **rptr)
387 {
388         guint8 b = *ptr;
389         gint32 len;
390         
391         if ((b & 0x80) == 0){
392                 len = b;
393                 ++ptr;
394         } else if ((b & 0x40) == 0){
395                 len = ((b & 0x3f) << 8 | ptr [1]);
396                 ptr += 2;
397         } else if (b != 0xff) {
398                 len = ((b & 0x1f) << 24) |
399                         (ptr [1] << 16) |
400                         (ptr [2] << 8) |
401                         ptr [3];
402                 ptr += 4;
403         }
404         else {
405                 len = (ptr [1] << 24) | (ptr [2] << 16) | (ptr [3] << 8) | ptr [4];
406                 ptr += 5;
407         }
408         if (rptr)
409                 *rptr = ptr;
410
411         //printf ("DECODE: %d.\n", len);
412         return len;
413 }
414
415 static void
416 serialize_variable (MonoDebugVarInfo *var, guint8 *p, guint8 **endbuf)
417 {
418         guint32 flags = var->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS;
419
420         encode_value (var->index, p, &p);
421
422         switch (flags) {
423         case MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER:
424                 break;
425         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET:
426         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET_INDIR:
427         case MONO_DEBUG_VAR_ADDRESS_MODE_VTADDR:
428                 encode_value (var->offset, p, &p);
429                 break;
430         case MONO_DEBUG_VAR_ADDRESS_MODE_GSHAREDVT_LOCAL:
431         case MONO_DEBUG_VAR_ADDRESS_MODE_DEAD:
432                 break;
433         default:
434                 g_assert_not_reached ();
435         }
436         *endbuf = p;
437 }
438
439 void
440 mono_debug_serialize_debug_info (MonoCompile *cfg, guint8 **out_buf, guint32 *buf_len)
441 {
442         MonoDebugMethodJitInfo *jit;
443         guint32 size, prev_offset, prev_native_offset;
444         guint8 *buf, *p;
445         int i;
446
447         /* Can't use cfg->debug_info as it is freed by close_method () */
448         jit = mono_debug_find_method (cfg->method, mono_domain_get ());
449         if (!jit) {
450                 *buf_len = 0;
451                 return;
452         }
453
454         size = ((jit->num_params + jit->num_locals + 1) * 10) + (jit->num_line_numbers * 10) + 64;
455         p = buf = g_malloc (size);
456         encode_value (jit->epilogue_begin, p, &p);
457         encode_value (jit->prologue_end, p, &p);
458         encode_value (jit->code_size, p, &p);
459
460         for (i = 0; i < jit->num_params; ++i)
461                 serialize_variable (&jit->params [i], p, &p);
462
463         if (mono_method_signature (cfg->method)->hasthis)
464                 serialize_variable (jit->this_var, p, &p);
465
466         for (i = 0; i < jit->num_locals; i++)
467                 serialize_variable (&jit->locals [i], p, &p);
468
469         if (jit->gsharedvt_info_var) {
470                 encode_value (1, p, &p);
471                 serialize_variable (jit->gsharedvt_info_var, p, &p);
472                 serialize_variable (jit->gsharedvt_locals_var, p, &p);
473         } else {
474                 encode_value (0, p, &p);
475         }
476
477         encode_value (jit->num_line_numbers, p, &p);
478
479         prev_offset = 0;
480         prev_native_offset = 0;
481         for (i = 0; i < jit->num_line_numbers; ++i) {
482                 /* Sometimes, the offset values are not in increasing order */
483                 MonoDebugLineNumberEntry *lne = &jit->line_numbers [i];
484                 encode_value (lne->il_offset - prev_offset, p, &p);
485                 encode_value (lne->native_offset - prev_native_offset, p, &p);
486                 prev_offset = lne->il_offset;
487                 prev_native_offset = lne->native_offset;
488         }
489
490         g_assert (p - buf < size);
491
492         *out_buf = buf;
493         *buf_len = p - buf;
494 }
495
496 static void
497 deserialize_variable (MonoDebugVarInfo *var, guint8 *p, guint8 **endbuf)
498 {
499         guint32 flags;
500
501         var->index = decode_value (p, &p);
502
503         flags = var->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS;
504
505         switch (flags) {
506         case MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER:
507                 break;
508         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET:
509         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET_INDIR:
510         case MONO_DEBUG_VAR_ADDRESS_MODE_VTADDR:
511                 var->offset = decode_value (p, &p);
512                 break;
513         case MONO_DEBUG_VAR_ADDRESS_MODE_GSHAREDVT_LOCAL:
514         case MONO_DEBUG_VAR_ADDRESS_MODE_DEAD:
515                 break;
516         default:
517                 g_assert_not_reached ();
518         }
519         *endbuf = p;
520 }
521
522 static MonoDebugMethodJitInfo *
523 deserialize_debug_info (MonoMethod *method, guint8 *code_start, guint8 *buf, guint32 buf_len)
524 {
525         MonoMethodHeader *header;
526         gint32 offset, native_offset, prev_offset, prev_native_offset;
527         MonoDebugMethodJitInfo *jit;
528         guint8 *p;
529         int i;
530
531         header = mono_method_get_header (method);
532         g_assert (header);
533
534         jit = g_new0 (MonoDebugMethodJitInfo, 1);
535         jit->code_start = code_start;
536         jit->num_locals = header->num_locals;
537         jit->locals = g_new0 (MonoDebugVarInfo, jit->num_locals);
538         jit->num_params = mono_method_signature (method)->param_count;
539         jit->params = g_new0 (MonoDebugVarInfo, jit->num_params);
540
541         p = buf;
542         jit->epilogue_begin = decode_value (p, &p);
543         jit->prologue_end = decode_value (p, &p);
544         jit->code_size = decode_value (p, &p);
545
546         for (i = 0; i < jit->num_params; ++i)
547                 deserialize_variable (&jit->params [i], p, &p);
548
549         if (mono_method_signature (method)->hasthis) {
550                 jit->this_var = g_new0 (MonoDebugVarInfo, 1);
551                 deserialize_variable (jit->this_var, p, &p);
552         }
553
554         for (i = 0; i < jit->num_locals; i++)
555                 deserialize_variable (&jit->locals [i], p, &p);
556
557         if (decode_value (p, &p)) {
558                 jit->gsharedvt_info_var = g_new0 (MonoDebugVarInfo, 1);
559                 jit->gsharedvt_locals_var = g_new0 (MonoDebugVarInfo, 1);
560                 deserialize_variable (jit->gsharedvt_info_var, p, &p);
561                 deserialize_variable (jit->gsharedvt_locals_var, p, &p);
562         }
563
564         jit->num_line_numbers = decode_value (p, &p);
565         jit->line_numbers = g_new0 (MonoDebugLineNumberEntry, jit->num_line_numbers);
566
567         prev_offset = 0;
568         prev_native_offset = 0;
569         for (i = 0; i < jit->num_line_numbers; ++i) {
570                 MonoDebugLineNumberEntry *lne = &jit->line_numbers [i];
571
572                 offset = prev_offset + decode_value (p, &p);
573                 native_offset = prev_native_offset + decode_value (p, &p);
574
575                 lne->native_offset = native_offset;
576                 lne->il_offset = offset;
577
578                 prev_offset = offset;
579                 prev_native_offset = native_offset;
580         }
581
582         mono_metadata_free_mh (header);
583         return jit;
584 }
585
586 void
587 mono_debug_add_aot_method (MonoDomain *domain, MonoMethod *method, guint8 *code_start, 
588                            guint8 *debug_info, guint32 debug_info_len)
589 {
590         MonoDebugMethodJitInfo *jit;
591
592         if (!mono_debug_enabled ())
593                 return;
594
595         if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
596             (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) ||
597             (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
598             (method->flags & METHOD_ATTRIBUTE_ABSTRACT) ||
599             (method->wrapper_type != MONO_WRAPPER_NONE))
600                 return;
601
602         if (debug_info_len == 0)
603                 return;
604
605         jit = deserialize_debug_info (method, code_start, debug_info, debug_info_len);
606
607         mono_debug_add_method (method, jit, domain);
608
609         mono_debug_add_vg_method (method, jit);
610
611         mono_debug_free_method_jit_info (jit);
612 }
613
614 static void
615 print_var_info (MonoDebugVarInfo *info, int idx, const char *name, const char *type)
616 {
617         switch (info->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS) {
618         case MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER:
619                 g_print ("%s %s (%d) in register %s\n", type, name, idx, mono_arch_regname (info->index & (~MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS)));
620                 break;
621         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET:
622                 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);
623                 break;
624         case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET_INDIR:
625                 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);
626                 break;
627         case MONO_DEBUG_VAR_ADDRESS_MODE_GSHAREDVT_LOCAL:
628                 g_print ("%s %s (%d) gsharedvt local.\n", type, name, idx);
629                 break;
630         case MONO_DEBUG_VAR_ADDRESS_MODE_VTADDR:
631                 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);
632                 break;
633         case MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS:
634         default:
635                 g_assert_not_reached ();
636         }
637 }
638
639 /**
640  * mono_debug_print_locals:
641  *
642  * Prints to stdout the information about the local variables in
643  * a method (if @only_arguments is false) or about the arguments.
644  * The information includes the storage info (where the variable 
645  * lives, in a register or in memory).
646  * The method is found by looking up what method has been emitted at
647  * the instruction address @ip.
648  * This is for use inside a debugger.
649  */
650 void
651 mono_debug_print_vars (gpointer ip, gboolean only_arguments)
652 {
653         MonoDomain *domain = mono_domain_get ();
654         MonoJitInfo *ji = mono_jit_info_table_find (domain, ip);
655         MonoDebugMethodJitInfo *jit;
656         int i;
657
658         if (!ji)
659                 return;
660
661         jit = mono_debug_find_method (jinfo_get_method (ji), domain);
662         if (!jit)
663                 return;
664
665         if (only_arguments) {
666                 char **names;
667                 names = g_new (char *, jit->num_params);
668                 mono_method_get_param_names (jinfo_get_method (ji), (const char **) names);
669                 if (jit->this_var)
670                         print_var_info (jit->this_var, 0, "this", "Arg");
671                 for (i = 0; i < jit->num_params; ++i) {
672                         print_var_info (&jit->params [i], i, names [i]? names [i]: "unknown name", "Arg");
673                 }
674                 g_free (names);
675         } else {
676                 for (i = 0; i < jit->num_locals; ++i) {
677                         print_var_info (&jit->locals [i], i, "", "Local");
678                 }
679         }
680         mono_debug_free_method_jit_info (jit);
681 }
682
683 /*
684  * The old Debugger breakpoint interface.
685  *
686  * This interface is used to insert breakpoints on methods which are not yet JITed.
687  * The debugging code keeps a list of all such breakpoints and automatically inserts the
688  * breakpoint when the method is JITed.
689  */
690
691 static GPtrArray *breakpoints;
692
693 static int
694 mono_debugger_insert_breakpoint_full (MonoMethodDesc *desc)
695 {
696         static int last_breakpoint_id = 0;
697         MiniDebugBreakpointInfo *info;
698
699         info = g_new0 (MiniDebugBreakpointInfo, 1);
700         info->desc = desc;
701         info->index = ++last_breakpoint_id;
702
703         if (!breakpoints)
704                 breakpoints = g_ptr_array_new ();
705
706         g_ptr_array_add (breakpoints, info);
707
708         return info->index;
709 }
710
711 /*FIXME This is part of the public API by accident, remove it from there when possible. */
712 int
713 mono_debugger_insert_breakpoint (const gchar *method_name, gboolean include_namespace)
714 {
715         MonoMethodDesc *desc;
716
717         desc = mono_method_desc_new (method_name, include_namespace);
718         if (!desc)
719                 return 0;
720
721         return mono_debugger_insert_breakpoint_full (desc);
722 }
723
724 /*FIXME This is part of the public API by accident, remove it from there when possible. */
725 int
726 mono_debugger_method_has_breakpoint (MonoMethod *method)
727 {
728         int i;
729
730         if (!breakpoints)
731                 return 0;
732
733         for (i = 0; i < breakpoints->len; i++) {
734                 MiniDebugBreakpointInfo *info = g_ptr_array_index (breakpoints, i);
735
736                 if (!mono_method_desc_full_match (info->desc, method))
737                         continue;
738
739                 return info->index;
740         }
741
742         return 0;
743 }