Some sample code
[mono.git] / doc / jit-debug-sample2
1 * A debugging session using a symbol file which has been created by MCS.
2
3         Let's assume we have the following C# application which we want to debug:
4
5         <pre>
6         using System;
7
8         public class Foo
9         {
10                 public struct MyStruct {
11                         int a;
12                         long b;
13                         double c;
14                 }
15
16                 public static void Main ()
17                 {
18                         Int32 value = 5;
19                         long test = 512;
20
21                         MyStruct my_struct;
22                         my_struct.a = 5;
23                         my_struct.b = test;
24                         my_struct.c = 23323.5235;
25                 }
26         }
27         </pre>
28
29         First of all, we need to compile it with MCS, assemble the generated .s file and
30         create the .il files for all referenced assemblies which were not compiled with MCS:
31
32         <pre>
33         $ mcs -g ./Foo.cs
34         $ as -o Foo-debug.o Foo-debug.s
35         $ monodis /home/export/martin/MONO-LINUX/lib/corlib.dll > corlib.il
36         </pre>
37
38         Now we can start the JIT in the debugger:
39
40         <pre>
41         $ gdb ~/monocvs/mono/mono/jit/mono
42         (gdb) r --dwarf-plus --debug Foo:Main ./Foo.exe
43         Starting program: /home/martin/monocvs/mono/mono/jit/mono --dwarf-plus --debug Foo:Main ./Foo.exe
44         Program received signal SIGTRAP, Trace/breakpoint trap.
45         0x081e8681 in ?? ()
46         (gdb) call mono_debug_make_symbols ()
47         (gdb) add-symbol-file Foo-debug.o
48         (gdb) add-symbol-file /tmp/corlib.o
49 `       (gdb) frame
50         #0  Main () at ./Foo.cs:11
51         11              public static void Main ()
52         (gdb) n
53         Main () at ./Foo.cs:13
54         13                      Int32 value = 5;
55         (gdb)
56         14                      long test = 512;
57         (gdb)
58         17                      my_struct.a = 5;
59         (gdb)
60         18                      my_struct.b = test;
61         (gdb)
62         19                      my_struct.c = 23323.5235;
63         (gdb)
64         20              }
65         (gdb) info locals
66         value = 5
67         test = 512
68         my_struct = { a = 5, b = 512, c = 23323.5235 }
69         </pre>
70