remove genxs2 (no 2.0 profile assembly is built)
[mono-project/dkf.git] / mono / metadata / debug-helpers.c
blobe45ccb8248a1a0038cdc723a71d829eaf841f20d
1 /*
2 * console-io.c: ConsoleDriver internal calls
4 * Author:
5 * Mono Project (http://www.mono-project.com)
7 * Copyright (C) 2005-2008 Novell, Inc. (http://www.novell.com)
8 */
10 #include <string.h>
11 #include "mono/metadata/tokentype.h"
12 #include "mono/metadata/opcodes.h"
13 #include "mono/metadata/class-internals.h"
14 #include "mono/metadata/mono-endian.h"
15 #include "mono/metadata/debug-helpers.h"
16 #include "mono/metadata/tabledefs.h"
17 #include "mono/metadata/appdomain.h"
19 struct MonoMethodDesc {
20 char *namespace;
21 char *klass;
22 char *name;
23 char *args;
24 guint num_args;
25 gboolean include_namespace;
28 #ifdef HAVE_ARRAY_ELEM_INIT
29 #define MSGSTRFIELD(line) MSGSTRFIELD1(line)
30 #define MSGSTRFIELD1(line) str##line
31 static const struct msgstr_t {
32 #define WRAPPER(a,b) char MSGSTRFIELD(__LINE__) [sizeof (b)];
33 #include "wrapper-types.h"
34 #undef WRAPPER
35 } opstr = {
36 #define WRAPPER(a,b) b,
37 #include "wrapper-types.h"
38 #undef WRAPPER
40 static const gint16 opidx [] = {
41 #define WRAPPER(a,b) [MONO_WRAPPER_ ## a] = offsetof (struct msgstr_t, MSGSTRFIELD(__LINE__)),
42 #include "wrapper-types.h"
43 #undef WRAPPER
46 static const char*
47 wrapper_type_to_str (guint32 wrapper_type)
49 g_assert (wrapper_type < MONO_WRAPPER_NUM);
51 return (const char*)&opstr + opidx [wrapper_type];
54 #else
55 #define WRAPPER(a,b) b,
56 static const char* const
57 wrapper_type_names [MONO_WRAPPER_NUM + 1] = {
58 #include "wrapper-types.h"
59 NULL
62 static const char*
63 wrapper_type_to_str (guint32 wrapper_type)
65 g_assert (wrapper_type < MONO_WRAPPER_NUM);
67 return wrapper_type_names [wrapper_type];
70 #endif
72 static void
73 append_class_name (GString *res, MonoClass *class, gboolean include_namespace)
75 if (!class) {
76 g_string_append (res, "Unknown");
77 return;
79 if (class->nested_in) {
80 append_class_name (res, class->nested_in, include_namespace);
81 g_string_append_c (res, '/');
83 if (include_namespace && *(class->name_space))
84 g_string_sprintfa (res, "%s.", class->name_space);
85 g_string_sprintfa (res, "%s", class->name);
88 void
89 mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace)
91 int i;
93 switch (type->type) {
94 case MONO_TYPE_VOID:
95 g_string_append (res, "void"); break;
96 case MONO_TYPE_CHAR:
97 g_string_append (res, "char"); break;
98 case MONO_TYPE_BOOLEAN:
99 g_string_append (res, "bool"); break;
100 case MONO_TYPE_U1:
101 g_string_append (res, "byte"); break;
102 case MONO_TYPE_I1:
103 g_string_append (res, "sbyte"); break;
104 case MONO_TYPE_U2:
105 g_string_append (res, "uint16"); break;
106 case MONO_TYPE_I2:
107 g_string_append (res, "int16"); break;
108 case MONO_TYPE_U4:
109 g_string_append (res, "uint"); break;
110 case MONO_TYPE_I4:
111 g_string_append (res, "int"); break;
112 case MONO_TYPE_U8:
113 g_string_append (res, "ulong"); break;
114 case MONO_TYPE_I8:
115 g_string_append (res, "long"); break;
116 case MONO_TYPE_FNPTR: /* who cares for the exact signature? */
117 g_string_append (res, "*()"); break;
118 case MONO_TYPE_U:
119 g_string_append (res, "uintptr"); break;
120 case MONO_TYPE_I:
121 g_string_append (res, "intptr"); break;
122 case MONO_TYPE_R4:
123 g_string_append (res, "single"); break;
124 case MONO_TYPE_R8:
125 g_string_append (res, "double"); break;
126 case MONO_TYPE_STRING:
127 g_string_append (res, "string"); break;
128 case MONO_TYPE_OBJECT:
129 g_string_append (res, "object"); break;
130 case MONO_TYPE_PTR:
131 mono_type_get_desc (res, type->data.type, include_namespace);
132 g_string_append_c (res, '*');
133 break;
134 case MONO_TYPE_ARRAY:
135 mono_type_get_desc (res, &type->data.array->eklass->byval_arg, include_namespace);
136 g_string_sprintfa (res, "[%d]", type->data.array->rank);
137 break;
138 case MONO_TYPE_SZARRAY:
139 mono_type_get_desc (res, &type->data.klass->byval_arg, include_namespace);
140 g_string_append (res, "[]");
141 break;
142 case MONO_TYPE_CLASS:
143 case MONO_TYPE_VALUETYPE:
144 append_class_name (res, type->data.klass, include_namespace);
145 break;
146 case MONO_TYPE_GENERICINST: {
147 MonoGenericContext *context;
149 mono_type_get_desc (res, &type->data.generic_class->container_class->byval_arg, include_namespace);
150 g_string_append (res, "<");
151 context = &type->data.generic_class->context;
152 if (context->class_inst) {
153 for (i = 0; i < context->class_inst->type_argc; ++i) {
154 if (i > 0)
155 g_string_append (res, ", ");
156 mono_type_get_desc (res, context->class_inst->type_argv [i], include_namespace);
159 if (context->method_inst) {
160 if (context->class_inst)
161 g_string_append (res, "; ");
162 for (i = 0; i < context->method_inst->type_argc; ++i) {
163 if (i > 0)
164 g_string_append (res, ", ");
165 mono_type_get_desc (res, context->method_inst->type_argv [i], include_namespace);
168 g_string_append (res, ">");
169 break;
171 case MONO_TYPE_VAR:
172 case MONO_TYPE_MVAR:
173 g_string_append (res, type->data.generic_param->name);
174 break;
175 default:
176 break;
178 if (type->byref)
179 g_string_append_c (res, '&');
182 char*
183 mono_type_full_name (MonoType *type)
185 GString *str;
186 char *res;
188 str = g_string_new ("");
189 mono_type_get_desc (str, type, TRUE);
191 res = g_strdup (str->str);
192 g_string_free (str, TRUE);
193 return res;
196 char*
197 mono_signature_get_desc (MonoMethodSignature *sig, gboolean include_namespace)
199 int i;
200 char *result;
201 GString *res = g_string_new ("");
203 for (i = 0; i < sig->param_count; ++i) {
204 if (i > 0)
205 g_string_append_c (res, ',');
206 mono_type_get_desc (res, sig->params [i], include_namespace);
208 result = res->str;
209 g_string_free (res, FALSE);
210 return result;
213 static void
214 ginst_get_desc (GString *str, MonoGenericInst *ginst)
216 int i;
218 for (i = 0; i < ginst->type_argc; ++i) {
219 if (i > 0)
220 g_string_append (str, ", ");
221 mono_type_get_desc (str, ginst->type_argv [i], TRUE);
225 char*
226 mono_context_get_desc (MonoGenericContext *context)
228 GString *str;
229 char *res;
231 str = g_string_new ("");
232 g_string_append (str, "<");
234 if (context->class_inst)
235 ginst_get_desc (str, context->class_inst);
236 if (context->method_inst) {
237 if (context->class_inst)
238 g_string_append (str, "; ");
239 ginst_get_desc (str, context->method_inst);
242 g_string_append (str, ">");
243 res = g_strdup (str->str);
244 g_string_free (str, TRUE);
245 return res;
249 * mono_method_desc_new:
250 * @name: the method name.
251 * @include_namespace: whether the name includes a namespace or not.
253 * Creates a method description for @name, which conforms to the following
254 * specification:
256 * [namespace.]classname:methodname[(args...)]
258 * in all the loaded assemblies.
260 * Returns: a parsed representation of the method description.
262 MonoMethodDesc*
263 mono_method_desc_new (const char *name, gboolean include_namespace)
265 MonoMethodDesc *result;
266 char *class_name, *class_nspace, *method_name, *use_args, *end;
267 int use_namespace;
269 class_nspace = g_strdup (name);
270 use_args = strchr (class_nspace, '(');
271 if (use_args) {
272 *use_args++ = 0;
273 end = strchr (use_args, ')');
274 if (!end) {
275 g_free (class_nspace);
276 return NULL;
278 *end = 0;
280 method_name = strrchr (class_nspace, ':');
281 if (!method_name) {
282 g_free (class_nspace);
283 return NULL;
285 *method_name++ = 0;
286 /* allow two :: to separate the method name */
287 if (*method_name == ':')
288 method_name++;
289 class_name = strrchr (class_nspace, '.');
290 if (class_name) {
291 *class_name++ = 0;
292 use_namespace = 1;
293 } else {
294 class_name = class_nspace;
295 use_namespace = 0;
297 result = g_new0 (MonoMethodDesc, 1);
298 result->include_namespace = include_namespace;
299 result->name = method_name;
300 result->klass = class_name;
301 result->namespace = use_namespace? class_nspace: NULL;
302 result->args = use_args? use_args: NULL;
303 if (use_args) {
304 end = use_args;
305 if (*end)
306 result->num_args = 1;
307 while (*end) {
308 if (*end == ',')
309 result->num_args++;
310 ++end;
314 return result;
317 MonoMethodDesc*
318 mono_method_desc_from_method (MonoMethod *method)
320 MonoMethodDesc *result;
322 result = g_new0 (MonoMethodDesc, 1);
323 result->include_namespace = TRUE;
324 result->name = g_strdup (method->name);
325 result->klass = g_strdup (method->klass->name);
326 result->namespace = g_strdup (method->klass->name_space);
328 return result;
332 * mono_method_desc_free:
333 * @desc: method description to be released
335 * Releases the MonoMethodDesc object @desc.
337 void
338 mono_method_desc_free (MonoMethodDesc *desc)
340 if (desc->namespace)
341 g_free (desc->namespace);
342 else if (desc->klass)
343 g_free (desc->klass);
344 g_free (desc);
348 * namespace and class are supposed to match already if this function is used.
350 gboolean
351 mono_method_desc_match (MonoMethodDesc *desc, MonoMethod *method)
353 char *sig;
354 if (strcmp (desc->name, method->name))
355 return FALSE;
356 if (!desc->args)
357 return TRUE;
358 if (desc->num_args != mono_method_signature (method)->param_count)
359 return FALSE;
360 sig = mono_signature_get_desc (mono_method_signature (method), desc->include_namespace);
361 if (strcmp (sig, desc->args)) {
362 g_free (sig);
363 return FALSE;
365 g_free (sig);
366 return TRUE;
369 static const char *
370 my_strrchr (const char *str, char ch, int *len)
372 int pos;
374 for (pos = (*len)-1; pos >= 0; pos--) {
375 if (str [pos] != ch)
376 continue;
378 *len = pos;
379 return str + pos;
382 return NULL;
385 static gboolean
386 match_class (MonoMethodDesc *desc, int pos, MonoClass *klass)
388 const char *p;
390 p = my_strrchr (desc->klass, '/', &pos);
391 if (!p) {
392 if (strncmp (desc->klass, klass->name, pos))
393 return FALSE;
394 if (desc->namespace && strcmp (desc->namespace, klass->name_space))
395 return FALSE;
396 return TRUE;
399 if (strcmp (p+1, klass->name))
400 return FALSE;
401 if (!klass->nested_in)
402 return FALSE;
404 return match_class (desc, pos, klass->nested_in);
407 gboolean
408 mono_method_desc_full_match (MonoMethodDesc *desc, MonoMethod *method)
410 if (!match_class (desc, strlen (desc->klass), method->klass))
411 return FALSE;
413 return mono_method_desc_match (desc, method);
416 MonoMethod*
417 mono_method_desc_search_in_class (MonoMethodDesc *desc, MonoClass *klass)
419 MonoMethod* m;
420 gpointer iter = NULL;
422 while ((m = mono_class_get_methods (klass, &iter)))
423 if (mono_method_desc_match (desc, m))
424 return m;
425 return NULL;
428 MonoMethod*
429 mono_method_desc_search_in_image (MonoMethodDesc *desc, MonoImage *image)
431 MonoClass *klass;
432 const MonoTableInfo *tdef;
433 const MonoTableInfo *methods;
434 MonoMethod *method;
435 int i;
437 if (desc->namespace && desc->klass) {
438 klass = mono_class_from_name (image, desc->namespace, desc->klass);
439 if (!klass)
440 return NULL;
441 return mono_method_desc_search_in_class (desc, klass);
444 tdef = mono_image_get_table_info (image, MONO_TABLE_TYPEDEF);
445 methods = mono_image_get_table_info (image, MONO_TABLE_METHOD);
446 for (i = 0; i < mono_table_info_get_rows (methods); ++i) {
447 guint32 token = mono_metadata_decode_row_col (methods, i, MONO_METHOD_NAME);
448 const char *n = mono_metadata_string_heap (image, token);
450 if (strcmp (n, desc->name))
451 continue;
452 method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL);
453 if (mono_method_desc_full_match (desc, method))
454 return method;
456 return NULL;
459 static const unsigned char*
460 dis_one (GString *str, MonoDisHelper *dh, MonoMethod *method, const unsigned char *ip, const unsigned char *end)
462 MonoMethodHeader *header = mono_method_get_header (method);
463 const MonoOpcode *opcode;
464 guint32 label, token;
465 gint32 sval;
466 int i;
467 char *tmp;
468 const unsigned char* il_code = mono_method_header_get_code (header, NULL, NULL);
470 label = ip - il_code;
471 if (dh->indenter) {
472 tmp = dh->indenter (dh, method, label);
473 g_string_append (str, tmp);
474 g_free (tmp);
476 if (dh->label_format)
477 g_string_sprintfa (str, dh->label_format, label);
479 i = mono_opcode_value (&ip, end);
480 ip++;
481 opcode = &mono_opcodes [i];
482 g_string_sprintfa (str, "%-10s", mono_opcode_name (i));
484 switch (opcode->argument) {
485 case MonoInlineNone:
486 break;
487 case MonoInlineType:
488 case MonoInlineField:
489 case MonoInlineMethod:
490 case MonoInlineTok:
491 case MonoInlineSig:
492 token = read32 (ip);
493 if (dh->tokener) {
494 tmp = dh->tokener (dh, method, token);
495 g_string_append (str, tmp);
496 g_free (tmp);
497 } else {
498 g_string_sprintfa (str, "0x%08x", token);
500 ip += 4;
501 break;
502 case MonoInlineString:
503 /* TODO */
504 ip += 4;
505 break;
506 case MonoInlineVar:
507 g_string_sprintfa (str, "%d", read16 (ip));
508 ip += 2;
509 break;
510 case MonoShortInlineVar:
511 g_string_sprintfa (str, "%d", (*ip));
512 ip ++;
513 break;
514 case MonoInlineBrTarget:
515 sval = read32 (ip);
516 ip += 4;
517 if (dh->label_target)
518 g_string_sprintfa (str, dh->label_target, ip + sval - il_code);
519 else
520 g_string_sprintfa (str, "%d", sval);
521 break;
522 case MonoShortInlineBrTarget:
523 sval = *(const signed char*)ip;
524 ip ++;
525 if (dh->label_target)
526 g_string_sprintfa (str, dh->label_target, ip + sval - il_code);
527 else
528 g_string_sprintfa (str, "%d", sval);
529 break;
530 case MonoInlineSwitch: {
531 const unsigned char *end;
532 sval = read32 (ip);
533 ip += 4;
534 end = ip + sval * 4;
535 g_string_append_c (str, '(');
536 for (i = 0; i < sval; ++i) {
537 if (i > 0)
538 g_string_append (str, ", ");
539 label = read32 (ip);
540 if (dh->label_target)
541 g_string_sprintfa (str, dh->label_target, end + label - il_code);
542 else
543 g_string_sprintfa (str, "%d", label);
544 ip += 4;
546 g_string_append_c (str, ')');
547 break;
549 case MonoInlineR: {
550 double r;
551 readr8 (ip, &r);
552 g_string_sprintfa (str, "%g", r);
553 ip += 8;
554 break;
556 case MonoShortInlineR: {
557 float r;
558 readr4 (ip, &r);
559 g_string_sprintfa (str, "%g", r);
560 ip += 4;
561 break;
563 case MonoInlineI:
564 g_string_sprintfa (str, "%d", (gint32)read32 (ip));
565 ip += 4;
566 break;
567 case MonoShortInlineI:
568 g_string_sprintfa (str, "%d", *(const signed char*)ip);
569 ip ++;
570 break;
571 case MonoInlineI8:
572 ip += 8;
573 break;
574 default:
575 g_assert_not_reached ();
577 if (dh->newline)
578 g_string_append (str, dh->newline);
580 return ip;
583 static MonoDisHelper
584 default_dh = {
585 "\n",
586 "IL_%04x: ", /* label_format */
587 "IL_%04x", /* label_target */
588 NULL, /* indenter */
589 NULL, /* tokener */
590 NULL /* user data */
593 char*
594 mono_disasm_code_one (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const guchar **endp)
596 char *result;
597 GString *res = g_string_new ("");
599 if (!dh)
600 dh = &default_dh;
601 /* set ip + 2 as the end: this is just a debugging method */
602 ip = dis_one (res, dh, method, ip, ip + 2);
603 if (endp)
604 *endp = ip;
606 result = res->str;
607 g_string_free (res, FALSE);
608 return result;
611 char*
612 mono_disasm_code (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const guchar* end)
614 char *result;
615 GString *res = g_string_new ("");
617 if (!dh)
618 dh = &default_dh;
619 while (ip < end) {
620 ip = dis_one (res, dh, method, ip, end);
623 result = res->str;
624 g_string_free (res, FALSE);
625 return result;
628 char *
629 mono_field_full_name (MonoClassField *field)
631 char *res;
632 const char *nspace = field->parent->name_space;
634 res = g_strdup_printf ("%s%s%s:%s", nspace, *nspace ? "." : "",
635 field->parent->name, mono_field_get_name (field));
637 return res;
640 char *
641 mono_method_full_name (MonoMethod *method, gboolean signature)
643 char *res;
644 char wrapper [64];
645 char *klass_desc = mono_type_full_name (&method->klass->byval_arg);
646 char *inst_desc = NULL;
648 if (method->is_inflated && ((MonoMethodInflated*)method)->context.method_inst) {
649 GString *str = g_string_new ("");
650 g_string_append (str, "<");
651 ginst_get_desc (str, ((MonoMethodInflated*)method)->context.method_inst);
652 g_string_append (str, ">");
654 inst_desc = str->str;
655 g_string_free (str, FALSE);
658 if (method->wrapper_type != MONO_WRAPPER_NONE)
659 sprintf (wrapper, "(wrapper %s) ", wrapper_type_to_str (method->wrapper_type));
660 else
661 strcpy (wrapper, "");
663 if (signature) {
664 char *tmpsig = mono_signature_get_desc (mono_method_signature (method), TRUE);
666 if (method->wrapper_type != MONO_WRAPPER_NONE)
667 sprintf (wrapper, "(wrapper %s) ", wrapper_type_to_str (method->wrapper_type));
668 else
669 strcpy (wrapper, "");
670 res = g_strdup_printf ("%s%s:%s%s (%s)", wrapper, klass_desc,
671 method->name, inst_desc ? inst_desc : "", tmpsig);
672 g_free (tmpsig);
673 } else {
674 res = g_strdup_printf ("%s%s:%s%s", wrapper, klass_desc,
675 method->name, inst_desc ? inst_desc : "");
678 g_free (klass_desc);
679 g_free (inst_desc);
681 return res;
684 static const char*
685 print_name_space (MonoClass *klass)
687 if (klass->nested_in) {
688 print_name_space (klass->nested_in);
689 g_print (klass->nested_in->name);
690 return "/";
692 if (klass->name_space [0]) {
693 g_print (klass->name_space);
694 return ".";
696 return "";
700 * mono_object_describe:
702 * Prints to stdout a small description of the object @obj.
703 * For use in a debugger.
705 void
706 mono_object_describe (MonoObject *obj)
708 MonoClass* klass;
709 const char* sep;
710 if (!obj) {
711 g_print ("(null)\n");
712 return;
714 klass = mono_object_class (obj);
715 if (klass == mono_defaults.string_class) {
716 char *utf8 = mono_string_to_utf8 ((MonoString*)obj);
717 if (strlen (utf8) > 60) {
718 utf8 [57] = '.';
719 utf8 [58] = '.';
720 utf8 [59] = '.';
721 utf8 [60] = 0;
723 g_print ("String at %p, length: %d, '%s'\n", obj, mono_string_length ((MonoString*) obj), utf8);
724 g_free (utf8);
725 } else if (klass->rank) {
726 MonoArray *array = (MonoArray*)obj;
727 sep = print_name_space (klass);
728 g_print ("%s%s", sep, klass->name);
729 g_print (" at %p, rank: %d, length: %d\n", obj, klass->rank, mono_array_length (array));
730 } else {
731 sep = print_name_space (klass);
732 g_print ("%s%s", sep, klass->name);
733 g_print (" object at %p (klass: %p)\n", obj, klass);
738 static void
739 print_field_value (const char *field_ptr, MonoClassField *field, int type_offset)
741 MonoType *type;
742 g_print ("At %p (ofs: %2d) %s: ", field_ptr, field->offset + type_offset, mono_field_get_name (field));
743 type = mono_type_get_underlying_type (field->type);
745 switch (type->type) {
746 case MONO_TYPE_I:
747 case MONO_TYPE_U:
748 case MONO_TYPE_PTR:
749 case MONO_TYPE_FNPTR:
750 g_print ("%p\n", *(const void**)field_ptr);
751 break;
752 case MONO_TYPE_STRING:
753 case MONO_TYPE_SZARRAY:
754 case MONO_TYPE_CLASS:
755 case MONO_TYPE_OBJECT:
756 case MONO_TYPE_ARRAY:
757 mono_object_describe (*(MonoObject**)field_ptr);
758 break;
759 case MONO_TYPE_GENERICINST:
760 if (!mono_type_generic_inst_is_valuetype (type)) {
761 mono_object_describe (*(MonoObject**)field_ptr);
762 break;
763 } else {
764 /* fall through */
766 case MONO_TYPE_VALUETYPE: {
767 MonoClass *k = mono_class_from_mono_type (type);
768 g_print ("%s ValueType (type: %p) at %p\n", k->name, k, field_ptr);
769 break;
771 case MONO_TYPE_I1:
772 g_print ("%d\n", *(gint8*)field_ptr);
773 break;
774 case MONO_TYPE_U1:
775 g_print ("%d\n", *(guint8*)field_ptr);
776 break;
777 case MONO_TYPE_I2:
778 g_print ("%d\n", *(gint16*)field_ptr);
779 break;
780 case MONO_TYPE_U2:
781 g_print ("%d\n", *(guint16*)field_ptr);
782 break;
783 case MONO_TYPE_I4:
784 g_print ("%d\n", *(gint32*)field_ptr);
785 break;
786 case MONO_TYPE_U4:
787 g_print ("%u\n", *(guint32*)field_ptr);
788 break;
789 case MONO_TYPE_I8:
790 g_print ("%lld\n", (long long int)*(gint64*)field_ptr);
791 break;
792 case MONO_TYPE_U8:
793 g_print ("%llu\n", (long long unsigned int)*(guint64*)field_ptr);
794 break;
795 case MONO_TYPE_R4:
796 g_print ("%f\n", *(gfloat*)field_ptr);
797 break;
798 case MONO_TYPE_R8:
799 g_print ("%f\n", *(gdouble*)field_ptr);
800 break;
801 case MONO_TYPE_BOOLEAN:
802 g_print ("%s (%d)\n", *(guint8*)field_ptr? "True": "False", *(guint8*)field_ptr);
803 break;
804 case MONO_TYPE_CHAR:
805 g_print ("'%c' (%d 0x%04x)\n", *(guint16*)field_ptr, *(guint16*)field_ptr, *(guint16*)field_ptr);
806 break;
807 default:
808 g_assert_not_reached ();
809 break;
813 static void
814 objval_describe (MonoClass *class, const char *addr)
816 MonoClassField *field;
817 MonoClass *p;
818 const char *field_ptr;
819 gssize type_offset = 0;
820 if (class->valuetype)
821 type_offset = -sizeof (MonoObject);
823 for (p = class; p != NULL; p = p->parent) {
824 gpointer iter = NULL;
825 int printed_header = FALSE;
826 while ((field = mono_class_get_fields (p, &iter))) {
827 if (field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA))
828 continue;
830 if (p != class && !printed_header) {
831 const char *sep;
832 g_print ("In class ");
833 sep = print_name_space (p);
834 g_print ("%s%s:\n", sep, p->name);
835 printed_header = TRUE;
837 field_ptr = (const char*)addr + field->offset + type_offset;
839 print_field_value (field_ptr, field, type_offset);
845 * mono_object_describe_fields:
847 * Prints to stdout a small description of each field of the object @obj.
848 * For use in a debugger.
850 void
851 mono_object_describe_fields (MonoObject *obj)
853 MonoClass *class = mono_object_class (obj);
854 objval_describe (class, (char*)obj);
858 * mono_value_describe_fields:
860 * Prints to stdout a small description of each field of the value type
861 * stored at @addr of type @klass.
862 * For use in a debugger.
864 void
865 mono_value_describe_fields (MonoClass* klass, const char* addr)
867 objval_describe (klass, addr);
871 * mono_class_describe_statics:
873 * Prints to stdout a small description of each static field of the type @klass
874 * in the current application domain.
875 * For use in a debugger.
877 void
878 mono_class_describe_statics (MonoClass* klass)
880 MonoClassField *field;
881 MonoClass *p;
882 const char *field_ptr;
883 const char *addr = mono_class_vtable (mono_domain_get (), klass)->data;
884 if (!addr)
885 return;
887 for (p = klass; p != NULL; p = p->parent) {
888 gpointer iter = NULL;
889 while ((field = mono_class_get_fields (p, &iter))) {
890 if (field->type->attrs & FIELD_ATTRIBUTE_LITERAL)
891 continue;
892 if (!(field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA)))
893 continue;
895 field_ptr = (const char*)addr + field->offset;
897 print_field_value (field_ptr, field, 0);