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"
24 #if defined(__native_client__) && defined(__GLIBC__)
25 volatile int __nacl_thread_suspension_needed = 0;
26 void __nacl_suspend_thread_if_needed() {}
30 dump_table_assembly (MonoImage *m)
32 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLY];
33 guint32 cols [MONO_ASSEMBLY_SIZE];
37 fprintf (output, "Assembly Table\n");
42 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
44 fprintf (output, "Name: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_NAME]));
45 fprintf (output, "Hash Algoritm: 0x%08x\n", cols [MONO_ASSEMBLY_HASH_ALG]);
46 fprintf (output, "Version: %d.%d.%d.%d\n", cols [MONO_ASSEMBLY_MAJOR_VERSION],
47 cols [MONO_ASSEMBLY_MINOR_VERSION],
48 cols [MONO_ASSEMBLY_BUILD_NUMBER],
49 cols [MONO_ASSEMBLY_REV_NUMBER]);
50 fprintf (output, "Flags: 0x%08x\n", cols [MONO_ASSEMBLY_FLAGS]);
51 fprintf (output, "PublicKey: BlobPtr (0x%08x)\n", cols [MONO_ASSEMBLY_PUBLIC_KEY]);
53 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
54 len = mono_metadata_decode_value (ptr, &ptr);
56 fprintf (output, "\tDump:");
57 hex_dump (ptr, 0, len);
58 fprintf (output, "\n");
60 fprintf (output, "\tZero sized public key\n");
62 fprintf (output, "Culture: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_CULTURE]));
63 fprintf (output, "\n");
67 dump_table_typeref (MonoImage *m)
69 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEREF];
72 fprintf (output, "Typeref Table\n");
74 for (i = 1; i <= t->rows; i++){
75 char *s = get_typeref (m, i);
77 fprintf (output, "%d: %s\n", i, s);
80 fprintf (output, "\n");
84 dump_table_typedef (MonoImage *m)
86 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
89 fprintf (output, "Typedef Table\n");
91 for (i = 1; i <= t->rows; i++){
92 char *s = get_typedef (m, i);
93 guint32 cols [MONO_TYPEDEF_SIZE];
95 mono_metadata_decode_row (&m->tables [MONO_TABLE_TYPEDEF], i - 1, cols, MONO_TYPEDEF_SIZE);
97 fprintf (output, "%d: %s (flist=%d, mlist=%d, flags=0x%x, extends=0x%x)\n", i, s,
98 cols [MONO_TYPEDEF_FIELD_LIST], cols [MONO_TYPEDEF_METHOD_LIST],
99 cols [MONO_TYPEDEF_FLAGS], cols [MONO_TYPEDEF_EXTENDS]);
102 fprintf (output, "\n");
106 dump_table_typespec (MonoImage *m)
108 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPESPEC];
111 fprintf (output, "Typespec Table\n");
113 for (i = 1; i <= t->rows; i++){
114 char *typespec = get_typespec (m, i, TRUE, NULL);
116 fprintf (output, "%d: %s\n", i, typespec);
119 fprintf (output, "\n");
123 dump_table_assemblyref (MonoImage *m)
125 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLYREF];
128 fprintf (output, "AssemblyRef Table\n");
130 for (i = 0; i < t->rows; i++){
133 guint32 cols [MONO_ASSEMBLYREF_SIZE];
135 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
136 fprintf (output, "%d: Version=%d.%d.%d.%d\n\tName=%s\n", i + 1,
137 cols [MONO_ASSEMBLYREF_MAJOR_VERSION],
138 cols [MONO_ASSEMBLYREF_MINOR_VERSION],
139 cols [MONO_ASSEMBLYREF_BUILD_NUMBER],
140 cols [MONO_ASSEMBLYREF_REV_NUMBER],
141 mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_NAME]));
142 fprintf (output, "\tFlags=0x%08x\n", cols [MONO_ASSEMBLYREF_FLAGS]);
143 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
144 len = mono_metadata_decode_value (ptr, &ptr);
146 fprintf (output, "\tPublic Key:");
147 hex_dump (ptr, 0, len);
148 fprintf (output, "\n");
150 fprintf (output, "\tZero sized public key\n");
153 fprintf (output, "\n");
157 dump_table_param (MonoImage *m)
159 MonoTableInfo *t = &m->tables [MONO_TABLE_PARAM];
162 fprintf (output, "Param Table\n");
164 for (i = 0; i < t->rows; i++){
165 guint32 cols [MONO_PARAM_SIZE];
167 mono_metadata_decode_row (t, i, cols, MONO_PARAM_SIZE);
168 fprintf (output, "%d: 0x%04x %d %s\n",
170 cols [MONO_PARAM_FLAGS], cols [MONO_PARAM_SEQUENCE],
171 mono_metadata_string_heap (m, cols [MONO_PARAM_NAME]));
173 fprintf (output, "\n");
177 dump_table_field (MonoImage *m)
179 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
180 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
181 MonoTableInfo *fl = &m->tables [MONO_TABLE_FIELDLAYOUT];
182 MonoTableInfo *rva = &m->tables [MONO_TABLE_FIELDRVA];
183 int i, current_type, offset_row, rva_row;
184 guint32 first_m, last_m;
186 fprintf (output, "Field Table (1..%d)\n", t->rows);
188 rva_row = offset_row = current_type = 1;
189 last_m = first_m = 1;
190 for (i = 1; i <= t->rows; i++){
191 guint32 cols [MONO_FIELD_SIZE];
195 * Find the next type.
197 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_FIELD_LIST))) {
201 fprintf (output, "########## %s.%s\n",
202 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
203 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
206 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_SIZE);
207 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE], NULL);
208 flags = field_flags (cols [MONO_FIELD_FLAGS]);
209 fprintf (output, "%d: %s %s: %s\n",
212 mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]),
216 if (offset_row <= fl->rows && (mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_FIELD) == i)) {
217 fprintf (output, "\texplicit offset: %d\n", mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_OFFSET));
220 if (rva_row <= rva->rows && (mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_FIELD) == i)) {
221 fprintf (output, "\trva: %d\n", mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_RVA));
225 fprintf (output, "\n");
229 dump_table_memberref (MonoImage *m)
231 MonoTableInfo *t = &m->tables [MONO_TABLE_MEMBERREF];
235 const char *blob, *ks = NULL;
237 fprintf (output, "MemberRef Table (1..%d)\n", t->rows);
239 for (i = 0; i < t->rows; i++){
240 guint32 cols [MONO_MEMBERREF_SIZE];
242 mono_metadata_decode_row (t, i, cols, MONO_MEMBERREF_SIZE);
244 kind = cols [MONO_MEMBERREF_CLASS] & 7;
245 idx = cols [MONO_MEMBERREF_CLASS] >> 3;
247 x = g_strdup ("UNHANDLED CASE");
252 xx = get_typedef (m, idx);
253 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
258 xx = get_typeref (m, idx);
259 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
263 ks = "ModuleRef"; break;
266 x = get_methoddef (m, idx);
270 xx = get_typespec (m, idx, FALSE, NULL);
271 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
275 g_error ("Unknown tag: %d\n", kind);
277 blob = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
278 mono_metadata_decode_blob_size (blob, &blob);
279 if (*blob == 0x6) { /* it's a field */
280 sig = get_field_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
282 sig = get_methodref_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
284 fprintf (output, "%d: %s[%d] %s\n\tResolved: %s\n\tSignature: %s\n\t\n",
287 mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]),
298 dump_table_class_layout (MonoImage *m)
300 MonoTableInfo *t = &m->tables [MONO_TABLE_CLASSLAYOUT];
302 fprintf (output, "ClassLayout Table (1..%d)\n", t->rows);
304 for (i = 0; i < t->rows; i++){
305 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
307 mono_metadata_decode_row (t, i, cols, MONO_CLASS_LAYOUT_SIZE);
309 fprintf (output, "%d: PackingSize=%d ClassSize=%d Parent=%s\n",
310 i + 1, cols [MONO_CLASS_LAYOUT_PACKING_SIZE],
311 cols [MONO_CLASS_LAYOUT_CLASS_SIZE],
312 get_typedef (m, cols [MONO_CLASS_LAYOUT_PARENT]));
317 dump_table_constant (MonoImage *m)
319 MonoTableInfo *t = &m->tables [MONO_TABLE_CONSTANT];
321 const char *desc [] = {
327 fprintf (output, "Constant Table (1..%d)\n", t->rows);
329 for (i = 0; i < t->rows; i++){
330 guint32 cols [MONO_CONSTANT_SIZE];
332 mono_metadata_decode_row (t, i, cols, MONO_CONSTANT_SIZE);
333 parent = desc [cols [MONO_CONSTANT_PARENT] & MONO_HASCONSTANT_MASK];
335 fprintf (output, "%d: Parent= %s: %d %s\n",
336 i + 1, parent, cols [MONO_CONSTANT_PARENT] >> MONO_HASCONSTANT_BITS,
337 get_constant (m, (MonoTypeEnum) cols [MONO_CONSTANT_TYPE], cols [MONO_CONSTANT_VALUE]));
343 dump_table_property_map (MonoImage *m)
345 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTYMAP];
349 fprintf (output, "Property Map Table (1..%d)\n", t->rows);
351 for (i = 0; i < t->rows; i++){
352 guint32 cols [MONO_PROPERTY_MAP_SIZE];
354 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_MAP_SIZE);
355 s = get_typedef (m, cols [MONO_PROPERTY_MAP_PARENT]);
356 fprintf (output, "%d: %s (%d) %d\n", i + 1, s, cols [MONO_PROPERTY_MAP_PARENT], cols [MONO_PROPERTY_MAP_PROPERTY_LIST]);
362 dump_table_property (MonoImage *m)
364 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTY];
369 fprintf (output, "Property Table (1..%d)\n", t->rows);
371 for (i = 0; i < t->rows; i++){
372 guint32 cols [MONO_PROPERTY_SIZE];
377 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_SIZE);
379 prop_flags = cols [MONO_PROPERTY_FLAGS];
380 if (prop_flags & 0x0200)
381 strcat (flags, "special ");
382 if (prop_flags & 0x0400)
383 strcat (flags, "runtime ");
384 if (prop_flags & 0x1000)
385 strcat (flags, "hasdefault ");
387 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
388 bsize = mono_metadata_decode_blob_size (ptr, &ptr);
389 /* ECMA claims 0x08 ... */
390 if (*ptr != 0x28 && *ptr != 0x08)
391 g_warning("incorrect signature in propert blob: 0x%x", *ptr);
393 pcount = mono_metadata_decode_value (ptr, &ptr);
394 ptr = get_type (m, ptr, &type, FALSE, NULL);
395 fprintf (output, "%d: %s %s (",
396 i + 1, type, mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]));
399 for (j = 0; j < pcount; j++){
400 ptr = get_param (m, ptr, &type, NULL);
401 fprintf (output, "%s%s", j > 0? ", " : "",type);
404 fprintf (output, ") %s\n", flags);
409 dump_table_event (MonoImage *m)
411 MonoTableInfo *t = &m->tables [MONO_TABLE_EVENT];
413 fprintf (output, "Event Table (1..%d)\n", t->rows);
415 for (i = 0; i < t->rows; i++){
416 guint32 cols [MONO_EVENT_SIZE];
420 mono_metadata_decode_row (t, i, cols, MONO_EVENT_SIZE);
422 name = mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]);
423 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE], NULL);
424 fprintf (output, "%d: %s %s %s\n", i + 1, type, name,
425 cols [MONO_EVENT_FLAGS] & 0x200 ? "specialname " : "");
432 dump_table_file (MonoImage *m)
434 MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
436 fprintf (output, "File Table (1..%d)\n", t->rows);
438 for (i = 0; i < t->rows; i++){
439 guint32 cols [MONO_FILE_SIZE];
440 const char *name, *hash;
442 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
444 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
445 fprintf (output, "%d: %s %s [", i + 1, name,
446 cols [MONO_FILE_FLAGS] & 0x1 ? "nometadata" : "containsmetadata");
447 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
448 len = mono_metadata_decode_blob_size (hash, &hash);
449 for (j = 0; j < len; ++j)
450 fprintf (output, "%s%02X", j? " ": "", hash [j] & 0xff);
451 fprintf (output, "]\n");
457 get_manifest_implementation (MonoImage *m, guint32 idx)
460 const char* table = "";
462 return g_strdup ("current module");
463 row = idx >> MONO_IMPLEMENTATION_BITS;
464 switch (idx & MONO_IMPLEMENTATION_MASK) {
465 case MONO_IMPLEMENTATION_FILE:
468 case MONO_IMPLEMENTATION_ASSEMBLYREF:
469 table = "assemblyref";
471 case MONO_IMPLEMENTATION_EXP_TYPE:
472 table = "exportedtype";
475 g_assert_not_reached ();
477 return g_strdup_printf ("%s %d", table, row);
481 get_manifest_flags (guint32 mf)
485 case 1: return "public";
486 case 2: return "private";
493 dump_table_manifest (MonoImage *m)
495 MonoTableInfo *t = &m->tables [MONO_TABLE_MANIFESTRESOURCE];
497 fprintf (output, "Manifestresource Table (1..%d)\n", t->rows);
499 for (i = 0; i < t->rows; i++){
500 guint32 cols [MONO_MANIFEST_SIZE];
501 const char *name, *mf;
504 mono_metadata_decode_row (t, i, cols, MONO_MANIFEST_SIZE);
506 name = mono_metadata_string_heap (m, cols [MONO_MANIFEST_NAME]);
507 mf = get_manifest_flags (cols [MONO_MANIFEST_FLAGS]);
508 impl = get_manifest_implementation (m, cols [MONO_MANIFEST_IMPLEMENTATION]);
509 fprintf (output, "%d: %s '%s' at offset %u in %s\n", i + 1, mf, name, cols [MONO_MANIFEST_OFFSET], impl);
516 dump_table_moduleref (MonoImage *m)
518 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
520 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
522 for (i = 0; i < t->rows; i++){
523 guint32 cols [MONO_MODULEREF_SIZE];
526 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
528 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
529 fprintf (output, "%d: %s\n", i + 1, name);
535 dump_table_module (MonoImage *m)
537 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
539 fprintf (output, "Module Table (1..%d)\n", t->rows);
541 for (i = 0; i < t->rows; i++){
542 guint32 cols [MONO_MODULE_SIZE];
546 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
548 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
549 guid = get_guid (m, cols [MONO_MODULE_MVID]);
550 fprintf (output, "%d: %s %d %s\n", i + 1, name, cols [MONO_MODULE_MVID], guid);
555 dump_table_method (MonoImage *m)
557 MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
558 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
560 guint32 first_m, last_m;
561 /* Generic container for Type & method */
562 MonoGenericContainer *type_container = NULL, *method_container = NULL;
564 fprintf (output, "Method Table (1..%d)\n", t->rows);
567 last_m = first_m = 1;
568 for (i = 1; i <= t->rows; i++){
570 guint32 cols [MONO_METHOD_SIZE];
571 char *sig, *impl_flags;
573 MonoMethodSignature *method;
576 * Find the next type.
578 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_METHOD_LIST))) {
582 fprintf (output, "########## %s.%s\n",
583 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
584 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
586 type_container = mono_metadata_load_generic_params (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), NULL);
587 if (type_container) {
588 mono_metadata_load_generic_param_constraints_checked (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), type_container, &error);
589 g_assert (mono_error_ok (&error)); /*FIXME don't swallow the error message*/
593 method_container = mono_metadata_load_generic_params (m, MONO_TOKEN_METHOD_DEF | i, type_container);
594 if (method_container) {
595 mono_metadata_load_generic_param_constraints_checked (m, MONO_TOKEN_METHOD_DEF | i, method_container, &error);
596 g_assert (mono_error_ok (&error)); /*FIXME don't swallow the error message*/
598 mono_metadata_decode_table_row (m, MONO_TABLE_METHOD, i - 1, cols, MONO_METHOD_SIZE);
599 sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
600 mono_metadata_decode_blob_size (sigblob, &sigblob);
601 method = mono_metadata_parse_method_signature_full (m, method_container ? method_container : type_container, i, sigblob, &sigblob, &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 *class, *impl, *decl;
667 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODIMPL_SIZE);
668 class = 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, class, 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++) {
948 guint32 cols [MONO_CUSTOM_ATTR_SIZE];
955 mono_metadata_decode_row (t, i - 1, cols, MONO_CUSTOM_ATTR_SIZE);
956 desc = has_cattr_get_table (m, cols [MONO_CUSTOM_ATTR_PARENT]);
957 mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS;
958 switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) {
959 case MONO_CUSTOM_ATTR_TYPE_METHODDEF:
960 mtoken |= MONO_TOKEN_METHOD_DEF;
962 case MONO_CUSTOM_ATTR_TYPE_MEMBERREF:
963 mtoken |= MONO_TOKEN_MEMBER_REF;
966 g_warning ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
969 method = get_method (m, mtoken, NULL);
970 meth = mono_get_method (m, mtoken, NULL);
971 params = custom_attr_params (m, mono_method_signature (meth), mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE]));
972 fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params);
980 dump_table_nestedclass (MonoImage *m)
982 MonoTableInfo *t = &m->tables [MONO_TABLE_NESTEDCLASS];
983 guint32 cols [MONO_NESTED_CLASS_SIZE];
985 char *nested, *nesting;
986 fprintf (output, "NestedClass Table (1..%d)\n", t->rows);
988 for (i = 1; i <= t->rows; i++){
989 mono_metadata_decode_row (t, i - 1, cols, MONO_NESTED_CLASS_SIZE);
990 nested = get_typedef (m, cols [MONO_NESTED_CLASS_NESTED]);
991 nesting = get_typedef (m, cols [MONO_NESTED_CLASS_ENCLOSING]);
992 fprintf (output, "%d: %d %d: %s in %s\n", i,
993 cols [MONO_NESTED_CLASS_NESTED],
994 cols [MONO_NESTED_CLASS_ENCLOSING], nested, nesting);
1002 dump_table_exported (MonoImage *m)
1004 MonoTableInfo *t = &m->tables [MONO_TABLE_EXPORTEDTYPE];
1005 guint32 cols [MONO_EXP_TYPE_SIZE];
1007 const char *name, *nspace;
1009 guint32 index, flags;
1010 fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
1012 for (i = 1; i <= t->rows; i++) {
1013 mono_metadata_decode_row (t, i - 1, cols, MONO_EXP_TYPE_SIZE);
1014 name = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAME]);
1015 nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
1016 impl = get_manifest_implementation (m, cols [MONO_EXP_TYPE_IMPLEMENTATION]);
1017 index = cols [MONO_EXP_TYPE_TYPEDEF];
1018 flags = cols [MONO_EXP_TYPE_FLAGS];
1019 fprintf (output, "%d: %s%s%s is in %s, index=%x, flags=0x%x\n", i, nspace, *nspace ? "." : "", name, impl, index, flags);
1026 dump_blob (MonoImage *m, const char* blob)
1030 bsize = mono_metadata_decode_blob_size (blob, &blob);
1032 for (j = 0; j < bsize; j++) {
1033 fprintf (output, "%02x ", blob [j] & 0xff);
1038 dump_table_field_marshal (MonoImage *m)
1040 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDMARSHAL];
1041 guint32 cols [MONO_FIELD_MARSHAL_SIZE];
1042 int i, is_field, idx;
1046 fprintf (output, "FieldMarshal Table (1..%d)\n", t->rows);
1048 for (i = 1; i <= t->rows; i++) {
1049 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_MARSHAL_SIZE);
1050 blob = mono_metadata_blob_heap (m, cols [MONO_FIELD_MARSHAL_NATIVE_TYPE]);
1051 native = get_marshal_info (m, blob);
1052 is_field = (cols [MONO_FIELD_MARSHAL_PARENT] & MONO_HAS_FIELD_MARSHAL_MASK) == MONO_HAS_FIELD_MARSHAL_FIELDSREF;
1053 idx = cols [MONO_FIELD_MARSHAL_PARENT] >> MONO_HAS_FIELD_MARSHAL_BITS;
1054 fprintf (output, "%d: (0x%04x) %s %d: %s\n", i, cols [MONO_FIELD_MARSHAL_PARENT], is_field? "Field" : "Param", idx, native);
1055 fprintf (output, "\tblob encoding: ");
1056 dump_blob (m, blob);
1057 fprintf (output, "\n");
1064 get_security_action (int val) {
1065 static char buf [32];
1068 case SECURITY_ACTION_DEMAND:
1070 case SECURITY_ACTION_ASSERT:
1072 case SECURITY_ACTION_DENY:
1074 case SECURITY_ACTION_PERMITONLY:
1075 return "PermitOnly";
1076 case SECURITY_ACTION_LINKDEMAND:
1077 return "LinkDemand";
1078 case SECURITY_ACTION_INHERITDEMAND:
1079 return "InheritanceDemand";
1080 case SECURITY_ACTION_REQMIN:
1081 return "RequestMinimum";
1082 case SECURITY_ACTION_REQOPT:
1083 return "RequestOptional";
1084 case SECURITY_ACTION_REQREFUSE:
1085 return "RequestRefuse";
1086 /* Special actions (for non CAS permissions) */
1087 case SECURITY_ACTION_NONCASDEMAND:
1088 return "NonCasDemand";
1089 case SECURITY_ACTION_NONCASLINKDEMAND:
1090 return "NonCasLinkDemand";
1091 case SECURITY_ACTION_NONCASINHERITANCE:
1092 return "NonCasInheritance";
1093 /* Fx 2.0 actions (for both CAS and non-CAS permissions) */
1094 case SECURITY_ACTION_LINKDEMANDCHOICE:
1095 return "LinkDemandChoice";
1096 case SECURITY_ACTION_INHERITDEMANDCHOICE:
1097 return "InheritanceDemandChoice";
1098 case SECURITY_ACTION_DEMANDCHOICE:
1099 return "DemandChoice";
1101 g_snprintf (buf, sizeof (buf), "0x%04X", val);
1107 dump_table_declsec (MonoImage *m)
1109 MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
1110 guint32 cols [MONO_DECL_SECURITY_SIZE];
1113 const char *blob, *action;
1114 const char* parent[] = {
1115 "TypeDef", "MethodDef", "Assembly", ""
1118 fprintf (output, "DeclSecurity Table (1..%d)\n", t->rows);
1120 for (i = 1; i <= t->rows; i++) {
1121 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
1122 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
1123 len = mono_metadata_decode_blob_size (blob, &blob);
1124 action = get_security_action (cols [MONO_DECL_SECURITY_ACTION]);
1125 idx = cols [MONO_DECL_SECURITY_PARENT];
1126 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");
1129 if (blob [0] == MONO_DECLSEC_FORMAT_20) {
1130 /* 2.0 declarative security format */
1131 char *declsec = dump_declsec_entry20 (m, blob, "\t");
1132 fprintf (output, "%s", declsec);
1135 /* 1.0 declarative security format - Unicode XML */
1136 for (idx = 0; idx < len; ++idx)
1137 fprintf (output, "%c", blob [idx]);
1139 fprintf (output, "\n");
1144 dump_table_genericpar (MonoImage *m)
1146 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAM];
1147 guint32 cols [MONO_GENERICPARAM_SIZE];
1150 fprintf (output, "GenericParameters (1..%d)\n", t->rows);
1152 for (i = 1; i <= t->rows; i++) {
1154 mono_metadata_decode_row (t, i - 1, cols, MONO_GENERICPARAM_SIZE);
1156 // sig = get_type_or_methdef (m, cols [MONO_GENERICPARAM_OWNER]);
1157 sig = g_strdup_printf ("%x", cols [MONO_GENERICPARAM_OWNER]);
1158 fprintf (output, "%d: %d, flags=%d, owner=%s %s\n", i,
1159 cols [MONO_GENERICPARAM_NUMBER],
1160 cols [MONO_GENERICPARAM_FLAGS], sig,
1161 mono_metadata_string_heap (m, cols [MONO_GENERICPARAM_NAME]));
1167 dump_table_methodspec (MonoImage *m)
1169 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSPEC];
1170 guint32 cols [MONO_METHODSPEC_SIZE];
1173 fprintf (output, "MethodSpec (1..%d)\n", t->rows);
1175 for (i = 1; i <= t->rows; i++) {
1180 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODSPEC_SIZE);
1182 /* build a methodspec token to get the method */
1183 token = MONO_TOKEN_METHOD_SPEC | i;
1184 method = get_method (m, token, NULL);
1186 sig = get_method_type_param (m, cols [MONO_METHODSPEC_SIGNATURE], NULL);
1187 fprintf (output, "%d: %s, %s\n", i, method, sig);
1194 dump_table_parconstraint (MonoImage *m)
1196 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
1197 guint32 cols [MONO_GENPARCONSTRAINT_SIZE];
1200 fprintf (output, "Generic Param Constraint (1..%d)\n", t->rows);
1202 for (i = 1; i <= t->rows; i++) {
1204 mono_metadata_decode_row (t, i - 1, cols, MONO_GENPARCONSTRAINT_SIZE);
1206 // sig = get_typedef_or_ref (m, cols [MONO_GENPARCONSTRAINT_CONSTRAINT], NULL);
1207 sig = g_strdup_printf ("%x", cols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
1208 fprintf (output, "%d: gen-par=%d, Constraint=%s\n", i,
1209 cols [MONO_GENPARCONSTRAINT_GENERICPAR], sig);
1215 dump_stream_blob (MonoImage *m)
1219 fprintf (output, "Blob heap contents\n");
1221 for (i = 0; i < m->heap_blob.size; i++) {
1224 fprintf (output, "\n");
1225 else if ((i % 8) == 0)
1226 fprintf (output, "- ");
1228 fprintf (output, "%02x ", m->heap_blob.data [i] & 0xff);
1231 fprintf (output, "\n");
1235 dump_stream_strings (MonoImage *m)
1239 fprintf (output, "Strings heap contents\n");
1241 for (i = 0; i < m->heap_strings.size; ) {
1242 const char *str = mono_metadata_string_heap (m, i);
1243 fprintf (output, "%02x: \"%s\"\n", i, str);
1244 i += strlen (str) + 1;
1249 dump_stream_us (MonoImage *m)
1253 fprintf (output, "User Strings heap contents\n");
1255 for (i = 0; i < m->heap_us.size; ) {
1256 const char *us_ptr = mono_metadata_user_string (m, i);
1257 int len = mono_metadata_decode_blob_size (us_ptr, (const char**)&us_ptr);
1259 char *str = get_encoded_user_string_or_bytearray ((const guchar*)us_ptr, len);
1260 fprintf (output, "%02x: %s\n", i, str);
1267 dump_table_standalonesig (MonoImage *m)
1269 MonoTableInfo *t = &m->tables [MONO_TABLE_STANDALONESIG];
1270 guint32 cols [MONO_STAND_ALONE_SIGNATURE_SIZE];
1273 fprintf (output, "Stand alone signature (1..%d)\n", t->rows);
1275 for (i = 1; i <= t->rows; i++) {
1276 const char *locals_ptr;
1279 mono_metadata_decode_row (t, i - 1, cols, MONO_STAND_ALONE_SIGNATURE_SIZE);
1281 locals_ptr = mono_metadata_blob_heap (m, cols [MONO_STAND_ALONE_SIGNATURE]);
1282 bsize = mono_metadata_decode_blob_size (locals_ptr, &locals_ptr);
1284 fprintf (output, "%d: blob[0x%x] = ", i, cols [MONO_STAND_ALONE_SIGNATURE]);
1286 for (j = 0; j < bsize; j++) {
1287 fprintf (output, "%02x ", locals_ptr [j] & 0xff);
1289 fprintf (output, "\n");
1294 dump_table_ptr (MonoImage *m, int table, const char *name)
1296 MonoTableInfo *t = &m->tables [table];
1300 fprintf (output, "%s (1..%d)\n", name, t->rows);
1302 for (i = 1; i <= t->rows; i++) {
1303 mono_metadata_decode_row (t, i - 1, cols, 1);
1305 fprintf (output, "%d: %d\n", i, cols [0]);
1310 dump_table_methodptr (MonoImage *m)
1312 dump_table_ptr (m, MONO_TABLE_METHOD_POINTER, "Method Ptr");
1316 dump_table_fieldptr (MonoImage *m)
1318 dump_table_ptr (m, MONO_TABLE_FIELD_POINTER, "Field Ptr");
1322 dump_table_paramptr (MonoImage *m)
1324 dump_table_ptr (m, MONO_TABLE_PARAM_POINTER, "Param Ptr");
1328 dump_table_eventptr (MonoImage *m)
1330 dump_table_ptr (m, MONO_TABLE_EVENT_POINTER, "Event Ptr");
1334 dump_table_propertyptr (MonoImage *m)
1336 dump_table_ptr (m, MONO_TABLE_PROPERTY_POINTER, "Property Ptr");