Add exception handlers to MethodBodyMirror
[mono.git] / mcs / class / Mono.Debugger.Soft / Mono.Debugger.Soft / MethodBodyMirror.cs
index c03f4cdb47625e076c12a4e5556013b26e35f6fd..c383005a0d41979d8d92977b7f96d93c4b7091f3 100644 (file)
@@ -4,6 +4,7 @@ using System.Text;
 using Mono.Cecil.Cil;
 using Mono.Cecil.Metadata;
 using System.IO;
+using System.Linq;
 using System.Reflection;
 
 namespace Mono.Debugger.Soft
@@ -11,11 +12,11 @@ namespace Mono.Debugger.Soft
        public class MethodBodyMirror : Mirror
        {
                MethodMirror method;
-               byte[] il;
+               MethodBodyInfo info;
 
-               internal MethodBodyMirror (VirtualMachine vm, MethodMirror method, byte[] il) : base (vm, 0) {
+               internal MethodBodyMirror (VirtualMachine vm, MethodMirror method, MethodBodyInfo info) : base (vm, 0) {
                        this.method = method;
-                       this.il = il;
+                       this.info = info;
                }
 
                public MethodMirror Method {
@@ -24,13 +25,29 @@ namespace Mono.Debugger.Soft
                        }
                }
 
+               public List<ILExceptionHandler> ExceptionHandlers {
+                       get {
+                               vm.CheckProtocolVersion (2, 18);
+                               return info.clauses.Select (c =>
+                               {
+                                       var handler = new ILExceptionHandler (c.try_offset, c.try_length, (ILExceptionHandlerType) c.flags, c.handler_offset, c.handler_length);
+                                       if (c.flags == ExceptionClauseFlags.None)
+                                               handler.CatchType = vm.GetType (c.catch_type_id);
+                                       else if (c.flags == ExceptionClauseFlags.Filter)
+                                               handler.FilterOffset = c.filter_offset;
+
+                                       return handler;
+                               }).ToList ();
+                       }
+               }
+
                public byte[] GetILAsByteArray () {
-                       return il;
+                       return info.il;
                }
 
                public List<ILInstruction> Instructions {
                        get {
-                               return ReadCilBody (new BinaryReader (new MemoryStream (il)), il.Length);
+                               return ReadCilBody (new BinaryReader (new MemoryStream (info.il)), info.il.Length);
                        }
                }