2 * dump.c: Dumping routines for the disassembler.
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc.
19 #include "mono/metadata/loader.h"
20 #include "mono/metadata/class.h"
21 #include "mono/metadata/class-internals.h"
22 #include "mono/utils/mono-compiler.h"
25 dump_table_assembly (MonoImage *m)
27 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLY];
28 guint32 cols [MONO_ASSEMBLY_SIZE];
32 fprintf (output, "Assembly Table\n");
37 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
39 fprintf (output, "Name: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_NAME]));
40 fprintf (output, "Hash Algoritm: 0x%08x\n", cols [MONO_ASSEMBLY_HASH_ALG]);
41 fprintf (output, "Version: %d.%d.%d.%d\n", cols [MONO_ASSEMBLY_MAJOR_VERSION],
42 cols [MONO_ASSEMBLY_MINOR_VERSION],
43 cols [MONO_ASSEMBLY_BUILD_NUMBER],
44 cols [MONO_ASSEMBLY_REV_NUMBER]);
45 fprintf (output, "Flags: 0x%08x\n", cols [MONO_ASSEMBLY_FLAGS]);
46 fprintf (output, "PublicKey: BlobPtr (0x%08x)\n", cols [MONO_ASSEMBLY_PUBLIC_KEY]);
48 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
49 len = mono_metadata_decode_value (ptr, &ptr);
51 fprintf (output, "\tDump:");
52 hex_dump (ptr, 0, len);
53 fprintf (output, "\n");
55 fprintf (output, "\tZero sized public key\n");
57 fprintf (output, "Culture: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_CULTURE]));
58 fprintf (output, "\n");
62 dump_table_typeref (MonoImage *m)
64 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEREF];
67 fprintf (output, "Typeref Table\n");
69 for (i = 1; i <= t->rows; i++){
70 char *s = get_typeref (m, i);
72 fprintf (output, "%d: %s\n", i, s);
75 fprintf (output, "\n");
79 dump_table_typedef (MonoImage *m)
81 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
84 fprintf (output, "Typedef Table\n");
86 for (i = 1; i <= t->rows; i++){
87 char *s = get_typedef (m, i);
88 guint32 cols [MONO_TYPEDEF_SIZE];
90 mono_metadata_decode_row (&m->tables [MONO_TABLE_TYPEDEF], i - 1, cols, MONO_TYPEDEF_SIZE);
92 fprintf (output, "%d: %s (flist=%d, mlist=%d, flags=0x%x, extends=0x%x)\n", i, s,
93 cols [MONO_TYPEDEF_FIELD_LIST], cols [MONO_TYPEDEF_METHOD_LIST],
94 cols [MONO_TYPEDEF_FLAGS], cols [MONO_TYPEDEF_EXTENDS]);
97 fprintf (output, "\n");
101 dump_table_typespec (MonoImage *m)
103 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPESPEC];
106 fprintf (output, "Typespec Table\n");
108 for (i = 1; i <= t->rows; i++){
109 char *typespec = get_typespec (m, i, TRUE, NULL);
111 fprintf (output, "%d: %s\n", i, typespec);
114 fprintf (output, "\n");
118 dump_table_assemblyref (MonoImage *m)
120 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLYREF];
123 fprintf (output, "AssemblyRef Table\n");
125 for (i = 0; i < t->rows; i++){
128 guint32 cols [MONO_ASSEMBLYREF_SIZE];
130 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
131 fprintf (output, "%d: Version=%d.%d.%d.%d\n\tName=%s\n", i + 1,
132 cols [MONO_ASSEMBLYREF_MAJOR_VERSION],
133 cols [MONO_ASSEMBLYREF_MINOR_VERSION],
134 cols [MONO_ASSEMBLYREF_BUILD_NUMBER],
135 cols [MONO_ASSEMBLYREF_REV_NUMBER],
136 mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_NAME]));
137 fprintf (output, "\tFlags=0x%08x\n", cols [MONO_ASSEMBLYREF_FLAGS]);
138 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
139 len = mono_metadata_decode_value (ptr, &ptr);
141 fprintf (output, "\tPublic Key:");
142 hex_dump (ptr, 0, len);
143 fprintf (output, "\n");
145 fprintf (output, "\tZero sized public key\n");
148 fprintf (output, "\n");
152 dump_table_param (MonoImage *m)
154 MonoTableInfo *t = &m->tables [MONO_TABLE_PARAM];
157 fprintf (output, "Param Table\n");
159 for (i = 0; i < t->rows; i++){
160 guint32 cols [MONO_PARAM_SIZE];
162 mono_metadata_decode_row (t, i, cols, MONO_PARAM_SIZE);
163 fprintf (output, "%d: 0x%04x %d %s\n",
165 cols [MONO_PARAM_FLAGS], cols [MONO_PARAM_SEQUENCE],
166 mono_metadata_string_heap (m, cols [MONO_PARAM_NAME]));
168 fprintf (output, "\n");
172 dump_table_field (MonoImage *m)
174 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
175 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
176 MonoTableInfo *fl = &m->tables [MONO_TABLE_FIELDLAYOUT];
177 MonoTableInfo *rva = &m->tables [MONO_TABLE_FIELDRVA];
178 int i, current_type, offset_row, rva_row;
179 guint32 first_m, last_m;
181 fprintf (output, "Field Table (1..%d)\n", t->rows);
183 rva_row = offset_row = current_type = 1;
184 last_m = first_m = 1;
185 for (i = 1; i <= t->rows; i++){
186 guint32 cols [MONO_FIELD_SIZE];
190 * Find the next type.
192 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_FIELD_LIST))) {
196 fprintf (output, "########## %s.%s\n",
197 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
198 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
201 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_SIZE);
202 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE], NULL);
203 flags = field_flags (cols [MONO_FIELD_FLAGS]);
204 fprintf (output, "%d: %s %s: %s\n",
207 mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]),
211 if (offset_row <= fl->rows && (mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_FIELD) == i)) {
212 fprintf (output, "\texplicit offset: %d\n", mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_OFFSET));
215 if (rva_row <= rva->rows && (mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_FIELD) == i)) {
216 fprintf (output, "\trva: %d\n", mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_RVA));
220 fprintf (output, "\n");
224 dump_table_memberref (MonoImage *m)
226 MonoTableInfo *t = &m->tables [MONO_TABLE_MEMBERREF];
230 const char *blob, *ks = NULL;
232 fprintf (output, "MemberRef Table (1..%d)\n", t->rows);
234 for (i = 0; i < t->rows; i++){
235 guint32 cols [MONO_MEMBERREF_SIZE];
237 mono_metadata_decode_row (t, i, cols, MONO_MEMBERREF_SIZE);
239 kind = cols [MONO_MEMBERREF_CLASS] & 7;
240 idx = cols [MONO_MEMBERREF_CLASS] >> 3;
242 x = g_strdup ("UNHANDLED CASE");
247 xx = get_typedef (m, idx);
248 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
253 xx = get_typeref (m, idx);
254 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
258 ks = "ModuleRef"; break;
261 x = get_methoddef (m, idx);
265 xx = get_typespec (m, idx, FALSE, NULL);
266 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
270 g_error ("Unknown tag: %d\n", kind);
272 blob = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
273 mono_metadata_decode_blob_size (blob, &blob);
274 if (*blob == 0x6) { /* it's a field */
275 sig = get_field_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
277 sig = get_methodref_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
279 fprintf (output, "%d: %s[%d] %s\n\tResolved: %s\n\tSignature: %s\n\t\n",
282 mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]),
293 dump_table_class_layout (MonoImage *m)
295 MonoTableInfo *t = &m->tables [MONO_TABLE_CLASSLAYOUT];
297 fprintf (output, "ClassLayout Table (1..%d)\n", t->rows);
299 for (i = 0; i < t->rows; i++){
300 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
302 mono_metadata_decode_row (t, i, cols, MONO_CLASS_LAYOUT_SIZE);
304 fprintf (output, "%d: PackingSize=%d ClassSize=%d Parent=%s\n",
305 i + 1, cols [MONO_CLASS_LAYOUT_PACKING_SIZE],
306 cols [MONO_CLASS_LAYOUT_CLASS_SIZE],
307 get_typedef (m, cols [MONO_CLASS_LAYOUT_PARENT]));
312 dump_table_constant (MonoImage *m)
314 MonoTableInfo *t = &m->tables [MONO_TABLE_CONSTANT];
316 const char *desc [] = {
322 fprintf (output, "Constant Table (1..%d)\n", t->rows);
324 for (i = 0; i < t->rows; i++){
325 guint32 cols [MONO_CONSTANT_SIZE];
327 mono_metadata_decode_row (t, i, cols, MONO_CONSTANT_SIZE);
328 parent = desc [cols [MONO_CONSTANT_PARENT] & MONO_HASCONSTANT_MASK];
330 fprintf (output, "%d: Parent= %s: %d %s\n",
331 i + 1, parent, cols [MONO_CONSTANT_PARENT] >> MONO_HASCONSTANT_BITS,
332 get_constant (m, (MonoTypeEnum) cols [MONO_CONSTANT_TYPE], cols [MONO_CONSTANT_VALUE]));
338 dump_table_property_map (MonoImage *m)
340 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTYMAP];
344 fprintf (output, "Property Map Table (1..%d)\n", t->rows);
346 for (i = 0; i < t->rows; i++){
347 guint32 cols [MONO_PROPERTY_MAP_SIZE];
349 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_MAP_SIZE);
350 s = get_typedef (m, cols [MONO_PROPERTY_MAP_PARENT]);
351 fprintf (output, "%d: %s (%d) %d\n", i + 1, s, cols [MONO_PROPERTY_MAP_PARENT], cols [MONO_PROPERTY_MAP_PROPERTY_LIST]);
357 dump_table_property (MonoImage *m)
359 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTY];
364 fprintf (output, "Property Table (1..%d)\n", t->rows);
366 for (i = 0; i < t->rows; i++){
367 guint32 cols [MONO_PROPERTY_SIZE];
371 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_SIZE);
373 prop_flags = cols [MONO_PROPERTY_FLAGS];
374 if (prop_flags & 0x0200)
375 strcat (flags, "special ");
376 if (prop_flags & 0x0400)
377 strcat (flags, "runtime ");
378 if (prop_flags & 0x1000)
379 strcat (flags, "hasdefault ");
381 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
382 /* bsize = */ mono_metadata_decode_blob_size (ptr, &ptr);
383 /* ECMA claims 0x08 ... */
384 if (*ptr != 0x28 && *ptr != 0x08)
385 g_warning("incorrect signature in propert blob: 0x%x", *ptr);
387 pcount = mono_metadata_decode_value (ptr, &ptr);
388 ptr = get_type (m, ptr, &type, FALSE, NULL);
389 fprintf (output, "%d: %s %s (",
390 i + 1, type, mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]));
393 for (j = 0; j < pcount; j++){
394 ptr = get_param (m, ptr, &type, NULL);
395 fprintf (output, "%s%s", j > 0? ", " : "",type);
398 fprintf (output, ") %s\n", flags);
403 dump_table_event (MonoImage *m)
405 MonoTableInfo *t = &m->tables [MONO_TABLE_EVENT];
407 fprintf (output, "Event Table (1..%d)\n", t->rows);
409 for (i = 0; i < t->rows; i++){
410 guint32 cols [MONO_EVENT_SIZE];
414 mono_metadata_decode_row (t, i, cols, MONO_EVENT_SIZE);
416 name = mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]);
417 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE], NULL);
418 fprintf (output, "%d: %s %s %s\n", i + 1, type, name,
419 cols [MONO_EVENT_FLAGS] & 0x200 ? "specialname " : "");
426 dump_table_file (MonoImage *m)
428 MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
430 fprintf (output, "File Table (1..%d)\n", t->rows);
432 for (i = 0; i < t->rows; i++){
433 guint32 cols [MONO_FILE_SIZE];
434 const char *name, *hash;
436 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
438 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
439 fprintf (output, "%d: %s %s [", i + 1, name,
440 cols [MONO_FILE_FLAGS] & 0x1 ? "nometadata" : "containsmetadata");
441 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
442 len = mono_metadata_decode_blob_size (hash, &hash);
443 for (j = 0; j < len; ++j)
444 fprintf (output, "%s%02X", j? " ": "", hash [j] & 0xff);
445 fprintf (output, "]\n");
451 get_manifest_implementation (MonoImage *m, guint32 idx)
454 const char* table = "";
456 return g_strdup ("current module");
457 row = idx >> MONO_IMPLEMENTATION_BITS;
458 switch (idx & MONO_IMPLEMENTATION_MASK) {
459 case MONO_IMPLEMENTATION_FILE:
462 case MONO_IMPLEMENTATION_ASSEMBLYREF:
463 table = "assemblyref";
465 case MONO_IMPLEMENTATION_EXP_TYPE:
466 table = "exportedtype";
469 g_assert_not_reached ();
471 return g_strdup_printf ("%s %d", table, row);
475 get_manifest_flags (guint32 mf)
479 case 1: return "public";
480 case 2: return "private";
487 dump_table_manifest (MonoImage *m)
489 MonoTableInfo *t = &m->tables [MONO_TABLE_MANIFESTRESOURCE];
491 fprintf (output, "Manifestresource Table (1..%d)\n", t->rows);
493 for (i = 0; i < t->rows; i++){
494 guint32 cols [MONO_MANIFEST_SIZE];
495 const char *name, *mf;
498 mono_metadata_decode_row (t, i, cols, MONO_MANIFEST_SIZE);
500 name = mono_metadata_string_heap (m, cols [MONO_MANIFEST_NAME]);
501 mf = get_manifest_flags (cols [MONO_MANIFEST_FLAGS]);
502 impl = get_manifest_implementation (m, cols [MONO_MANIFEST_IMPLEMENTATION]);
503 fprintf (output, "%d: %s '%s' at offset %u in %s\n", i + 1, mf, name, cols [MONO_MANIFEST_OFFSET], impl);
510 dump_table_moduleref (MonoImage *m)
512 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
514 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
516 for (i = 0; i < t->rows; i++){
517 guint32 cols [MONO_MODULEREF_SIZE];
520 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
522 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
523 fprintf (output, "%d: %s\n", i + 1, name);
529 dump_table_module (MonoImage *m)
531 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
533 fprintf (output, "Module Table (1..%d)\n", t->rows);
535 for (i = 0; i < t->rows; i++){
536 guint32 cols [MONO_MODULE_SIZE];
540 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
542 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
543 guid = get_guid (m, cols [MONO_MODULE_MVID]);
544 fprintf (output, "%d: %s %d %s\n", i + 1, name, cols [MONO_MODULE_MVID], guid);
549 dump_table_method (MonoImage *m)
551 MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
552 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
554 guint32 first_m, last_m;
555 /* Generic container for Type & method */
556 MonoGenericContainer *type_container = NULL, *method_container = NULL;
558 fprintf (output, "Method Table (1..%d)\n", t->rows);
561 last_m = first_m = 1;
562 for (i = 1; i <= t->rows; i++){
564 guint32 cols [MONO_METHOD_SIZE];
565 char *sig, *impl_flags;
567 MonoMethodSignature *method;
570 * Find the next type.
572 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_METHOD_LIST))) {
576 fprintf (output, "########## %s.%s\n",
577 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
578 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
580 type_container = mono_metadata_load_generic_params (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), NULL);
581 if (type_container) {
582 mono_metadata_load_generic_param_constraints_checked (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), type_container, &error);
583 g_assert (mono_error_ok (&error)); /*FIXME don't swallow the error message*/
587 method_container = mono_metadata_load_generic_params (m, MONO_TOKEN_METHOD_DEF | i, type_container);
588 if (method_container) {
589 mono_metadata_load_generic_param_constraints_checked (m, MONO_TOKEN_METHOD_DEF | i, method_container, &error);
590 g_assert (mono_error_ok (&error)); /*FIXME don't swallow the error message*/
592 mono_metadata_decode_table_row (m, MONO_TABLE_METHOD, i - 1, cols, MONO_METHOD_SIZE);
593 sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
594 mono_metadata_decode_blob_size (sigblob, &sigblob);
595 method = mono_metadata_parse_method_signature_full (m, method_container ? method_container : type_container, i, sigblob, &sigblob, &error);
596 if (!mono_error_ok (&error)) {
597 fprintf (output,"%d: failed to parse due to %s\n", i, mono_error_get_message (&error));
598 mono_error_cleanup (&error);
602 g_assert (mono_error_ok (&error)); /*FIXME don't swallow the error message*/
603 sig = dis_stringify_method_signature (m, method, i, method_container ? method_container : type_container, FALSE);
604 impl_flags = get_method_impl_flags (cols [MONO_METHOD_IMPLFLAGS]);
605 fprintf (output, "%d: %s (param: %d impl_flags: %s)\n", i, sig, cols [MONO_METHOD_PARAMLIST], impl_flags);
608 mono_metadata_free_method_signature (method);
614 dump_table_implmap (MonoImage *m)
616 MonoTableInfo *t = &m->tables [MONO_TABLE_IMPLMAP];
617 MonoTableInfo *td = &m->tables [MONO_TABLE_MODULEREF];
620 fprintf (output, "ImplMap Table (1..%d)\n", t->rows);
622 for (i = 1; i <= t->rows; i++){
623 guint32 cols [MONO_IMPLMAP_SIZE];
626 mono_metadata_decode_row (t, i - 1, cols, MONO_IMPLMAP_SIZE);
628 method = get_method (m, MONO_TOKEN_METHOD_DEF | (cols [MONO_IMPLMAP_MEMBER] >> MONO_MEMBERFORWD_BITS), NULL);
630 fprintf (output, "%d: %s %d (%s %s)\n", i,
632 cols [MONO_IMPLMAP_FLAGS],
633 mono_metadata_string_heap (m, cols [MONO_IMPLMAP_NAME]),
634 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME)));
639 dump_table_fieldrva (MonoImage *m)
641 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDRVA];
644 fprintf (output, "FieldRVA Table (1..%d)\n", t->rows);
646 for (i = 1; i <= t->rows; i++){
647 guint32 cols [MONO_FIELD_RVA_SIZE];
649 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_RVA_SIZE);
650 fprintf (output, "%d: Field %d: %x\n", i, cols [MONO_FIELD_RVA_FIELD], cols [MONO_FIELD_RVA_RVA]);
655 dump_table_methodimpl (MonoImage *m)
657 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODIMPL];
658 /*MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];*/
661 fprintf (output, "MethodImpl Table (1..%d)\n", t->rows);
663 for (i = 1; i <= t->rows; i++){
664 guint32 cols [MONO_METHODIMPL_SIZE];
665 char *klass, *impl, *decl;
667 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODIMPL_SIZE);
668 klass = get_typedef (m, cols [MONO_METHODIMPL_CLASS]);
669 impl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_BODY]), NULL);
670 decl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_DECLARATION]), NULL);
671 fprintf (output, "%d: %s\n\tdecl: %s\n\timpl: %s\n", i, klass, decl, impl);
679 static dis_map_t semantics_map [] = {
690 dump_table_methodsem (MonoImage *m)
692 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSEMANTICS];
693 int i, is_property, index;
694 const char *semantics;
696 fprintf (output, "Method Semantics Table (1..%d)\n", t->rows);
697 for (i = 1; i <= t->rows; i++){
698 guint32 cols [MONO_METHOD_SEMA_SIZE];
700 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SEMA_SIZE);
701 semantics = flags (cols [MONO_METHOD_SEMA_SEMANTICS], semantics_map);
702 is_property = cols [MONO_METHOD_SEMA_ASSOCIATION] & MONO_HAS_SEMANTICS_MASK;
703 index = cols [MONO_METHOD_SEMA_ASSOCIATION] >> MONO_HAS_SEMANTICS_BITS;
704 fprintf (output, "%d: [%d] %s method: %d %s %d\n", i, cols [MONO_METHOD_SEMA_ASSOCIATION], semantics,
705 cols [MONO_METHOD_SEMA_METHOD] - 1,
706 is_property? "property" : "event",
712 dump_table_interfaceimpl (MonoImage *m)
714 MonoTableInfo *t = &m->tables [MONO_TABLE_INTERFACEIMPL];
717 fprintf (output, "Interface Implementation Table (1..%d)\n", t->rows);
718 for (i = 1; i <= t->rows; i++) {
719 guint32 cols [MONO_INTERFACEIMPL_SIZE];
721 mono_metadata_decode_row (t, i - 1, cols, MONO_INTERFACEIMPL_SIZE);
722 fprintf (output, "%d: %s implements %s\n", i,
723 get_typedef (m, cols [MONO_INTERFACEIMPL_CLASS]),
724 get_typedef_or_ref (m, cols [MONO_INTERFACEIMPL_INTERFACE], NULL));
729 has_cattr_get_table (MonoImage *m, guint32 val)
731 guint32 t = val & MONO_CUSTOM_ATTR_MASK;
732 guint32 index = val >> MONO_CUSTOM_ATTR_BITS;
736 case MONO_CUSTOM_ATTR_METHODDEF:
739 case MONO_CUSTOM_ATTR_FIELDDEF:
742 case MONO_CUSTOM_ATTR_TYPEREF:
745 case MONO_CUSTOM_ATTR_TYPEDEF:
748 case MONO_CUSTOM_ATTR_PARAMDEF:
751 case MONO_CUSTOM_ATTR_INTERFACE:
752 table = "InterfaceImpl";
754 case MONO_CUSTOM_ATTR_MEMBERREF:
757 case MONO_CUSTOM_ATTR_MODULE:
760 case MONO_CUSTOM_ATTR_PERMISSION:
761 table = "DeclSecurity?";
763 case MONO_CUSTOM_ATTR_PROPERTY:
766 case MONO_CUSTOM_ATTR_EVENT:
769 case MONO_CUSTOM_ATTR_SIGNATURE:
770 table = "StandAloneSignature";
772 case MONO_CUSTOM_ATTR_MODULEREF:
775 case MONO_CUSTOM_ATTR_TYPESPEC:
778 case MONO_CUSTOM_ATTR_ASSEMBLY:
781 case MONO_CUSTOM_ATTR_ASSEMBLYREF:
782 table = "AssemblyRef";
784 case MONO_CUSTOM_ATTR_FILE:
787 case MONO_CUSTOM_ATTR_EXP_TYPE:
788 table = "ExportedType";
790 case MONO_CUSTOM_ATTR_MANIFEST:
793 case MONO_CUSTOM_ATTR_GENERICPAR:
794 table = "GenericParam";
801 * FIXME: we should decode the index into something more uman-friendly.
803 return g_strdup_printf ("%s: %d", table, index);
807 custom_attr_params (MonoImage *m, MonoMethodSignature* sig, const char* value)
809 int len, i, slen, type;
812 const char *p = value;
814 len = mono_metadata_decode_value (p, &p);
815 if (len < 2 || read16 (p) != 0x0001) /* Prolog */
816 return g_strdup ("");
820 res = g_string_new ("");
821 for (i = 0; i < sig->param_count; ++i) {
823 g_string_append (res, ", ");
824 type = sig->params [i]->type;
828 g_string_append_printf (res, "%d", (unsigned int)*p);
832 g_string_append_printf (res, "%d", *p);
835 case MONO_TYPE_BOOLEAN:
836 g_string_append_printf (res, "%s", *p?"true":"false");
840 g_string_append_printf (res, "'%c'", read16 (p));
844 g_string_append_printf (res, "%d", read16 (p));
848 g_string_append_printf (res, "%d", (gint16)read16 (p));
852 g_string_append_printf (res, "%d", read32 (p));
856 g_string_append_printf (res, "%d", (gint32)read32 (p));
860 g_string_append_printf (res, "%lld", (long long)read64 (p));
864 g_string_append_printf (res, "%lld", (long long)read64 (p));
871 inf = dis_isinf (val);
873 g_string_append_printf (res, "(00 00 80 ff)"); /* negative infinity */
875 g_string_append_printf (res, "(00 00 80 7f)"); /* positive infinity */
876 else if (dis_isnan (val))
877 g_string_append_printf (res, "(00 00 c0 ff)"); /* NaN */
879 g_string_append_printf (res, "%g", val);
888 inf = dis_isinf (val);
890 g_string_append_printf (res, "(00 00 00 00 00 00 f0 ff)"); /* negative infinity */
892 g_string_append_printf (res, "(00 00 00 00 00 00 f0 7f)"); /* positive infinity */
893 else if (isnan (val))
894 g_string_append_printf (res, "(00 00 00 00 00 00 f8 ff)"); /* NaN */
896 g_string_append_printf (res, "%g", val);
900 case MONO_TYPE_VALUETYPE:
901 if (mono_class_is_enum (sig->params [i]->data.klass)) {
902 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
905 g_warning ("generic valutype not handled in custom attr value decoding");
908 case MONO_TYPE_CLASS: /* It must be a Type: check? */
909 case MONO_TYPE_STRING:
910 if (*p == (char)0xff) {
911 g_string_append (res, "null");
915 slen = mono_metadata_decode_value (p, &p);
916 g_string_append_c (res, '"');
917 g_string_append (res, p);
918 g_string_append_c (res, '"');
922 g_warning ("Type %02x not handled in custom attr value decoding", sig->params [i]->type);
928 g_string_append_printf (res, " %d named args: (", slen);
929 slen = len - (p - value) + 1;
930 for (i = 0; i < slen; ++i) {
931 g_string_append_printf (res, " %02X", (p [i] & 0xff));
933 g_string_append_c (res, ')');
936 g_string_free (res, FALSE);
941 dump_table_customattr (MonoImage *m)
943 MonoTableInfo *t = &m->tables [MONO_TABLE_CUSTOMATTRIBUTE];
946 fprintf (output, "Custom Attributes Table (1..%d)\n", t->rows);
947 for (i = 1; i <= t->rows; i++) {
949 guint32 cols [MONO_CUSTOM_ATTR_SIZE];
956 mono_metadata_decode_row (t, i - 1, cols, MONO_CUSTOM_ATTR_SIZE);
957 desc = has_cattr_get_table (m, cols [MONO_CUSTOM_ATTR_PARENT]);
958 mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS;
959 switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) {
960 case MONO_CUSTOM_ATTR_TYPE_METHODDEF:
961 mtoken |= MONO_TOKEN_METHOD_DEF;
963 case MONO_CUSTOM_ATTR_TYPE_MEMBERREF:
964 mtoken |= MONO_TOKEN_MEMBER_REF;
967 g_warning ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
970 method = get_method (m, mtoken, NULL);
971 meth = mono_get_method_checked (m, mtoken, NULL, NULL, &error);
973 params = custom_attr_params (m, mono_method_signature (meth), mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE]));
974 fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params);
977 fprintf (output, "Could not decode method due to %s", mono_error_get_message (&error));
978 mono_error_cleanup (&error);
987 dump_table_nestedclass (MonoImage *m)
989 MonoTableInfo *t = &m->tables [MONO_TABLE_NESTEDCLASS];
990 guint32 cols [MONO_NESTED_CLASS_SIZE];
992 char *nested, *nesting;
993 fprintf (output, "NestedClass Table (1..%d)\n", t->rows);
995 for (i = 1; i <= t->rows; i++){
996 mono_metadata_decode_row (t, i - 1, cols, MONO_NESTED_CLASS_SIZE);
997 nested = get_typedef (m, cols [MONO_NESTED_CLASS_NESTED]);
998 nesting = get_typedef (m, cols [MONO_NESTED_CLASS_ENCLOSING]);
999 fprintf (output, "%d: %d %d: %s in %s\n", i,
1000 cols [MONO_NESTED_CLASS_NESTED],
1001 cols [MONO_NESTED_CLASS_ENCLOSING], nested, nesting);
1009 dump_table_exported (MonoImage *m)
1011 MonoTableInfo *t = &m->tables [MONO_TABLE_EXPORTEDTYPE];
1012 guint32 cols [MONO_EXP_TYPE_SIZE];
1014 const char *name, *nspace;
1016 guint32 index, flags;
1017 fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
1019 for (i = 1; i <= t->rows; i++) {
1020 mono_metadata_decode_row (t, i - 1, cols, MONO_EXP_TYPE_SIZE);
1021 name = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAME]);
1022 nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
1023 impl = get_manifest_implementation (m, cols [MONO_EXP_TYPE_IMPLEMENTATION]);
1024 index = cols [MONO_EXP_TYPE_TYPEDEF];
1025 flags = cols [MONO_EXP_TYPE_FLAGS];
1026 fprintf (output, "%d: %s%s%s is in %s, index=%x, flags=0x%x\n", i, nspace, *nspace ? "." : "", name, impl, index, flags);
1033 dump_blob (MonoImage *m, const char* blob)
1037 bsize = mono_metadata_decode_blob_size (blob, &blob);
1039 for (j = 0; j < bsize; j++) {
1040 fprintf (output, "%02x ", blob [j] & 0xff);
1045 dump_table_field_marshal (MonoImage *m)
1047 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDMARSHAL];
1048 guint32 cols [MONO_FIELD_MARSHAL_SIZE];
1049 int i, is_field, idx;
1053 fprintf (output, "FieldMarshal Table (1..%d)\n", t->rows);
1055 for (i = 1; i <= t->rows; i++) {
1056 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_MARSHAL_SIZE);
1057 blob = mono_metadata_blob_heap (m, cols [MONO_FIELD_MARSHAL_NATIVE_TYPE]);
1058 native = get_marshal_info (m, blob);
1059 is_field = (cols [MONO_FIELD_MARSHAL_PARENT] & MONO_HAS_FIELD_MARSHAL_MASK) == MONO_HAS_FIELD_MARSHAL_FIELDSREF;
1060 idx = cols [MONO_FIELD_MARSHAL_PARENT] >> MONO_HAS_FIELD_MARSHAL_BITS;
1061 fprintf (output, "%d: (0x%04x) %s %d: %s\n", i, cols [MONO_FIELD_MARSHAL_PARENT], is_field? "Field" : "Param", idx, native);
1062 fprintf (output, "\tblob encoding: ");
1063 dump_blob (m, blob);
1064 fprintf (output, "\n");
1071 get_security_action (int val) {
1072 static char buf [32];
1075 case SECURITY_ACTION_DEMAND:
1077 case SECURITY_ACTION_ASSERT:
1079 case SECURITY_ACTION_DENY:
1081 case SECURITY_ACTION_PERMITONLY:
1082 return "PermitOnly";
1083 case SECURITY_ACTION_LINKDEMAND:
1084 return "LinkDemand";
1085 case SECURITY_ACTION_INHERITDEMAND:
1086 return "InheritanceDemand";
1087 case SECURITY_ACTION_REQMIN:
1088 return "RequestMinimum";
1089 case SECURITY_ACTION_REQOPT:
1090 return "RequestOptional";
1091 case SECURITY_ACTION_REQREFUSE:
1092 return "RequestRefuse";
1093 /* Special actions (for non CAS permissions) */
1094 case SECURITY_ACTION_NONCASDEMAND:
1095 return "NonCasDemand";
1096 case SECURITY_ACTION_NONCASLINKDEMAND:
1097 return "NonCasLinkDemand";
1098 case SECURITY_ACTION_NONCASINHERITANCE:
1099 return "NonCasInheritance";
1100 /* Fx 2.0 actions (for both CAS and non-CAS permissions) */
1101 case SECURITY_ACTION_LINKDEMANDCHOICE:
1102 return "LinkDemandChoice";
1103 case SECURITY_ACTION_INHERITDEMANDCHOICE:
1104 return "InheritanceDemandChoice";
1105 case SECURITY_ACTION_DEMANDCHOICE:
1106 return "DemandChoice";
1108 g_snprintf (buf, sizeof (buf), "0x%04X", val);
1114 dump_table_declsec (MonoImage *m)
1116 MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
1117 guint32 cols [MONO_DECL_SECURITY_SIZE];
1120 const char *blob, *action;
1121 const char* parent[] = {
1122 "TypeDef", "MethodDef", "Assembly", ""
1125 fprintf (output, "DeclSecurity Table (1..%d)\n", t->rows);
1127 for (i = 1; i <= t->rows; i++) {
1128 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
1129 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
1130 len = mono_metadata_decode_blob_size (blob, &blob);
1131 action = get_security_action (cols [MONO_DECL_SECURITY_ACTION]);
1132 idx = cols [MONO_DECL_SECURITY_PARENT];
1133 fprintf (output, "%d: %s on %s %d%s", i, action, parent [idx & MONO_HAS_DECL_SECURITY_MASK], idx >> MONO_HAS_DECL_SECURITY_BITS, len? ":\n\t":"\n");
1136 if (blob [0] == MONO_DECLSEC_FORMAT_20) {
1137 /* 2.0 declarative security format */
1138 char *declsec = dump_declsec_entry20 (m, blob, "\t");
1139 fprintf (output, "%s", declsec);
1142 /* 1.0 declarative security format - Unicode XML */
1143 for (idx = 0; idx < len; ++idx)
1144 fprintf (output, "%c", blob [idx]);
1146 fprintf (output, "\n");
1151 dump_table_genericpar (MonoImage *m)
1153 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAM];
1154 guint32 cols [MONO_GENERICPARAM_SIZE];
1157 fprintf (output, "GenericParameters (1..%d)\n", t->rows);
1159 for (i = 1; i <= t->rows; i++) {
1161 mono_metadata_decode_row (t, i - 1, cols, MONO_GENERICPARAM_SIZE);
1163 // sig = get_type_or_methdef (m, cols [MONO_GENERICPARAM_OWNER]);
1164 sig = g_strdup_printf ("%x", cols [MONO_GENERICPARAM_OWNER]);
1165 fprintf (output, "%d: %d, flags=%d, owner=%s %s\n", i,
1166 cols [MONO_GENERICPARAM_NUMBER],
1167 cols [MONO_GENERICPARAM_FLAGS], sig,
1168 mono_metadata_string_heap (m, cols [MONO_GENERICPARAM_NAME]));
1174 dump_table_methodspec (MonoImage *m)
1176 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSPEC];
1177 guint32 cols [MONO_METHODSPEC_SIZE];
1180 fprintf (output, "MethodSpec (1..%d)\n", t->rows);
1182 for (i = 1; i <= t->rows; i++) {
1187 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODSPEC_SIZE);
1189 /* build a methodspec token to get the method */
1190 token = MONO_TOKEN_METHOD_SPEC | i;
1191 method = get_method (m, token, NULL);
1193 sig = get_method_type_param (m, cols [MONO_METHODSPEC_SIGNATURE], NULL);
1194 fprintf (output, "%d: %s, %s\n", i, method, sig);
1201 dump_table_parconstraint (MonoImage *m)
1203 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
1204 guint32 cols [MONO_GENPARCONSTRAINT_SIZE];
1207 fprintf (output, "Generic Param Constraint (1..%d)\n", t->rows);
1209 for (i = 1; i <= t->rows; i++) {
1211 mono_metadata_decode_row (t, i - 1, cols, MONO_GENPARCONSTRAINT_SIZE);
1213 // sig = get_typedef_or_ref (m, cols [MONO_GENPARCONSTRAINT_CONSTRAINT], NULL);
1214 sig = g_strdup_printf ("%x", cols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
1215 fprintf (output, "%d: gen-par=%d, Constraint=%s\n", i,
1216 cols [MONO_GENPARCONSTRAINT_GENERICPAR], sig);
1222 dump_stream_blob (MonoImage *m)
1226 fprintf (output, "Blob heap contents\n");
1228 for (i = 0; i < m->heap_blob.size; i++) {
1231 fprintf (output, "\n");
1232 else if ((i % 8) == 0)
1233 fprintf (output, "- ");
1235 fprintf (output, "%02x ", m->heap_blob.data [i] & 0xff);
1238 fprintf (output, "\n");
1242 dump_stream_strings (MonoImage *m)
1246 fprintf (output, "Strings heap contents\n");
1248 for (i = 0; i < m->heap_strings.size; ) {
1249 const char *str = mono_metadata_string_heap (m, i);
1250 fprintf (output, "%02x: \"%s\"\n", i, str);
1251 i += strlen (str) + 1;
1256 dump_stream_us (MonoImage *m)
1260 fprintf (output, "User Strings heap contents\n");
1262 for (i = 0; i < m->heap_us.size; ) {
1263 const char *us_ptr = mono_metadata_user_string (m, i);
1264 int len = mono_metadata_decode_blob_size (us_ptr, (const char**)&us_ptr);
1266 char *str = get_encoded_user_string_or_bytearray ((const guchar*)us_ptr, len);
1267 fprintf (output, "%02x: %s\n", i, str);
1274 dump_table_standalonesig (MonoImage *m)
1276 MonoTableInfo *t = &m->tables [MONO_TABLE_STANDALONESIG];
1277 guint32 cols [MONO_STAND_ALONE_SIGNATURE_SIZE];
1280 fprintf (output, "Stand alone signature (1..%d)\n", t->rows);
1282 for (i = 1; i <= t->rows; i++) {
1283 const char *locals_ptr;
1286 mono_metadata_decode_row (t, i - 1, cols, MONO_STAND_ALONE_SIGNATURE_SIZE);
1288 locals_ptr = mono_metadata_blob_heap (m, cols [MONO_STAND_ALONE_SIGNATURE]);
1289 bsize = mono_metadata_decode_blob_size (locals_ptr, &locals_ptr);
1291 fprintf (output, "%d: blob[0x%x] = ", i, cols [MONO_STAND_ALONE_SIGNATURE]);
1293 for (j = 0; j < bsize; j++) {
1294 fprintf (output, "%02x ", locals_ptr [j] & 0xff);
1296 fprintf (output, "\n");
1301 dump_table_ptr (MonoImage *m, int table, const char *name)
1303 MonoTableInfo *t = &m->tables [table];
1307 fprintf (output, "%s (1..%d)\n", name, t->rows);
1309 for (i = 1; i <= t->rows; i++) {
1310 mono_metadata_decode_row (t, i - 1, cols, 1);
1312 fprintf (output, "%d: %d\n", i, cols [0]);
1317 dump_table_methodptr (MonoImage *m)
1319 dump_table_ptr (m, MONO_TABLE_METHOD_POINTER, "Method Ptr");
1323 dump_table_fieldptr (MonoImage *m)
1325 dump_table_ptr (m, MONO_TABLE_FIELD_POINTER, "Field Ptr");
1329 dump_table_paramptr (MonoImage *m)
1331 dump_table_ptr (m, MONO_TABLE_PARAM_POINTER, "Param Ptr");
1335 dump_table_eventptr (MonoImage *m)
1337 dump_table_ptr (m, MONO_TABLE_EVENT_POINTER, "Event Ptr");
1341 dump_table_propertyptr (MonoImage *m)
1343 dump_table_ptr (m, MONO_TABLE_PROPERTY_POINTER, "Property Ptr");