jit-debug-sample2 1.6 KB

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