6 #include "mono/metadata/debug-helpers.h"
7 #include "mono/metadata/verify.h"
11 * @assembly: reference to an assembly
13 * JIT compilation of all methods in the assembly. Prints debugging
14 * information on stdout.
17 mono_jit_assembly (MonoAssembly *assembly)
19 MonoImage *image = assembly->image;
21 MonoTableInfo *t = &image->tables [MONO_TABLE_METHOD];
24 for (i = 0; i < t->rows; i++) {
26 method = mono_get_method (image,
27 (MONO_TABLE_METHOD << 24) | (i + 1),
30 printf ("\nMethod: %s\n\n", method->name);
32 if (method->flags & METHOD_ATTRIBUTE_ABSTRACT)
33 printf ("ABSTARCT\n");
35 arch_compile_method (method);
45 "%s %s, the Mono ECMA CLI JIT Compiler, (C) 2001 Ximian, Inc.\n\n"
46 "Usage is: %s [options] executable args...\n", name, VERSION, name);
48 "Valid Options are:\n"
49 "-d debug the jit, show disassembler output.\n"
50 "--dump-asm dumps the assembly code generated\n"
51 "--dump-forest dumps the reconstructed forest\n"
52 "--trace-calls printf function call trace\n"
53 "--share-code force jit to produce shared code\n"
54 "--print-vtable print the VTable of all used classes\n"
55 "--workers n maximum number of worker threads\n"
56 "--stabs write stabs debug information\n"
57 "--dwarf write dwarf2 debug information\n"
58 "--dwarf-plus write extended dwarf2 debug information\n"
59 "--stats print statistics about the jit operations\n"
60 "--compile cname compile methods in given class (namespace.name[:methodname])\n"
61 "--ncompile num compile methods num times (default: 1000)\n"
62 "--debug name insert a breakpoint at the start of method name\n"
63 "--help print this help message\n");
69 main (int argc, char *argv [])
72 MonoAssembly *assembly;
74 int compile_times = 1000;
75 char *compile_class = NULL;
77 gboolean testjit = FALSE;
78 int stack, verbose = FALSE;
80 mono_end_of_stack = &stack; /* a pointer to a local variable is always < BP */
85 for (i = 1; i < argc && argv [i][0] == '-'; i++){
86 if (strcmp (argv [i], "--help") == 0) {
88 } else if (strcmp (argv [i], "-d") == 0) {
90 mono_jit_dump_asm = TRUE;
91 mono_jit_dump_forest = TRUE;
92 } else if (strcmp (argv [i], "--dump-asm") == 0)
93 mono_jit_dump_asm = TRUE;
94 else if (strcmp (argv [i], "--dump-forest") == 0)
95 mono_jit_dump_forest = TRUE;
96 else if (strcmp (argv [i], "--trace-calls") == 0)
97 mono_jit_trace_calls = TRUE;
98 else if (strcmp (argv [i], "--share-code") == 0)
99 mono_jit_share_code = TRUE;
100 else if (strcmp (argv [i], "--print-vtable") == 0)
101 mono_print_vtable = TRUE;
102 else if (strcmp (argv [i], "--debug") == 0) {
103 MonoMethodDesc *desc = mono_method_desc_new (argv [++i], FALSE);
105 g_error ("Invalid method name '%s'", argv [i]);
106 mono_debug_methods = g_list_append (mono_debug_methods, desc);
107 } else if (strcmp (argv [i], "--count") == 0) {
108 compile_times = atoi (argv [++i]);
109 } else if (strcmp (argv [i], "--workers") == 0) {
110 mono_worker_threads = atoi (argv [++i]);
111 if (mono_worker_threads < 1)
112 mono_worker_threads = 1;
113 } else if (strcmp (argv [i], "--compile") == 0) {
114 compile_class = argv [++i];
115 } else if (strcmp (argv [i], "--ncompile") == 0) {
116 compile_times = atoi (argv [++i]);
117 } else if (strcmp (argv [i], "--stats") == 0) {
118 memset (&mono_jit_stats, 0, sizeof (MonoJitStats));
119 mono_jit_stats.enabled = TRUE;
120 } else if (strcmp (argv [i], "--stabs") == 0) {
121 if (mono_debug_handle)
122 g_error ("You can use either --stabs or --dwarf, but not both.");
123 mono_debug_handle = mono_debug_open_file ("", MONO_DEBUG_FORMAT_STABS);
124 } else if (strcmp (argv [i], "--dwarf") == 0) {
125 if (mono_debug_handle)
126 g_error ("You can use either --stabs or --dwarf, but not both.");
127 mono_debug_handle = mono_debug_open_file ("", MONO_DEBUG_FORMAT_DWARF2);
128 } else if (strcmp (argv [i], "--dwarf-plus") == 0) {
129 if (mono_debug_handle)
130 g_error ("You can use either --stabs or --dwarf, but not both.");
131 mono_debug_handle = mono_debug_open_file ("", MONO_DEBUG_FORMAT_DWARF2_PLUS);
132 } else if (strcmp (argv [i], "--verbose") == 0) {
143 domain = mono_jit_init (file);
145 error = mono_verify_corlib ();
147 fprintf (stderr, "Corlib not in sync with this runtime: %s\n", error);
151 assembly = mono_domain_assembly_open (domain, file);
153 fprintf (stderr, "Can not open image %s\n", file);
158 mono_jit_assembly (assembly);
159 } else if (compile_class) {
160 const char *cmethod = strrchr (compile_class, ':');
167 MonoMethodDesc *mdesc;
169 mdesc = mono_method_desc_new (compile_class, FALSE);
171 g_error ("Invalid method name '%s'", compile_class);
172 m = mono_method_desc_search_in_image (mdesc, assembly->image);
174 g_error ("Cannot find method '%s'", compile_class);
175 for (j = 0; j < compile_times; ++j) {
176 code = arch_compile_method (m);
180 cname = strrchr (compile_class, '.');
184 cname = compile_class;
185 compile_class = (char *)"";
187 class = mono_class_from_name (assembly->image, compile_class, cname);
189 g_error ("Cannot find class %s.%s", compile_class, cname);
190 mono_class_init (class);
191 for (j = 0; j < compile_times; ++j) {
192 for (i = 0; i < class->method.count; ++i) {
193 if (class->methods [i]->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)
195 if (class->methods [i]->flags & METHOD_ATTRIBUTE_ABSTRACT)
198 g_print ("Compiling: %s\n", class->methods [i]->name);
199 code = arch_compile_method (class->methods [i]);
206 * skip the program name from the args.
209 retval = mono_jit_exec (domain, assembly, argc - i, argv + i);
210 printf ("RESULT: %d\n", retval);
213 mono_jit_cleanup (domain);