Reduce TLS accesses. (#11487)
[mono-project.git] / mono / dis / dump.c
blob5bfc80614c6084a95213d3fb5b44b3aff584c3c5
1 /*
2 * dump.c: Dumping routines for the disassembler.
4 * Author:
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc.
8 */
9 #include <config.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <glib.h>
13 #include <math.h>
14 #include "meta.h"
15 #include "util.h"
16 #include "dump.h"
17 #include "get.h"
18 #include "declsec.h"
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"
23 #include "mono/utils/mono-error-internals.h"
24 #include "mono/utils/mono-math.h"
26 void
27 dump_table_assembly (MonoImage *m)
29 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLY];
30 guint32 cols [MONO_ASSEMBLY_SIZE];
31 const char *ptr;
32 int len;
34 fprintf (output, "Assembly Table\n");
36 if (!t->rows)
37 return;
39 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
41 fprintf (output, "Name: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_NAME]));
42 fprintf (output, "Hash Algoritm: 0x%08x\n", cols [MONO_ASSEMBLY_HASH_ALG]);
43 fprintf (output, "Version: %d.%d.%d.%d\n", cols [MONO_ASSEMBLY_MAJOR_VERSION],
44 cols [MONO_ASSEMBLY_MINOR_VERSION],
45 cols [MONO_ASSEMBLY_BUILD_NUMBER],
46 cols [MONO_ASSEMBLY_REV_NUMBER]);
47 fprintf (output, "Flags: 0x%08x\n", cols [MONO_ASSEMBLY_FLAGS]);
48 fprintf (output, "PublicKey: BlobPtr (0x%08x)\n", cols [MONO_ASSEMBLY_PUBLIC_KEY]);
50 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
51 len = mono_metadata_decode_value (ptr, &ptr);
52 if (len > 0){
53 fprintf (output, "\tDump:");
54 hex_dump (ptr, 0, len);
55 fprintf (output, "\n");
56 } else
57 fprintf (output, "\tZero sized public key\n");
59 fprintf (output, "Culture: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_CULTURE]));
60 fprintf (output, "\n");
63 void
64 dump_table_typeref (MonoImage *m)
66 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEREF];
67 int i;
69 fprintf (output, "Typeref Table\n");
71 for (i = 1; i <= t->rows; i++){
72 char *s = get_typeref (m, i);
74 fprintf (output, "%d: %s\n", i, s);
75 g_free (s);
77 fprintf (output, "\n");
80 void
81 dump_table_typedef (MonoImage *m)
83 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
84 int i;
86 fprintf (output, "Typedef Table\n");
88 for (i = 1; i <= t->rows; i++){
89 char *s = get_typedef (m, i);
90 guint32 cols [MONO_TYPEDEF_SIZE];
92 mono_metadata_decode_row (&m->tables [MONO_TABLE_TYPEDEF], i - 1, cols, MONO_TYPEDEF_SIZE);
94 fprintf (output, "%d: %s (flist=%d, mlist=%d, flags=0x%x, extends=0x%x)\n", i, s,
95 cols [MONO_TYPEDEF_FIELD_LIST], cols [MONO_TYPEDEF_METHOD_LIST],
96 cols [MONO_TYPEDEF_FLAGS], cols [MONO_TYPEDEF_EXTENDS]);
97 g_free (s);
99 fprintf (output, "\n");
102 void
103 dump_table_typespec (MonoImage *m)
105 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPESPEC];
106 int i;
108 fprintf (output, "Typespec Table\n");
110 for (i = 1; i <= t->rows; i++){
111 char *typespec = get_typespec (m, i, TRUE, NULL);
113 fprintf (output, "%d: %s\n", i, typespec);
114 g_free (typespec);
116 fprintf (output, "\n");
119 void
120 dump_table_assemblyref (MonoImage *m)
122 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLYREF];
123 int i;
125 fprintf (output, "AssemblyRef Table\n");
127 for (i = 0; i < t->rows; i++){
128 const char *ptr;
129 int len;
130 guint32 cols [MONO_ASSEMBLYREF_SIZE];
132 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
133 fprintf (output, "%d: Version=%d.%d.%d.%d\n\tName=%s\n", i + 1,
134 cols [MONO_ASSEMBLYREF_MAJOR_VERSION],
135 cols [MONO_ASSEMBLYREF_MINOR_VERSION],
136 cols [MONO_ASSEMBLYREF_BUILD_NUMBER],
137 cols [MONO_ASSEMBLYREF_REV_NUMBER],
138 mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_NAME]));
139 fprintf (output, "\tFlags=0x%08x\n", cols [MONO_ASSEMBLYREF_FLAGS]);
140 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
141 len = mono_metadata_decode_value (ptr, &ptr);
142 if (len > 0){
143 fprintf (output, "\tPublic Key:");
144 hex_dump (ptr, 0, len);
145 fprintf (output, "\n");
146 } else
147 fprintf (output, "\tZero sized public key\n");
150 fprintf (output, "\n");
153 void
154 dump_table_param (MonoImage *m)
156 MonoTableInfo *t = &m->tables [MONO_TABLE_PARAM];
157 int i;
159 fprintf (output, "Param Table\n");
161 for (i = 0; i < t->rows; i++){
162 guint32 cols [MONO_PARAM_SIZE];
164 mono_metadata_decode_row (t, i, cols, MONO_PARAM_SIZE);
165 fprintf (output, "%d: 0x%04x %d %s\n",
166 i + 1,
167 cols [MONO_PARAM_FLAGS], cols [MONO_PARAM_SEQUENCE],
168 mono_metadata_string_heap (m, cols [MONO_PARAM_NAME]));
170 fprintf (output, "\n");
173 void
174 dump_table_field (MonoImage *m)
176 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
177 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
178 MonoTableInfo *fl = &m->tables [MONO_TABLE_FIELDLAYOUT];
179 MonoTableInfo *rva = &m->tables [MONO_TABLE_FIELDRVA];
180 int i, current_type, offset_row, rva_row;
181 guint32 first_m, last_m;
183 fprintf (output, "Field Table (1..%d)\n", t->rows);
185 rva_row = offset_row = current_type = 1;
186 last_m = first_m = 1;
187 for (i = 1; i <= t->rows; i++){
188 guint32 cols [MONO_FIELD_SIZE];
189 char *sig, *flags;
192 * Find the next type.
194 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_FIELD_LIST))) {
195 current_type++;
197 if (i == first_m) {
198 fprintf (output, "########## %s.%s\n",
199 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
200 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
201 first_m = last_m;
203 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_SIZE);
204 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE], NULL);
205 flags = field_flags (cols [MONO_FIELD_FLAGS]);
206 fprintf (output, "%d: %s %s: %s\n",
208 sig,
209 mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]),
210 flags);
211 g_free (sig);
212 g_free (flags);
213 if (offset_row <= fl->rows && (mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_FIELD) == i)) {
214 fprintf (output, "\texplicit offset: %d\n", mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_OFFSET));
215 offset_row ++;
217 if (rva_row <= rva->rows && (mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_FIELD) == i)) {
218 fprintf (output, "\trva: %d\n", mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_RVA));
219 rva_row ++;
222 fprintf (output, "\n");
225 void
226 dump_table_memberref (MonoImage *m)
228 MonoTableInfo *t = &m->tables [MONO_TABLE_MEMBERREF];
229 int i, kind, idx;
230 char *x, *xx;
231 char *sig;
232 const char *blob, *ks = NULL;
234 fprintf (output, "MemberRef Table (1..%d)\n", t->rows);
236 for (i = 0; i < t->rows; i++){
237 guint32 cols [MONO_MEMBERREF_SIZE];
239 mono_metadata_decode_row (t, i, cols, MONO_MEMBERREF_SIZE);
241 kind = cols [MONO_MEMBERREF_CLASS] & 7;
242 idx = cols [MONO_MEMBERREF_CLASS] >> 3;
244 x = g_strdup ("UNHANDLED CASE");
246 switch (kind){
247 case 0:
248 ks = "TypeDef";
249 xx = get_typedef (m, idx);
250 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
251 g_free (xx);
252 break;
253 case 1:
254 ks = "TypeRef";
255 xx = get_typeref (m, idx);
256 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
257 g_free (xx);
258 break;
259 case 2:
260 ks = "ModuleRef"; break;
261 case 3:
262 ks = "MethodDef";
263 x = get_methoddef (m, idx);
264 break;
265 case 4:
266 ks = "TypeSpec";
267 xx = get_typespec (m, idx, FALSE, NULL);
268 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
269 g_free (xx);
270 break;
271 default:
272 g_error ("Unknown tag: %d\n", kind);
274 blob = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
275 mono_metadata_decode_blob_size (blob, &blob);
276 if (*blob == 0x6) { /* it's a field */
277 sig = get_field_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
278 } else {
279 sig = get_methodref_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
281 fprintf (output, "%d: %s[%d] %s\n\tResolved: %s\n\tSignature: %s\n\t\n",
282 i + 1,
283 ks, idx,
284 mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]),
285 x ? x : "",
286 sig);
288 g_free (x);
289 g_free (sig);
293 void
294 dump_table_class_layout (MonoImage *m)
296 MonoTableInfo *t = &m->tables [MONO_TABLE_CLASSLAYOUT];
297 int i;
298 fprintf (output, "ClassLayout Table (1..%d)\n", t->rows);
300 for (i = 0; i < t->rows; i++){
301 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
303 mono_metadata_decode_row (t, i, cols, MONO_CLASS_LAYOUT_SIZE);
305 fprintf (output, "%d: PackingSize=%d ClassSize=%d Parent=%s\n",
306 i + 1, cols [MONO_CLASS_LAYOUT_PACKING_SIZE],
307 cols [MONO_CLASS_LAYOUT_CLASS_SIZE],
308 get_typedef (m, cols [MONO_CLASS_LAYOUT_PARENT]));
312 void
313 dump_table_constant (MonoImage *m)
315 MonoTableInfo *t = &m->tables [MONO_TABLE_CONSTANT];
316 int i;
317 const char *desc [] = {
318 "Field",
319 "Param",
320 "Property",
323 fprintf (output, "Constant Table (1..%d)\n", t->rows);
325 for (i = 0; i < t->rows; i++){
326 guint32 cols [MONO_CONSTANT_SIZE];
327 const char *parent;
328 mono_metadata_decode_row (t, i, cols, MONO_CONSTANT_SIZE);
329 parent = desc [cols [MONO_CONSTANT_PARENT] & MONO_HASCONSTANT_MASK];
331 fprintf (output, "%d: Parent= %s: %d %s\n",
332 i + 1, parent, cols [MONO_CONSTANT_PARENT] >> MONO_HASCONSTANT_BITS,
333 get_constant (m, (MonoTypeEnum) cols [MONO_CONSTANT_TYPE], cols [MONO_CONSTANT_VALUE]));
338 void
339 dump_table_property_map (MonoImage *m)
341 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTYMAP];
342 int i;
343 char *s;
345 fprintf (output, "Property Map Table (1..%d)\n", t->rows);
347 for (i = 0; i < t->rows; i++){
348 guint32 cols [MONO_PROPERTY_MAP_SIZE];
350 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_MAP_SIZE);
351 s = get_typedef (m, cols [MONO_PROPERTY_MAP_PARENT]);
352 fprintf (output, "%d: %s (%d) %d\n", i + 1, s, cols [MONO_PROPERTY_MAP_PARENT], cols [MONO_PROPERTY_MAP_PROPERTY_LIST]);
353 g_free (s);
357 void
358 dump_table_property (MonoImage *m)
360 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTY];
361 int i, j, pcount;
362 const char *ptr;
363 char flags[128];
365 fprintf (output, "Property Table (1..%d)\n", t->rows);
367 for (i = 0; i < t->rows; i++){
368 guint32 cols [MONO_PROPERTY_SIZE];
369 char *type;
370 int prop_flags;
372 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_SIZE);
373 flags [0] = 0;
374 prop_flags = cols [MONO_PROPERTY_FLAGS];
375 if (prop_flags & 0x0200)
376 strcat (flags, "special ");
377 if (prop_flags & 0x0400)
378 strcat (flags, "runtime ");
379 if (prop_flags & 0x1000)
380 strcat (flags, "hasdefault ");
382 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
383 /* bsize = */ mono_metadata_decode_blob_size (ptr, &ptr);
384 /* ECMA claims 0x08 ... */
385 if (*ptr != 0x28 && *ptr != 0x08)
386 g_warning("incorrect signature in propert blob: 0x%x", *ptr);
387 ptr++;
388 pcount = mono_metadata_decode_value (ptr, &ptr);
389 ptr = get_type (m, ptr, &type, FALSE, NULL);
390 fprintf (output, "%d: %s %s (",
391 i + 1, type, mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]));
392 g_free (type);
394 for (j = 0; j < pcount; j++){
395 ptr = get_param (m, ptr, &type, NULL);
396 fprintf (output, "%s%s", j > 0? ", " : "",type);
397 g_free (type);
399 fprintf (output, ") %s\n", flags);
403 void
404 dump_table_event (MonoImage *m)
406 MonoTableInfo *t = &m->tables [MONO_TABLE_EVENT];
407 int i;
408 fprintf (output, "Event Table (1..%d)\n", t->rows);
410 for (i = 0; i < t->rows; i++){
411 guint32 cols [MONO_EVENT_SIZE];
412 const char *name;
413 char *type;
415 mono_metadata_decode_row (t, i, cols, MONO_EVENT_SIZE);
417 name = mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]);
418 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE], NULL);
419 fprintf (output, "%d: %s %s %s\n", i + 1, type, name,
420 cols [MONO_EVENT_FLAGS] & 0x200 ? "specialname " : "");
421 g_free (type);
426 void
427 dump_table_file (MonoImage *m)
429 MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
430 int i, j, len;
431 fprintf (output, "File Table (1..%d)\n", t->rows);
433 for (i = 0; i < t->rows; i++){
434 guint32 cols [MONO_FILE_SIZE];
435 const char *name, *hash;
437 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
439 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
440 fprintf (output, "%d: %s %s [", i + 1, name,
441 cols [MONO_FILE_FLAGS] & 0x1 ? "nometadata" : "containsmetadata");
442 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
443 len = mono_metadata_decode_blob_size (hash, &hash);
444 for (j = 0; j < len; ++j)
445 fprintf (output, "%s%02X", j? " ": "", hash [j] & 0xff);
446 fprintf (output, "]\n");
451 static char*
452 get_manifest_implementation (MonoImage *m, guint32 idx)
454 guint32 row;
455 const char* table = "";
456 if (!idx)
457 return g_strdup ("current module");
458 row = idx >> MONO_IMPLEMENTATION_BITS;
459 switch (idx & MONO_IMPLEMENTATION_MASK) {
460 case MONO_IMPLEMENTATION_FILE:
461 table = "file";
462 break;
463 case MONO_IMPLEMENTATION_ASSEMBLYREF:
464 table = "assemblyref";
465 break;
466 case MONO_IMPLEMENTATION_EXP_TYPE:
467 table = "exportedtype";
468 break;
469 default:
470 g_assert_not_reached ();
472 return g_strdup_printf ("%s %d", table, row);
475 static const char*
476 get_manifest_flags (guint32 mf)
478 mf &= 3;
479 switch (mf) {
480 case 1: return "public";
481 case 2: return "private";
482 default:
483 return "";
487 void
488 dump_table_manifest (MonoImage *m)
490 MonoTableInfo *t = &m->tables [MONO_TABLE_MANIFESTRESOURCE];
491 int i;
492 fprintf (output, "Manifestresource Table (1..%d)\n", t->rows);
494 for (i = 0; i < t->rows; i++){
495 guint32 cols [MONO_MANIFEST_SIZE];
496 const char *name, *mf;
497 char *impl;
499 mono_metadata_decode_row (t, i, cols, MONO_MANIFEST_SIZE);
501 name = mono_metadata_string_heap (m, cols [MONO_MANIFEST_NAME]);
502 mf = get_manifest_flags (cols [MONO_MANIFEST_FLAGS]);
503 impl = get_manifest_implementation (m, cols [MONO_MANIFEST_IMPLEMENTATION]);
504 fprintf (output, "%d: %s '%s' at offset %u in %s\n", i + 1, mf, name, cols [MONO_MANIFEST_OFFSET], impl);
505 g_free (impl);
510 void
511 dump_table_moduleref (MonoImage *m)
513 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
514 int i;
515 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
517 for (i = 0; i < t->rows; i++){
518 guint32 cols [MONO_MODULEREF_SIZE];
519 const char *name;
521 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
523 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
524 fprintf (output, "%d: %s\n", i + 1, name);
529 void
530 dump_table_module (MonoImage *m)
532 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
533 int i;
534 fprintf (output, "Module Table (1..%d)\n", t->rows);
536 for (i = 0; i < t->rows; i++){
537 guint32 cols [MONO_MODULE_SIZE];
538 const char *name;
539 char *guid;
541 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
543 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
544 guid = get_guid (m, cols [MONO_MODULE_MVID]);
545 fprintf (output, "%d: %s %d %s\n", i + 1, name, cols [MONO_MODULE_MVID], guid);
549 void
550 dump_table_method (MonoImage *m)
552 MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
553 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
554 int i, current_type;
555 guint32 first_m, last_m;
556 /* Generic container for Type & method */
557 MonoGenericContainer *type_container = NULL, *method_container = NULL;
559 fprintf (output, "Method Table (1..%d)\n", t->rows);
561 current_type = 1;
562 last_m = first_m = 1;
563 for (i = 1; i <= t->rows; i++){
564 ERROR_DECL (error);
565 guint32 cols [MONO_METHOD_SIZE];
566 char *sig, *impl_flags;
567 const char *sigblob;
568 MonoMethodSignature *method;
571 * Find the next type.
573 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_METHOD_LIST))) {
574 current_type++;
576 if (i == first_m) {
577 fprintf (output, "########## %s.%s\n",
578 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
579 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
580 first_m = last_m;
581 type_container = mono_metadata_load_generic_params (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), NULL, NULL);
582 if (type_container) {
583 mono_metadata_load_generic_param_constraints_checked (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), type_container, error);
584 g_assert (mono_error_ok (error)); /*FIXME don't swallow the error message*/
588 method_container = mono_metadata_load_generic_params (m, MONO_TOKEN_METHOD_DEF | i, type_container, NULL);
589 if (method_container) {
590 mono_metadata_load_generic_param_constraints_checked (m, MONO_TOKEN_METHOD_DEF | i, method_container, error);
591 g_assert (mono_error_ok (error)); /*FIXME don't swallow the error message*/
593 mono_metadata_decode_table_row (m, MONO_TABLE_METHOD, i - 1, cols, MONO_METHOD_SIZE);
594 sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
595 mono_metadata_decode_blob_size (sigblob, &sigblob);
596 method = mono_metadata_parse_method_signature_full (m, method_container ? method_container : type_container, i, sigblob, &sigblob, error);
597 if (!mono_error_ok (error)) {
598 fprintf (output,"%d: failed to parse due to %s\n", i, mono_error_get_message (error));
599 mono_error_cleanup (error);
600 continue;
603 g_assert (mono_error_ok (error)); /*FIXME don't swallow the error message*/
604 sig = dis_stringify_method_signature (m, method, i, method_container ? method_container : type_container, FALSE);
605 impl_flags = get_method_impl_flags (cols [MONO_METHOD_IMPLFLAGS]);
606 fprintf (output, "%d: %s (param: %d impl_flags: %s)\n", i, sig, cols [MONO_METHOD_PARAMLIST], impl_flags);
607 g_free (sig);
608 g_free (impl_flags);
609 mono_metadata_free_method_signature (method);
614 void
615 dump_table_implmap (MonoImage *m)
617 MonoTableInfo *t = &m->tables [MONO_TABLE_IMPLMAP];
618 MonoTableInfo *td = &m->tables [MONO_TABLE_MODULEREF];
619 int i;
621 fprintf (output, "ImplMap Table (1..%d)\n", t->rows);
623 for (i = 1; i <= t->rows; i++){
624 guint32 cols [MONO_IMPLMAP_SIZE];
625 char *method;
627 mono_metadata_decode_row (t, i - 1, cols, MONO_IMPLMAP_SIZE);
629 method = get_method (m, MONO_TOKEN_METHOD_DEF | (cols [MONO_IMPLMAP_MEMBER] >> MONO_MEMBERFORWD_BITS), NULL);
631 fprintf (output, "%d: %s %d (%s %s)\n", i,
632 method,
633 cols [MONO_IMPLMAP_FLAGS],
634 mono_metadata_string_heap (m, cols [MONO_IMPLMAP_NAME]),
635 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME)));
639 void
640 dump_table_fieldrva (MonoImage *m)
642 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDRVA];
643 int i;
645 fprintf (output, "FieldRVA Table (1..%d)\n", t->rows);
647 for (i = 1; i <= t->rows; i++){
648 guint32 cols [MONO_FIELD_RVA_SIZE];
650 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_RVA_SIZE);
651 fprintf (output, "%d: Field %d: %x\n", i, cols [MONO_FIELD_RVA_FIELD], cols [MONO_FIELD_RVA_RVA]);
655 void
656 dump_table_methodimpl (MonoImage *m)
658 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODIMPL];
659 /*MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];*/
660 int i;
662 fprintf (output, "MethodImpl Table (1..%d)\n", t->rows);
664 for (i = 1; i <= t->rows; i++){
665 guint32 cols [MONO_METHODIMPL_SIZE];
666 char *klass, *impl, *decl;
668 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODIMPL_SIZE);
669 klass = get_typedef (m, cols [MONO_METHODIMPL_CLASS]);
670 impl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_BODY]), NULL);
671 decl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_DECLARATION]), NULL);
672 fprintf (output, "%d: %s\n\tdecl: %s\n\timpl: %s\n", i, klass, decl, impl);
673 g_free (klass);
674 g_free (impl);
675 g_free (decl);
680 static dis_map_t semantics_map [] = {
681 {1, "setter"},
682 {2, "getter"},
683 {4, "other"},
684 {8, "add-on"},
685 {0x10, "remove-on"},
686 {0x20, "fire"},
687 {0, NULL},
690 void
691 dump_table_methodsem (MonoImage *m)
693 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSEMANTICS];
694 int i, is_property, index;
695 const char *semantics;
697 fprintf (output, "Method Semantics Table (1..%d)\n", t->rows);
698 for (i = 1; i <= t->rows; i++){
699 guint32 cols [MONO_METHOD_SEMA_SIZE];
701 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SEMA_SIZE);
702 semantics = flags (cols [MONO_METHOD_SEMA_SEMANTICS], semantics_map);
703 is_property = cols [MONO_METHOD_SEMA_ASSOCIATION] & MONO_HAS_SEMANTICS_MASK;
704 index = cols [MONO_METHOD_SEMA_ASSOCIATION] >> MONO_HAS_SEMANTICS_BITS;
705 fprintf (output, "%d: [%d] %s method: %d %s %d\n", i, cols [MONO_METHOD_SEMA_ASSOCIATION], semantics,
706 cols [MONO_METHOD_SEMA_METHOD] - 1,
707 is_property? "property" : "event",
708 index);
712 void
713 dump_table_interfaceimpl (MonoImage *m)
715 MonoTableInfo *t = &m->tables [MONO_TABLE_INTERFACEIMPL];
716 int i;
718 fprintf (output, "Interface Implementation Table (1..%d)\n", t->rows);
719 for (i = 1; i <= t->rows; i++) {
720 guint32 cols [MONO_INTERFACEIMPL_SIZE];
722 mono_metadata_decode_row (t, i - 1, cols, MONO_INTERFACEIMPL_SIZE);
723 fprintf (output, "%d: %s implements %s\n", i,
724 get_typedef (m, cols [MONO_INTERFACEIMPL_CLASS]),
725 get_typedef_or_ref (m, cols [MONO_INTERFACEIMPL_INTERFACE], NULL));
729 static char*
730 has_cattr_get_table (MonoImage *m, guint32 val)
732 guint32 t = val & MONO_CUSTOM_ATTR_MASK;
733 guint32 index = val >> MONO_CUSTOM_ATTR_BITS;
734 const char *table;
736 switch (t) {
737 case MONO_CUSTOM_ATTR_METHODDEF:
738 table = "MethodDef";
739 break;
740 case MONO_CUSTOM_ATTR_FIELDDEF:
741 table = "FieldDef";
742 break;
743 case MONO_CUSTOM_ATTR_TYPEREF:
744 table = "TypeRef";
745 break;
746 case MONO_CUSTOM_ATTR_TYPEDEF:
747 table = "TypeDef";
748 break;
749 case MONO_CUSTOM_ATTR_PARAMDEF:
750 table = "Param";
751 break;
752 case MONO_CUSTOM_ATTR_INTERFACE:
753 table = "InterfaceImpl";
754 break;
755 case MONO_CUSTOM_ATTR_MEMBERREF:
756 table = "MemberRef";
757 break;
758 case MONO_CUSTOM_ATTR_MODULE:
759 table = "Module";
760 break;
761 case MONO_CUSTOM_ATTR_PERMISSION:
762 table = "DeclSecurity?";
763 break;
764 case MONO_CUSTOM_ATTR_PROPERTY:
765 table = "Property";
766 break;
767 case MONO_CUSTOM_ATTR_EVENT:
768 table = "Event";
769 break;
770 case MONO_CUSTOM_ATTR_SIGNATURE:
771 table = "StandAloneSignature";
772 break;
773 case MONO_CUSTOM_ATTR_MODULEREF:
774 table = "ModuleRef";
775 break;
776 case MONO_CUSTOM_ATTR_TYPESPEC:
777 table = "TypeSpec";
778 break;
779 case MONO_CUSTOM_ATTR_ASSEMBLY:
780 table = "Assembly";
781 break;
782 case MONO_CUSTOM_ATTR_ASSEMBLYREF:
783 table = "AssemblyRef";
784 break;
785 case MONO_CUSTOM_ATTR_FILE:
786 table = "File";
787 break;
788 case MONO_CUSTOM_ATTR_EXP_TYPE:
789 table = "ExportedType";
790 break;
791 case MONO_CUSTOM_ATTR_MANIFEST:
792 table = "Manifest";
793 break;
794 case MONO_CUSTOM_ATTR_GENERICPAR:
795 table = "GenericParam";
796 break;
797 default:
798 table = "Unknown";
799 break;
802 * FIXME: we should decode the index into something more uman-friendly.
804 return g_strdup_printf ("%s: %d", table, index);
807 static char*
808 custom_attr_params (MonoImage *m, MonoMethodSignature* sig, const char* value)
810 int len, i, slen, type;
811 GString *res;
812 char *s;
813 const char *p = value;
815 len = mono_metadata_decode_value (p, &p);
816 if (len < 2 || read16 (p) != 0x0001) /* Prolog */
817 return g_strdup ("");
819 /* skip prolog */
820 p += 2;
821 res = g_string_new ("");
822 for (i = 0; i < sig->param_count; ++i) {
823 if (i != 0)
824 g_string_append (res, ", ");
825 type = sig->params [i]->type;
826 handle_enum:
827 switch (type) {
828 case MONO_TYPE_U1:
829 g_string_append_printf (res, "%d", (unsigned int)*p);
830 ++p;
831 break;
832 case MONO_TYPE_I1:
833 g_string_append_printf (res, "%d", *p);
834 ++p;
835 break;
836 case MONO_TYPE_BOOLEAN:
837 g_string_append_printf (res, "%s", *p?"true":"false");
838 ++p;
839 break;
840 case MONO_TYPE_CHAR:
841 g_string_append_printf (res, "'%c'", read16 (p));
842 p += 2;
843 break;
844 case MONO_TYPE_U2:
845 g_string_append_printf (res, "%d", read16 (p));
846 p += 2;
847 break;
848 case MONO_TYPE_I2:
849 g_string_append_printf (res, "%d", (gint16)read16 (p));
850 p += 2;
851 break;
852 case MONO_TYPE_U4:
853 g_string_append_printf (res, "%d", read32 (p));
854 p += 4;
855 break;
856 case MONO_TYPE_I4:
857 g_string_append_printf (res, "%d", (gint32)read32 (p));
858 p += 4;
859 break;
860 case MONO_TYPE_U8:
861 g_string_append_printf (res, "%lld", (long long)read64 (p));
862 p += 8;
863 break;
864 case MONO_TYPE_I8:
865 g_string_append_printf (res, "%lld", (long long)read64 (p));
866 p += 8;
867 break;
868 case MONO_TYPE_R4: {
869 float val;
870 readr4 (p, &val);
871 const int inf = mono_isinf (val);
872 if (inf == -1)
873 g_string_append_printf (res, "(00 00 80 ff)"); /* negative infinity */
874 else if (inf == 1)
875 g_string_append_printf (res, "(00 00 80 7f)"); /* positive infinity */
876 else if (mono_isnan (val))
877 g_string_append_printf (res, "(00 00 c0 ff)"); /* NaN */
878 else
879 g_string_append_printf (res, "%g", val);
880 p += 4;
881 break;
883 case MONO_TYPE_R8: {
884 double val;
885 readr8 (p, &val);
886 const int inf = mono_isinf (val);
887 if (inf == -1)
888 g_string_append_printf (res, "(00 00 00 00 00 00 f0 ff)"); /* negative infinity */
889 else if (inf == 1)
890 g_string_append_printf (res, "(00 00 00 00 00 00 f0 7f)"); /* positive infinity */
891 else if (mono_isnan (val))
892 g_string_append_printf (res, "(00 00 00 00 00 00 f8 ff)"); /* NaN */
893 else
894 g_string_append_printf (res, "%g", val);
895 p += 8;
896 break;
898 case MONO_TYPE_VALUETYPE:
899 if (m_class_is_enumtype (sig->params [i]->data.klass)) {
900 type = mono_class_enum_basetype_internal (sig->params [i]->data.klass)->type;
901 goto handle_enum;
902 } else {
903 g_warning ("generic valutype not handled in custom attr value decoding");
905 break;
906 case MONO_TYPE_CLASS: /* It must be a Type: check? */
907 case MONO_TYPE_STRING:
908 if (*p == (char)0xff) {
909 g_string_append (res, "null");
910 p++;
911 break;
913 slen = mono_metadata_decode_value (p, &p);
914 g_string_append_c (res, '"');
915 g_string_append (res, p);
916 g_string_append_c (res, '"');
917 p += slen;
918 break;
919 default:
920 g_warning ("Type %02x not handled in custom attr value decoding", sig->params [i]->type);
921 break;
924 slen = read16 (p);
925 if (slen) {
926 g_string_append_printf (res, " %d named args: (", slen);
927 slen = len - (p - value) + 1;
928 for (i = 0; i < slen; ++i) {
929 g_string_append_printf (res, " %02X", (p [i] & 0xff));
931 g_string_append_c (res, ')');
933 s = res->str;
934 g_string_free (res, FALSE);
935 return s;
938 void
939 dump_table_customattr (MonoImage *m)
941 MonoTableInfo *t = &m->tables [MONO_TABLE_CUSTOMATTRIBUTE];
942 int i;
944 fprintf (output, "Custom Attributes Table (1..%d)\n", t->rows);
945 for (i = 1; i <= t->rows; i++) {
946 ERROR_DECL (error);
947 guint32 cols [MONO_CUSTOM_ATTR_SIZE];
948 guint32 mtoken;
949 char * desc;
950 char *method;
951 char *params;
952 MonoMethod *meth;
954 mono_metadata_decode_row (t, i - 1, cols, MONO_CUSTOM_ATTR_SIZE);
955 desc = has_cattr_get_table (m, cols [MONO_CUSTOM_ATTR_PARENT]);
956 mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS;
957 switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) {
958 case MONO_CUSTOM_ATTR_TYPE_METHODDEF:
959 mtoken |= MONO_TOKEN_METHOD_DEF;
960 break;
961 case MONO_CUSTOM_ATTR_TYPE_MEMBERREF:
962 mtoken |= MONO_TOKEN_MEMBER_REF;
963 break;
964 default:
965 g_warning ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
966 break;
968 method = get_method (m, mtoken, NULL);
969 meth = mono_get_method_checked (m, mtoken, NULL, NULL, error);
970 if (meth) {
971 params = custom_attr_params (m, mono_method_signature_internal (meth), mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE]));
972 fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params);
973 g_free (params);
974 } else {
975 fprintf (output, "Could not decode method due to %s", mono_error_get_message (error));
976 mono_error_cleanup (error);
979 g_free (desc);
980 g_free (method);
984 void
985 dump_table_nestedclass (MonoImage *m)
987 MonoTableInfo *t = &m->tables [MONO_TABLE_NESTEDCLASS];
988 guint32 cols [MONO_NESTED_CLASS_SIZE];
989 int i;
990 char *nested, *nesting;
991 fprintf (output, "NestedClass Table (1..%d)\n", t->rows);
993 for (i = 1; i <= t->rows; i++){
994 mono_metadata_decode_row (t, i - 1, cols, MONO_NESTED_CLASS_SIZE);
995 nested = get_typedef (m, cols [MONO_NESTED_CLASS_NESTED]);
996 nesting = get_typedef (m, cols [MONO_NESTED_CLASS_ENCLOSING]);
997 fprintf (output, "%d: %d %d: %s in %s\n", i,
998 cols [MONO_NESTED_CLASS_NESTED],
999 cols [MONO_NESTED_CLASS_ENCLOSING], nested, nesting);
1000 g_free (nested);
1001 g_free (nesting);
1006 void
1007 dump_table_exported (MonoImage *m)
1009 MonoTableInfo *t = &m->tables [MONO_TABLE_EXPORTEDTYPE];
1010 guint32 cols [MONO_EXP_TYPE_SIZE];
1011 int i;
1012 const char *name, *nspace;
1013 char *impl;
1014 guint32 index, flags;
1015 fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
1017 for (i = 1; i <= t->rows; i++) {
1018 mono_metadata_decode_row (t, i - 1, cols, MONO_EXP_TYPE_SIZE);
1019 name = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAME]);
1020 nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
1021 impl = get_manifest_implementation (m, cols [MONO_EXP_TYPE_IMPLEMENTATION]);
1022 index = cols [MONO_EXP_TYPE_TYPEDEF];
1023 flags = cols [MONO_EXP_TYPE_FLAGS];
1024 fprintf (output, "%d: %s%s%s is in %s, index=%x, flags=0x%x\n", i, nspace, *nspace ? "." : "", name, impl, index, flags);
1025 g_free (impl);
1030 static void
1031 dump_blob (MonoImage *m, const char* blob)
1033 int j, bsize;
1035 bsize = mono_metadata_decode_blob_size (blob, &blob);
1037 for (j = 0; j < bsize; j++) {
1038 fprintf (output, "%02x ", blob [j] & 0xff);
1042 void
1043 dump_table_field_marshal (MonoImage *m)
1045 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDMARSHAL];
1046 guint32 cols [MONO_FIELD_MARSHAL_SIZE];
1047 int i, is_field, idx;
1048 const char *blob;
1049 char *native;
1051 fprintf (output, "FieldMarshal Table (1..%d)\n", t->rows);
1053 for (i = 1; i <= t->rows; i++) {
1054 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_MARSHAL_SIZE);
1055 blob = mono_metadata_blob_heap (m, cols [MONO_FIELD_MARSHAL_NATIVE_TYPE]);
1056 native = get_marshal_info (m, blob);
1057 is_field = (cols [MONO_FIELD_MARSHAL_PARENT] & MONO_HAS_FIELD_MARSHAL_MASK) == MONO_HAS_FIELD_MARSHAL_FIELDSREF;
1058 idx = cols [MONO_FIELD_MARSHAL_PARENT] >> MONO_HAS_FIELD_MARSHAL_BITS;
1059 fprintf (output, "%d: (0x%04x) %s %d: %s\n", i, cols [MONO_FIELD_MARSHAL_PARENT], is_field? "Field" : "Param", idx, native);
1060 fprintf (output, "\tblob encoding: ");
1061 dump_blob (m, blob);
1062 fprintf (output, "\n");
1063 g_free (native);
1068 static const char*
1069 get_security_action (int val) {
1070 static char buf [32];
1072 switch (val) {
1073 case SECURITY_ACTION_DEMAND:
1074 return "Demand";
1075 case SECURITY_ACTION_ASSERT:
1076 return "Assert";
1077 case SECURITY_ACTION_DENY:
1078 return "Deny";
1079 case SECURITY_ACTION_PERMITONLY:
1080 return "PermitOnly";
1081 case SECURITY_ACTION_LINKDEMAND:
1082 return "LinkDemand";
1083 case SECURITY_ACTION_INHERITDEMAND:
1084 return "InheritanceDemand";
1085 case SECURITY_ACTION_REQMIN:
1086 return "RequestMinimum";
1087 case SECURITY_ACTION_REQOPT:
1088 return "RequestOptional";
1089 case SECURITY_ACTION_REQREFUSE:
1090 return "RequestRefuse";
1091 /* Special actions (for non CAS permissions) */
1092 case SECURITY_ACTION_NONCASDEMAND:
1093 return "NonCasDemand";
1094 case SECURITY_ACTION_NONCASLINKDEMAND:
1095 return "NonCasLinkDemand";
1096 case SECURITY_ACTION_NONCASINHERITANCE:
1097 return "NonCasInheritance";
1098 /* Fx 2.0 actions (for both CAS and non-CAS permissions) */
1099 case SECURITY_ACTION_LINKDEMANDCHOICE:
1100 return "LinkDemandChoice";
1101 case SECURITY_ACTION_INHERITDEMANDCHOICE:
1102 return "InheritanceDemandChoice";
1103 case SECURITY_ACTION_DEMANDCHOICE:
1104 return "DemandChoice";
1105 default:
1106 g_snprintf (buf, sizeof (buf), "0x%04X", val);
1107 return buf;
1111 void
1112 dump_table_declsec (MonoImage *m)
1114 MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
1115 guint32 cols [MONO_DECL_SECURITY_SIZE];
1116 int i, len;
1117 guint32 idx;
1118 const char *blob, *action;
1119 const char* parent[] = {
1120 "TypeDef", "MethodDef", "Assembly", ""
1123 fprintf (output, "DeclSecurity Table (1..%d)\n", t->rows);
1125 for (i = 1; i <= t->rows; i++) {
1126 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
1127 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
1128 len = mono_metadata_decode_blob_size (blob, &blob);
1129 action = get_security_action (cols [MONO_DECL_SECURITY_ACTION]);
1130 idx = cols [MONO_DECL_SECURITY_PARENT];
1131 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");
1132 if (!len)
1133 continue;
1134 if (blob [0] == MONO_DECLSEC_FORMAT_20) {
1135 /* 2.0 declarative security format */
1136 char *declsec = dump_declsec_entry20 (m, blob, "\t");
1137 fprintf (output, "%s", declsec);
1138 g_free (declsec);
1139 } else {
1140 /* 1.0 declarative security format - Unicode XML */
1141 for (idx = 0; idx < len; ++idx)
1142 fprintf (output, "%c", blob [idx]);
1144 fprintf (output, "\n");
1148 void
1149 dump_table_genericpar (MonoImage *m)
1151 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAM];
1152 guint32 cols [MONO_GENERICPARAM_SIZE];
1153 int i;
1155 fprintf (output, "GenericParameters (1..%d)\n", t->rows);
1157 for (i = 1; i <= t->rows; i++) {
1158 char *sig;
1159 mono_metadata_decode_row (t, i - 1, cols, MONO_GENERICPARAM_SIZE);
1161 // sig = get_type_or_methdef (m, cols [MONO_GENERICPARAM_OWNER]);
1162 sig = g_strdup_printf ("%x", cols [MONO_GENERICPARAM_OWNER]);
1163 fprintf (output, "%d: %d, flags=%d, owner=%s %s\n", i,
1164 cols [MONO_GENERICPARAM_NUMBER],
1165 cols [MONO_GENERICPARAM_FLAGS], sig,
1166 mono_metadata_string_heap (m, cols [MONO_GENERICPARAM_NAME]));
1167 g_free (sig);
1171 void
1172 dump_table_methodspec (MonoImage *m)
1174 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSPEC];
1175 guint32 cols [MONO_METHODSPEC_SIZE];
1176 int i;
1178 fprintf (output, "MethodSpec (1..%d)\n", t->rows);
1180 for (i = 1; i <= t->rows; i++) {
1181 char *sig;
1182 char *method;
1183 guint32 token;
1185 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODSPEC_SIZE);
1187 /* build a methodspec token to get the method */
1188 token = MONO_TOKEN_METHOD_SPEC | i;
1189 method = get_method (m, token, NULL);
1191 sig = get_method_type_param (m, cols [MONO_METHODSPEC_SIGNATURE], NULL);
1192 fprintf (output, "%d: %s, %s\n", i, method, sig);
1193 g_free (sig);
1194 g_free (method);
1198 void
1199 dump_table_parconstraint (MonoImage *m)
1201 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
1202 guint32 cols [MONO_GENPARCONSTRAINT_SIZE];
1203 int i;
1205 fprintf (output, "Generic Param Constraint (1..%d)\n", t->rows);
1207 for (i = 1; i <= t->rows; i++) {
1208 char *sig;
1209 mono_metadata_decode_row (t, i - 1, cols, MONO_GENPARCONSTRAINT_SIZE);
1211 // sig = get_typedef_or_ref (m, cols [MONO_GENPARCONSTRAINT_CONSTRAINT], NULL);
1212 sig = g_strdup_printf ("%x", cols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
1213 fprintf (output, "%d: gen-par=%d, Constraint=%s\n", i,
1214 cols [MONO_GENPARCONSTRAINT_GENERICPAR], sig);
1215 g_free (sig);
1219 void
1220 dump_stream_blob (MonoImage *m)
1222 int i;
1224 fprintf (output, "Blob heap contents\n");
1226 for (i = 0; i < m->heap_blob.size; i++) {
1227 if (i > 0) {
1228 if ((i % 16) == 0)
1229 fprintf (output, "\n");
1230 else if ((i % 8) == 0)
1231 fprintf (output, "- ");
1233 fprintf (output, "%02x ", m->heap_blob.data [i] & 0xff);
1236 fprintf (output, "\n");
1239 void
1240 dump_stream_strings (MonoImage *m)
1242 guint32 i;
1244 fprintf (output, "Strings heap contents\n");
1246 for (i = 0; i < m->heap_strings.size; ) {
1247 const char *str = mono_metadata_string_heap (m, i);
1248 fprintf (output, "%02x: \"%s\"\n", i, str);
1249 i += strlen (str) + 1;
1253 void
1254 dump_stream_us (MonoImage *m)
1256 guint32 i;
1258 fprintf (output, "User Strings heap contents\n");
1260 for (i = 0; i < m->heap_us.size; ) {
1261 const char *us_ptr = mono_metadata_user_string (m, i);
1262 int len = mono_metadata_decode_blob_size (us_ptr, (const char**)&us_ptr);
1264 char *str = get_encoded_user_string_or_bytearray ((const guchar*)us_ptr, len);
1265 fprintf (output, "%02x: %s\n", i, str);
1266 g_free (str);
1267 i += len + 1;
1271 void
1272 dump_table_standalonesig (MonoImage *m)
1274 MonoTableInfo *t = &m->tables [MONO_TABLE_STANDALONESIG];
1275 guint32 cols [MONO_STAND_ALONE_SIGNATURE_SIZE];
1276 int i;
1278 fprintf (output, "Stand alone signature (1..%d)\n", t->rows);
1280 for (i = 1; i <= t->rows; i++) {
1281 const char *locals_ptr;
1282 int j, bsize;
1284 mono_metadata_decode_row (t, i - 1, cols, MONO_STAND_ALONE_SIGNATURE_SIZE);
1286 locals_ptr = mono_metadata_blob_heap (m, cols [MONO_STAND_ALONE_SIGNATURE]);
1287 bsize = mono_metadata_decode_blob_size (locals_ptr, &locals_ptr);
1289 fprintf (output, "%d: blob[0x%x] = ", i, cols [MONO_STAND_ALONE_SIGNATURE]);
1291 for (j = 0; j < bsize; j++) {
1292 fprintf (output, "%02x ", locals_ptr [j] & 0xff);
1294 fprintf (output, "\n");
1298 static void
1299 dump_table_ptr (MonoImage *m, int table, const char *name)
1301 MonoTableInfo *t = &m->tables [table];
1302 guint32 cols [1];
1303 int i;
1305 fprintf (output, "%s (1..%d)\n", name, t->rows);
1307 for (i = 1; i <= t->rows; i++) {
1308 mono_metadata_decode_row (t, i - 1, cols, 1);
1310 fprintf (output, "%d: %d\n", i, cols [0]);
1314 void
1315 dump_table_methodptr (MonoImage *m)
1317 dump_table_ptr (m, MONO_TABLE_METHOD_POINTER, "Method Ptr");
1320 void
1321 dump_table_fieldptr (MonoImage *m)
1323 dump_table_ptr (m, MONO_TABLE_FIELD_POINTER, "Field Ptr");
1326 void
1327 dump_table_paramptr (MonoImage *m)
1329 dump_table_ptr (m, MONO_TABLE_PARAM_POINTER, "Param Ptr");
1332 void
1333 dump_table_eventptr (MonoImage *m)
1335 dump_table_ptr (m, MONO_TABLE_EVENT_POINTER, "Event Ptr");
1338 void
1339 dump_table_propertyptr (MonoImage *m)
1341 dump_table_ptr (m, MONO_TABLE_PROPERTY_POINTER, "Property Ptr");