26
26
//
27
27
28
28
using System ;
29
- using MonoDevelop . Ide . Gui ;
30
- using MonoDevelop . Components . Commands ;
31
- using Mono . Debugging . Client ;
32
- using MonoDevelop . Ide . Commands ;
33
- using MonoDevelop . Core ;
34
- using MonoDevelop . Ide ;
35
29
using System . IO ;
30
+ using System . Threading . Tasks ;
31
+
32
+ using Mono . Debugging . Client ;
36
33
37
- using Xwt ;
34
+ using MonoDevelop . Ide ;
35
+ using MonoDevelop . Core ;
36
+ using MonoDevelop . Ide . Gui ;
38
37
using MonoDevelop . Core . Web ;
38
+ using MonoDevelop . Ide . Commands ;
39
+ using MonoDevelop . Components . Commands ;
39
40
40
41
namespace MonoDevelop . Debugger
41
42
{
@@ -68,41 +69,40 @@ void OnStackChanged (object s, EventArgs a)
68
69
69
70
async void OnFrameChanged ( object s , EventArgs a )
70
71
{
71
- if ( changingFrame ) {
72
+ if ( changingFrame )
72
73
return ;
73
- }
74
+
75
+ changingFrame = true ;
76
+
74
77
try {
75
- changingFrame = true ;
76
78
if ( disassemblyDoc != null && DebuggingService . IsFeatureSupported ( DebuggerFeatures . Disassembly ) )
77
79
disassemblyView . Update ( ) ;
78
80
79
81
var frame = DebuggingService . CurrentFrame ;
80
- if ( frame == null ) {
82
+ if ( frame == null )
81
83
return ;
82
- }
83
84
85
+ var debuggerOptions = DebuggingService . GetUserOptions ( ) ;
84
86
FilePath file = frame . SourceLocation . FileName ;
85
-
86
87
int line = frame . SourceLocation . Line ;
88
+
87
89
if ( line != - 1 ) {
88
90
if ( ! file . IsNullOrEmpty && File . Exists ( file ) ) {
89
91
var doc = await IdeApp . Workbench . OpenDocument ( file , null , line , 1 , OpenDocumentOptions . Debugger ) ;
90
- if ( doc != null ) {
92
+ if ( doc != null )
91
93
return ;
92
- }
93
94
}
94
- bool alternateLocationExists = false ;
95
+
95
96
if ( frame . SourceLocation . FileHash != null ) {
96
97
var newFilePath = SourceCodeLookup . FindSourceFile ( file , frame . SourceLocation . FileHash ) ;
97
98
if ( newFilePath != null && File . Exists ( newFilePath ) ) {
98
99
frame . UpdateSourceFile ( newFilePath ) ;
99
100
var doc = await IdeApp . Workbench . OpenDocument ( newFilePath , null , line , 1 , OpenDocumentOptions . Debugger ) ;
100
- if ( doc != null ) {
101
+ if ( doc != null )
101
102
return ;
102
- }
103
103
}
104
104
}
105
- var debuggerOptions = DebuggingService . GetUserOptions ( ) ;
105
+
106
106
var automaticSourceDownload = debuggerOptions . AutomaticSourceLinkDownload ;
107
107
108
108
var sourceLink = frame . SourceLocation . SourceLink ;
@@ -111,53 +111,23 @@ async void OnFrameChanged (object s, EventArgs a)
111
111
Document doc = null ;
112
112
// ~/Library/Caches/VisualStudio/8.0/Symbols/org/projectname/git-sha/path/to/file.cs
113
113
if ( ! File . Exists ( downloadLocation ) ) {
114
- if ( automaticSourceDownload == AutomaticSourceDownload . Always ) {
115
- doc = await DownloadAndOpenFileAsync ( frame , line , sourceLink ) ;
116
- } else {
117
- var hyperlink = $ "<a href='{ sourceLink . Uri } '>{ Path . GetFileName ( sourceLink . RelativeFilePath ) } </a>";
118
- var stackframeText = $ "<b>{ frame . FullStackframeText } </b>";
119
-
120
- var text = GettextCatalog . GetString
121
- ( "{0} is a call to external source code. Would you like to get '{1}' and view it?" , stackframeText , hyperlink ) ;
122
- var message = new Ide . GenericMessage {
123
- Text = GettextCatalog . GetString ( "External source code available" ) ,
124
- SecondaryText = text
125
- } ;
126
- message . AddOption ( nameof ( automaticSourceDownload ) , GettextCatalog . GetString ( "Always get source code automatically" ) , false ) ;
127
- message . Buttons . Add ( AlertButton . Cancel ) ;
128
- message . Buttons . Add ( new AlertButton ( GettextCatalog . GetString ( "Get and Open" ) ) ) ;
129
- message . DefaultButton = 1 ;
130
-
131
- var didNotCancel = MessageService . GenericAlert ( message ) != AlertButton . Cancel ;
132
- if ( didNotCancel ) {
133
- if ( message . GetOptionValue ( nameof ( automaticSourceDownload ) ) ) {
134
- debuggerOptions . AutomaticSourceLinkDownload = AutomaticSourceDownload . Always ;
135
- DebuggingService . SetUserOptions ( debuggerOptions ) ;
136
- }
137
- doc = await DownloadAndOpenFileAsync ( frame , line , sourceLink ) ;
138
- }
139
- }
114
+ if ( automaticSourceDownload == AutomaticSourceDownload . Always )
115
+ doc = await NoSourceView . DownloadAndOpenAsync ( frame ) ;
140
116
} else {
141
117
// The file has previously been downloaded for a different solution.
142
118
// We need to map the cached location
143
119
frame . UpdateSourceFile ( downloadLocation ) ;
144
120
doc = await IdeApp . Workbench . OpenDocument ( downloadLocation , null , line , 1 , OpenDocumentOptions . Debugger ) ;
145
121
}
146
- if ( doc != null ) {
122
+ if ( doc != null )
147
123
return ;
148
- }
149
124
}
150
125
}
151
126
152
- bool disassemblyNotSupported = false ;
153
- // If we don't have an address space, we can't disassemble
154
- if ( string . IsNullOrEmpty ( frame . AddressSpace ) )
155
- disassemblyNotSupported = true ;
156
-
157
- if ( ! DebuggingService . CurrentSessionSupportsFeature ( DebuggerFeatures . Disassembly ) )
158
- disassemblyNotSupported = true ;
127
+ bool disassemblySupported = ! string . IsNullOrEmpty ( frame . AddressSpace ) &&
128
+ DebuggingService . CurrentSessionSupportsFeature ( DebuggerFeatures . Disassembly ) ;
159
129
160
- if ( disassemblyNotSupported && disassemblyDoc != null ) {
130
+ if ( ! disassemblySupported && disassemblyDoc != null ) {
161
131
disassemblyDoc . Close ( ) . Ignore ( ) ;
162
132
disassemblyDoc = null ;
163
133
disassemblyView = null ;
@@ -167,14 +137,14 @@ async void OnFrameChanged (object s, EventArgs a)
167
137
if ( disassemblyDoc == null ) {
168
138
if ( noSourceDoc == null ) {
169
139
noSourceView = new NoSourceView ( ) ;
170
- noSourceView . Update ( disassemblyNotSupported ) ;
140
+ noSourceView . Update ( debuggerOptions , frame , disassemblySupported ) ;
171
141
noSourceDoc = await IdeApp . Workbench . OpenDocument ( noSourceView , true ) ;
172
142
noSourceDoc . Closed += delegate {
173
143
noSourceDoc = null ;
174
144
noSourceView = null ;
175
145
} ;
176
146
} else {
177
- noSourceView . Update ( disassemblyNotSupported ) ;
147
+ noSourceView . Update ( debuggerOptions , frame , disassemblySupported ) ;
178
148
noSourceDoc . Select ( ) ;
179
149
}
180
150
} else {
@@ -185,34 +155,6 @@ async void OnFrameChanged (object s, EventArgs a)
185
155
}
186
156
}
187
157
188
- async System . Threading . Tasks . Task < Document > DownloadAndOpenFileAsync ( StackFrame frame , int line , SourceLink sourceLink )
189
- {
190
- var pm = IdeApp . Workbench . ProgressMonitors . GetStatusProgressMonitor (
191
- GettextCatalog . GetString ( "Downloading {0}" , sourceLink . Uri ) ,
192
- Stock . StatusDownload ,
193
- true
194
- ) ;
195
-
196
- Document doc = null ;
197
- try {
198
- var downloadLocation = sourceLink . GetDownloadLocation ( symbolCachePath ) ;
199
- Directory . CreateDirectory ( Path . GetDirectoryName ( downloadLocation ) ) ;
200
- DocumentRegistry . SkipNextChange ( downloadLocation ) ;
201
- var client = HttpClientProvider . CreateHttpClient ( sourceLink . Uri ) ;
202
- using ( var stream = await client . GetStreamAsync ( sourceLink . Uri ) . ConfigureAwait ( false ) )
203
- using ( var fs = new FileStream ( downloadLocation , FileMode . Create ) ) {
204
- await stream . CopyToAsync ( fs ) . ConfigureAwait ( false ) ;
205
- }
206
- frame . UpdateSourceFile ( downloadLocation ) ;
207
- doc = await Runtime . RunInMainThread ( ( ) => IdeApp . Workbench . OpenDocument ( downloadLocation , null , line , 1 , OpenDocumentOptions . Debugger ) ) ;
208
- } catch ( Exception ex ) {
209
- LoggingService . LogInternalError ( "Error downloading SourceLink file" , ex ) ;
210
- } finally {
211
- pm . Dispose ( ) ;
212
- }
213
- return doc ;
214
- }
215
-
216
158
async void OnShowDisassembly ( object s , EventArgs a )
217
159
{
218
160
if ( disassemblyDoc == null ) {
@@ -230,11 +172,11 @@ async void OnShowDisassembly (object s, EventArgs a)
230
172
231
173
static void SetSourceCodeFrame ( )
232
174
{
233
- Backtrace bt = DebuggingService . CurrentCallStack ;
175
+ var bt = DebuggingService . CurrentCallStack ;
234
176
235
177
if ( bt != null ) {
236
178
for ( int n = 0 ; n < bt . FrameCount ; n ++ ) {
237
- StackFrame sf = bt . GetFrame ( n ) ;
179
+ var sf = bt . GetFrame ( n ) ;
238
180
239
181
if ( ! sf . IsExternalCode &&
240
182
sf . SourceLocation . Line != - 1 &&
0 commit comments