[runtime] Store the values of some TLS variables into an array in MonoThreadInfo...
[mono.git] / mono / dis / dump.c
old mode 100644 (file)
new mode 100755 (executable)
index 37e2bc9..2b3a485
 #include "mono/metadata/class-internals.h"
 #include "mono/utils/mono-compiler.h"
 
-#ifndef HAVE_ISINF
-
-#ifdef HAVE_IEEEFP_H
-extern int isinf (double);
-#endif
-
+#if defined(__native_client__) && defined(__GLIBC__)
+volatile int __nacl_thread_suspension_needed = 0;
+void __nacl_suspend_thread_if_needed() {}
 #endif
 
 void
@@ -142,6 +139,7 @@ dump_table_assemblyref (MonoImage *m)
                         cols [MONO_ASSEMBLYREF_BUILD_NUMBER], 
                         cols [MONO_ASSEMBLYREF_REV_NUMBER],
                         mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_NAME]));
+               fprintf (output, "\tFlags=0x%08x\n", cols [MONO_ASSEMBLYREF_FLAGS]);
                ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
                len = mono_metadata_decode_value (ptr, &ptr);
                if (len > 0){
@@ -538,7 +536,7 @@ dump_table_module (MonoImage *m)
 {
        MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
        int i;
-       fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
+       fprintf (output, "Module Table (1..%d)\n", t->rows);
 
        for (i = 0; i < t->rows; i++){
                guint32 cols [MONO_MODULE_SIZE];
@@ -569,7 +567,7 @@ dump_table_method (MonoImage *m)
        last_m = first_m = 1;
        for (i = 1; i <= t->rows; i++){
                guint32 cols [MONO_METHOD_SIZE];
-               char *sig;
+               char *sig, *impl_flags;
                const char *sigblob;
                MonoMethodSignature *method;
 
@@ -592,13 +590,15 @@ dump_table_method (MonoImage *m)
                method_container = mono_metadata_load_generic_params (m, MONO_TOKEN_METHOD_DEF | i, type_container);
                if (method_container)
                        mono_metadata_load_generic_param_constraints (m, MONO_TOKEN_METHOD_DEF | i, method_container);
-               mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SIZE);
+               mono_metadata_decode_table_row (m, MONO_TABLE_METHOD, i - 1, cols, MONO_METHOD_SIZE);
                sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
                mono_metadata_decode_blob_size (sigblob, &sigblob);
                method = mono_metadata_parse_method_signature_full (m, method_container ? method_container : type_container, i, sigblob, &sigblob);
-               sig = dis_stringify_method_signature (m, method, i, (MonoGenericContext *) (method_container ? method_container : type_container), FALSE);
-               fprintf (output, "%d: %s (param: %d)\n", i, sig, cols [MONO_METHOD_PARAMLIST]);
+               sig = dis_stringify_method_signature (m, method, i, method_container ? method_container : type_container, FALSE);
+                impl_flags = get_method_impl_flags (cols [MONO_METHOD_IMPLFLAGS]);
+               fprintf (output, "%d: %s (param: %d impl_flags: %s)\n", i, sig, cols [MONO_METHOD_PARAMLIST], impl_flags);
                g_free (sig);
+               g_free (impl_flags);
                mono_metadata_free_method_signature (method);
        }
        
@@ -629,6 +629,22 @@ dump_table_implmap (MonoImage *m)
        }
 }
 
+void
+dump_table_fieldrva  (MonoImage *m)
+{
+       MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDRVA];
+       int i;
+
+       fprintf (output, "FieldRVA Table (1..%d)\n", t->rows);
+
+       for (i = 1; i <= t->rows; i++){
+               guint32 cols [MONO_FIELD_RVA_SIZE];
+
+               mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_RVA_SIZE);
+               fprintf (output, "%d: Field %d: %x\n", i, cols [MONO_FIELD_RVA_FIELD], cols [MONO_FIELD_RVA_RVA]);
+       }
+}
+
 void
 dump_table_methodimpl (MonoImage *m)
 {
@@ -803,58 +819,58 @@ custom_attr_params (MonoImage *m, MonoMethodSignature* sig, const char* value)
 handle_enum:
                switch (type) {
                case MONO_TYPE_U1:
-                       g_string_sprintfa (res, "%d", (unsigned int)*p);
+                       g_string_append_printf (res, "%d", (unsigned int)*p);
                        ++p;
                        break;
                case MONO_TYPE_I1:
-                       g_string_sprintfa (res, "%d", *p);
+                       g_string_append_printf (res, "%d", *p);
                        ++p;
                        break;
                case MONO_TYPE_BOOLEAN:
-                       g_string_sprintfa (res, "%s", *p?"true":"false");
+                       g_string_append_printf (res, "%s", *p?"true":"false");
                        ++p;
                        break;
                case MONO_TYPE_CHAR:
-                       g_string_sprintfa (res, "'%c'", read16 (p));
+                       g_string_append_printf (res, "'%c'", read16 (p));
                        p += 2;
                        break;
                case MONO_TYPE_U2:
-                       g_string_sprintfa (res, "%d", read16 (p));
+                       g_string_append_printf (res, "%d", read16 (p));
                        p += 2;
                        break;
                case MONO_TYPE_I2:
-                       g_string_sprintfa (res, "%d", (gint16)read16 (p));
+                       g_string_append_printf (res, "%d", (gint16)read16 (p));
                        p += 2;
                        break;
                case MONO_TYPE_U4:
-                       g_string_sprintfa (res, "%d", read32 (p));
+                       g_string_append_printf (res, "%d", read32 (p));
                        p += 4;
                        break;
                case MONO_TYPE_I4:
-                       g_string_sprintfa (res, "%d", (gint32)read32 (p));
+                       g_string_append_printf (res, "%d", (gint32)read32 (p));
                        p += 4;
                        break;
                case MONO_TYPE_U8:
-                       g_string_sprintfa (res, "%lld", (long long)read64 (p));
+                       g_string_append_printf (res, "%lld", (long long)read64 (p));
                        p += 8;
                        break;
                case MONO_TYPE_I8:
-                       g_string_sprintfa (res, "%lld", (long long)read64 (p));
+                       g_string_append_printf (res, "%lld", (long long)read64 (p));
                        p += 8;
                        break;
                case MONO_TYPE_R4: {
                        float val;
                        int inf;
                        readr4 (p, &val);
-                       inf = isinf (val);
+                       inf = dis_isinf (val);
                        if (inf == -1) 
-                               g_string_sprintfa (res, "(00 00 80 ff)"); /* negative infinity */
+                               g_string_append_printf (res, "(00 00 80 ff)"); /* negative infinity */
                        else if (inf == 1)
-                               g_string_sprintfa (res, "(00 00 80 7f)"); /* positive infinity */
-                       else if (isnan (val))
-                               g_string_sprintfa (res, "(00 00 c0 ff)"); /* NaN */
+                               g_string_append_printf (res, "(00 00 80 7f)"); /* positive infinity */
+                       else if (dis_isnan (val))
+                               g_string_append_printf (res, "(00 00 c0 ff)"); /* NaN */
                        else
-                               g_string_sprintfa (res, "%g", val);
+                               g_string_append_printf (res, "%g", val);
                        p += 4;
                        break;
                }
@@ -863,15 +879,15 @@ handle_enum:
                        int inf;
                        
                        readr8 (p, &val);
-                       inf = isinf (val);
+                       inf = dis_isinf (val);
                        if (inf == -1) 
-                               g_string_sprintfa (res, "(00 00 00 00 00 00 f0 ff)"); /* negative infinity */
+                               g_string_append_printf (res, "(00 00 00 00 00 00 f0 ff)"); /* negative infinity */
                        else if (inf == 1)
-                               g_string_sprintfa (res, "(00 00 00 00 00 00 f0 7f)"); /* positive infinity */
+                               g_string_append_printf (res, "(00 00 00 00 00 00 f0 7f)"); /* positive infinity */
                        else if (isnan (val))
-                               g_string_sprintfa (res, "(00 00 00 00 00 00 f8 ff)"); /* NaN */
+                               g_string_append_printf (res, "(00 00 00 00 00 00 f8 ff)"); /* NaN */
                        else
-                               g_string_sprintfa (res, "%g", val);
+                               g_string_append_printf (res, "%g", val);
                        p += 8;
                        break;
                }
@@ -903,10 +919,10 @@ handle_enum:
        }
        slen = read16 (p);
        if (slen) {
-               g_string_sprintfa (res, " %d named args: (", slen);
+               g_string_append_printf (res, " %d named args: (", slen);
                slen = len - (p - value) + 1;
                for (i = 0; i < slen; ++i) {
-                       g_string_sprintfa (res, " %02X", (p [i] & 0xff));
+                       g_string_append_printf (res, " %02X", (p [i] & 0xff));
                }
                g_string_append_c (res, ')');
        }
@@ -984,7 +1000,7 @@ dump_table_exported (MonoImage *m)
        int i;
        const char *name, *nspace;
        char *impl;
-       guint32 index;
+       guint32 index, flags;
        fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
 
        for (i = 1; i <= t->rows; i++) {
@@ -993,7 +1009,8 @@ dump_table_exported (MonoImage *m)
                nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
                impl = get_manifest_implementation (m, cols [MONO_EXP_TYPE_IMPLEMENTATION]);
                index = cols [MONO_EXP_TYPE_TYPEDEF];
-               fprintf (output, "%d: %s%s%s is in %s, token %x\n", i, nspace, *nspace ? "." : "", name, impl, index);
+               flags = cols [MONO_EXP_TYPE_FLAGS];
+               fprintf (output, "%d: %s%s%s is in %s, index=%x, flags=0x%x\n", i, nspace, *nspace ? "." : "", name, impl, index, flags);
                g_free (impl);
        }
        
@@ -1208,6 +1225,38 @@ dump_stream_blob (MonoImage *m)
        fprintf (output, "\n");
 }
 
+void
+dump_stream_strings (MonoImage *m)
+{
+       guint32 i;
+
+       fprintf (output, "Strings heap contents\n");
+
+       for (i = 0; i < m->heap_strings.size; ) {
+               const char *str = mono_metadata_string_heap (m, i);
+               fprintf (output, "%02x: \"%s\"\n", i, str);
+               i += strlen (str) + 1;
+       }
+}
+
+void
+dump_stream_us (MonoImage *m)
+{
+       guint32 i;
+
+       fprintf (output, "User Strings heap contents\n");
+
+       for (i = 0; i < m->heap_us.size; ) {
+               const char *us_ptr = mono_metadata_user_string (m, i);
+               int len = mono_metadata_decode_blob_size (us_ptr, (const char**)&us_ptr);
+
+               char *str = get_encoded_user_string_or_bytearray ((const guchar*)us_ptr, len);
+               fprintf (output, "%02x: %s\n", i, str);
+               g_free (str);
+               i += len + 1;
+       }
+}
+
 void
 dump_table_standalonesig (MonoImage *m)
 {
@@ -1234,3 +1283,49 @@ dump_table_standalonesig (MonoImage *m)
                fprintf (output, "\n");
        }
 }
+
+static void
+dump_table_ptr (MonoImage *m, int table, const char *name)
+{
+       MonoTableInfo *t = &m->tables [table];
+       guint32 cols [1];
+       int i;
+       
+       fprintf (output, "%s (1..%d)\n", name, t->rows);
+
+       for (i = 1; i <= t->rows; i++) {
+               mono_metadata_decode_row (t, i - 1, cols, 1);
+
+               fprintf (output, "%d: %d\n", i, cols [0]);
+       }
+}
+
+void
+dump_table_methodptr (MonoImage *m)
+{
+       dump_table_ptr (m, MONO_TABLE_METHOD_POINTER, "Method Ptr");
+}
+
+void
+dump_table_fieldptr (MonoImage *m)
+{
+       dump_table_ptr (m, MONO_TABLE_FIELD_POINTER, "Field Ptr");
+}
+
+void
+dump_table_paramptr (MonoImage *m)
+{
+       dump_table_ptr (m, MONO_TABLE_PARAM_POINTER, "Param Ptr");
+}
+
+void
+dump_table_eventptr (MonoImage *m)
+{
+       dump_table_ptr (m, MONO_TABLE_EVENT_POINTER, "Event Ptr");
+}
+
+void
+dump_table_propertyptr (MonoImage *m)
+{
+       dump_table_ptr (m, MONO_TABLE_PROPERTY_POINTER, "Property Ptr");
+}