[Mono-devel-list] New tracing functionality.

Miguel de Icaza miguel at ximian.com
Sun Oct 12 17:59:47 EDT 2003


Hello guys,
 
   I have implemented a new tracing functionality for the Mono runtime
to help in debugging, taking bits of advise from the people in the group
over the past few days.

   My objective was to make the command line tracing facility useful,
that is why I decided to not use XML to describe the traces, nor to load
the information from a file.  That can be added later if someone wants
it very badly.

   By default mono --trace will continue to work like it used to do
before.  If you use --trace=EXPRESSION then the new behavior kicks-in.

   The syntax is:

		mono --trace=expr1[,expr2[,exprN]]

   The trace functionality allows you to selectively choose assemblies,
methods, classes or the main program and to exclude them.  There are a
couple of reserved words: `program' and `all'.

	program		- methods in the main  program
	all		- all methods.
	assembly	- methods in the assembly will be included
	M:Type:Name	- method `Name' in `Type' will be traced.
	T:Type		- all methods in `Type'

   You can also restrict the output, using '-expr'.

   So a typical invocation could be:

	mono --trace=program,T:System.String,-M:System.String.Concat

   I would like people to review this before I commit.

Miguel.
	
	
-------------- next part --------------
? autom4te.cache
? budget-plan
? mono-0.24
? mono-pre-0.26
? stamp-h1
? x
? doc/team
? doc/web/bugreports
? doc/web/deploy/index.rss
? doc/web/deploy/mono-build-w32.sh
? doc/web/deploy/mono-build.sh
? doc/web/deploy/team
? mono/a.cs
? mono/b.cs
? mono/x
? mono/io-layer/x
? mono/metadata/.loader.h.swp
? mono/metadata/.reflection.c.swp
? mono/metadata/runtime-patch
? mono/metadata/x
? mono/mini/a.cs
? mono/mini/trace.c
? mono/mini/trace.h
? samples/embed/teste
Index: man/mono.1
===================================================================
RCS file: /cvs/public/mono/man/mono.1,v
retrieving revision 1.27
diff -u -r1.27 mono.1
--- man/mono.1	13 Sep 2003 20:55:29 -0000	1.27
+++ man/mono.1	12 Oct 2003 22:04:34 -0000
@@ -168,9 +168,41 @@
 Inserts a breakpoint on exceptions.  This allows you to debug your
 application with a native debugger when an exception is thrown.
 .TP
-.I "--trace"
-Shows method names as they are invoked.
-
+.I "--trace[=expression]"
+Shows method names as they are invoked.  By default all methods are
+traced. 
+.TP
+The trace can be customized to include or exclude methods, classes or
+assemblies.  A trace expression is a comma separated list of targets,
+each target can be prefixed with a minus sign to turn off a particular
+target.  The words `program' and `all' have special meaning.
+`program' refers to the main program being executed, and `all' means
+all the method calls. 
+.TP
+Assemblies are specified by their name, for example, to trace all
+calls in the System assembly, use:
+.nf
+	mono --trace=System app.exe
+.fi
+Classes are specified with the T: prefix.  For example, to trace all
+calls to the System.String class, use:
+.nf
+	mono --trace=T:System.String app.exe
+.fi
+And individual methods are referenced with the M: prefix, and the
+standar method notation:
+.nf
+	mono --trace=M:System.Console.WriteLine app.exe
+.fi
+As previously noted, various rules can be specified at once:
+.nf
+	mono --trace=T:System.String,T:System.Random app.exe
+.fi
+You can exclude pieces, the next example traces calls to
+System.String except for the System.String:Concat method.
+.nf
+	mono --trace=T:System.String,-M:System.String:Concat
+.fi
 
 .SH ENVIRONMENT VARIABLES
 .TP
Index: mono/mini/Makefile.am
===================================================================
RCS file: /cvs/public/mono/mono/mini/Makefile.am,v
retrieving revision 1.34
diff -u -r1.34 Makefile.am
--- mono/mini/Makefile.am	9 Oct 2003 21:00:27 -0000	1.34
+++ mono/mini/Makefile.am	12 Oct 2003 22:04:34 -0000
@@ -83,6 +83,8 @@
 common_sources = \
 	mini.c		\
 	mini.h		\
+	trace.c		\
+	trace.h		\
 	mini-ops.h	\
 	mini-arch.h	\
 	dominators.c	\
Index: mono/mini/TODO
===================================================================
RCS file: /cvs/public/mono/mono/mini/TODO,v
retrieving revision 1.4
diff -u -r1.4 TODO
--- mono/mini/TODO	15 Sep 2003 10:39:30 -0000	1.4
+++ mono/mini/TODO	12 Oct 2003 22:04:34 -0000
@@ -39,4 +39,14 @@
   unwind tables generated by gcc 3.3. It allways tells the runtime that not all
   callee saved registers are saved, even when the icall is marked with
   MONO_ARCH_SAVE_REGS. This forces the runtime to generate wrapper functions
-  for all icalls, slowing things down greatly.
\ No newline at end of file
+  for all icalls, slowing things down greatly.
+
+Usability
+---------
+
+* Remove the various optimization list of flags description, have an 
+  extra --help-optimizations flag.
+
+* Remove the various graph options, have a separate --help-graph for 
+  that list.
+
Index: mono/mini/driver.c
===================================================================
RCS file: /cvs/public/mono/mono/mini/driver.c,v
retrieving revision 1.31
diff -u -r1.31 driver.c
--- mono/mini/driver.c	6 Oct 2003 15:48:33 -0000	1.31
+++ mono/mini/driver.c	12 Oct 2003 22:04:35 -0000
@@ -510,7 +510,7 @@
 		"    --ncompile N           Number of times to compile METHOD (default: 1)\n"
 		"    --regression           Runs the regression test contained in the assembly\n"
 		"    --print-vtable         Print the vtable of all used classes\n"
-		"    --trace                Enable tracing\n"
+		"    --trace[=EXPR]         Enable tracing, use --help-trace for details\n"
 		"    --compile-all          Compiles all the methods in the assembly\n"
 		"    --breakonex            Inserts a breakpoint on exceptions\n"
 		"    --break METHOD         Inserts a breakpoint at METHOD entry\n"
@@ -540,8 +540,27 @@
 		fprintf (stderr, "                           %-10s %s\n", opt_names [i].name, opt_names [i].desc);
 }
 
+static void
+mini_trace_usage (void)
+{
+	fprintf (stderr,
+		 "Tracing options:\n"
+		 "   --trace[=EXPR]        Trace every call, optional EXPR controls the scope\n"
+		 "\n"
+		 "EXPR is composed of:\n"
+		 "    all                  All assemblies\n"
+		 "    none                 No assemblies\n"
+		 "    program              Entry point assembly\n"
+		 "    assembly             Specifies an assembly\n"
+		 "    M:Type:Method        Specifies a method\n"
+		 "    T:Type               Specifies a type\n"
+		 "    +EXPR                Includes expression\n"
+		 "    -EXPR                Excludes expression\n");
+}
+
 int
-mono_main (int argc, char* argv[]) {
+mono_main (int argc, char* argv[])
+{
 	MainThreadArgs main_args;
 	MonoAssembly *assembly;
 	MonoMethodDesc *desc;
@@ -555,6 +574,7 @@
 	guint32 opt, action = DO_EXEC;
 	MonoGraphOptions mono_graph_options = 0;
 	int mini_verbose = 0;
+	char *trace_options = NULL;
 
 	setlocale (LC_ALL, "");
 	g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
@@ -575,6 +595,9 @@
 		} else if (strcmp (argv [i], "--help") == 0 || strcmp (argv [i], "-h") == 0) {
 			mini_usage ();
 			return 0;
+		} else if (strcmp (argv [i], "--help-trace") == 0){
+			mini_trace_usage ();
+			return 0;
 		} else if (strncmp (argv [i], "--statfile", 10) == 0) {
 			mini_stats_fd = fopen (argv [++i], "w+");
 		} else if (strncmp (argv [i], "--optimize=", 11) == 0) {
@@ -587,7 +610,9 @@
 			count = atoi (argv [++i]);
 			action = DO_BENCH;
 		} else if (strcmp (argv [i], "--trace") == 0) {
-			mono_jit_trace_calls = TRUE;
+			trace_options = "";
+		} else if (strncmp (argv [i], "--trace=", 8) == 0) {
+			trace_options = &argv [i][8];
 		} else if (strcmp (argv [i], "--breakonex") == 0) {
 			mono_break_on_exc = TRUE;
 		} else if (strcmp (argv [i], "--break") == 0) {
@@ -635,7 +660,7 @@
 
 	mono_set_defaults (mini_verbose, opt);
 	domain = mini_init (argv [i]);
-
+	
 	switch (action) {
 	case DO_REGRESSION:
 		if (mini_regression_list (mini_verbose, argc -i, argv + i)) {
@@ -687,6 +712,12 @@
 		fprintf (stderr, "cannot open assembly %s\n", aname);
 		mini_cleanup (domain);
 		return 2;
+	}
+
+	if (trace_options != NULL){
+		mono_jit_trace_calls = mono_trace_parse_options (assembly, trace_options);
+		if (mono_jit_trace_calls == NULL)
+			exit (1);
 	}
 
 	if (enable_debugging)
Index: mono/mini/exceptions-ppc.c
===================================================================
RCS file: /cvs/public/mono/mono/mini/exceptions-ppc.c,v
retrieving revision 1.2
diff -u -r1.2 exceptions-ppc.c
--- mono/mini/exceptions-ppc.c	21 May 2003 17:16:18 -0000	1.2
+++ mono/mini/exceptions-ppc.c	12 Oct 2003 22:04:36 -0000
@@ -917,7 +917,7 @@
 
 	if (!test_only) {
 		MonoContext ctx_cp = *ctx;
-		if (mono_jit_trace_calls)
+		if (mono_jit_trace_calls != NULL)
 			g_print ("EXCEPTION handling: %s\n", mono_object_class (obj)->name);
 		if (!mono_arch_handle_exception (&ctx_cp, obj, TRUE)) {
 			if (mono_break_on_exc)
@@ -978,7 +978,7 @@
 								g_free (trace);
 								return TRUE;
 							}
-							if (mono_jit_trace_calls)
+							if (mono_jit_trace_calls != NULL)
 								g_print ("EXCEPTION: catch found at clause %d of %s\n", i, mono_method_full_name (ji->method, TRUE));
 							MONO_CONTEXT_SET_IP (ctx, ei->handler_start);
 							*((gpointer *)((char *)MONO_CONTEXT_GET_BP (ctx) + ji->exvar_offset)) = obj;
@@ -989,7 +989,7 @@
 						if (!test_only && ei->try_start <= MONO_CONTEXT_GET_IP (ctx) && 
 						    MONO_CONTEXT_GET_IP (ctx) < ei->try_end &&
 						    (ei->flags & MONO_EXCEPTION_CLAUSE_FINALLY)) {
-							if (mono_jit_trace_calls)
+							if (mono_jit_trace_calls != NULL)
 								g_print ("EXCEPTION: finally clause %d of %s\n", i, mono_method_full_name (ji->method, TRUE));
 							call_filter (ctx, ei->handler_start, NULL);
 						}
Index: mono/mini/exceptions-x86.c
===================================================================
RCS file: /cvs/public/mono/mono/mini/exceptions-x86.c,v
retrieving revision 1.16
diff -u -r1.16 exceptions-x86.c
--- mono/mini/exceptions-x86.c	5 Oct 2003 02:52:02 -0000	1.16
+++ mono/mini/exceptions-x86.c	12 Oct 2003 22:04:36 -0000
@@ -993,7 +993,7 @@
 
 	if (!test_only) {
 		MonoContext ctx_cp = *ctx;
-		if (mono_jit_trace_calls)
+		if (mono_jit_trace_calls != NULL)
 			g_print ("EXCEPTION handling: %s\n", mono_object_class (obj)->name);
 		if (!mono_arch_handle_exception (&ctx_cp, obj, TRUE)) {
 			if (mono_break_on_exc)
@@ -1061,7 +1061,7 @@
 								g_free (trace);
 								return TRUE;
 							}
-							if (mono_jit_trace_calls)
+							if (mono_jit_trace_calls != NULL && mono_trace_eval (ji->method))
 								g_print ("EXCEPTION: catch found at clause %d of %s\n", i, mono_method_full_name (ji->method, TRUE));
 							MONO_CONTEXT_SET_IP (ctx, ei->handler_start);
 							jit_tls->lmf = lmf;
@@ -1071,7 +1071,7 @@
 						if (!test_only && ei->try_start <= MONO_CONTEXT_GET_IP (ctx) && 
 						    MONO_CONTEXT_GET_IP (ctx) < ei->try_end &&
 						    (ei->flags & MONO_EXCEPTION_CLAUSE_FINALLY)) {
-							if (mono_jit_trace_calls)
+							if (mono_jit_trace_calls != NULL && mono_trace_eval (ji->method))
 								g_print ("EXCEPTION: finally clause %d of %s\n", i, mono_method_full_name (ji->method, TRUE));
 							call_filter (ctx, ei->handler_start);
 						}
Index: mono/mini/mini-ppc.c
===================================================================
RCS file: /cvs/public/mono/mono/mini/mini-ppc.c,v
retrieving revision 1.8
diff -u -r1.8 mini-ppc.c
--- mono/mini/mini-ppc.c	7 Aug 2003 14:12:28 -0000	1.8
+++ mono/mini/mini-ppc.c	12 Oct 2003 22:04:36 -0000
@@ -2696,7 +2696,7 @@
 	if (cfg->method->save_lmf)
 		max_epilog_size += 128;
 	
-	if (mono_jit_trace_calls)
+	if (mono_jit_trace_calls != NULL)
 		max_epilog_size += 50;
 
 	if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
@@ -2810,7 +2810,7 @@
 		}
 	}
 
-	if (mono_jit_trace_calls)
+	if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
 		code = mono_arch_instrument_prolog (cfg, enter_method, code, TRUE);
 
 	/* load arguments allocated to register from the stack */
@@ -2850,7 +2850,7 @@
 
 	code = cfg->native_code + cfg->code_len;
 
-	if (mono_jit_trace_calls)
+	if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
 		code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
 
 	
Index: mono/mini/mini-sparc.c
===================================================================
RCS file: /cvs/public/mono/mono/mini/mini-sparc.c,v
retrieving revision 1.7
diff -u -r1.7 mini-sparc.c
--- mono/mini/mini-sparc.c	1 Sep 2003 20:07:08 -0000	1.7
+++ mono/mini/mini-sparc.c	12 Oct 2003 22:04:36 -0000
@@ -2585,7 +2585,7 @@
 	if (cfg->method->save_lmf)
 		max_epilog_size += 128;
 	
-	if (mono_jit_trace_calls)
+	if (mono_jit_trace_calls != NULL)
 		max_epilog_size += 50;
 
 	if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
@@ -2699,7 +2699,7 @@
 		}
 	}
 
-	if (mono_jit_trace_calls)
+	if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
 		code = mono_arch_instrument_prolog (cfg, enter_method, code, TRUE);
 
 	/* load arguments allocated to register from the stack */
@@ -2739,7 +2739,7 @@
 
 	code = cfg->native_code + cfg->code_len;
 
-	if (mono_jit_trace_calls)
+	if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
 		code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
 
 	
Index: mono/mini/mini-x86.c
===================================================================
RCS file: /cvs/public/mono/mono/mini/mini-x86.c,v
retrieving revision 1.44
diff -u -r1.44 mini-x86.c
--- mono/mini/mini-x86.c	8 Oct 2003 13:19:39 -0000	1.44
+++ mono/mini/mini-x86.c	12 Oct 2003 22:04:37 -0000
@@ -3129,7 +3129,7 @@
 	if (cfg->method->save_lmf)
 		max_epilog_size += 128;
 	
-	if (mono_jit_trace_calls)
+	if (mono_jit_trace_calls != NULL)
 		max_epilog_size += 50;
 
 	if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
@@ -3237,7 +3237,7 @@
 		}
 	}
 
-	if (mono_jit_trace_calls)
+	if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
 		code = mono_arch_instrument_prolog (cfg, enter_method, code, TRUE);
 
 	/* load arguments allocated to register from the stack */
@@ -3271,7 +3271,7 @@
 
 	code = cfg->native_code + cfg->code_len;
 
-	if (mono_jit_trace_calls)
+	if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
 		code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
 
 	/* the code restoring the registers must be kept in sync with CEE_JMP */
Index: mono/mini/mini.c
===================================================================
RCS file: /cvs/public/mono/mono/mini/mini.c,v
retrieving revision 1.124
diff -u -r1.124 mini.c
--- mono/mini/mini.c	10 Oct 2003 13:08:13 -0000	1.124
+++ mono/mini/mini.c	12 Oct 2003 22:04:38 -0000
@@ -93,7 +93,7 @@
 static guint32 default_opt = MONO_OPT_PEEPHOLE;
 
 guint32 mono_jit_tls_id = -1;
-gboolean mono_jit_trace_calls = FALSE;
+MonoTraceSpec *mono_jit_trace_calls = NULL;
 gboolean mono_break_on_exc = FALSE;
 gboolean mono_compile_aot = FALSE;
 
Index: mono/mini/mini.h
===================================================================
RCS file: /cvs/public/mono/mono/mini/mini.h,v
retrieving revision 1.38
diff -u -r1.38 mini.h
--- mono/mini/mini.h	30 Sep 2003 12:17:48 -0000	1.38
+++ mono/mini/mini.h	12 Oct 2003 22:04:38 -0000
@@ -81,9 +81,10 @@
 typedef struct MonoBasicBlock MonoBasicBlock;
 typedef struct MonoLMF MonoLMF;
 typedef struct MonoSpillInfo MonoSpillInfo;
+typedef struct MonoTraceSpec MonoTraceSpec;
 
 extern guint32 mono_jit_tls_id;
-extern gboolean mono_jit_trace_calls;
+extern MonoTraceSpec *mono_jit_trace_calls;
 extern gboolean mono_break_on_exc;
 extern int mono_exc_esp_offset;
 extern gboolean mono_compile_aot;
@@ -709,5 +710,10 @@
 void      mono_debug_close_method               (MonoCompile *cfg);
 void      mono_debug_open_block                 (MonoCompile *cfg, MonoBasicBlock *bb, guint32 address);
 void      mono_debug_record_line_number         (MonoCompile *cfg, MonoInst *ins, guint32 address);
+
+
+/* Tracing */
+MonoTraceSpec *mono_trace_parse_options         (MonoAssembly *assembly, char *options);
+gboolean       mono_trace_eval                  (MonoMethod *method);
 
 #endif /* __MONO_MINI_H__ */  
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trace.c
Type: text/x-c
Size: 5399 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20031012/1642b1fb/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trace.h
Type: text/x-c-header
Size: 436 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20031012/1642b1fb/attachment-0001.bin 


More information about the Mono-devel-list mailing list