5 * Mono Project (http://www.mono-project.com)
7 * Copyright (C) 2005-2008 Novell, Inc. (http://www.novell.com)
8 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
12 #include "mono/metadata/tokentype.h"
13 #include "mono/metadata/opcodes.h"
14 #include "mono/metadata/metadata-internals.h"
15 #include "mono/metadata/class-internals.h"
16 #include "mono/metadata/object-internals.h"
17 #include "mono/metadata/mono-endian.h"
18 #include "mono/metadata/debug-helpers.h"
19 #include "mono/metadata/tabledefs.h"
20 #include "mono/metadata/appdomain.h"
22 struct MonoMethodDesc {
28 gboolean include_namespace, klass_glob, name_glob;
31 #ifdef HAVE_ARRAY_ELEM_INIT
32 #define MSGSTRFIELD(line) MSGSTRFIELD1(line)
33 #define MSGSTRFIELD1(line) str##line
34 static const struct msgstr_t {
35 #define WRAPPER(a,b) char MSGSTRFIELD(__LINE__) [sizeof (b)];
36 #include "wrapper-types.h"
39 #define WRAPPER(a,b) b,
40 #include "wrapper-types.h"
43 static const gint16 opidx [] = {
44 #define WRAPPER(a,b) [MONO_WRAPPER_ ## a] = offsetof (struct msgstr_t, MSGSTRFIELD(__LINE__)),
45 #include "wrapper-types.h"
50 wrapper_type_to_str (guint32 wrapper_type)
52 g_assert (wrapper_type < MONO_WRAPPER_NUM);
54 return (const char*)&opstr + opidx [wrapper_type];
58 #define WRAPPER(a,b) b,
59 static const char* const
60 wrapper_type_names [MONO_WRAPPER_NUM + 1] = {
61 #include "wrapper-types.h"
66 wrapper_type_to_str (guint32 wrapper_type)
68 g_assert (wrapper_type < MONO_WRAPPER_NUM);
70 return wrapper_type_names [wrapper_type];
76 append_class_name (GString *res, MonoClass *klass, gboolean include_namespace)
79 g_string_append (res, "Unknown");
82 if (klass->nested_in) {
83 append_class_name (res, klass->nested_in, include_namespace);
84 g_string_append_c (res, '/');
86 if (include_namespace && *(klass->name_space)) {
87 g_string_append (res, klass->name_space);
88 g_string_append_c (res, '.');
90 g_string_append (res, klass->name);
94 find_system_class (const char *name)
96 if (!strcmp (name, "void"))
97 return mono_defaults.void_class;
98 else if (!strcmp (name, "char")) return mono_defaults.char_class;
99 else if (!strcmp (name, "bool")) return mono_defaults.boolean_class;
100 else if (!strcmp (name, "byte")) return mono_defaults.byte_class;
101 else if (!strcmp (name, "sbyte")) return mono_defaults.sbyte_class;
102 else if (!strcmp (name, "uint16")) return mono_defaults.uint16_class;
103 else if (!strcmp (name, "int16")) return mono_defaults.int16_class;
104 else if (!strcmp (name, "uint")) return mono_defaults.uint32_class;
105 else if (!strcmp (name, "int")) return mono_defaults.int32_class;
106 else if (!strcmp (name, "ulong")) return mono_defaults.uint64_class;
107 else if (!strcmp (name, "long")) return mono_defaults.int64_class;
108 else if (!strcmp (name, "uintptr")) return mono_defaults.uint_class;
109 else if (!strcmp (name, "intptr")) return mono_defaults.int_class;
110 else if (!strcmp (name, "single")) return mono_defaults.single_class;
111 else if (!strcmp (name, "double")) return mono_defaults.double_class;
112 else if (!strcmp (name, "string")) return mono_defaults.string_class;
113 else if (!strcmp (name, "object")) return mono_defaults.object_class;
119 mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace)
123 switch (type->type) {
125 g_string_append (res, "void"); break;
127 g_string_append (res, "char"); break;
128 case MONO_TYPE_BOOLEAN:
129 g_string_append (res, "bool"); break;
131 g_string_append (res, "byte"); break;
133 g_string_append (res, "sbyte"); break;
135 g_string_append (res, "uint16"); break;
137 g_string_append (res, "int16"); break;
139 g_string_append (res, "uint"); break;
141 g_string_append (res, "int"); break;
143 g_string_append (res, "ulong"); break;
145 g_string_append (res, "long"); break;
146 case MONO_TYPE_FNPTR: /* who cares for the exact signature? */
147 g_string_append (res, "*()"); break;
149 g_string_append (res, "uintptr"); break;
151 g_string_append (res, "intptr"); break;
153 g_string_append (res, "single"); break;
155 g_string_append (res, "double"); break;
156 case MONO_TYPE_STRING:
157 g_string_append (res, "string"); break;
158 case MONO_TYPE_OBJECT:
159 g_string_append (res, "object"); break;
161 mono_type_get_desc (res, type->data.type, include_namespace);
162 g_string_append_c (res, '*');
164 case MONO_TYPE_ARRAY:
165 mono_type_get_desc (res, &type->data.array->eklass->byval_arg, include_namespace);
166 g_string_append_printf (res, "[%d]", type->data.array->rank);
168 case MONO_TYPE_SZARRAY:
169 mono_type_get_desc (res, &type->data.klass->byval_arg, include_namespace);
170 g_string_append (res, "[]");
172 case MONO_TYPE_CLASS:
173 case MONO_TYPE_VALUETYPE:
174 append_class_name (res, type->data.klass, include_namespace);
176 case MONO_TYPE_GENERICINST: {
177 MonoGenericContext *context;
179 mono_type_get_desc (res, &type->data.generic_class->container_class->byval_arg, include_namespace);
180 g_string_append (res, "<");
181 context = &type->data.generic_class->context;
182 if (context->class_inst) {
183 for (i = 0; i < context->class_inst->type_argc; ++i) {
185 g_string_append (res, ", ");
186 mono_type_get_desc (res, context->class_inst->type_argv [i], include_namespace);
189 if (context->method_inst) {
190 if (context->class_inst)
191 g_string_append (res, "; ");
192 for (i = 0; i < context->method_inst->type_argc; ++i) {
194 g_string_append (res, ", ");
195 mono_type_get_desc (res, context->method_inst->type_argv [i], include_namespace);
198 g_string_append (res, ">");
203 if (type->data.generic_param) {
204 const char *name = mono_generic_param_name (type->data.generic_param);
206 g_string_append (res, name);
208 g_string_append_printf (res, "%s%d", type->type == MONO_TYPE_VAR ? "!" : "!!", mono_generic_param_num (type->data.generic_param));
210 g_string_append (res, "<unknown>");
213 case MONO_TYPE_TYPEDBYREF:
214 g_string_append (res, "typedbyref");
220 g_string_append_c (res, '&');
224 mono_type_full_name (MonoType *type)
228 str = g_string_new ("");
229 mono_type_get_desc (str, type, TRUE);
230 return g_string_free (str, FALSE);
234 mono_signature_get_desc (MonoMethodSignature *sig, gboolean include_namespace)
241 return g_strdup ("<invalid signature>");
243 res = g_string_new ("");
245 for (i = 0; i < sig->param_count; ++i) {
247 g_string_append_c (res, ',');
248 mono_type_get_desc (res, sig->params [i], include_namespace);
251 g_string_free (res, FALSE);
256 mono_signature_full_name (MonoMethodSignature *sig)
263 return g_strdup ("<invalid signature>");
265 res = g_string_new ("");
267 mono_type_get_desc (res, sig->ret, TRUE);
268 g_string_append_c (res, '(');
269 for (i = 0; i < sig->param_count; ++i) {
271 g_string_append_c (res, ',');
272 mono_type_get_desc (res, sig->params [i], TRUE);
274 g_string_append_c (res, ')');
276 g_string_free (res, FALSE);
281 ginst_get_desc (GString *str, MonoGenericInst *ginst)
285 for (i = 0; i < ginst->type_argc; ++i) {
287 g_string_append (str, ", ");
288 mono_type_get_desc (str, ginst->type_argv [i], TRUE);
293 mono_context_get_desc (MonoGenericContext *context)
298 str = g_string_new ("");
299 g_string_append (str, "<");
301 if (context->class_inst)
302 ginst_get_desc (str, context->class_inst);
303 if (context->method_inst) {
304 if (context->class_inst)
305 g_string_append (str, "; ");
306 ginst_get_desc (str, context->method_inst);
309 g_string_append (str, ">");
310 res = g_strdup (str->str);
311 g_string_free (str, TRUE);
316 * mono_method_desc_new:
317 * @name: the method name.
318 * @include_namespace: whether the name includes a namespace or not.
320 * Creates a method description for @name, which conforms to the following
323 * [namespace.]classname:methodname[(args...)]
325 * in all the loaded assemblies.
327 * Both classname and methodname can contain '*' which matches anything.
329 * Returns: a parsed representation of the method description.
332 mono_method_desc_new (const char *name, gboolean include_namespace)
334 MonoMethodDesc *result;
335 char *class_name, *class_nspace, *method_name, *use_args, *end;
337 int generic_delim_stack;
339 class_nspace = g_strdup (name);
340 use_args = strchr (class_nspace, '(');
342 /* Allow a ' ' between the method name and the signature */
343 if (use_args > class_nspace && use_args [-1] == ' ')
346 end = strchr (use_args, ')');
348 g_free (class_nspace);
353 method_name = strrchr (class_nspace, ':');
355 g_free (class_nspace);
358 /* allow two :: to separate the method name */
359 if (method_name != class_nspace && method_name [-1] == ':')
360 method_name [-1] = 0;
362 class_name = strrchr (class_nspace, '.');
367 class_name = class_nspace;
370 result = g_new0 (MonoMethodDesc, 1);
371 result->include_namespace = include_namespace;
372 result->name = method_name;
373 result->klass = class_name;
374 result->name_space = use_namespace? class_nspace: NULL;
375 result->args = use_args? use_args: NULL;
376 if (strstr (result->name, "*"))
377 result->name_glob = TRUE;
378 if (strstr (result->klass, "*"))
379 result->klass_glob = TRUE;
383 result->num_args = 1;
384 generic_delim_stack = 0;
387 generic_delim_stack++;
388 else if (*end == '>')
389 generic_delim_stack--;
391 if (*end == ',' && generic_delim_stack == 0)
401 mono_method_desc_from_method (MonoMethod *method)
403 MonoMethodDesc *result;
405 result = g_new0 (MonoMethodDesc, 1);
406 result->include_namespace = TRUE;
407 result->name = g_strdup (method->name);
408 result->klass = g_strdup (method->klass->name);
409 result->name_space = g_strdup (method->klass->name_space);
415 * mono_method_desc_free:
416 * @desc: method description to be released
418 * Releases the MonoMethodDesc object @desc.
421 mono_method_desc_free (MonoMethodDesc *desc)
423 if (desc->name_space)
424 g_free (desc->name_space);
425 else if (desc->klass)
426 g_free (desc->klass);
431 * mono_method_descr_match:
432 * @desc: MonoMethoDescription
433 * @method: MonoMethod to test
435 * Determines whether the specified @method matches the provided @desc description.
437 * namespace and class are supposed to match already if this function is used.
438 * Returns: True if the method matches the description, false otherwise.
441 mono_method_desc_match (MonoMethodDesc *desc, MonoMethod *method)
446 name_match = strcmp (desc->name, method->name) == 0;
451 if (desc->num_args != mono_method_signature (method)->param_count)
453 sig = mono_signature_get_desc (mono_method_signature (method), desc->include_namespace);
454 if (strcmp (sig, desc->args)) {
463 my_strrchr (const char *str, char ch, int *len)
467 for (pos = (*len)-1; pos >= 0; pos--) {
479 match_class (MonoMethodDesc *desc, int pos, MonoClass *klass)
483 if (desc->klass_glob && !strcmp (desc->klass, "*"))
486 if (desc->klass_glob && g_pattern_match_simple (desc->klass, klass->name))
489 p = my_strrchr (desc->klass, '/', &pos);
491 if (strncmp (desc->klass, klass->name, pos))
493 if (desc->name_space && strcmp (desc->name_space, klass->name_space))
498 if (strcmp (p+1, klass->name))
500 if (!klass->nested_in)
503 return match_class (desc, pos, klass->nested_in);
507 mono_method_desc_full_match (MonoMethodDesc *desc, MonoMethod *method)
511 if (!match_class (desc, strlen (desc->klass), method->klass))
514 return mono_method_desc_match (desc, method);
518 mono_method_desc_search_in_class (MonoMethodDesc *desc, MonoClass *klass)
521 gpointer iter = NULL;
523 while ((m = mono_class_get_methods (klass, &iter)))
524 if (mono_method_desc_match (desc, m))
530 mono_method_desc_search_in_image (MonoMethodDesc *desc, MonoImage *image)
533 const MonoTableInfo *methods;
537 /* Handle short names for system classes */
538 if (!desc->name_space && image == mono_defaults.corlib) {
539 klass = find_system_class (desc->klass);
541 return mono_method_desc_search_in_class (desc, klass);
544 if (desc->name_space && desc->klass) {
545 klass = mono_class_try_load_from_name (image, desc->name_space, desc->klass);
548 return mono_method_desc_search_in_class (desc, klass);
551 /* FIXME: Is this call necessary? We don't use its result. */
552 mono_image_get_table_info (image, MONO_TABLE_TYPEDEF);
553 methods = mono_image_get_table_info (image, MONO_TABLE_METHOD);
554 for (i = 0; i < mono_table_info_get_rows (methods); ++i) {
556 guint32 token = mono_metadata_decode_row_col (methods, i, MONO_METHOD_NAME);
557 const char *n = mono_metadata_string_heap (image, token);
559 if (strcmp (n, desc->name))
561 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
563 mono_error_cleanup (&error);
566 if (mono_method_desc_full_match (desc, method))
572 static const unsigned char*
573 dis_one (GString *str, MonoDisHelper *dh, MonoMethod *method, const unsigned char *ip, const unsigned char *end)
576 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
577 const MonoOpcode *opcode;
578 guint32 label, token;
582 const unsigned char* il_code;
585 g_string_append_printf (str, "could not disassemble, bad header due to %s", mono_error_get_message (&error));
586 mono_error_cleanup (&error);
589 il_code = mono_method_header_get_code (header, NULL, NULL);
591 label = ip - il_code;
593 tmp = dh->indenter (dh, method, label);
594 g_string_append (str, tmp);
597 if (dh->label_format)
598 g_string_append_printf (str, dh->label_format, label);
600 i = mono_opcode_value (&ip, end);
602 opcode = &mono_opcodes [i];
603 g_string_append_printf (str, "%-10s", mono_opcode_name (i));
605 switch (opcode->argument) {
609 case MonoInlineField:
610 case MonoInlineMethod:
615 tmp = dh->tokener (dh, method, token);
616 g_string_append (str, tmp);
619 g_string_append_printf (str, "0x%08x", token);
623 case MonoInlineString: {
629 if (!image_is_dynamic (method->klass->image) && !method_is_dynamic (method)) {
631 blob = mono_metadata_user_string (method->klass->image, mono_metadata_token_index (token));
633 len2 = mono_metadata_decode_blob_size (blob, &blob);
636 #ifdef NO_UNALIGNED_ACCESS
637 /* The blob might not be 2 byte aligned */
638 blob2 = g_malloc ((len2 * 2) + 1);
639 memcpy (blob2, blob, len2 * 2);
644 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
646 guint16 *buf = g_new (guint16, len2 + 1);
649 for (i = 0; i < len2; ++i)
650 buf [i] = GUINT16_FROM_LE (((guint16*)blob2) [i]);
651 s = g_utf16_to_utf8 (buf, len2, NULL, NULL, NULL);
655 s = g_utf16_to_utf8 ((gunichar2*)blob2, len2, NULL, NULL, NULL);
658 g_string_append_printf (str, "\"%s\"", s);
667 g_string_append_printf (str, "%d", read16 (ip));
670 case MonoShortInlineVar:
671 g_string_append_printf (str, "%d", (*ip));
674 case MonoInlineBrTarget:
677 if (dh->label_target)
678 g_string_append_printf (str, dh->label_target, ip + sval - il_code);
680 g_string_append_printf (str, "%d", sval);
682 case MonoShortInlineBrTarget:
683 sval = *(const signed char*)ip;
685 if (dh->label_target)
686 g_string_append_printf (str, dh->label_target, ip + sval - il_code);
688 g_string_append_printf (str, "%d", sval);
690 case MonoInlineSwitch: {
691 const unsigned char *end;
695 g_string_append_c (str, '(');
696 for (i = 0; i < sval; ++i) {
698 g_string_append (str, ", ");
700 if (dh->label_target)
701 g_string_append_printf (str, dh->label_target, end + label - il_code);
703 g_string_append_printf (str, "%d", label);
706 g_string_append_c (str, ')');
712 g_string_append_printf (str, "%g", r);
716 case MonoShortInlineR: {
719 g_string_append_printf (str, "%g", r);
724 g_string_append_printf (str, "%d", (gint32)read32 (ip));
727 case MonoShortInlineI:
728 g_string_append_printf (str, "%d", *(const signed char*)ip);
735 g_assert_not_reached ();
738 g_string_append (str, dh->newline);
740 mono_metadata_free_mh (header);
747 "IL_%04x: ", /* label_format */
748 "IL_%04x", /* label_target */
755 mono_disasm_code_one (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const guchar **endp)
758 GString *res = g_string_new ("");
762 /* set ip + 2 as the end: this is just a debugging method */
763 ip = dis_one (res, dh, method, ip, ip + 2);
768 g_string_free (res, FALSE);
773 mono_disasm_code (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const guchar* end)
776 GString *res = g_string_new ("");
781 ip = dis_one (res, dh, method, ip, end);
785 g_string_free (res, FALSE);
790 * mono_field_full_name:
791 * @field: field to retrieve information for
793 * Returns: the full name for the field, made up of the namespace, type name and the field name.
796 mono_field_full_name (MonoClassField *field)
799 const char *nspace = field->parent->name_space;
801 res = g_strdup_printf ("%s%s%s:%s", nspace, *nspace ? "." : "",
802 field->parent->name, mono_field_get_name (field));
808 mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret, MonoTypeNameFormat format)
813 char *inst_desc = NULL;
815 if (format == MONO_TYPE_NAME_FORMAT_IL)
816 klass_desc = mono_type_full_name (&method->klass->byval_arg);
818 klass_desc = mono_type_get_name_full (&method->klass->byval_arg, format);
820 if (method->is_inflated && ((MonoMethodInflated*)method)->context.method_inst) {
821 GString *str = g_string_new ("");
822 if (format == MONO_TYPE_NAME_FORMAT_IL)
823 g_string_append (str, "<");
825 g_string_append (str, "[");
826 ginst_get_desc (str, ((MonoMethodInflated*)method)->context.method_inst);
827 if (format == MONO_TYPE_NAME_FORMAT_IL)
828 g_string_append_c (str, '>');
830 g_string_append_c (str, ']');
832 inst_desc = str->str;
833 g_string_free (str, FALSE);
834 } else if (method->is_generic) {
835 MonoGenericContainer *container = mono_method_get_generic_container (method);
837 GString *str = g_string_new ("");
838 if (format == MONO_TYPE_NAME_FORMAT_IL)
839 g_string_append (str, "<");
841 g_string_append (str, "[");
842 ginst_get_desc (str, container->context.method_inst);
843 if (format == MONO_TYPE_NAME_FORMAT_IL)
844 g_string_append_c (str, '>');
846 g_string_append_c (str, ']');
848 inst_desc = str->str;
849 g_string_free (str, FALSE);
852 if (method->wrapper_type != MONO_WRAPPER_NONE)
853 sprintf (wrapper, "(wrapper %s) ", wrapper_type_to_str (method->wrapper_type));
855 strcpy (wrapper, "");
858 char *tmpsig = mono_signature_get_desc (mono_method_signature (method), TRUE);
860 if (method->wrapper_type != MONO_WRAPPER_NONE)
861 sprintf (wrapper, "(wrapper %s) ", wrapper_type_to_str (method->wrapper_type));
863 strcpy (wrapper, "");
865 char *ret_str = mono_type_full_name (mono_method_signature (method)->ret);
866 res = g_strdup_printf ("%s%s %s:%s%s (%s)", wrapper, ret_str, klass_desc,
867 method->name, inst_desc ? inst_desc : "", tmpsig);
870 res = g_strdup_printf ("%s%s:%s%s (%s)", wrapper, klass_desc,
871 method->name, inst_desc ? inst_desc : "", tmpsig);
875 res = g_strdup_printf ("%s%s:%s%s", wrapper, klass_desc,
876 method->name, inst_desc ? inst_desc : "");
886 mono_method_full_name (MonoMethod *method, gboolean signature)
888 return mono_method_get_name_full (method, signature, FALSE, MONO_TYPE_NAME_FORMAT_IL);
892 mono_method_get_full_name (MonoMethod *method)
894 return mono_method_get_name_full (method, TRUE, TRUE, MONO_TYPE_NAME_FORMAT_IL);
898 print_name_space (MonoClass *klass)
900 if (klass->nested_in) {
901 print_name_space (klass->nested_in);
902 g_print ("%s", klass->nested_in->name);
905 if (klass->name_space [0]) {
906 g_print ("%s", klass->name_space);
913 * mono_object_describe:
915 * Prints to stdout a small description of the object @obj.
916 * For use in a debugger.
919 mono_object_describe (MonoObject *obj)
925 g_print ("(null)\n");
928 klass = mono_object_class (obj);
929 if (klass == mono_defaults.string_class) {
930 char *utf8 = mono_string_to_utf8_checked ((MonoString*)obj, &error);
931 mono_error_cleanup (&error); /* FIXME don't swallow the error */
932 if (utf8 && strlen (utf8) > 60) {
939 g_print ("String at %p, length: %d, '%s'\n", obj, mono_string_length ((MonoString*) obj), utf8);
941 g_print ("String at %p, length: %d, unable to decode UTF16\n", obj, mono_string_length ((MonoString*) obj));
944 } else if (klass->rank) {
945 MonoArray *array = (MonoArray*)obj;
946 sep = print_name_space (klass);
947 g_print ("%s%s", sep, klass->name);
948 g_print (" at %p, rank: %d, length: %d\n", obj, klass->rank, (int)mono_array_length (array));
950 sep = print_name_space (klass);
951 g_print ("%s%s", sep, klass->name);
952 g_print (" object at %p (klass: %p)\n", obj, klass);
958 print_field_value (const char *field_ptr, MonoClassField *field, int type_offset)
961 g_print ("At %p (ofs: %2d) %s: ", field_ptr, field->offset + type_offset, mono_field_get_name (field));
962 type = mono_type_get_underlying_type (field->type);
964 switch (type->type) {
968 case MONO_TYPE_FNPTR:
969 g_print ("%p\n", *(const void**)field_ptr);
971 case MONO_TYPE_STRING:
972 case MONO_TYPE_SZARRAY:
973 case MONO_TYPE_CLASS:
974 case MONO_TYPE_OBJECT:
975 case MONO_TYPE_ARRAY:
976 mono_object_describe (*(MonoObject**)field_ptr);
978 case MONO_TYPE_GENERICINST:
979 if (!mono_type_generic_inst_is_valuetype (type)) {
980 mono_object_describe (*(MonoObject**)field_ptr);
985 case MONO_TYPE_VALUETYPE: {
986 MonoClass *k = mono_class_from_mono_type (type);
987 g_print ("%s ValueType (type: %p) at %p\n", k->name, k, field_ptr);
991 g_print ("%d\n", *(gint8*)field_ptr);
994 g_print ("%d\n", *(guint8*)field_ptr);
997 g_print ("%d\n", *(gint16*)field_ptr);
1000 g_print ("%d\n", *(guint16*)field_ptr);
1003 g_print ("%d\n", *(gint32*)field_ptr);
1006 g_print ("%u\n", *(guint32*)field_ptr);
1009 g_print ("%lld\n", (long long int)*(gint64*)field_ptr);
1012 g_print ("%llu\n", (long long unsigned int)*(guint64*)field_ptr);
1015 g_print ("%f\n", *(gfloat*)field_ptr);
1018 g_print ("%f\n", *(gdouble*)field_ptr);
1020 case MONO_TYPE_BOOLEAN:
1021 g_print ("%s (%d)\n", *(guint8*)field_ptr? "True": "False", *(guint8*)field_ptr);
1023 case MONO_TYPE_CHAR:
1024 g_print ("'%c' (%d 0x%04x)\n", *(guint16*)field_ptr, *(guint16*)field_ptr, *(guint16*)field_ptr);
1027 g_assert_not_reached ();
1033 objval_describe (MonoClass *klass, const char *addr)
1035 MonoClassField *field;
1037 const char *field_ptr;
1038 gssize type_offset = 0;
1040 if (klass->valuetype)
1041 type_offset = -sizeof (MonoObject);
1043 for (p = klass; p != NULL; p = p->parent) {
1044 gpointer iter = NULL;
1045 int printed_header = FALSE;
1046 while ((field = mono_class_get_fields (p, &iter))) {
1047 if (field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA))
1050 if (p != klass && !printed_header) {
1052 g_print ("In class ");
1053 sep = print_name_space (p);
1054 g_print ("%s%s:\n", sep, p->name);
1055 printed_header = TRUE;
1057 field_ptr = (const char*)addr + field->offset + type_offset;
1059 print_field_value (field_ptr, field, type_offset);
1065 * mono_object_describe_fields:
1067 * Prints to stdout a small description of each field of the object @obj.
1068 * For use in a debugger.
1071 mono_object_describe_fields (MonoObject *obj)
1073 MonoClass *klass = mono_object_class (obj);
1074 objval_describe (klass, (char*)obj);
1078 * mono_value_describe_fields:
1080 * Prints to stdout a small description of each field of the value type
1081 * stored at @addr of type @klass.
1082 * For use in a debugger.
1085 mono_value_describe_fields (MonoClass* klass, const char* addr)
1087 objval_describe (klass, addr);
1091 * mono_class_describe_statics:
1093 * Prints to stdout a small description of each static field of the type @klass
1094 * in the current application domain.
1095 * For use in a debugger.
1098 mono_class_describe_statics (MonoClass* klass)
1101 MonoClassField *field;
1103 const char *field_ptr;
1104 MonoVTable *vtable = mono_class_vtable_full (mono_domain_get (), klass, &error);
1107 if (!vtable || !is_ok (&error)) {
1108 mono_error_cleanup (&error);
1112 if (!(addr = (const char *)mono_vtable_get_static_field_data (vtable)))
1115 for (p = klass; p != NULL; p = p->parent) {
1116 gpointer iter = NULL;
1117 while ((field = mono_class_get_fields (p, &iter))) {
1118 if (field->type->attrs & FIELD_ATTRIBUTE_LITERAL)
1120 if (!(field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA)))
1123 field_ptr = (const char*)addr + field->offset;
1125 print_field_value (field_ptr, field, 0);
1131 * mono_print_method_code
1132 * @MonoMethod: a pointer to the method
1134 * This method is used from a debugger to print the code of the method.
1136 * This prints the IL code of the method in the standard output.
1139 mono_method_print_code (MonoMethod *method)
1143 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
1145 printf ("METHOD HEADER NOT FOUND DUE TO: %s\n", mono_error_get_message (&error));
1146 mono_error_cleanup (&error);
1149 code = mono_disasm_code (0, method, header->code, header->code + header->code_size);
1150 printf ("CODE FOR %s:\n%s\n", mono_method_full_name (method, TRUE), code);