~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/DebuggingService.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
                static IConsole console;
64
64
                static DebugExecutionHandlerFactory executionHandlerFactory;
65
65
                
 
66
                static string oldLayout;
 
67
                
66
68
                static DebuggerEngine currentEngine;
67
69
                static DebuggerSession session;
68
70
                static Backtrace currentBacktrace;
192
194
                
193
195
                public static void ShowValueVisualizer (ObjectValue val)
194
196
                {
195
 
                        ValueVisualizerDialog dlg = new ValueVisualizerDialog ();
196
 
                        try {
197
 
                                dlg.Show (val);
198
 
                                dlg.Run ();
199
 
                        } finally {
200
 
                                dlg.Destroy ();
201
 
                        }
 
197
                        var dlg = new ValueVisualizerDialog ();
 
198
                        dlg.Show (val);
 
199
                        MessageService.ShowCustomDialog (dlg);
202
200
                }
203
201
                
204
202
                public static bool ShowBreakpointProperties (Breakpoint bp, bool editNew)
284
282
                        ExceptionInfo val = CurrentFrame.GetException ();
285
283
                        if (val != null) {
286
284
                                ExceptionCaughtDialog dlg = new ExceptionCaughtDialog (val);
 
285
                                dlg.TransientFor = IdeApp.Workbench.RootWindow;
 
286
                                MessageService.PlaceDialog (dlg, IdeApp.Workbench.RootWindow);
287
287
                                dlg.Show ();
288
288
                        }
289
289
                }
305
305
                        session.TypeResolverHandler = ResolveType;
306
306
                        session.BreakpointTraceHandler = BreakpointTraceHandler;
307
307
                        session.GetExpressionEvaluator = OnGetExpressionEvaluator;
 
308
                        session.ConnectionDialogCreator = delegate {
 
309
                                return new GtkConnectionDialog ();
 
310
                        };
308
311
 
309
312
                        console.CancelRequested += OnCancelRequested;
310
313
                        
311
 
                        if (DebugSessionStarted != null)
312
 
                                DebugSessionStarted (null, EventArgs.Empty);
 
314
                        DispatchService.GuiDispatch (delegate {
 
315
                                if (DebugSessionStarted != null)
 
316
                                        DebugSessionStarted (null, EventArgs.Empty);
 
317
                                NotifyLocationChanged ();
 
318
                        });
313
319
 
314
 
                        NotifyLocationChanged ();
315
320
                }
316
321
                
317
322
                static void Cleanup ()
318
323
                {
 
324
                        if (oldLayout != null) {
 
325
                                string layout = oldLayout;
 
326
                                oldLayout = null;
 
327
                                // Dispatch asynchronously to avoid start/stop races
 
328
                                DispatchService.GuiSyncDispatch (delegate {
 
329
                                        if (IdeApp.Workbench.CurrentLayout == "Debug")
 
330
                                                IdeApp.Workbench.CurrentLayout = layout;
 
331
                                });
 
332
                        }
 
333
                        
319
334
                        currentBacktrace = null;
320
335
                        
321
336
                        if (!IsDebugging)
339
354
                        // Dispose the session at the end, since it may take a while.
340
355
                        DebuggerSession oldSession = session;
341
356
                        session = null;
342
 
 
343
 
                        if (StoppedEvent != null)
344
 
                                StoppedEvent (null, new EventArgs ());
 
357
                        
 
358
                        DispatchService.GuiDispatch (delegate {
 
359
                                if (StoppedEvent != null)
 
360
                                        StoppedEvent (null, new EventArgs ());
 
361
                        });
345
362
                        
346
363
                        if (console != null) {
347
364
                                console.Dispose ();
372
389
                        }
373
390
                }
374
391
 
 
392
                public static bool IsPaused {
 
393
                        get {
 
394
                                return IsDebugging && !IsRunning && currentBacktrace != null;
 
395
                        }
 
396
                }
 
397
 
375
398
                public static void Pause ()
376
399
                {
377
400
                        session.Stop ();
454
477
                                        throw new InvalidOperationException ("Unsupported command: " + cmd);
455
478
                        }
456
479
                        
 
480
                        if (session != null)
 
481
                                throw new InvalidOperationException ("A debugger session is already started");
 
482
 
457
483
                        DebuggerStartInfo startInfo = factory.CreateDebuggerStartInfo (cmd);
458
484
                        startInfo.UseExternalConsole = c is ExternalConsole;
459
485
                        startInfo.CloseExternalConsoleOnExit = c.CloseOnDispose;
460
486
                        currentEngine = factory;
461
487
                        session = factory.CreateSession ();
462
488
                        session.ExceptionHandler = ExceptionHandler;
463
 
                        session.Initialize ();
464
 
                        console = c;
 
489
                        
 
490
                        // When using an external console, create a new internal console which will be used
 
491
                        // to show the debugger log
 
492
                        if (startInfo.UseExternalConsole)
 
493
                                console = (IConsole) IdeApp.Workbench.ProgressMonitors.GetRunProgressMonitor ();
 
494
                        else
 
495
                                console = c;
465
496
                        
466
497
                        SetupSession ();
467
 
 
 
498
                        
 
499
                        // Dispatch synchronously to avoid start/stop races
 
500
                        DispatchService.GuiSyncDispatch (delegate {
 
501
                                oldLayout = IdeApp.Workbench.CurrentLayout;
 
502
                                IdeApp.Workbench.CurrentLayout = "Debug";
 
503
                        });
 
504
                        
468
505
                        try {
469
506
                                session.Run (startInfo, GetUserOptions ());
470
507
                        } catch {
475
512
                
476
513
                static bool ExceptionHandler (Exception ex)
477
514
                {
 
515
                        LoggingService.LogError ("Error in debugger", ex);
478
516
                        Gtk.Application.Invoke (delegate {
479
517
                                if (ex is DebuggerException)
480
518
                                        MessageService.ShowError (ex.Message);
546
584
                {
547
585
                        try {
548
586
                                Console.WriteLine ("OnTargetEvent, type - {0}", args.Type);
549
 
                                if (args.Type != TargetEventType.TargetExited) {
550
 
                                        SetCurrentBacktrace (args.Backtrace);
551
 
                                }
552
587
 
553
588
                                switch (args.Type) {
554
589
                                        case TargetEventType.TargetExited:
556
591
                                                break;
557
592
                                        case TargetEventType.TargetSignaled:
558
593
                                        case TargetEventType.TargetStopped:
559
 
                                        case TargetEventType.TargetRunning:
560
594
                                        case TargetEventType.TargetHitBreakpoint:
561
595
                                        case TargetEventType.TargetInterrupted:
562
596
                                        case TargetEventType.UnhandledException:
563
597
                                        case TargetEventType.ExceptionThrown:
 
598
                                                SetCurrentBacktrace (args.Backtrace);
564
599
                                                NotifyPaused ();
565
600
                                                NotifyException (args);
566
601
                                                break;
733
768
                {
734
769
                        if (currentBacktrace != null) {
735
770
                                var sf = GetCurrentVisibleFrame ();
736
 
                                if (!string.IsNullOrEmpty (sf.SourceLocation.Filename) && System.IO.File.Exists (sf.SourceLocation.Filename) && sf.SourceLocation.Line != -1) {
737
 
                                        Document document = IdeApp.Workbench.OpenDocument (sf.SourceLocation.Filename, sf.SourceLocation.Line, 1, true, false);
 
771
                                if (!string.IsNullOrEmpty (sf.SourceLocation.FileName) && System.IO.File.Exists (sf.SourceLocation.FileName) && sf.SourceLocation.Line != -1) {
 
772
                                        Document document = IdeApp.Workbench.OpenDocument (sf.SourceLocation.FileName, sf.SourceLocation.Line, 1, OpenDocumentOptions.BringToFront);
738
773
                                        OnDisableConditionalCompilation (new DocumentEventArgs (document));
739
774
                                }
740
775
                        }
837
872
                
838
873
                static string ResolveType (string identifier, SourceLocation location)
839
874
                {
840
 
                        Document doc = IdeApp.Workbench.GetDocument (location.Filename);
 
875
                        Document doc = IdeApp.Workbench.GetDocument (location.FileName);
841
876
                        if (doc != null) {
842
877
                                ITextEditorResolver textEditorResolver = doc.GetContent <ITextEditorResolver> ();
843
878
                                if (textEditorResolver != null) {
844
 
                                        ResolveResult rr = textEditorResolver.GetLanguageItem (doc.TextEditor.GetPositionFromLineColumn (location.Line, 1), identifier);
 
879
                                        ResolveResult rr = textEditorResolver.GetLanguageItem (doc.Editor.Document.LocationToOffset (location.Line, 1), identifier);
845
880
                                        NamespaceResolveResult ns = rr as NamespaceResolveResult;
846
881
                                        if (ns != null)
847
882
                                                return ns.Namespace;
907
942
                        return h.Execute (command, console);
908
943
                }
909
944
        }
 
945
        
 
946
        internal class GtkConnectionDialog : IConnectionDialog
 
947
        {
 
948
                bool disposed;
 
949
                Gtk.Dialog dialog;
 
950
                Gtk.Label label;
 
951
                
 
952
                public event EventHandler UserCancelled;
 
953
                
 
954
                string DefaultListenMessage {
 
955
                        get { return GettextCatalog.GetString ("Waiting for debugger to connect..."); }
 
956
                }
 
957
 
 
958
                public void SetMessage (DebuggerStartInfo dsi, string message, bool listening, int attemptNumber)
 
959
                {
 
960
                        if (disposed)
 
961
                                return;
 
962
                        
 
963
                        if (string.IsNullOrEmpty (message))
 
964
                                message = DefaultListenMessage;
 
965
                        
 
966
                        if (dialog == null) {
 
967
                                Gtk.Application.Invoke (delegate {
 
968
                                        if (disposed)
 
969
                                                return;
 
970
                                        RunDialog (message);
 
971
                                });
 
972
                        } else {
 
973
                                Gtk.Application.Invoke (delegate {
 
974
                                        if (disposed)
 
975
                                                return;
 
976
                                        if (label != null)
 
977
                                                label.Text = message;
 
978
                                });
 
979
                        }
 
980
                }
 
981
                
 
982
                void RunDialog (string message)
 
983
                {
 
984
                        if (disposed)
 
985
                                return;
 
986
                        
 
987
                        dialog = new Gtk.Dialog () {
 
988
                                Title = "Waiting for debugger"
 
989
                        };
 
990
                        
 
991
                        var label = new Gtk.Alignment (0.5f, 0.5f, 1f, 1f) {
 
992
                                Child = new Gtk.Label (message),
 
993
                                BorderWidth = 12
 
994
                        };
 
995
                        dialog.VBox.PackStart (label);
 
996
                        label.ShowAll ();
 
997
                        
 
998
                        dialog.AddButton ("Cancel", Gtk.ResponseType.Cancel);
 
999
                        
 
1000
                        int response = MonoDevelop.Ide.MessageService.ShowCustomDialog (dialog);
 
1001
                        dialog.Destroy ();
 
1002
                        dialog = null;
 
1003
                        
 
1004
                        if (!disposed && response != (int) Gtk.ResponseType.Ok && UserCancelled != null) {
 
1005
                                UserCancelled (null, null);
 
1006
                        }
 
1007
                }
 
1008
 
 
1009
                public void Dispose ()
 
1010
                {
 
1011
                        if (disposed)
 
1012
                                return;
 
1013
                        disposed = true;
 
1014
                        
 
1015
                        if (dialog != null) {
 
1016
                                Gtk.Application.Invoke (delegate {
 
1017
                                        if (dialog != null)
 
1018
                                                dialog.Respond (Gtk.ResponseType.Ok);
 
1019
                                });
 
1020
                        }
 
1021
                }
 
1022
        }
910
1023
}