~ubuntu-branches/ubuntu/natty/monodevelop/natty

« back to all changes in this revision

Viewing changes to src/core/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-01-07 19:06:58 UTC
  • mto: (1.6.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 46.
  • Revision ID: james.westby@ubuntu.com-20100107190658-z9z95lgk4kwfes7p
ImportĀ upstreamĀ versionĀ 2.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
                ThreadInfo activeThread;
56
56
                BreakEventHitHandler customBreakpointHitHandler;
57
57
                ExceptionHandler exceptionHandler;
 
58
                DebuggerSessionOptions options;
58
59
                
59
60
                ProcessInfo[] currentProcesses;
60
61
                
69
70
                public event EventHandler<TargetEventArgs> TargetExceptionThrown;
70
71
                public event EventHandler<TargetEventArgs> TargetUnhandledException;
71
72
                
 
73
                public event EventHandler<BusyStateEventArgs> BusyStateChanged;
 
74
                
72
75
                public DebuggerSession ()
73
76
                {
 
77
                        UseOperationThread = true;
74
78
                        frontend = new InternalDebuggerSession (this);
75
79
                }
76
80
                
141
145
                        }
142
146
                }
143
147
                
144
 
                public void Run (DebuggerStartInfo startInfo)
145
 
                {
146
 
                        lock (slock) {
147
 
                                OnRunning ();
148
 
                                try {
149
 
                                        OnRun (startInfo);
150
 
                                } catch (Exception ex) {
151
 
                                        ForceStop ();
152
 
                                        if (!HandleException (ex))
153
 
                                                throw;
154
 
                                }
155
 
                        }
156
 
                }
157
 
                
158
 
                public void AttachToProcess (ProcessInfo proc)
159
 
                {
160
 
                        lock (slock) {
161
 
                                OnRunning ();
162
 
                                try {
163
 
                                        OnAttachToProcess (proc.Id);
164
 
                                        attached = true;
165
 
                                } catch (Exception ex) {
166
 
                                        ForceStop ();
167
 
                                        if (!HandleException (ex))
168
 
                                                throw;
169
 
                                }
 
148
                void Dispatch (Action action)
 
149
                {
 
150
                        if (UseOperationThread) {
 
151
                                System.Threading.ThreadPool.QueueUserWorkItem (delegate {
 
152
                                        lock (slock) {
 
153
                                                action ();
 
154
                                        }
 
155
                                });
 
156
                        } else {
 
157
                                lock (slock) {
 
158
                                        action ();
 
159
                                }
 
160
                        }
 
161
                }
 
162
                
 
163
                public void Run (DebuggerStartInfo startInfo, DebuggerSessionOptions options)
 
164
                {
 
165
                        if (startInfo == null)
 
166
                                throw new ArgumentNullException ("startInfo");
 
167
                        if (options == null)
 
168
                                throw new ArgumentNullException ("options");
 
169
                        
 
170
                        lock (slock) {
 
171
                                this.options = options;
 
172
                                OnRunning ();
 
173
                                Dispatch (delegate {
 
174
                                        try {
 
175
                                                OnRun (startInfo);
 
176
                                        } catch (Exception ex) {
 
177
                                                ForceExit ();
 
178
                                                if (!HandleException (ex))
 
179
                                                        throw;
 
180
                                        }
 
181
                                });
 
182
                        }
 
183
                }
 
184
                
 
185
                public void AttachToProcess (ProcessInfo proc, DebuggerSessionOptions options)
 
186
                {
 
187
                        if (proc == null)
 
188
                                throw new ArgumentNullException ("proc");
 
189
                        if (options == null)
 
190
                                throw new ArgumentNullException ("options");
 
191
                        
 
192
                        lock (slock) {
 
193
                                this.options = options;
 
194
                                OnRunning ();
 
195
                                Dispatch (delegate {
 
196
                                        try {
 
197
                                                OnAttachToProcess (proc.Id);
 
198
                                                attached = true;
 
199
                                        } catch (Exception ex) {
 
200
                                                ForceExit ();
 
201
                                                if (!HandleException (ex))
 
202
                                                        throw;
 
203
                                        }
 
204
                                });
170
205
                        }
171
206
                }
172
207
                
213
248
                {
214
249
                        lock (slock) {
215
250
                                OnRunning ();
216
 
                                try {
217
 
                                        OnNextLine ();
218
 
                                } catch (Exception ex) {
219
 
                                        ForceStop ();
220
 
                                        if (!HandleException (ex))
221
 
                                                throw;
222
 
                                }
 
251
                                Dispatch (delegate {
 
252
                                        try {
 
253
                                                OnNextLine ();
 
254
                                        } catch (Exception ex) {
 
255
                                                ForceStop ();
 
256
                                                if (!HandleException (ex))
 
257
                                                        throw;
 
258
                                        }
 
259
                                });
223
260
                        }
224
261
                }
225
262
 
227
264
                {
228
265
                        lock (slock) {
229
266
                                OnRunning ();
230
 
                                try {
231
 
                                        OnStepLine ();
232
 
                                } catch (Exception ex) {
233
 
                                        ForceStop ();
234
 
                                        if (!HandleException (ex))
235
 
                                                throw;
236
 
                                }
 
267
                                Dispatch (delegate {
 
268
                                        try {
 
269
                                                OnStepLine ();
 
270
                                        } catch (Exception ex) {
 
271
                                                ForceStop ();
 
272
                                                if (!HandleException (ex))
 
273
                                                        throw;
 
274
                                        }
 
275
                                });
237
276
                        }
238
277
                }
239
278
                
241
280
                {
242
281
                        lock (slock) {
243
282
                                OnRunning ();
244
 
                                try {
245
 
                                        OnNextInstruction ();
246
 
                                } catch (Exception ex) {
247
 
                                        ForceStop ();
248
 
                                        if (!HandleException (ex))
249
 
                                                throw;
250
 
                                }
 
283
                                Dispatch (delegate {
 
284
                                        try {
 
285
                                                OnNextInstruction ();
 
286
                                        } catch (Exception ex) {
 
287
                                                ForceStop ();
 
288
                                                if (!HandleException (ex))
 
289
                                                        throw;
 
290
                                        }
 
291
                                });
251
292
                        }
252
293
                }
253
294
 
255
296
                {
256
297
                        lock (slock) {
257
298
                                OnRunning ();
258
 
                                try {
259
 
                                        OnStepInstruction ();
260
 
                                } catch (Exception ex) {
261
 
                                        ForceStop ();
262
 
                                        if (!HandleException (ex))
263
 
                                                throw;
264
 
                                }
 
299
                                Dispatch (delegate {
 
300
                                        try {
 
301
                                                OnStepInstruction ();
 
302
                                        } catch (Exception ex) {
 
303
                                                ForceStop ();
 
304
                                                if (!HandleException (ex))
 
305
                                                        throw;
 
306
                                        }
 
307
                                });
265
308
                        }
266
309
                }
267
310
 
269
312
                {
270
313
                        lock (slock) {
271
314
                                OnRunning ();
272
 
                                try {
273
 
                                        OnFinish ();
274
 
                                } catch (Exception ex) {
275
 
                                        ForceStop ();
276
 
                                        if (!HandleException (ex))
277
 
                                                throw;
278
 
                                }
 
315
                                Dispatch (delegate {
 
316
                                        try {
 
317
                                                OnFinish ();
 
318
                                        } catch (Exception ex) {
 
319
                                                ForceExit ();
 
320
                                                if (!HandleException (ex))
 
321
                                                        throw;
 
322
                                        }
 
323
                                });
279
324
                        }
280
325
                }
281
326
                
425
470
                {
426
471
                        return breakpoints.TryGetValue (be, out handle);
427
472
                }
 
473
                
 
474
                public DebuggerSessionOptions Options {
 
475
                        get { return options; }
 
476
                }
 
477
 
 
478
                public EvaluationOptions EvaluationOptions {
 
479
                        get { return options.EvaluationOptions; }
 
480
                }
428
481
 
429
482
                public void Continue ()
430
483
                {
431
484
                        lock (slock) {
432
485
                                OnRunning ();
433
 
                                try {
434
 
                                        OnContinue ();
435
 
                                } catch (Exception ex) {
436
 
                                        ForceStop ();
437
 
                                        if (!HandleException (ex))
438
 
                                                throw;
439
 
                                }
 
486
                                Dispatch (delegate {
 
487
                                        try {
 
488
                                                OnContinue ();
 
489
                                        } catch (Exception ex) {
 
490
                                                ForceStop ();
 
491
                                                if (!HandleException (ex))
 
492
                                                        throw;
 
493
                                        }
 
494
                                });
440
495
                        }
441
496
                }
442
497
 
443
498
                public void Stop ()
444
499
                {
445
 
                        lock (slock) {
 
500
                        Dispatch (delegate {
446
501
                                try {
447
502
                                        OnStop ();
448
503
                                } catch (Exception ex) {
449
504
                                        if (!HandleException (ex))
450
505
                                                throw;
451
506
                                }
452
 
                        }
 
507
                        });
453
508
                }
454
509
 
455
510
                public void Exit ()
456
511
                {
457
 
                        lock (slock) {
 
512
                        Dispatch (delegate {
458
513
                                try {
459
514
                                        OnExit ();
460
515
                                } catch (Exception ex) {
461
516
                                        if (!HandleException (ex))
462
517
                                                throw;
463
518
                                }
464
 
                        }
 
519
                        });
465
520
                }
466
521
 
467
522
                public bool IsRunning {
468
523
                        get {
469
 
                                lock (slock) {
470
 
                                        return isRunning;
471
 
                                }
 
524
                                return isRunning;
472
525
                        }
473
526
                }
474
527
                
475
 
                public ProcessInfo[] GetPocesses ()
 
528
                public ProcessInfo[] GetProcesses ()
476
529
                {
477
530
                        lock (slock) {
478
531
                                if (currentProcesses == null) {
479
 
                                        currentProcesses = OnGetPocesses ();
 
532
                                        currentProcesses = OnGetProcesses ();
480
533
                                        foreach (ProcessInfo p in currentProcesses)
481
534
                                                p.Attach (this);
482
535
                                }
535
588
                        OnTargetEvent (args);
536
589
                }
537
590
                
 
591
                void ForceExit ()
 
592
                {
 
593
                        TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetExited);
 
594
                        OnTargetEvent (args);
 
595
                }
 
596
                
538
597
                internal protected void OnTargetEvent (TargetEventArgs args)
539
598
                {
540
599
                        currentProcesses = null;
545
604
                                args.Thread.Attach (this);
546
605
                                activeThread = args.Thread;
547
606
                        }
 
607
                        if (args.Backtrace != null)
 
608
                                args.Backtrace.Attach (this);
548
609
                        
549
610
                        switch (args.Type) {
550
611
                                case TargetEventType.ExceptionThrown:
634
695
                                if (logWriter != null)
635
696
                                        logWriter (isStderr, text);
636
697
                        }
637
 
                }
638
 
 
 
698
                }
 
699
                
 
700
                internal protected void SetBusyState (BusyStateEventArgs args)
 
701
                {
 
702
                        if (BusyStateChanged != null)
 
703
                                BusyStateChanged (this, args);
 
704
                }
 
705
                
639
706
                internal protected void NotifySourceFileLoaded (string fullFilePath)
640
707
                {
641
708
                        lock (breakpoints) {
712
779
                        }
713
780
                }
714
781
                
 
782
                /// <summary>
 
783
                /// When set, operations such as OnRun, OnAttachToProcess, OnStepLine, etc, are run in
 
784
                /// a background thread, so it will not block the caller of the corresponding public methods.
 
785
                /// </summary>
 
786
                protected bool UseOperationThread { get; set; }
 
787
                
715
788
                protected abstract void OnRun (DebuggerStartInfo startInfo);
716
789
 
717
790
                protected abstract void OnAttachToProcess (long processId);
756
829
                
757
830
                protected abstract ThreadInfo[] OnGetThreads (long processId);
758
831
                
759
 
                protected abstract ProcessInfo[] OnGetPocesses ();
 
832
                protected abstract ProcessInfo[] OnGetProcesses ();
760
833
                
761
834
                protected abstract Backtrace OnGetThreadBacktrace (long processId, long threadId);
762
835
 
818
891
        }
819
892
 
820
893
        public delegate void OutputWriterDelegate (bool isStderr, string text);
821
 
        
 
894
 
 
895
        public class BusyStateEventArgs: EventArgs
 
896
        {
 
897
                public bool IsBusy { get; internal set; }
 
898
                
 
899
                public string Description { get; internal set; }
 
900
        }
822
901
}