Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / Mono.Debugger.Soft / Mono.Debugger.Soft / VirtualMachine.cs
index 61c284dfcfcdef30048998733af22ab625bc2607..cb2cafdb71401b7669d1ca28d17335594dd67f64 100644 (file)
@@ -124,7 +124,7 @@ namespace Mono.Debugger.Soft
                                conn.VM_Resume ();
                        } catch (CommandException ex) {
                                if (ex.ErrorCode == ErrorCode.NOT_SUSPENDED)
-                                       throw new InvalidOperationException ("The vm is not suspended.");
+                                       throw new VMNotSuspendedException ();
                                else
                                        throw;
                        }
@@ -137,7 +137,7 @@ namespace Mono.Debugger.Soft
                public void Detach () {
                        conn.VM_Dispose ();
                        conn.Close ();
-                       notify_vm_event (EventType.VMDisconnect, SuspendPolicy.None, 0, 0, null);
+                       notify_vm_event (EventType.VMDisconnect, SuspendPolicy.None, 0, 0, null, 0);
                }
 
                [Obsolete ("This method was poorly named; use the Detach() method instead")]
@@ -227,10 +227,14 @@ namespace Mono.Debugger.Soft
                }
 
                public void EnableEvents (params EventType[] events) {
+                       EnableEvents (events, SuspendPolicy.All);
+               }
+
+               public void EnableEvents (EventType[] events, SuspendPolicy suspendPolicy) {
                        foreach (EventType etype in events) {
                                if (etype == EventType.Breakpoint)
                                        throw new ArgumentException ("Breakpoint events cannot be requested using EnableEvents", "events");
-                               conn.EnableEvent (etype, SuspendPolicy.All, null);
+                               conn.EnableEvent (etype, suspendPolicy, null);
                        }
                }
 
@@ -290,7 +294,7 @@ namespace Mono.Debugger.Soft
                        case ErrorCode.INVALID_FRAMEID:
                                throw new InvalidStackFrameException ();
                        case ErrorCode.NOT_SUSPENDED:
-                               throw new InvalidOperationException ("The vm is not suspended.");
+                               throw new VMNotSuspendedException ();
                        case ErrorCode.NOT_IMPLEMENTED:
                                throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
                        case ErrorCode.ABSENT_INFORMATION:
@@ -315,7 +319,7 @@ namespace Mono.Debugger.Soft
                        root_domain = GetDomain (root_domain_id);
                }
 
-               internal void notify_vm_event (EventType evtype, SuspendPolicy spolicy, int req_id, long thread_id, string vm_uri) {
+               internal void notify_vm_event (EventType evtype, SuspendPolicy spolicy, int req_id, long thread_id, string vm_uri, int exit_code) {
                        //Console.WriteLine ("Event: " + evtype + "(" + vm_uri + ")");
 
                        switch (evtype) {
@@ -327,7 +331,7 @@ namespace Mono.Debugger.Soft
                                queue_event_set (new EventSet (this, spolicy, new Event[] { new VMStartEvent (vm, req_id, thread_id) }));
                                break;
                        case EventType.VMDeath:
-                               queue_event_set (new EventSet (this, spolicy, new Event[] { new VMDeathEvent (vm, req_id) }));
+                               queue_event_set (new EventSet (this, spolicy, new Event[] { new VMDeathEvent (vm, req_id, exit_code) }));
                                break;
                        case EventType.VMDisconnect:
                                queue_event_set (new EventSet (this, spolicy, new Event[] { new VMDisconnectEvent (vm, req_id) }));
@@ -620,10 +624,10 @@ namespace Mono.Debugger.Soft
 
                                switch (ei.EventType) {
                                case EventType.VMStart:
-                                       vm.notify_vm_event (EventType.VMStart, suspend_policy, req_id, thread_id, null);
+                                       vm.notify_vm_event (EventType.VMStart, suspend_policy, req_id, thread_id, null, 0);
                                        break;
                                case EventType.VMDeath:
-                                       vm.notify_vm_event (EventType.VMDeath, suspend_policy, req_id, thread_id, null);
+                                       vm.notify_vm_event (EventType.VMDeath, suspend_policy, req_id, thread_id, null, ei.ExitCode);
                                        break;
                                case EventType.ThreadStart:
                                        l.Add (new ThreadStartEvent (vm, req_id, id));
@@ -677,13 +681,13 @@ namespace Mono.Debugger.Soft
                }
 
                public void VMDisconnect (int req_id, long thread_id, string vm_uri) {
-                       vm.notify_vm_event (EventType.VMDisconnect, SuspendPolicy.None, req_id, thread_id, vm_uri);
+                       vm.notify_vm_event (EventType.VMDisconnect, SuspendPolicy.None, req_id, thread_id, vm_uri, 0);
         }
     }
 
-       internal class CommandException : Exception {
+       public class CommandException : Exception {
 
-               public CommandException (ErrorCode error_code) : base ("Debuggee returned error code " + error_code + ".") {
+               internal CommandException (ErrorCode error_code) : base ("Debuggee returned error code " + error_code + ".") {
                        ErrorCode = error_code;
                }
 
@@ -691,4 +695,11 @@ namespace Mono.Debugger.Soft
                        get; set;
                }
        }
+
+       public class VMNotSuspendedException : InvalidOperationException
+       {
+               public VMNotSuspendedException () : base ("The vm is not suspended.")
+               {
+               }
+       }
 }