a3ed4480ff08f9fb6d9812ff2ee77404664ef0b0
[mono.git] / mono / dis / dump.c
1 /*
2  * dump.c: Dumping routines for the disassembler.
3  *
4  * Author:
5  *   Miguel de Icaza (miguel@ximian.com)
6  *
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 "mono/metadata/loader.h"
19 #include "mono/metadata/class.h"
20 #include "mono/utils/mono-compiler.h"
21
22 #ifdef HAVE_IEEEFP_H
23 extern int isinf (double);
24 #endif
25
26 void
27 dump_table_assembly (MonoImage *m)
28 {
29         MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLY];
30         guint32 cols [MONO_ASSEMBLY_SIZE];
31         const char *ptr;
32         int len;
33
34         fprintf (output, "Assembly Table\n");
35
36         if (!t->rows)
37                 return;
38
39         mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
40
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]);
49
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");
58         
59         fprintf (output, "Culture:       %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_CULTURE]));
60         fprintf (output, "\n");
61 }
62
63 void
64 dump_table_typeref (MonoImage *m)
65 {
66         MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEREF];
67         int i;
68
69         fprintf (output, "Typeref Table\n");
70         
71         for (i = 1; i <= t->rows; i++){
72                 char *s = get_typeref (m, i);
73                 
74                 fprintf (output, "%d: %s\n", i, s);
75                 g_free (s);
76         }
77         fprintf (output, "\n");
78 }
79
80 void
81 dump_table_typedef (MonoImage *m)
82 {
83         MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
84         int i;
85
86         fprintf (output, "Typedef Table\n");
87         
88         for (i = 1; i <= t->rows; i++){
89                 char *s = get_typedef (m, i);
90                 guint32 cols [MONO_TYPEDEF_SIZE];
91
92                 mono_metadata_decode_row (&m->tables [MONO_TABLE_TYPEDEF], i - 1, cols, MONO_TYPEDEF_SIZE);
93
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);
98         }
99         fprintf (output, "\n");
100 }
101
102 void
103 dump_table_typespec (MonoImage *m)
104 {
105         MonoTableInfo *t = &m->tables [MONO_TABLE_TYPESPEC];
106         int i;
107
108         fprintf (output, "Typespec Table\n");
109         
110         for (i = 1; i <= t->rows; i++){         
111                 char *typespec = get_typespec (m, i, TRUE, NULL);
112
113                 fprintf (output, "%d: %s\n", i, typespec);
114                 g_free (typespec);
115         }
116         fprintf (output, "\n");
117 }
118
119 void
120 dump_table_assemblyref (MonoImage *m)
121 {
122         MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLYREF];
123         int i;
124
125         fprintf (output, "AssemblyRef Table\n");
126         
127         for (i = 0; i < t->rows; i++){
128                 const char *ptr;
129                 int len;
130                 guint32 cols [MONO_ASSEMBLYREF_SIZE];
131
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                 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
140                 len = mono_metadata_decode_value (ptr, &ptr);
141                 if (len > 0){
142                         fprintf (output, "\tPublic Key:");
143                         hex_dump (ptr, 0, len);
144                         fprintf (output, "\n");
145                 } else
146                         fprintf (output, "\tZero sized public key\n");
147                 
148         }
149         fprintf (output, "\n");
150 }
151
152 void
153 dump_table_param (MonoImage *m)
154 {
155         MonoTableInfo *t = &m->tables [MONO_TABLE_PARAM];
156         int i;
157
158         fprintf (output, "Param Table\n");
159         
160         for (i = 0; i < t->rows; i++){
161                 guint32 cols [MONO_PARAM_SIZE];
162
163                 mono_metadata_decode_row (t, i, cols, MONO_PARAM_SIZE);
164                 fprintf (output, "%d: 0x%04x %d %s\n",
165                          i + 1,
166                          cols [MONO_PARAM_FLAGS], cols [MONO_PARAM_SEQUENCE], 
167                          mono_metadata_string_heap (m, cols [MONO_PARAM_NAME]));
168         }
169         fprintf (output, "\n");
170 }
171
172 void
173 dump_table_field (MonoImage *m)
174 {
175         MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
176         MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
177         MonoTableInfo *fl = &m->tables [MONO_TABLE_FIELDLAYOUT];
178         MonoTableInfo *rva = &m->tables [MONO_TABLE_FIELDRVA];
179         int i, current_type, offset_row, rva_row;
180         guint32 first_m, last_m;
181
182         fprintf (output, "Field Table (1..%d)\n", t->rows);
183         
184         rva_row = offset_row = current_type = 1;
185         last_m = first_m = 1;
186         for (i = 1; i <= t->rows; i++){
187                 guint32 cols [MONO_FIELD_SIZE];
188                 char *sig, *flags;
189
190                 /*
191                  * Find the next type.
192                  */
193                 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_FIELD_LIST))) {
194                         current_type++;
195                 }
196                 if (i == first_m) {
197                         fprintf (output, "########## %s.%s\n",
198                                 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
199                                 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
200                         first_m = last_m;
201                 }
202                 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_SIZE);
203                 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE], NULL);
204                 flags = field_flags (cols [MONO_FIELD_FLAGS]);
205                 fprintf (output, "%d: %s %s: %s\n",
206                          i,
207                          sig,
208                          mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]),
209                          flags);
210                 g_free (sig);
211                 g_free (flags);
212                 if (offset_row <= fl->rows && (mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_FIELD) == i)) {
213                         fprintf (output, "\texplicit offset: %d\n", mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_OFFSET));
214                         offset_row ++;
215                 }
216                 if (rva_row <= rva->rows && (mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_FIELD) == i)) {
217                         fprintf (output, "\trva: %d\n", mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_RVA));
218                         rva_row ++;
219                 }
220         }
221         fprintf (output, "\n");
222 }
223
224 void
225 dump_table_memberref (MonoImage *m)
226 {
227         MonoTableInfo *t = &m->tables [MONO_TABLE_MEMBERREF];
228         int i, kind, idx;
229         char *x, *xx;
230         char *sig;
231         const char *blob, *ks = NULL;
232
233         fprintf (output, "MemberRef Table (1..%d)\n", t->rows);
234
235         for (i = 0; i < t->rows; i++){
236                 guint32 cols [MONO_MEMBERREF_SIZE];
237
238                 mono_metadata_decode_row (t, i, cols, MONO_MEMBERREF_SIZE);
239                 
240                 kind = cols [MONO_MEMBERREF_CLASS] & 7;
241                 idx = cols [MONO_MEMBERREF_CLASS] >> 3;
242
243                 x = g_strdup ("UNHANDLED CASE");
244                 
245                 switch (kind){
246                 case 0:
247                         ks = "TypeDef";
248                         xx = get_typedef (m, idx);
249                         x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
250                         g_free (xx);
251                         break;
252                 case 1:
253                         ks = "TypeRef";
254                         xx = get_typeref (m, idx);
255                         x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
256                         g_free (xx);
257                         break;
258                 case 2:
259                         ks = "ModuleRef"; break;
260                 case 3:
261                         ks = "MethodDef";
262                         x = get_methoddef (m, idx);
263                         break;
264                 case 4:
265                         ks = "TypeSpec";
266                         xx = get_typespec (m, idx, FALSE, NULL);
267                         x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
268                         g_free (xx);
269                         break;
270                 default:
271                         g_error ("Unknown tag: %d\n", kind);
272                 }
273                 blob = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
274                 mono_metadata_decode_blob_size (blob, &blob);
275                 if (*blob == 0x6) { /* it's a field */
276                         sig = get_field_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
277                 } else {
278                         sig = get_methodref_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL, NULL);
279                 }
280                 fprintf (output, "%d: %s[%d] %s\n\tResolved: %s\n\tSignature: %s\n\t\n",
281                          i + 1,
282                          ks, idx,
283                          mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]),
284                          x ? x : "",
285                          sig);
286
287                 if (x)
288                         g_free (x);
289                 g_free (sig);
290         }
291 }
292
293 void
294 dump_table_class_layout (MonoImage *m)
295 {
296         MonoTableInfo *t = &m->tables [MONO_TABLE_CLASSLAYOUT];
297         int i;
298         fprintf (output, "ClassLayout Table (1..%d)\n", t->rows);
299
300         for (i = 0; i < t->rows; i++){
301                 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
302                 
303                 mono_metadata_decode_row (t, i, cols, MONO_CLASS_LAYOUT_SIZE);
304
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]));
309         }
310 }
311
312 void
313 dump_table_constant (MonoImage *m)
314 {
315         MonoTableInfo *t = &m->tables [MONO_TABLE_CONSTANT];
316         int i;
317         const char *desc [] = {
318                 "Field",
319                 "Param",
320                 "Property",
321                 ""
322         };
323         fprintf (output, "Constant Table (1..%d)\n", t->rows);
324
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];
330
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]));
334         }
335         
336 }
337
338 void
339 dump_table_property_map (MonoImage *m)
340 {
341         MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTYMAP];
342         int i;
343         char *s;
344         
345         fprintf (output, "Property Map Table (1..%d)\n", t->rows);
346         
347         for (i = 0; i < t->rows; i++){
348                 guint32 cols [MONO_PROPERTY_MAP_SIZE];
349                 
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);
354         }
355 }
356
357 void
358 dump_table_property (MonoImage *m)
359 {
360         MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTY];
361         int i, j, pcount;
362         const char *ptr;
363         char flags[128];
364
365         fprintf (output, "Property Table (1..%d)\n", t->rows);
366
367         for (i = 0; i < t->rows; i++){
368                 guint32 cols [MONO_PROPERTY_SIZE];
369                 char *type;
370                 int bsize;
371                 int prop_flags;
372                 
373                 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_SIZE);
374                 flags [0] = 0;
375                 prop_flags = cols [MONO_PROPERTY_FLAGS];
376                 if (prop_flags & 0x0200)
377                         strcat (flags, "special ");
378                 if (prop_flags & 0x0400)
379                         strcat (flags, "runtime ");
380                 if (prop_flags & 0x1000)
381                         strcat (flags, "hasdefault ");
382
383                 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
384                 bsize = mono_metadata_decode_blob_size (ptr, &ptr);
385                 /* ECMA claims 0x08 ... */
386                 if (*ptr != 0x28 && *ptr != 0x08)
387                         g_warning("incorrect signature in propert blob: 0x%x", *ptr);
388                 ptr++;
389                 pcount = mono_metadata_decode_value (ptr, &ptr);
390                 ptr = get_type (m, ptr, &type, NULL);
391                 fprintf (output, "%d: %s %s (",
392                          i + 1, type, mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]));
393                 g_free (type);
394
395                 for (j = 0; j < pcount; j++){
396                         ptr = get_param (m, ptr, &type, NULL);
397                         fprintf (output, "%s%s", j > 0? ", " : "",type);
398                         g_free (type);
399                 }
400                 fprintf (output, ") %s\n", flags);
401         }
402 }
403
404 void
405 dump_table_event (MonoImage *m)
406 {
407         MonoTableInfo *t = &m->tables [MONO_TABLE_EVENT];
408         int i;
409         fprintf (output, "Event Table (1..%d)\n", t->rows);
410
411         for (i = 0; i < t->rows; i++){
412                 guint32 cols [MONO_EVENT_SIZE];
413                 const char *name;
414                 char *type;
415                 
416                 mono_metadata_decode_row (t, i, cols, MONO_EVENT_SIZE);
417
418                 name = mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]);
419                 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE], NULL);
420                 fprintf (output, "%d: %s %s %s\n", i + 1, type, name,
421                          cols [MONO_EVENT_FLAGS] & 0x200 ? "specialname " : "");
422                 g_free (type);
423         }
424         
425 }
426
427 void
428 dump_table_file (MonoImage *m)
429 {
430         MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
431         int i, j, len;
432         fprintf (output, "File Table (1..%d)\n", t->rows);
433
434         for (i = 0; i < t->rows; i++){
435                 guint32 cols [MONO_FILE_SIZE];
436                 const char *name, *hash;
437                 
438                 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
439
440                 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
441                 fprintf (output, "%d: %s %s [", i + 1, name, 
442                                 cols [MONO_FILE_FLAGS] & 0x1 ? "nometadata" : "containsmetadata");
443                 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
444                 len = mono_metadata_decode_blob_size (hash, &hash);
445                 for (j = 0; j < len; ++j)
446                         fprintf (output, "%s%02X", j? " ": "", hash [j] & 0xff);
447                 fprintf (output, "]\n");
448         }
449         
450 }
451
452 static char*
453 get_manifest_implementation (MonoImage *m, guint32 idx)
454 {
455         guint32 row;
456         const char* table = "";
457         if (!idx)
458                 return g_strdup ("current module");
459         row = idx >> MONO_IMPLEMENTATION_BITS;
460         switch (idx & MONO_IMPLEMENTATION_MASK) {
461         case MONO_IMPLEMENTATION_FILE:
462                 table = "file";
463                 break;
464         case MONO_IMPLEMENTATION_ASSEMBLYREF:
465                 table = "assemblyref";
466                 break;
467         case MONO_IMPLEMENTATION_EXP_TYPE:
468                 table = "exportedtype";
469                 break;
470         default:
471                 g_assert_not_reached ();
472         }
473         return g_strdup_printf ("%s %d", table, row);
474 }
475
476 static const char*
477 get_manifest_flags (guint32 mf)
478 {
479         mf &= 3;
480         switch (mf) {
481         case 1: return "public";
482         case 2: return "private";
483         default:
484                 return "";
485         }
486 }
487
488 void
489 dump_table_manifest (MonoImage *m)
490 {
491         MonoTableInfo *t = &m->tables [MONO_TABLE_MANIFESTRESOURCE];
492         int i;
493         fprintf (output, "Manifestresource Table (1..%d)\n", t->rows);
494
495         for (i = 0; i < t->rows; i++){
496                 guint32 cols [MONO_MANIFEST_SIZE];
497                 const char *name, *mf;
498                 char *impl;
499                 
500                 mono_metadata_decode_row (t, i, cols, MONO_MANIFEST_SIZE);
501
502                 name = mono_metadata_string_heap (m, cols [MONO_MANIFEST_NAME]);
503                 mf = get_manifest_flags (cols [MONO_MANIFEST_FLAGS]);
504                 impl = get_manifest_implementation (m, cols [MONO_MANIFEST_IMPLEMENTATION]);
505                 fprintf (output, "%d: %s '%s' at offset %u in %s\n", i + 1, mf, name, cols [MONO_MANIFEST_OFFSET], impl);
506                 g_free (impl);
507         }
508         
509 }
510
511 void
512 dump_table_moduleref (MonoImage *m)
513 {
514         MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
515         int i;
516         fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
517
518         for (i = 0; i < t->rows; i++){
519                 guint32 cols [MONO_MODULEREF_SIZE];
520                 const char *name;
521                 
522                 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
523
524                 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
525                 fprintf (output, "%d: %s\n", i + 1, name);
526         }
527         
528 }
529
530 void
531 dump_table_module (MonoImage *m)
532 {
533         MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
534         int i;
535         fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
536
537         for (i = 0; i < t->rows; i++){
538                 guint32 cols [MONO_MODULE_SIZE];
539                 const char *name;
540                 char *guid;
541                 
542                 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
543
544                 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
545                 guid = get_guid (m, cols [MONO_MODULE_MVID]);
546                 fprintf (output, "%d: %s %d %s\n", i + 1, name, cols [MONO_MODULE_MVID], guid);
547         }       
548 }
549
550 void
551 dump_table_method (MonoImage *m)
552 {
553         MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
554         MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
555         int i, current_type;
556         guint32 first_m, last_m;
557         fprintf (output, "Method Table (1..%d)\n", t->rows);
558
559         current_type = 1;
560         last_m = first_m = 1;
561         for (i = 1; i <= t->rows; i++){
562                 guint32 cols [MONO_METHOD_SIZE];
563                 char *sig;
564                 const char *sigblob;
565                 MonoMethodSignature *method;
566
567                 /*
568                  * Find the next type.
569                  */
570                 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_METHOD_LIST))) {
571                         current_type++;
572                 }
573                 if (i == first_m) {
574                         fprintf (output, "########## %s.%s\n",
575                                 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
576                                 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
577                         first_m = last_m;
578                 }
579                 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SIZE);
580                 sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
581                 mono_metadata_decode_blob_size (sigblob, &sigblob);
582                 method = mono_metadata_parse_method_signature (m, i, sigblob, &sigblob);
583                 sig = dis_stringify_method_signature (m, method, i, NULL, FALSE);
584                 fprintf (output, "%d: %s (param: %d)\n", i, sig, cols [MONO_METHOD_PARAMLIST]);
585                 g_free (sig);
586                 mono_metadata_free_method_signature (method);
587         }
588         
589 }
590
591 void
592 dump_table_implmap (MonoImage *m)
593 {
594         MonoTableInfo *t = &m->tables [MONO_TABLE_IMPLMAP];
595         MonoTableInfo *td = &m->tables [MONO_TABLE_MODULEREF];
596         int i;
597
598         fprintf (output, "ImplMap Table (1..%d)\n", t->rows);
599
600         for (i = 1; i <= t->rows; i++){
601                 guint32 cols [MONO_IMPLMAP_SIZE];
602                 char *method;
603
604                 mono_metadata_decode_row (t, i - 1, cols, MONO_IMPLMAP_SIZE);
605
606                 method = get_method (m, MONO_TOKEN_METHOD_DEF | (cols [MONO_IMPLMAP_MEMBER] >> MONO_MEMBERFORWD_BITS), NULL);
607                 
608                 fprintf (output, "%d: %s %d (%s %s)\n", i, 
609                                  method,
610                                  cols [MONO_IMPLMAP_FLAGS], 
611                                  mono_metadata_string_heap (m, cols [MONO_IMPLMAP_NAME]),
612                                  mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME)));
613         }
614 }
615
616 void
617 dump_table_methodimpl (MonoImage *m)
618 {
619         MonoTableInfo *t = &m->tables [MONO_TABLE_METHODIMPL];
620         /*MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];*/
621         int i;
622
623         fprintf (output, "MethodImpl Table (1..%d)\n", t->rows);
624
625         for (i = 1; i <= t->rows; i++){
626                 guint32 cols [MONO_METHODIMPL_SIZE];
627                 char *class, *impl, *decl;
628
629                 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODIMPL_SIZE);
630                 class = get_typedef (m, cols [MONO_METHODIMPL_CLASS]);
631                 impl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_BODY]), NULL);
632                 decl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_DECLARATION]), NULL);
633                 fprintf (output, "%d: %s\n\tdecl: %s\n\timpl: %s\n", i, class, decl, impl);
634                 g_free (class);
635                 g_free (impl);
636                 g_free (decl);
637         }
638         
639 }
640
641 static dis_map_t semantics_map [] = {
642                 {1, "setter"},
643                 {2, "getter"},
644                 {4, "other"},
645                 {8, "add-on"},
646                 {0x10, "remove-on"},
647                 {0x20, "fire"},
648                 {0, NULL},
649 };
650
651 void
652 dump_table_methodsem (MonoImage *m)
653 {
654         MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSEMANTICS];
655         int i, is_property, index;
656         const char *semantics;
657         
658         fprintf (output, "Method Semantics Table (1..%d)\n", t->rows);
659         for (i = 1; i <= t->rows; i++){
660                 guint32 cols [MONO_METHOD_SEMA_SIZE];
661                 
662                 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SEMA_SIZE);
663                 semantics = flags (cols [MONO_METHOD_SEMA_SEMANTICS], semantics_map);
664                 is_property = cols [MONO_METHOD_SEMA_ASSOCIATION] & MONO_HAS_SEMANTICS_MASK;
665                 index = cols [MONO_METHOD_SEMA_ASSOCIATION] >> MONO_HAS_SEMANTICS_BITS;
666                 fprintf (output, "%d: [%d] %s method: %d %s %d\n", i, cols [MONO_METHOD_SEMA_ASSOCIATION], semantics,
667                                                 cols [MONO_METHOD_SEMA_METHOD] - 1, 
668                                                 is_property? "property" : "event",
669                                                 index);
670         }
671 }
672
673 void 
674 dump_table_interfaceimpl (MonoImage *m)
675 {
676         MonoTableInfo *t = &m->tables [MONO_TABLE_INTERFACEIMPL];
677         int i;
678
679         fprintf (output, "Interface Implementation Table (1..%d)\n", t->rows);
680         for (i = 1; i <= t->rows; i++) {
681                 guint32 cols [MONO_INTERFACEIMPL_SIZE];
682                 
683                 mono_metadata_decode_row (t, i - 1, cols, MONO_INTERFACEIMPL_SIZE);
684                 fprintf (output, "%d: %s implements %s\n", i,
685                          get_typedef (m, cols [MONO_INTERFACEIMPL_CLASS]),
686                          get_typedef_or_ref (m, cols [MONO_INTERFACEIMPL_INTERFACE], NULL));
687         }
688 }
689
690 static char*
691 has_cattr_get_table (MonoImage *m, guint32 val)
692 {
693         guint32 t = val & MONO_CUSTOM_ATTR_MASK;
694         guint32 index = val >> MONO_CUSTOM_ATTR_BITS;
695         const char *table;
696
697         switch (t) {
698         case MONO_CUSTOM_ATTR_METHODDEF:
699                 table = "MethodDef";
700                 break;
701         case MONO_CUSTOM_ATTR_FIELDDEF:
702                 table = "FieldDef";
703                 break;
704         case MONO_CUSTOM_ATTR_TYPEREF:
705                 table = "TypeRef";
706                 break;
707         case MONO_CUSTOM_ATTR_TYPEDEF:
708                 table = "TypeDef";
709                 break;
710         case MONO_CUSTOM_ATTR_PARAMDEF:
711                 table = "Param";
712                 break;
713         case MONO_CUSTOM_ATTR_INTERFACE:
714                 table = "InterfaceImpl";
715                 break;
716         case MONO_CUSTOM_ATTR_MEMBERREF:
717                 table = "MemberRef";
718                 break;
719         case MONO_CUSTOM_ATTR_MODULE:
720                 table = "Module";
721                 break;
722         case MONO_CUSTOM_ATTR_PERMISSION:
723                 table = "DeclSecurity?";
724                 break;
725         case MONO_CUSTOM_ATTR_PROPERTY:
726                 table = "Property";
727                 break;
728         case MONO_CUSTOM_ATTR_EVENT:
729                 table = "Event";
730                 break;
731         case MONO_CUSTOM_ATTR_SIGNATURE:
732                 table = "StandAloneSignature";
733                 break;
734         case MONO_CUSTOM_ATTR_MODULEREF:
735                 table = "ModuleRef";
736                 break;
737         case MONO_CUSTOM_ATTR_TYPESPEC:
738                 table = "TypeSpec";
739                 break;
740         case MONO_CUSTOM_ATTR_ASSEMBLY:
741                 table = "Assembly";
742                 break;
743         case MONO_CUSTOM_ATTR_ASSEMBLYREF:
744                 table = "AssemblyRef";
745                 break;
746         case MONO_CUSTOM_ATTR_FILE:
747                 table = "File";
748                 break;
749         case MONO_CUSTOM_ATTR_EXP_TYPE:
750                 table = "ExportedType";
751                 break;
752         case MONO_CUSTOM_ATTR_MANIFEST:
753                 table = "Manifest";
754                 break;
755         default:
756                 table = "Unknown";
757                 break;
758         }
759         /*
760          * FIXME: we should decode the index into something more uman-friendly.
761          */
762         return g_strdup_printf ("%s: %d", table, index);
763 }
764
765 static char*
766 custom_attr_params (MonoImage *m, MonoMethodSignature* sig, const char* value)
767 {
768         int len, i, slen, type;
769         GString *res;
770         char *s;
771         const char *p = value;
772
773         len = mono_metadata_decode_value (p, &p);
774         if (len < 2 || read16 (p) != 0x0001) /* Prolog */
775                 return g_strdup ("");
776
777         /* skip prolog */
778         p += 2;
779         res = g_string_new ("");
780         for (i = 0; i < sig->param_count; ++i) {
781                 if (i != 0)
782                         g_string_append (res, ", ");
783                 type = sig->params [i]->type;
784 handle_enum:
785                 switch (type) {
786                 case MONO_TYPE_U1:
787                         g_string_sprintfa (res, "%d", (unsigned int)*p);
788                         ++p;
789                         break;
790                 case MONO_TYPE_I1:
791                         g_string_sprintfa (res, "%d", *p);
792                         ++p;
793                         break;
794                 case MONO_TYPE_BOOLEAN:
795                         g_string_sprintfa (res, "%s", *p?"true":"false");
796                         ++p;
797                         break;
798                 case MONO_TYPE_CHAR:
799                         g_string_sprintfa (res, "'%c'", read16 (p));
800                         p += 2;
801                         break;
802                 case MONO_TYPE_U2:
803                         g_string_sprintfa (res, "%d", read16 (p));
804                         p += 2;
805                         break;
806                 case MONO_TYPE_I2:
807                         g_string_sprintfa (res, "%d", (gint16)read16 (p));
808                         p += 2;
809                         break;
810                 case MONO_TYPE_U4:
811                         g_string_sprintfa (res, "%d", read32 (p));
812                         p += 4;
813                         break;
814                 case MONO_TYPE_I4:
815                         g_string_sprintfa (res, "%d", (gint32)read32 (p));
816                         p += 4;
817                         break;
818                 case MONO_TYPE_U8:
819                         g_string_sprintfa (res, "%lld", (long long)read64 (p));
820                         p += 8;
821                         break;
822                 case MONO_TYPE_I8:
823                         g_string_sprintfa (res, "%lld", (long long)read64 (p));
824                         p += 8;
825                         break;
826                 case MONO_TYPE_R4: {
827                         float val;
828                         int inf;
829                         readr4 (p, &val);
830                         inf = isinf (val);
831                         if (inf == -1) 
832                                 g_string_sprintfa (res, "(00 00 80 ff)"); /* negative infinity */
833                         else if (inf == 1)
834                                 g_string_sprintfa (res, "(00 00 80 7f)"); /* positive infinity */
835                         else if (isnan (val))
836                                 g_string_sprintfa (res, "(00 00 c0 ff)"); /* NaN */
837                         else
838                                 g_string_sprintfa (res, "%g", val);
839                         p += 4;
840                         break;
841                 }
842                 case MONO_TYPE_R8: {
843                         double val;
844                         int inf;
845                         
846                         readr8 (p, &val);
847                         inf = isinf (val);
848                         if (inf == -1) 
849                                 g_string_sprintfa (res, "(00 00 00 00 00 00 f0 ff)"); /* negative infinity */
850                         else if (inf == 1)
851                                 g_string_sprintfa (res, "(00 00 00 00 00 00 f0 7f)"); /* positive infinity */
852                         else if (isnan (val))
853                                 g_string_sprintfa (res, "(00 00 00 00 00 00 f8 ff)"); /* NaN */
854                         else
855                                 g_string_sprintfa (res, "%g", val);
856                         p += 8;
857                         break;
858                 }
859                 case MONO_TYPE_VALUETYPE:
860                         if (mono_class_is_enum (sig->params [i]->data.klass)) {
861                                 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
862                                 goto handle_enum;
863                         } else {
864                                 g_warning ("generic valutype not handled in custom attr value decoding");
865                         }
866                         break;
867                 case MONO_TYPE_CLASS: /* It must be a Type: check? */
868                 case MONO_TYPE_STRING:
869                         if (*p == (char)0xff) {
870                                 g_string_append (res, "null");
871                                 p++;
872                                 break;
873                         }
874                         slen = mono_metadata_decode_value (p, &p);
875                         g_string_append_c (res, '"');
876                         g_string_append (res, p);
877                         g_string_append_c (res, '"');
878                         p += slen;
879                         break;
880                 default:
881                         g_warning ("Type %02x not handled in custom attr value decoding", sig->params [i]->type);
882                         break;
883                 }
884         }
885         slen = read16 (p);
886         if (slen) {
887                 g_string_sprintfa (res, " %d named args: (", slen);
888                 slen = len - (p - value) + 1;
889                 for (i = 0; i < slen; ++i) {
890                         g_string_sprintfa (res, " %02X", (p [i] & 0xff));
891                 }
892                 g_string_append_c (res, ')');
893         }
894         s = res->str;
895         g_string_free (res, FALSE);
896         return s;
897 }
898
899 void
900 dump_table_customattr (MonoImage *m)
901 {
902         MonoTableInfo *t = &m->tables [MONO_TABLE_CUSTOMATTRIBUTE];
903         int i;
904
905         fprintf (output, "Custom Attributes Table (1..%d)\n", t->rows);
906         for (i = 1; i <= t->rows; i++) {
907                 guint32 cols [MONO_CUSTOM_ATTR_SIZE];
908                 guint32 mtoken;
909                 char * desc;
910                 char *method;
911                 char *params;
912                 MonoMethod *meth;
913                 
914                 mono_metadata_decode_row (t, i - 1, cols, MONO_CUSTOM_ATTR_SIZE);
915                 desc = has_cattr_get_table (m, cols [MONO_CUSTOM_ATTR_PARENT]);
916                 mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS;
917                 switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) {
918                 case MONO_CUSTOM_ATTR_TYPE_METHODDEF:
919                         mtoken |= MONO_TOKEN_METHOD_DEF;
920                         break;
921                 case MONO_CUSTOM_ATTR_TYPE_MEMBERREF:
922                         mtoken |= MONO_TOKEN_MEMBER_REF;
923                         break;
924                 default:
925                         g_warning ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
926                         break;
927                 }
928                 method = get_method (m, mtoken, NULL);
929                 meth = mono_get_method (m, mtoken, NULL);
930                 params = custom_attr_params (m, mono_method_signature (meth), mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE]));
931                 fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params);
932                 g_free (desc);
933                 g_free (method);
934                 g_free (params);
935         }
936 }
937
938 void
939 dump_table_nestedclass (MonoImage *m)
940 {
941         MonoTableInfo *t = &m->tables [MONO_TABLE_NESTEDCLASS];
942         guint32 cols [MONO_NESTED_CLASS_SIZE];
943         int i;
944         char *nested, *nesting;
945         fprintf (output, "NestedClass Table (1..%d)\n", t->rows);
946
947         for (i = 1; i <= t->rows; i++){
948                 mono_metadata_decode_row (t, i - 1, cols, MONO_NESTED_CLASS_SIZE);
949                 nested = get_typedef (m, cols [MONO_NESTED_CLASS_NESTED]);
950                 nesting = get_typedef (m, cols [MONO_NESTED_CLASS_ENCLOSING]);
951                 fprintf (output, "%d: %d %d: %s in %s\n", i,
952                                 cols [MONO_NESTED_CLASS_NESTED], 
953                                 cols [MONO_NESTED_CLASS_ENCLOSING], nested, nesting);
954                 g_free (nested);
955                 g_free (nesting);
956         }
957         
958 }
959
960 void
961 dump_table_exported (MonoImage *m)
962 {
963         MonoTableInfo *t = &m->tables [MONO_TABLE_EXPORTEDTYPE];
964         guint32 cols [MONO_EXP_TYPE_SIZE];
965         int i;
966         const char *name, *nspace;
967         char *impl;
968         guint32 index;
969         fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
970
971         for (i = 1; i <= t->rows; i++) {
972                 mono_metadata_decode_row (t, i - 1, cols, MONO_EXP_TYPE_SIZE);
973                 name = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAME]);
974                 nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
975                 impl = get_manifest_implementation (m, cols [MONO_EXP_TYPE_IMPLEMENTATION]);
976                 index = cols [MONO_EXP_TYPE_TYPEDEF];
977                 fprintf (output, "%d: %s%s%s is in %s, token %x\n", i, nspace, *nspace ? "." : "", name, impl, index);
978                 g_free (impl);
979         }
980         
981 }
982
983 void
984 dump_table_field_marshal (MonoImage *m)
985 {
986         MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDMARSHAL];
987         guint32 cols [MONO_FIELD_MARSHAL_SIZE];
988         int i, is_field, idx;
989         const char *blob;
990         char *native;
991         
992         fprintf (output, "FieldMarshal Table (1..%d)\n", t->rows);
993
994         for (i = 1; i <= t->rows; i++) {
995                 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_MARSHAL_SIZE);
996                 blob = mono_metadata_blob_heap (m, cols [MONO_FIELD_MARSHAL_NATIVE_TYPE]);
997                 native = get_marshal_info (m, blob);
998                 is_field = (cols [MONO_FIELD_MARSHAL_PARENT] & MONO_HAS_FIELD_MARSHAL_MASK) == MONO_HAS_FIELD_MARSHAL_FIELDSREF;
999                 idx = cols [MONO_FIELD_MARSHAL_PARENT] >> MONO_HAS_FIELD_MARSHAL_BITS;
1000                 fprintf (output, "%d: (0x%04x) %s %d: %s\n", i, cols [MONO_FIELD_MARSHAL_PARENT], is_field? "Field" : "Param", idx, native);
1001                 g_free (native);
1002         }
1003         
1004 }
1005
1006 static const char*
1007 get_security_action (int val) {
1008         static char buf [32];
1009
1010         switch (val) {
1011         case SECURITY_ACTION_DEMAND:
1012                 return "Demand";
1013         case SECURITY_ACTION_ASSERT:
1014                 return "Assert";
1015         case SECURITY_ACTION_DENY:
1016                 return "Deny";
1017         case SECURITY_ACTION_PERMITONLY:
1018                 return "PermitOnly";
1019         case SECURITY_ACTION_LINKDEMAND:
1020                 return "LinkDemand";
1021         case SECURITY_ACTION_INHERITDEMAND:
1022                 return "InheritanceDemand";
1023         case SECURITY_ACTION_REQMIN:
1024                 return "RequestMinimum";
1025         case SECURITY_ACTION_REQOPT:
1026                 return "RequestOptional";
1027         case SECURITY_ACTION_REQREFUSE:
1028                 return "RequestRefuse";
1029         /* Special actions (for non CAS permissions) */
1030         case SECURITY_ACTION_NONCASDEMAND:
1031                 return "NonCasDemand";
1032         case SECURITY_ACTION_NONCASLINKDEMAND:
1033                 return "NonCasLinkDemand";
1034         case SECURITY_ACTION_NONCASINHERITANCE:
1035                 return "NonCasInheritance";
1036         /* Fx 2.0 actions (for both CAS and non-CAS permissions) */
1037         case SECURITY_ACTION_LINKDEMANDCHOICE:
1038                 return "LinkDemandChoice";
1039         case SECURITY_ACTION_INHERITDEMANDCHOICE:
1040                 return "InheritanceDemandChoice";
1041         case SECURITY_ACTION_DEMANDCHOICE:
1042                 return "DemandChoice";
1043         default:
1044                 g_snprintf (buf, sizeof (buf), "0x%04X", val);
1045                 return buf;
1046         }
1047 }
1048
1049 void 
1050 dump_table_declsec (MonoImage *m)
1051 {
1052         MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
1053         guint32 cols [MONO_DECL_SECURITY_SIZE];
1054         int i, len;
1055         guint32 idx;
1056         const char *blob, *action;
1057         const char* parent[] = {
1058                 "TypeDef", "MethodDef", "Assembly", ""
1059         };
1060         
1061         fprintf (output, "DeclSecurity Table (1..%d)\n", t->rows);
1062
1063         for (i = 1; i <= t->rows; i++) {
1064                 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
1065                 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
1066                 len = mono_metadata_decode_blob_size (blob, &blob);
1067                 action = get_security_action (cols [MONO_DECL_SECURITY_ACTION]);
1068                 idx = cols [MONO_DECL_SECURITY_PARENT];
1069                 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");
1070                 if (!len)
1071                         continue;
1072                 for (idx = 0; idx < len; ++idx)
1073                         fprintf (output, "%c", blob [idx]);
1074                 fprintf (output, "\n");
1075         }
1076 }
1077
1078 void 
1079 dump_table_genericpar (MonoImage *m)
1080 {
1081         MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAM];
1082         guint32 cols [MONO_GENERICPARAM_SIZE];
1083         int i;
1084
1085         fprintf (output, "GenericParameters (1..%d)\n", t->rows);
1086         
1087         for (i = 1; i <= t->rows; i++) {
1088                 char *sig;
1089                 mono_metadata_decode_row (t, i - 1, cols, MONO_GENERICPARAM_SIZE);
1090
1091                 // sig = get_type_or_methdef (m, cols [MONO_GENERICPARAM_OWNER]);
1092                 sig = g_strdup_printf ("%x", cols [MONO_GENERICPARAM_OWNER]);
1093                 fprintf (output, "%d: %d, flags=%d, owner=%s %s\n", i,
1094                          cols [MONO_GENERICPARAM_NUMBER],
1095                          cols [MONO_GENERICPARAM_FLAGS], sig,
1096                          mono_metadata_string_heap (m, cols [MONO_GENERICPARAM_NAME]));
1097                 g_free (sig);
1098         }
1099 }
1100
1101 void
1102 dump_table_methodspec (MonoImage *m)
1103 {
1104         MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSPEC];
1105         guint32 cols [MONO_METHODSPEC_SIZE];
1106         int i;
1107         
1108         fprintf (output, "MethodSpec (1..%d)\n", t->rows);
1109
1110         for (i = 1; i <= t->rows; i++) {
1111                 char *sig;
1112                 char *method;
1113                 guint32 token;
1114                 
1115                 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODSPEC_SIZE);
1116
1117                 /* build a methodspec token to get the method */
1118                 token = MONO_TOKEN_METHOD_SPEC | i;
1119                 method = get_method (m, token, NULL);
1120                 
1121                 sig = get_method_type_param (m, cols [MONO_METHODSPEC_SIGNATURE], NULL);
1122                 fprintf (output, "%d: %s, %s\n", i, method, sig);
1123                 g_free (sig);
1124                 g_free (method);
1125         }
1126 }
1127
1128 void
1129 dump_table_parconstraint (MonoImage *m)
1130 {
1131         MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
1132         guint32 cols [MONO_GENPARCONSTRAINT_SIZE];
1133         int i;
1134         
1135         fprintf (output, "Generic Param Constraint (1..%d)\n", t->rows);
1136
1137         for (i = 1; i <= t->rows; i++) {
1138                 char *sig;
1139                 mono_metadata_decode_row (t, i - 1, cols, MONO_GENPARCONSTRAINT_SIZE);
1140
1141                 // sig = get_typedef_or_ref (m, cols [MONO_GENPARCONSTRAINT_CONSTRAINT], NULL);
1142                 sig = g_strdup_printf ("%x", cols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
1143                 fprintf (output, "%d: gen-par=%d, Constraint=%s\n", i,
1144                          cols [MONO_GENPARCONSTRAINT_GENERICPAR], sig);
1145                 g_free (sig);
1146         }
1147 }
1148
1149 void
1150 dump_stream_blob (MonoImage *m)
1151 {
1152         int i;
1153
1154         fprintf (output, "Blob heap contents\n");
1155
1156         for (i = 0; i < m->heap_blob.size; i++) {
1157                 if (i > 0) {
1158                         if ((i % 16) == 0)
1159                                 fprintf (output, "\n");
1160                         else if ((i % 8) == 0)
1161                                 fprintf (output, "- ");
1162                 }
1163                 fprintf (output, "%02x ", m->heap_blob.data [i] & 0xff);
1164         }
1165
1166         fprintf (output, "\n");
1167 }
1168
1169 void
1170 dump_table_standalonesig (MonoImage *m)
1171 {
1172         MonoTableInfo *t = &m->tables [MONO_TABLE_STANDALONESIG];
1173         guint32 cols [MONO_STAND_ALONE_SIGNATURE_SIZE];
1174         int i;
1175         
1176         fprintf (output, "Stand alone signature (1..%d)\n", t->rows);
1177
1178         for (i = 1; i <= t->rows; i++) {
1179                 const char *locals_ptr;
1180                 int j, bsize;
1181
1182                 mono_metadata_decode_row (t, i - 1, cols, MONO_STAND_ALONE_SIGNATURE_SIZE);
1183
1184                 locals_ptr = mono_metadata_blob_heap (m, cols [MONO_STAND_ALONE_SIGNATURE]);
1185                 bsize = mono_metadata_decode_blob_size (locals_ptr, &locals_ptr);
1186
1187                 fprintf (output, "%d: blob[0x%x] = ", i, cols [MONO_STAND_ALONE_SIGNATURE]);
1188
1189                 for (j = 0; j < bsize; j++) {
1190                         fprintf (output, "%02x ", locals_ptr [j]);
1191                 }
1192                 fprintf (output, "\n");
1193         }
1194 }