5 * Mono Project (http://www.mono-project.com)
7 * Copyright (C) 2005-2008 Novell, Inc. (http://www.novell.com)
11 #include "mono/metadata/tokentype.h"
12 #include "mono/metadata/opcodes.h"
13 #include "mono/metadata/metadata-internals.h"
14 #include "mono/metadata/class-internals.h"
15 #include "mono/metadata/object-internals.h"
16 #include "mono/metadata/mono-endian.h"
17 #include "mono/metadata/debug-helpers.h"
18 #include "mono/metadata/tabledefs.h"
19 #include "mono/metadata/appdomain.h"
21 struct MonoMethodDesc {
27 gboolean include_namespace, klass_glob, name_glob;
30 #ifdef HAVE_ARRAY_ELEM_INIT
31 #define MSGSTRFIELD(line) MSGSTRFIELD1(line)
32 #define MSGSTRFIELD1(line) str##line
33 static const struct msgstr_t {
34 #define WRAPPER(a,b) char MSGSTRFIELD(__LINE__) [sizeof (b)];
35 #include "wrapper-types.h"
38 #define WRAPPER(a,b) b,
39 #include "wrapper-types.h"
42 static const gint16 opidx [] = {
43 #define WRAPPER(a,b) [MONO_WRAPPER_ ## a] = offsetof (struct msgstr_t, MSGSTRFIELD(__LINE__)),
44 #include "wrapper-types.h"
49 wrapper_type_to_str (guint32 wrapper_type)
51 g_assert (wrapper_type < MONO_WRAPPER_NUM);
53 return (const char*)&opstr + opidx [wrapper_type];
57 #define WRAPPER(a,b) b,
58 static const char* const
59 wrapper_type_names [MONO_WRAPPER_NUM + 1] = {
60 #include "wrapper-types.h"
65 wrapper_type_to_str (guint32 wrapper_type)
67 g_assert (wrapper_type < MONO_WRAPPER_NUM);
69 return wrapper_type_names [wrapper_type];
75 append_class_name (GString *res, MonoClass *klass, gboolean include_namespace)
78 g_string_append (res, "Unknown");
81 if (klass->nested_in) {
82 append_class_name (res, klass->nested_in, include_namespace);
83 g_string_append_c (res, '/');
85 if (include_namespace && *(klass->name_space)) {
86 g_string_append (res, klass->name_space);
87 g_string_append_c (res, '.');
89 g_string_append (res, klass->name);
93 find_system_class (const char *name)
95 if (!strcmp (name, "void"))
96 return mono_defaults.void_class;
97 else if (!strcmp (name, "char")) return mono_defaults.char_class;
98 else if (!strcmp (name, "bool")) return mono_defaults.boolean_class;
99 else if (!strcmp (name, "byte")) return mono_defaults.byte_class;
100 else if (!strcmp (name, "sbyte")) return mono_defaults.sbyte_class;
101 else if (!strcmp (name, "uint16")) return mono_defaults.uint16_class;
102 else if (!strcmp (name, "int16")) return mono_defaults.int16_class;
103 else if (!strcmp (name, "uint")) return mono_defaults.uint32_class;
104 else if (!strcmp (name, "int")) return mono_defaults.int32_class;
105 else if (!strcmp (name, "ulong")) return mono_defaults.uint64_class;
106 else if (!strcmp (name, "long")) return mono_defaults.int64_class;
107 else if (!strcmp (name, "uintptr")) return mono_defaults.uint_class;
108 else if (!strcmp (name, "intptr")) return mono_defaults.int_class;
109 else if (!strcmp (name, "single")) return mono_defaults.single_class;
110 else if (!strcmp (name, "double")) return mono_defaults.double_class;
111 else if (!strcmp (name, "string")) return mono_defaults.string_class;
112 else if (!strcmp (name, "object")) return mono_defaults.object_class;
118 mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace)
122 switch (type->type) {
124 g_string_append (res, "void"); break;
126 g_string_append (res, "char"); break;
127 case MONO_TYPE_BOOLEAN:
128 g_string_append (res, "bool"); break;
130 g_string_append (res, "byte"); break;
132 g_string_append (res, "sbyte"); break;
134 g_string_append (res, "uint16"); break;
136 g_string_append (res, "int16"); break;
138 g_string_append (res, "uint"); break;
140 g_string_append (res, "int"); break;
142 g_string_append (res, "ulong"); break;
144 g_string_append (res, "long"); break;
145 case MONO_TYPE_FNPTR: /* who cares for the exact signature? */
146 g_string_append (res, "*()"); break;
148 g_string_append (res, "uintptr"); break;
150 g_string_append (res, "intptr"); break;
152 g_string_append (res, "single"); break;
154 g_string_append (res, "double"); break;
155 case MONO_TYPE_STRING:
156 g_string_append (res, "string"); break;
157 case MONO_TYPE_OBJECT:
158 g_string_append (res, "object"); break;
160 mono_type_get_desc (res, type->data.type, include_namespace);
161 g_string_append_c (res, '*');
163 case MONO_TYPE_ARRAY:
164 mono_type_get_desc (res, &type->data.array->eklass->byval_arg, include_namespace);
165 g_string_append_printf (res, "[%d]", type->data.array->rank);
167 case MONO_TYPE_SZARRAY:
168 mono_type_get_desc (res, &type->data.klass->byval_arg, include_namespace);
169 g_string_append (res, "[]");
171 case MONO_TYPE_CLASS:
172 case MONO_TYPE_VALUETYPE:
173 append_class_name (res, type->data.klass, include_namespace);
175 case MONO_TYPE_GENERICINST: {
176 MonoGenericContext *context;
178 mono_type_get_desc (res, &type->data.generic_class->container_class->byval_arg, include_namespace);
179 g_string_append (res, "<");
180 context = &type->data.generic_class->context;
181 if (context->class_inst) {
182 for (i = 0; i < context->class_inst->type_argc; ++i) {
184 g_string_append (res, ", ");
185 mono_type_get_desc (res, context->class_inst->type_argv [i], include_namespace);
188 if (context->method_inst) {
189 if (context->class_inst)
190 g_string_append (res, "; ");
191 for (i = 0; i < context->method_inst->type_argc; ++i) {
193 g_string_append (res, ", ");
194 mono_type_get_desc (res, context->method_inst->type_argv [i], include_namespace);
197 g_string_append (res, ">");
202 if (type->data.generic_param) {
203 const char *name = mono_generic_param_name (type->data.generic_param);
205 g_string_append (res, name);
207 g_string_append_printf (res, "%s%d", type->type == MONO_TYPE_VAR ? "!" : "!!", mono_generic_param_num (type->data.generic_param));
209 g_string_append (res, "<unknown>");
212 case MONO_TYPE_TYPEDBYREF:
213 g_string_append (res, "typedbyref");
219 g_string_append_c (res, '&');
223 mono_type_full_name (MonoType *type)
227 str = g_string_new ("");
228 mono_type_get_desc (str, type, TRUE);
229 return g_string_free (str, FALSE);
233 mono_signature_get_desc (MonoMethodSignature *sig, gboolean include_namespace)
240 return g_strdup ("<invalid signature>");
242 res = g_string_new ("");
244 for (i = 0; i < sig->param_count; ++i) {
246 g_string_append_c (res, ',');
247 mono_type_get_desc (res, sig->params [i], include_namespace);
250 g_string_free (res, FALSE);
255 mono_signature_full_name (MonoMethodSignature *sig)
262 return g_strdup ("<invalid signature>");
264 res = g_string_new ("");
266 mono_type_get_desc (res, sig->ret, TRUE);
267 g_string_append_c (res, '(');
268 for (i = 0; i < sig->param_count; ++i) {
270 g_string_append_c (res, ',');
271 mono_type_get_desc (res, sig->params [i], TRUE);
273 g_string_append_c (res, ')');
275 g_string_free (res, FALSE);
280 ginst_get_desc (GString *str, MonoGenericInst *ginst)
284 for (i = 0; i < ginst->type_argc; ++i) {
286 g_string_append (str, ", ");
287 mono_type_get_desc (str, ginst->type_argv [i], TRUE);
292 mono_context_get_desc (MonoGenericContext *context)
297 str = g_string_new ("");
298 g_string_append (str, "<");
300 if (context->class_inst)
301 ginst_get_desc (str, context->class_inst);
302 if (context->method_inst) {
303 if (context->class_inst)
304 g_string_append (str, "; ");
305 ginst_get_desc (str, context->method_inst);
308 g_string_append (str, ">");
309 res = g_strdup (str->str);
310 g_string_free (str, TRUE);
315 * mono_method_desc_new:
316 * @name: the method name.
317 * @include_namespace: whether the name includes a namespace or not.
319 * Creates a method description for @name, which conforms to the following
322 * [namespace.]classname:methodname[(args...)]
324 * in all the loaded assemblies.
326 * Both classname and methodname can contain '*' which matches anything.
328 * Returns: a parsed representation of the method description.
331 mono_method_desc_new (const char *name, gboolean include_namespace)
333 MonoMethodDesc *result;
334 char *class_name, *class_nspace, *method_name, *use_args, *end;
337 class_nspace = g_strdup (name);
338 use_args = strchr (class_nspace, '(');
340 /* Allow a ' ' between the method name and the signature */
341 if (use_args > class_nspace && use_args [-1] == ' ')
344 end = strchr (use_args, ')');
346 g_free (class_nspace);
351 method_name = strrchr (class_nspace, ':');
353 g_free (class_nspace);
356 /* allow two :: to separate the method name */
357 if (method_name != class_nspace && method_name [-1] == ':')
358 method_name [-1] = 0;
360 class_name = strrchr (class_nspace, '.');
365 class_name = class_nspace;
368 result = g_new0 (MonoMethodDesc, 1);
369 result->include_namespace = include_namespace;
370 result->name = method_name;
371 result->klass = class_name;
372 result->name_space = use_namespace? class_nspace: NULL;
373 result->args = use_args? use_args: NULL;
374 if (strstr (result->name, "*"))
375 result->name_glob = TRUE;
376 if (strstr (result->klass, "*"))
377 result->klass_glob = TRUE;
381 result->num_args = 1;
393 mono_method_desc_from_method (MonoMethod *method)
395 MonoMethodDesc *result;
397 result = g_new0 (MonoMethodDesc, 1);
398 result->include_namespace = TRUE;
399 result->name = g_strdup (method->name);
400 result->klass = g_strdup (method->klass->name);
401 result->name_space = g_strdup (method->klass->name_space);
407 * mono_method_desc_free:
408 * @desc: method description to be released
410 * Releases the MonoMethodDesc object @desc.
413 mono_method_desc_free (MonoMethodDesc *desc)
415 if (desc->name_space)
416 g_free (desc->name_space);
417 else if (desc->klass)
418 g_free (desc->klass);
423 * mono_method_descr_match:
424 * @desc: MonoMethoDescription
425 * @method: MonoMethod to test
427 * Determines whether the specified @method matches the provided @desc description.
429 * namespace and class are supposed to match already if this function is used.
430 * Returns: True if the method matches the description, false otherwise.
433 mono_method_desc_match (MonoMethodDesc *desc, MonoMethod *method)
438 name_match = strcmp (desc->name, method->name) == 0;
440 if (!name_match && desc->name_glob)
441 name_match = g_pattern_match_simple (desc->name, method->name);
447 if (desc->num_args != mono_method_signature (method)->param_count)
449 sig = mono_signature_get_desc (mono_method_signature (method), desc->include_namespace);
450 if (strcmp (sig, desc->args)) {
459 my_strrchr (const char *str, char ch, int *len)
463 for (pos = (*len)-1; pos >= 0; pos--) {
475 match_class (MonoMethodDesc *desc, int pos, MonoClass *klass)
479 if (desc->klass_glob && !strcmp (desc->klass, "*"))
482 if (desc->klass_glob && g_pattern_match_simple (desc->klass, klass->name))
485 p = my_strrchr (desc->klass, '/', &pos);
487 if (strncmp (desc->klass, klass->name, pos))
489 if (desc->name_space && strcmp (desc->name_space, klass->name_space))
494 if (strcmp (p+1, klass->name))
496 if (!klass->nested_in)
499 return match_class (desc, pos, klass->nested_in);
503 mono_method_desc_full_match (MonoMethodDesc *desc, MonoMethod *method)
507 if (!match_class (desc, strlen (desc->klass), method->klass))
510 return mono_method_desc_match (desc, method);
514 mono_method_desc_search_in_class (MonoMethodDesc *desc, MonoClass *klass)
517 gpointer iter = NULL;
519 while ((m = mono_class_get_methods (klass, &iter)))
520 if (mono_method_desc_match (desc, m))
526 mono_method_desc_search_in_image (MonoMethodDesc *desc, MonoImage *image)
529 const MonoTableInfo *methods;
533 /* Handle short names for system classes */
534 if (!desc->name_space && image == mono_defaults.corlib) {
535 klass = find_system_class (desc->klass);
537 return mono_method_desc_search_in_class (desc, klass);
540 if (desc->name_space && desc->klass) {
541 klass = mono_class_try_load_from_name (image, desc->name_space, desc->klass);
544 return mono_method_desc_search_in_class (desc, klass);
547 /* FIXME: Is this call necessary? We don't use its result. */
548 mono_image_get_table_info (image, MONO_TABLE_TYPEDEF);
549 methods = mono_image_get_table_info (image, MONO_TABLE_METHOD);
550 for (i = 0; i < mono_table_info_get_rows (methods); ++i) {
552 guint32 token = mono_metadata_decode_row_col (methods, i, MONO_METHOD_NAME);
553 const char *n = mono_metadata_string_heap (image, token);
555 if (strcmp (n, desc->name))
557 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
559 mono_error_cleanup (&error);
562 if (mono_method_desc_full_match (desc, method))
568 static const unsigned char*
569 dis_one (GString *str, MonoDisHelper *dh, MonoMethod *method, const unsigned char *ip, const unsigned char *end)
571 MonoMethodHeader *header = mono_method_get_header (method);
572 const MonoOpcode *opcode;
573 guint32 label, token;
577 const unsigned char* il_code = mono_method_header_get_code (header, NULL, NULL);
579 label = ip - il_code;
581 tmp = dh->indenter (dh, method, label);
582 g_string_append (str, tmp);
585 if (dh->label_format)
586 g_string_append_printf (str, dh->label_format, label);
588 i = mono_opcode_value (&ip, end);
590 opcode = &mono_opcodes [i];
591 g_string_append_printf (str, "%-10s", mono_opcode_name (i));
593 switch (opcode->argument) {
597 case MonoInlineField:
598 case MonoInlineMethod:
603 tmp = dh->tokener (dh, method, token);
604 g_string_append (str, tmp);
607 g_string_append_printf (str, "0x%08x", token);
611 case MonoInlineString: {
617 if (!image_is_dynamic (method->klass->image) && !method_is_dynamic (method)) {
619 blob = mono_metadata_user_string (method->klass->image, mono_metadata_token_index (token));
621 len2 = mono_metadata_decode_blob_size (blob, &blob);
624 #ifdef NO_UNALIGNED_ACCESS
625 /* The blob might not be 2 byte aligned */
626 blob2 = g_malloc ((len2 * 2) + 1);
627 memcpy (blob2, blob, len2 * 2);
632 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
634 guint16 *buf = g_new (guint16, len2 + 1);
637 for (i = 0; i < len2; ++i)
638 buf [i] = GUINT16_FROM_LE (((guint16*)blob2) [i]);
639 s = g_utf16_to_utf8 (buf, len2, NULL, NULL, NULL);
643 s = g_utf16_to_utf8 ((gunichar2*)blob2, len2, NULL, NULL, NULL);
646 g_string_append_printf (str, "\"%s\"", s);
655 g_string_append_printf (str, "%d", read16 (ip));
658 case MonoShortInlineVar:
659 g_string_append_printf (str, "%d", (*ip));
662 case MonoInlineBrTarget:
665 if (dh->label_target)
666 g_string_append_printf (str, dh->label_target, ip + sval - il_code);
668 g_string_append_printf (str, "%d", sval);
670 case MonoShortInlineBrTarget:
671 sval = *(const signed char*)ip;
673 if (dh->label_target)
674 g_string_append_printf (str, dh->label_target, ip + sval - il_code);
676 g_string_append_printf (str, "%d", sval);
678 case MonoInlineSwitch: {
679 const unsigned char *end;
683 g_string_append_c (str, '(');
684 for (i = 0; i < sval; ++i) {
686 g_string_append (str, ", ");
688 if (dh->label_target)
689 g_string_append_printf (str, dh->label_target, end + label - il_code);
691 g_string_append_printf (str, "%d", label);
694 g_string_append_c (str, ')');
700 g_string_append_printf (str, "%g", r);
704 case MonoShortInlineR: {
707 g_string_append_printf (str, "%g", r);
712 g_string_append_printf (str, "%d", (gint32)read32 (ip));
715 case MonoShortInlineI:
716 g_string_append_printf (str, "%d", *(const signed char*)ip);
723 g_assert_not_reached ();
726 g_string_append (str, dh->newline);
728 mono_metadata_free_mh (header);
735 "IL_%04x: ", /* label_format */
736 "IL_%04x", /* label_target */
743 mono_disasm_code_one (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const guchar **endp)
746 GString *res = g_string_new ("");
750 /* set ip + 2 as the end: this is just a debugging method */
751 ip = dis_one (res, dh, method, ip, ip + 2);
756 g_string_free (res, FALSE);
761 mono_disasm_code (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const guchar* end)
764 GString *res = g_string_new ("");
769 ip = dis_one (res, dh, method, ip, end);
773 g_string_free (res, FALSE);
778 * mono_field_full_name:
779 * @field: field to retrieve information for
781 * Returns: the full name for the field, made up of the namespace, type name and the field name.
784 mono_field_full_name (MonoClassField *field)
787 const char *nspace = field->parent->name_space;
789 res = g_strdup_printf ("%s%s%s:%s", nspace, *nspace ? "." : "",
790 field->parent->name, mono_field_get_name (field));
796 mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret, MonoTypeNameFormat format)
801 char *inst_desc = NULL;
803 if (format == MONO_TYPE_NAME_FORMAT_IL)
804 klass_desc = mono_type_full_name (&method->klass->byval_arg);
806 klass_desc = mono_type_get_name_full (&method->klass->byval_arg, format);
808 if (method->is_inflated && ((MonoMethodInflated*)method)->context.method_inst) {
809 GString *str = g_string_new ("");
810 if (format == MONO_TYPE_NAME_FORMAT_IL)
811 g_string_append (str, "<");
813 g_string_append (str, "[");
814 ginst_get_desc (str, ((MonoMethodInflated*)method)->context.method_inst);
815 if (format == MONO_TYPE_NAME_FORMAT_IL)
816 g_string_append_c (str, '>');
818 g_string_append_c (str, ']');
820 inst_desc = str->str;
821 g_string_free (str, FALSE);
822 } else if (method->is_generic) {
823 MonoGenericContainer *container = mono_method_get_generic_container (method);
825 GString *str = g_string_new ("");
826 if (format == MONO_TYPE_NAME_FORMAT_IL)
827 g_string_append (str, "<");
829 g_string_append (str, "[");
830 ginst_get_desc (str, container->context.method_inst);
831 if (format == MONO_TYPE_NAME_FORMAT_IL)
832 g_string_append_c (str, '>');
834 g_string_append_c (str, ']');
836 inst_desc = str->str;
837 g_string_free (str, FALSE);
840 if (method->wrapper_type != MONO_WRAPPER_NONE)
841 sprintf (wrapper, "(wrapper %s) ", wrapper_type_to_str (method->wrapper_type));
843 strcpy (wrapper, "");
846 char *tmpsig = mono_signature_get_desc (mono_method_signature (method), TRUE);
848 if (method->wrapper_type != MONO_WRAPPER_NONE)
849 sprintf (wrapper, "(wrapper %s) ", wrapper_type_to_str (method->wrapper_type));
851 strcpy (wrapper, "");
853 char *ret_str = mono_type_full_name (mono_method_signature (method)->ret);
854 res = g_strdup_printf ("%s%s %s:%s%s (%s)", wrapper, ret_str, klass_desc,
855 method->name, inst_desc ? inst_desc : "", tmpsig);
858 res = g_strdup_printf ("%s%s:%s%s (%s)", wrapper, klass_desc,
859 method->name, inst_desc ? inst_desc : "", tmpsig);
863 res = g_strdup_printf ("%s%s:%s%s", wrapper, klass_desc,
864 method->name, inst_desc ? inst_desc : "");
874 mono_method_full_name (MonoMethod *method, gboolean signature)
876 return mono_method_get_name_full (method, signature, FALSE, MONO_TYPE_NAME_FORMAT_IL);
880 mono_method_get_full_name (MonoMethod *method)
882 return mono_method_get_name_full (method, TRUE, TRUE, MONO_TYPE_NAME_FORMAT_IL);
886 print_name_space (MonoClass *klass)
888 if (klass->nested_in) {
889 print_name_space (klass->nested_in);
890 g_print ("%s", klass->nested_in->name);
893 if (klass->name_space [0]) {
894 g_print ("%s", klass->name_space);
901 * mono_object_describe:
903 * Prints to stdout a small description of the object @obj.
904 * For use in a debugger.
907 mono_object_describe (MonoObject *obj)
912 g_print ("(null)\n");
915 klass = mono_object_class (obj);
916 if (klass == mono_defaults.string_class) {
917 char *utf8 = mono_string_to_utf8 ((MonoString*)obj);
918 if (strlen (utf8) > 60) {
924 g_print ("String at %p, length: %d, '%s'\n", obj, mono_string_length ((MonoString*) obj), utf8);
926 } else if (klass->rank) {
927 MonoArray *array = (MonoArray*)obj;
928 sep = print_name_space (klass);
929 g_print ("%s%s", sep, klass->name);
930 g_print (" at %p, rank: %d, length: %d\n", obj, klass->rank, (int)mono_array_length (array));
932 sep = print_name_space (klass);
933 g_print ("%s%s", sep, klass->name);
934 g_print (" object at %p (klass: %p)\n", obj, klass);
940 print_field_value (const char *field_ptr, MonoClassField *field, int type_offset)
943 g_print ("At %p (ofs: %2d) %s: ", field_ptr, field->offset + type_offset, mono_field_get_name (field));
944 type = mono_type_get_underlying_type (field->type);
946 switch (type->type) {
950 case MONO_TYPE_FNPTR:
951 g_print ("%p\n", *(const void**)field_ptr);
953 case MONO_TYPE_STRING:
954 case MONO_TYPE_SZARRAY:
955 case MONO_TYPE_CLASS:
956 case MONO_TYPE_OBJECT:
957 case MONO_TYPE_ARRAY:
958 mono_object_describe (*(MonoObject**)field_ptr);
960 case MONO_TYPE_GENERICINST:
961 if (!mono_type_generic_inst_is_valuetype (type)) {
962 mono_object_describe (*(MonoObject**)field_ptr);
967 case MONO_TYPE_VALUETYPE: {
968 MonoClass *k = mono_class_from_mono_type (type);
969 g_print ("%s ValueType (type: %p) at %p\n", k->name, k, field_ptr);
973 g_print ("%d\n", *(gint8*)field_ptr);
976 g_print ("%d\n", *(guint8*)field_ptr);
979 g_print ("%d\n", *(gint16*)field_ptr);
982 g_print ("%d\n", *(guint16*)field_ptr);
985 g_print ("%d\n", *(gint32*)field_ptr);
988 g_print ("%u\n", *(guint32*)field_ptr);
991 g_print ("%lld\n", (long long int)*(gint64*)field_ptr);
994 g_print ("%llu\n", (long long unsigned int)*(guint64*)field_ptr);
997 g_print ("%f\n", *(gfloat*)field_ptr);
1000 g_print ("%f\n", *(gdouble*)field_ptr);
1002 case MONO_TYPE_BOOLEAN:
1003 g_print ("%s (%d)\n", *(guint8*)field_ptr? "True": "False", *(guint8*)field_ptr);
1005 case MONO_TYPE_CHAR:
1006 g_print ("'%c' (%d 0x%04x)\n", *(guint16*)field_ptr, *(guint16*)field_ptr, *(guint16*)field_ptr);
1009 g_assert_not_reached ();
1015 objval_describe (MonoClass *klass, const char *addr)
1017 MonoClassField *field;
1019 const char *field_ptr;
1020 gssize type_offset = 0;
1022 if (klass->valuetype)
1023 type_offset = -sizeof (MonoObject);
1025 for (p = klass; p != NULL; p = p->parent) {
1026 gpointer iter = NULL;
1027 int printed_header = FALSE;
1028 while ((field = mono_class_get_fields (p, &iter))) {
1029 if (field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA))
1032 if (p != klass && !printed_header) {
1034 g_print ("In class ");
1035 sep = print_name_space (p);
1036 g_print ("%s%s:\n", sep, p->name);
1037 printed_header = TRUE;
1039 field_ptr = (const char*)addr + field->offset + type_offset;
1041 print_field_value (field_ptr, field, type_offset);
1047 * mono_object_describe_fields:
1049 * Prints to stdout a small description of each field of the object @obj.
1050 * For use in a debugger.
1053 mono_object_describe_fields (MonoObject *obj)
1055 MonoClass *klass = mono_object_class (obj);
1056 objval_describe (klass, (char*)obj);
1060 * mono_value_describe_fields:
1062 * Prints to stdout a small description of each field of the value type
1063 * stored at @addr of type @klass.
1064 * For use in a debugger.
1067 mono_value_describe_fields (MonoClass* klass, const char* addr)
1069 objval_describe (klass, addr);
1073 * mono_class_describe_statics:
1075 * Prints to stdout a small description of each static field of the type @klass
1076 * in the current application domain.
1077 * For use in a debugger.
1080 mono_class_describe_statics (MonoClass* klass)
1083 MonoClassField *field;
1085 const char *field_ptr;
1086 MonoVTable *vtable = mono_class_vtable_full (mono_domain_get (), klass, &error);
1089 if (!vtable || !is_ok (&error)) {
1090 mono_error_cleanup (&error);
1094 if (!(addr = (const char *)mono_vtable_get_static_field_data (vtable)))
1097 for (p = klass; p != NULL; p = p->parent) {
1098 gpointer iter = NULL;
1099 while ((field = mono_class_get_fields (p, &iter))) {
1100 if (field->type->attrs & FIELD_ATTRIBUTE_LITERAL)
1102 if (!(field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA)))
1105 field_ptr = (const char*)addr + field->offset;
1107 print_field_value (field_ptr, field, 0);
1113 * mono_print_method_code
1114 * @MonoMethod: a pointer to the method
1116 * This method is used from a debugger to print the code of the method.
1118 * This prints the IL code of the method in the standard output.
1121 mono_method_print_code (MonoMethod *method)
1124 MonoMethodHeader *header = mono_method_get_header (method);
1126 printf ("METHOD HEADER NOT FOUND\n");
1129 code = mono_disasm_code (0, method, header->code, header->code + header->code_size);
1130 printf ("CODE FOR %s:\n%s\n", mono_method_full_name (method, TRUE), code);