~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/Base/Project/Src/Services/Debugger/DefaultDebugger.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Diagnostics;
 
6
using ICSharpCode.NRefactory;
 
7
using ICSharpCode.SharpDevelop.Gui;
 
8
using ICSharpCode.SharpDevelop.Project;
 
9
 
 
10
namespace ICSharpCode.SharpDevelop.Debugging
 
11
{
 
12
        public class DefaultDebugger : IDebugger
 
13
        {
 
14
                Process attachedProcess = null;
 
15
                
 
16
                public bool IsDebugging {
 
17
                        get {
 
18
                                return attachedProcess != null;
 
19
                        }
 
20
                }
 
21
                
 
22
                public bool IsProcessRunning {
 
23
                        get {
 
24
                                return IsDebugging;
 
25
                        }
 
26
                }
 
27
                
 
28
                /// <inheritdoc/>
 
29
                public bool BreakAtBeginning {
 
30
                        get; set; 
 
31
                }
 
32
                
 
33
                public bool CanDebug(IProject project)
 
34
                {
 
35
                        return true;
 
36
                }
 
37
                
 
38
                public void Start(ProcessStartInfo processStartInfo)
 
39
                {
 
40
                        if (attachedProcess != null) {
 
41
                                return;
 
42
                        }
 
43
                        
 
44
                        OnDebugStarting(EventArgs.Empty);
 
45
                        try {
 
46
                                attachedProcess = new Process();
 
47
                                attachedProcess.StartInfo = processStartInfo;
 
48
                                attachedProcess.Exited += new EventHandler(AttachedProcessExited);
 
49
                                attachedProcess.EnableRaisingEvents = true;
 
50
                                attachedProcess.Start();
 
51
                                OnDebugStarted(EventArgs.Empty);
 
52
                        } catch (Exception) {
 
53
                                OnDebugStopped(EventArgs.Empty);
 
54
                                throw new ApplicationException("Can't execute \"" + processStartInfo.FileName + "\"\n");
 
55
                        }
 
56
                }
 
57
                
 
58
                public void ShowAttachDialog()
 
59
                {
 
60
                }
 
61
                
 
62
                public void Attach(Process process)
 
63
                {
 
64
                }
 
65
                
 
66
                public void Detach()
 
67
                {
 
68
                }
 
69
                
 
70
                void AttachedProcessExited(object sender, EventArgs e)
 
71
                {
 
72
                        attachedProcess.Exited -= new EventHandler(AttachedProcessExited);
 
73
                        attachedProcess.Dispose();
 
74
                        attachedProcess = null;
 
75
                        WorkbenchSingleton.SafeThreadAsyncCall(new Action<EventArgs>(OnDebugStopped),
 
76
                                                               EventArgs.Empty);
 
77
                }
 
78
                
 
79
                public void StartWithoutDebugging(ProcessStartInfo processStartInfo)
 
80
                {
 
81
                        Process.Start(processStartInfo);
 
82
                }
 
83
                
 
84
                public void Stop()
 
85
                {
 
86
                        if (attachedProcess != null) {
 
87
                                attachedProcess.Exited -= new EventHandler(AttachedProcessExited);
 
88
                                attachedProcess.Kill();
 
89
                                attachedProcess.Close();
 
90
                                attachedProcess.Dispose();
 
91
                                attachedProcess = null;
 
92
                        }
 
93
                }
 
94
                
 
95
                // ExecutionControl:
 
96
                
 
97
                public void Break()
 
98
                {
 
99
                        throw new NotSupportedException();
 
100
                }
 
101
                
 
102
                public void Continue()
 
103
                {
 
104
                        throw new NotSupportedException();
 
105
                }
 
106
                // Stepping:
 
107
                
 
108
                public void StepInto()
 
109
                {
 
110
                        throw new NotSupportedException();
 
111
                }
 
112
                
 
113
                public void StepOver()
 
114
                {
 
115
                        throw new NotSupportedException();
 
116
                }
 
117
                
 
118
                public void StepOut()
 
119
                {
 
120
                        throw new NotSupportedException();
 
121
                }
 
122
                
 
123
                /// <summary>
 
124
                /// Gets the current value of the variable as string that can be displayed in tooltips.
 
125
                /// </summary>
 
126
                public string GetValueAsString(string variable)
 
127
                {
 
128
                        return null;
 
129
                }
 
130
                
 
131
                /// <summary>
 
132
                /// Gets the tooltip control that shows the value of given variable.
 
133
                /// Return null if no tooltip is available.
 
134
                /// </summary>
 
135
                public object GetTooltipControl(Location logicalPosition, string variable)
 
136
                {
 
137
                        return null;
 
138
                }
 
139
                
 
140
                public bool CanSetInstructionPointer(string filename, int line, int column)
 
141
                {
 
142
                        return false;
 
143
                }
 
144
                
 
145
                public bool SetInstructionPointer(string filename, int line, int column)
 
146
                {
 
147
                        return false;
 
148
                }
 
149
                
 
150
                
 
151
                public event EventHandler DebugStarted;
 
152
                
 
153
                protected virtual void OnDebugStarted(EventArgs e)
 
154
                {
 
155
                        if (DebugStarted != null) {
 
156
                                DebugStarted(this, e);
 
157
                        }
 
158
                }
 
159
 
 
160
 
 
161
                public event EventHandler IsProcessRunningChanged;
 
162
                
 
163
                protected virtual void OnIsProcessRunningChanged(EventArgs e)
 
164
                {
 
165
                        if (IsProcessRunningChanged != null) {
 
166
                                IsProcessRunningChanged(this, e);
 
167
                        }
 
168
                }
 
169
 
 
170
 
 
171
                public event EventHandler DebugStopped;
 
172
 
 
173
                protected virtual void OnDebugStopped(EventArgs e)
 
174
                {
 
175
                        if (DebugStopped != null) {
 
176
                                DebugStopped(this, e);
 
177
                        }
 
178
                }
 
179
                
 
180
                public event EventHandler DebugStarting;
 
181
                
 
182
                protected virtual void OnDebugStarting(EventArgs e)
 
183
                {
 
184
                        if (DebugStarting != null) {
 
185
                                DebugStarting(this, e);
 
186
                        }
 
187
                }
 
188
                
 
189
                public void Dispose()
 
190
                {
 
191
                        Stop();
 
192
                }
 
193
        }
 
194
}