2008-09-04 Robert Jordan <robertj@gmx.net>
[mono.git] / mono / dis / main.c
index 9a44836ed1545209c53c1d2ef992d3419cc1af68..59613f093e21d2650d254714cc5c31a96d3b85b6 100644 (file)
@@ -717,7 +717,7 @@ dis_code (MonoImage *m, guint32 token, guint32 rva, MonoGenericContainer *contai
        }
 
        mh = mono_metadata_parse_mh_full (m, container, ptr);
-       if ((entry_point = mono_image_get_entry_point (m))){
+       if ((entry_point = mono_image_get_entry_point (m)) && mono_metadata_token_index (entry_point)){
                loc = mono_metadata_locate_token (m, entry_point);
                if (rva == read32 (loc))
                        fprintf (output, "\t.entrypoint\n");
@@ -1016,14 +1016,12 @@ dis_property_signature (MonoImage *m, guint32 prop_idx, MonoGenericContainer *co
        g_string_sprintfa (res, "%s %s (", blurb, qk);
        g_free (qk);
        g_free (blurb);
-       mono_metadata_free_type (type);
        for (i = 0; i < pcount; i++) {
                if (i)
                        g_string_append (res, ", ");
                param = mono_metadata_parse_type_full (m, container, MONO_PARSE_PARAM, 0, ptr, &ptr);
                blurb = dis_stringify_param (m, param);
                g_string_append (res, blurb);
-               mono_metadata_free_type (param);
                g_free (blurb);
        }
        g_string_append_c (res, ')');
@@ -1388,6 +1386,23 @@ dis_types (MonoImage *m, int forward)
        }
 }
 
+static const char *
+get_uninitialized_data_type (guint32 size)
+{
+       switch (size) {
+       case 1:
+               return "int8";
+       case 2:
+               return "int16";
+       case 4:
+               return "int32";
+       case 8:
+               return "int64";
+       default:
+               g_error ("get_uninitialized_data_type for size: %d\n", size);
+       }               
+}
+
 /**
  * dis_data:
  * @m: metadata context
@@ -1416,13 +1431,18 @@ dis_data (MonoImage *m)
                type = mono_metadata_parse_field_type (m, 0, sig + 1, &sig);
                mono_class_init (mono_class_from_mono_type (type));
                size = mono_type_size (type, &align);
-               fprintf (output, ".data D_%08x = bytearray (", cols [MONO_FIELD_RVA_RVA]);
-               for (b = 0; b < size; ++b) {
-                       if (!(b % 16))
-                               fprintf (output, "\n\t");
-                       fprintf (output, " %02X", rva [b] & 0xff);
-               }
-               fprintf (output, ") // size: %d\n", size);
+
+               if (rva) {
+                       fprintf (output, ".data D_%08x = bytearray (", cols [MONO_FIELD_RVA_RVA]);
+                       for (b = 0; b < size; ++b) {
+                               if (!(b % 16))
+                                       fprintf (output, "\n\t");
+                               fprintf (output, " %02X", rva [b] & 0xff);
+                       }
+                       fprintf (output, ") // size: %d\n", size);
+               } else
+                       fprintf (output, ".data D_%08x = %s [%d]\n",
+                               cols [MONO_FIELD_RVA_RVA], get_uninitialized_data_type (size), size);
        }
 }
 
@@ -1483,21 +1503,15 @@ struct {
 static void
 disassemble_file (const char *file)
 {
-       MonoAssembly *ass;
        MonoImageOpenStatus status;
        MonoImage *img;
 
-       ass = mono_assembly_open (file, &status);
-       if (ass == NULL){
-               img = mono_image_open (file, &status);
-               if (!img) {
-                       fprintf (stderr, "Error while trying to process %s\n", file);
-                       return;
-               } else {
-                       mono_assembly_load_references (img, &status);
-               }
+       img = mono_image_open (file, &status);
+       if (!img) {
+               fprintf (stderr, "Error while trying to process %s\n", file);
+               return;
        } else {
-               img = ass->image;
+               mono_assembly_load_references (img, &status);
        }
 
        setup_filter (img);