2005-11-14 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mono / monograph / monograph.c
index 11f220226c193c838a00db9c566a7dacbf49038f..7fb66c17e04372ed6c9a244c401d79fbab51d77b 100644 (file)
@@ -8,6 +8,7 @@
 #include "mono/metadata/mono-endian.h"
 #include "mono/metadata/appdomain.h" /* mono_init */
 #include "mono/metadata/debug-helpers.h"
+#include "mono/utils/mono-compiler.h"
 
 static FILE *output;
 static int include_namespace = 0;
@@ -26,7 +27,7 @@ output_type_edge (MonoClass *first, MonoClass *second) {
 static void
 print_subtypes (MonoImage *image, MonoClass *class, int depth) {
        int i, token;
-       MonoTableInfo *t;
+       const MonoTableInfo *t;
        MonoClass *child;
 
        if (depth++ > max_depth)
@@ -91,7 +92,7 @@ interface_graph (MonoImage *image, const char* cname) {
        char *p;
        guint32 cols [MONO_INTERFACEIMPL_SIZE];
        guint32 token, i, count = 0;
-       MonoTableInfo *intf = mono_image_get_table_info (image, MONO_TABLE_INTERFACEIMPL);
+       const MonoTableInfo *intf = mono_image_get_table_info (image, MONO_TABLE_INTERFACEIMPL);
 
        cname = g_strdup (cname);
        p = strrchr (cname, '.');
@@ -514,14 +515,20 @@ print_method (MonoMethod *method, int depth) {
        const MonoOpcode *opcode;
        MonoMethodHeader *header;
        GHashTable *hash;
+       static GHashTable *visited = NULL;
        const unsigned char *ip;
        int i;
 
        if (depth++ > max_depth)
                return;
-       if (method->info) /* avoid recursion */
+       
+       if (! visited)
+               visited = g_hash_table_new (NULL, NULL);
+       
+       if (g_hash_table_lookup (visited, method))
                return;
-       method->info = method;
+       
+       g_hash_table_insert (visited, method, method);
 
        if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
                return;
@@ -1044,12 +1051,14 @@ main (int argc, char *argv[]) {
                aname = argv [i];
        if (argc > i + 1)
                cname = argv [i + 1];
-       if (!aname)
-               aname = "mscorlib";
+       if (aname) {
+               assembly = mono_assembly_open (aname, NULL);
+       } else {
+               assembly = mono_image_get_assembly (mono_get_corlib ());
+       }
        if (!cname && (graphtype == GRAPH_TYPES))
                cname = "System.Object";
 
-       assembly = mono_assembly_open (aname, NULL);
        if (!assembly) {
                g_print ("cannot open assembly %s\n", aname);
                exit (1);