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