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

Commit

Permalink
[Debugger] Added more logging for VsCodeDebugger protocol requests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jstedfast authored and mrward committed Jan 22, 2020
1 parent 52a5a0e commit 87f1d0e
Showing 1 changed file with 70 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ internal bool IsEnum (string type, int frameId)

protected override void OnContinue ()
{
protocolClient.SendRequestSync (new ContinueRequest (currentThreadId));
try {
protocolClient.SendRequestSync (new ContinueRequest (currentThreadId));
} catch (Exception ex) {
if (!HandleException (ex))
OnDebuggerOutput (true, ex.ToString ());
}
}

protected override void OnDetach ()
{
protocolClient.SendRequestSync (new DisconnectRequest ());
try {
protocolClient.SendRequestSync (new DisconnectRequest ());
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] Error detaching debugger session", ex);
}
}

protected override void OnEnableBreakEvent (BreakEventInfo eventInfo, bool enable)
Expand All @@ -85,13 +94,18 @@ protected override void OnExit ()
try {
HasExited = true;
protocolClient.SendRequestSync (new DisconnectRequest ());
} catch {
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] Error closing debugger session", ex);
}
}

protected override void OnFinish ()
{
protocolClient.SendRequestSync (new StepOutRequest (currentThreadId));
try {
protocolClient.SendRequestSync (new StepOutRequest (currentThreadId));
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] StepOut request failed", ex);
}
}

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

protected override ThreadInfo [] OnGetThreads (long processId)
{
var threadsResponse = protocolClient.SendRequestSync (new ThreadsRequest ());
var threads = new ThreadInfo [threadsResponse.Threads.Count];
ThreadsResponse response;

try {
response = protocolClient.SendRequestSync (new ThreadsRequest ());
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] Error getting threads", ex);
return new ThreadInfo[0];
}

var threads = new ThreadInfo[response.Threads.Count];
for (int i = 0; i < threads.Length; i++) {
threads [i] = new ThreadInfo (processId,
threadsResponse.Threads [i].Id,
threadsResponse.Threads [i].Name,
null);
var thread = response.Threads[i];

threads[i] = new ThreadInfo (processId, thread.Id, thread.Name, null);
}

return threads;
}

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

try {
response = protocolClient.SendRequestSync (request);
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] Requesting target locations failed", ex);
throw new NotSupportedException (ex.Message);
}

foreach (var location in response.Targets) {
if (location.Line <= line && location.EndLine >= line && location.Column <= column && location.EndColumn >= column) {
// exact match for location
Expand All @@ -143,9 +172,15 @@ protected override void OnSetNextStatement (long threadId, string fileName, int
}

if (target == null)
throw new NotImplementedException ();
throw new NotSupportedException ();

try {
protocolClient.SendRequestSync (new GotoRequest ((int) threadId, target.Id));
} catch (Exception ex) {
DebuggerLoggingService.LogMessage ("[VSCodeDebugger] Setting next statement failed", ex);
throw new NotSupportedException (ex.Message);
}

protocolClient.SendRequestSync (new GotoRequest ((int) threadId, target.Id));
RaiseStopEvent ();
}

Expand Down Expand Up @@ -194,12 +229,20 @@ void UpdateExceptions ()

protected override void OnNextInstruction ()
{
protocolClient.SendRequestSync (new NextRequest (currentThreadId));
try {
protocolClient.SendRequestSync (new NextRequest (currentThreadId));
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] NextInstruction request failed", ex);
}
}

protected override void OnNextLine ()
{
protocolClient.SendRequestSync (new NextRequest (currentThreadId));
try {
protocolClient.SendRequestSync (new NextRequest (currentThreadId));
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] StepOver request failed", ex);
}
}

protected override void OnRemoveBreakEvent (BreakEventInfo eventInfo)
Expand All @@ -216,7 +259,8 @@ void DebugAgentProcess_Exited (object sender, EventArgs e)
HasExited = true;
protocolClient.RequestReceived -= OnDebugAdaptorRequestReceived;
protocolClient.Stop ();
} catch {
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] Stop request failed", ex);
}
protocolClient = null;
}
Expand Down Expand Up @@ -575,12 +619,20 @@ protected override void OnSetActiveThread (long processId, long threadId)

protected override void OnStepInstruction ()
{
protocolClient.SendRequestSync (new StepInRequest (currentThreadId));
try {
protocolClient.SendRequestSync (new StepInRequest (currentThreadId));
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] StepInstruction request failed", ex);
}
}

protected override void OnStepLine ()
{
protocolClient.SendRequestSync (new StepInRequest (currentThreadId));
try {
protocolClient.SendRequestSync (new StepInRequest (currentThreadId));
} catch (Exception ex) {
DebuggerLoggingService.LogError ("[VSCodeDebugger] StepIn request failed", ex);
}
}

protected override void OnStop ()
Expand Down

0 comments on commit 87f1d0e

Please sign in to comment.