Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 87f1d0e

Browse files
jstedfastmrward
authored andcommitted
[Debugger] Added more logging for VsCodeDebugger protocol requests
For OnSetNextStatement(), convert exceptions into NotSupportedException so that higher-level code properly handles this case. For Stepping, just drop & log the exception like SoftDebuggerSession does. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1042237
1 parent 52a5a0e commit 87f1d0e

File tree

1 file changed

+70
-18
lines changed
  • main/src/addins/MonoDevelop.Debugger.VSCodeDebugProtocol/MonoDevelop.Debugger.VsCodeDebugProtocol

1 file changed

+70
-18
lines changed

main/src/addins/MonoDevelop.Debugger.VSCodeDebugProtocol/MonoDevelop.Debugger.VsCodeDebugProtocol/VSCodeDebuggerSession.cs

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,21 @@ internal bool IsEnum (string type, int frameId)
6666

6767
protected override void OnContinue ()
6868
{
69-
protocolClient.SendRequestSync (new ContinueRequest (currentThreadId));
69+
try {
70+
protocolClient.SendRequestSync (new ContinueRequest (currentThreadId));
71+
} catch (Exception ex) {
72+
if (!HandleException (ex))
73+
OnDebuggerOutput (true, ex.ToString ());
74+
}
7075
}
7176

7277
protected override void OnDetach ()
7378
{
74-
protocolClient.SendRequestSync (new DisconnectRequest ());
79+
try {
80+
protocolClient.SendRequestSync (new DisconnectRequest ());
81+
} catch (Exception ex) {
82+
DebuggerLoggingService.LogError ("[VSCodeDebugger] Error detaching debugger session", ex);
83+
}
7584
}
7685

7786
protected override void OnEnableBreakEvent (BreakEventInfo eventInfo, bool enable)
@@ -85,13 +94,18 @@ protected override void OnExit ()
8594
try {
8695
HasExited = true;
8796
protocolClient.SendRequestSync (new DisconnectRequest ());
88-
} catch {
97+
} catch (Exception ex) {
98+
DebuggerLoggingService.LogError ("[VSCodeDebugger] Error closing debugger session", ex);
8999
}
90100
}
91101

92102
protected override void OnFinish ()
93103
{
94-
protocolClient.SendRequestSync (new StepOutRequest (currentThreadId));
104+
try {
105+
protocolClient.SendRequestSync (new StepOutRequest (currentThreadId));
106+
} catch (Exception ex) {
107+
DebuggerLoggingService.LogError ("[VSCodeDebugger] StepOut request failed", ex);
108+
}
95109
}
96110

97111
List<ProcessInfo> processInfo = new List<ProcessInfo>();
@@ -107,14 +121,22 @@ protected override Backtrace OnGetThreadBacktrace (long processId, long threadId
107121

108122
protected override ThreadInfo [] OnGetThreads (long processId)
109123
{
110-
var threadsResponse = protocolClient.SendRequestSync (new ThreadsRequest ());
111-
var threads = new ThreadInfo [threadsResponse.Threads.Count];
124+
ThreadsResponse response;
125+
126+
try {
127+
response = protocolClient.SendRequestSync (new ThreadsRequest ());
128+
} catch (Exception ex) {
129+
DebuggerLoggingService.LogError ("[VSCodeDebugger] Error getting threads", ex);
130+
return new ThreadInfo[0];
131+
}
132+
133+
var threads = new ThreadInfo[response.Threads.Count];
112134
for (int i = 0; i < threads.Length; i++) {
113-
threads [i] = new ThreadInfo (processId,
114-
threadsResponse.Threads [i].Id,
115-
threadsResponse.Threads [i].Name,
116-
null);
135+
var thread = response.Threads[i];
136+
137+
threads[i] = new ThreadInfo (processId, thread.Id, thread.Name, null);
117138
}
139+
118140
return threads;
119141
}
120142

@@ -126,9 +148,16 @@ protected override void OnSetNextStatement (long threadId, string fileName, int
126148
{
127149
var source = new Source { Name = Path.GetFileName (fileName), Path = fileName };
128150
var request = new GotoTargetsRequest (source, line) { Column = column };
129-
var response = protocolClient.SendRequestSync (request);
151+
GotoTargetsResponse response;
130152
GotoTarget target = null;
131153

154+
try {
155+
response = protocolClient.SendRequestSync (request);
156+
} catch (Exception ex) {
157+
DebuggerLoggingService.LogError ("[VSCodeDebugger] Requesting target locations failed", ex);
158+
throw new NotSupportedException (ex.Message);
159+
}
160+
132161
foreach (var location in response.Targets) {
133162
if (location.Line <= line && location.EndLine >= line && location.Column <= column && location.EndColumn >= column) {
134163
// exact match for location
@@ -143,9 +172,15 @@ protected override void OnSetNextStatement (long threadId, string fileName, int
143172
}
144173

145174
if (target == null)
146-
throw new NotImplementedException ();
175+
throw new NotSupportedException ();
176+
177+
try {
178+
protocolClient.SendRequestSync (new GotoRequest ((int) threadId, target.Id));
179+
} catch (Exception ex) {
180+
DebuggerLoggingService.LogMessage ("[VSCodeDebugger] Setting next statement failed", ex);
181+
throw new NotSupportedException (ex.Message);
182+
}
147183

148-
protocolClient.SendRequestSync (new GotoRequest ((int) threadId, target.Id));
149184
RaiseStopEvent ();
150185
}
151186

@@ -194,12 +229,20 @@ void UpdateExceptions ()
194229

195230
protected override void OnNextInstruction ()
196231
{
197-
protocolClient.SendRequestSync (new NextRequest (currentThreadId));
232+
try {
233+
protocolClient.SendRequestSync (new NextRequest (currentThreadId));
234+
} catch (Exception ex) {
235+
DebuggerLoggingService.LogError ("[VSCodeDebugger] NextInstruction request failed", ex);
236+
}
198237
}
199238

200239
protected override void OnNextLine ()
201240
{
202-
protocolClient.SendRequestSync (new NextRequest (currentThreadId));
241+
try {
242+
protocolClient.SendRequestSync (new NextRequest (currentThreadId));
243+
} catch (Exception ex) {
244+
DebuggerLoggingService.LogError ("[VSCodeDebugger] StepOver request failed", ex);
245+
}
203246
}
204247

205248
protected override void OnRemoveBreakEvent (BreakEventInfo eventInfo)
@@ -216,7 +259,8 @@ void DebugAgentProcess_Exited (object sender, EventArgs e)
216259
HasExited = true;
217260
protocolClient.RequestReceived -= OnDebugAdaptorRequestReceived;
218261
protocolClient.Stop ();
219-
} catch {
262+
} catch (Exception ex) {
263+
DebuggerLoggingService.LogError ("[VSCodeDebugger] Stop request failed", ex);
220264
}
221265
protocolClient = null;
222266
}
@@ -575,12 +619,20 @@ protected override void OnSetActiveThread (long processId, long threadId)
575619

576620
protected override void OnStepInstruction ()
577621
{
578-
protocolClient.SendRequestSync (new StepInRequest (currentThreadId));
622+
try {
623+
protocolClient.SendRequestSync (new StepInRequest (currentThreadId));
624+
} catch (Exception ex) {
625+
DebuggerLoggingService.LogError ("[VSCodeDebugger] StepInstruction request failed", ex);
626+
}
579627
}
580628

581629
protected override void OnStepLine ()
582630
{
583-
protocolClient.SendRequestSync (new StepInRequest (currentThreadId));
631+
try {
632+
protocolClient.SendRequestSync (new StepInRequest (currentThreadId));
633+
} catch (Exception ex) {
634+
DebuggerLoggingService.LogError ("[VSCodeDebugger] StepIn request failed", ex);
635+
}
584636
}
585637

586638
protected override void OnStop ()

0 commit comments

Comments
 (0)