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