Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 2721b85

Browse files
committed
Refactor frame attaching. Frames are collected based on the event.
Refactoring set break point to make it more readable. Updated libraries from monodevelop master.
1 parent 0708816 commit 2721b85

33 files changed

+77
-103
lines changed

External/CorApi.dll

0 Bytes
Binary file not shown.

External/CorApi.pdb

0 Bytes
Binary file not shown.

External/CorApi2.dll

0 Bytes
Binary file not shown.

External/CorApi2.pdb

6 KB
Binary file not shown.
0 Bytes
Binary file not shown.
24 KB
Binary file not shown.

External/ICSharpCode.NRefactory.dll

0 Bytes
Binary file not shown.

External/ICSharpCode.NRefactory.pdb

12 KB
Binary file not shown.

External/Mono.Cecil.Mdb.dll

512 Bytes
Binary file not shown.

External/Mono.Cecil.Pdb.dll

512 Bytes
Binary file not shown.

External/Mono.Cecil.Rocks.dll

512 Bytes
Binary file not shown.

External/Mono.Cecil.dll

2 KB
Binary file not shown.

External/Mono.Debugger.Soft.dll

0 Bytes
Binary file not shown.

External/Mono.Debugger.Soft.pdb

6 KB
Binary file not shown.

External/Mono.Debugging.Soft.dll

0 Bytes
Binary file not shown.

External/Mono.Debugging.Soft.pdb

2 KB
Binary file not shown.

External/Mono.Debugging.Win32.dll

0 Bytes
Binary file not shown.

External/Mono.Debugging.Win32.pdb

2 KB
Binary file not shown.

External/Mono.Debugging.dll

0 Bytes
Binary file not shown.

External/Mono.Debugging.pdb

8 KB
Binary file not shown.

External/Mono.Posix.dll

-30 KB
Binary file not shown.
512 Bytes
Binary file not shown.

External/MonoDevelop.Debugger.dll

-8 KB
Binary file not shown.

External/atk-sharp.dll

3 KB
Binary file not shown.

External/atk-sharp.pdb

18 KB
Binary file not shown.

External/gdk-sharp.dll

7 KB
Binary file not shown.

External/gdk-sharp.pdb

54 KB
Binary file not shown.

External/glib-sharp.dll

7 KB
Binary file not shown.

External/glib-sharp.pdb

20 KB
Binary file not shown.

External/gtk-sharp.dll

90.5 KB
Binary file not shown.

External/pango-sharp.dll

0 Bytes
Binary file not shown.

External/pango-sharp.pdb

32 KB
Binary file not shown.

UnityDebug/UnityDebugSession.cs

Lines changed: 77 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using MonoDevelop.Unity.Debugger;
1717
using Newtonsoft.Json.Linq;
1818
using Breakpoint = Mono.Debugging.Client.Breakpoint;
19+
using StackFrame = Mono.Debugging.Client.StackFrame;
1920
using UnityProcessInfo = MonoDevelop.Debugger.Soft.Unity.UnityProcessInfo;
2021

2122
namespace UnityDebug
@@ -85,18 +86,31 @@ public UnityDebugSession() : base()
8586
};
8687

8788
_session.TargetStopped += (sender, e) => {
89+
if (e.Backtrace != null) {
90+
Frame = e.Backtrace.GetFrame (0);
91+
} else {
92+
SendOutput("stdout", "e.Bracktrace is null");
93+
}
8894
Stopped();
8995
SendEvent(CreateStoppedEvent("step", e.Thread));
9096
_resumeEvent.Set();
9197
};
9298

9399
_session.TargetHitBreakpoint += (sender, e) => {
100+
Frame = e.Backtrace.GetFrame(0);
94101
Stopped();
95102
SendEvent(CreateStoppedEvent("breakpoint", e.Thread));
96103
_resumeEvent.Set();
97104
};
98105

99106
_session.TargetExceptionThrown += (sender, e) => {
107+
Frame = e.Backtrace.GetFrame (0);
108+
for (var i = 0; i < e.Backtrace.FrameCount; i++) {
109+
if (!e.Backtrace.GetFrame (i).IsExternalCode) {
110+
Frame = e.Backtrace.GetFrame (i);
111+
break;
112+
}
113+
}
100114
Stopped();
101115
var ex = DebuggerActiveException();
102116
if (ex != null) {
@@ -163,6 +177,8 @@ public UnityDebugSession() : base()
163177
};
164178
}
165179

180+
public StackFrame Frame { get; set; }
181+
166182
public override void Initialize(Response response, dynamic args)
167183
{
168184
var os = Environment.OSVersion;
@@ -178,7 +194,7 @@ public override void Initialize(Response response, dynamic args)
178194
supportsConfigurationDoneRequest = false,
179195

180196
// This debug adapter does not support function breakpoints.
181-
supportsFunctionBreakpoints = false,
197+
supportsFunctionBreakpoints = true,
182198

183199
// This debug adapter doesn't support conditional breakpoints.
184200
supportsConditionalBreakpoints = true,
@@ -682,114 +698,72 @@ private static string ParseEvaluate(string expression)
682698
return parsedExpression;
683699
}
684700

685-
// public override void Evaluate(Response response, dynamic args)
686-
// {
687-
// string error = null;
688-
//
689-
// var expression = getString(args, "expression");
690-
// if (expression == null) {
691-
// error = "expression missing";
692-
// } else {
693-
// int frameId = getInt(args, "frameId", -1);
694-
// var frame = _frameHandles.Get(frameId, null);
695-
// if (frame != null) {
696-
//
697-
// var parsedExpression = ParseEvaluate (expression);
698-
//
699-
// if (!frame.ValidateExpression(expression) && parsedExpression.Length > 0 && frame.ValidateExpression (parsedExpression))
700-
// expression = parsedExpression;
701-
//
702-
// if (frame.ValidateExpression(expression)) {
703-
// var val = frame.GetExpressionValue(expression, Debugger.Options.EvaluationOptions);
704-
// val.WaitHandle.WaitOne();
705-
//
706-
// var flags = val.Flags;
707-
// if (flags.HasFlag(ObjectValueFlags.Error) || flags.HasFlag(ObjectValueFlags.NotSupported)) {
708-
// error = val.DisplayValue;
709-
// if (error.IndexOf("reference not available in the current evaluation context") > 0) {
710-
// error = "not available";
711-
// }
712-
// }
713-
// else if (flags.HasFlag(ObjectValueFlags.Unknown)) {
714-
// error = "invalid expression";
715-
// // maybe user hovered this's member
716-
// if (!expression.StartsWith("this", System.StringComparison.Ordinal)) {
717-
// args["expression"] = "this." + expression;
718-
// Evaluate(response, args);
719-
// return;
720-
// }
721-
// }
722-
// else if (flags.HasFlag(ObjectValueFlags.Object) && flags.HasFlag(ObjectValueFlags.Namespace)) {
723-
// error = "not available";
724-
// }
725-
// else {
726-
// int handle = 0;
727-
// if (val.HasChildren) {
728-
// handle = _variableHandles.Create(val.GetAllChildren());
729-
// }
730-
// SendResponse(response, new EvaluateResponseBody(val.DisplayValue, handle));
731-
// return;
732-
// }
733-
// }
734-
// else {
735-
// error = "invalid expression";
736-
// }
737-
// }
738-
// else {
739-
// error = "no active stackframe";
740-
// }
741-
// }
742-
// SendErrorResponse(response, 3014, "Evaluate request failed ({_reason}).", new { _reason = error } );
743-
// }
744-
745701
public override void Evaluate(Response response, dynamic args)
746702
{
747-
string error = null;
748-
703+
SendOutput("stdout", "Starting");
749704
var expression = getString(args, "expression");
705+
750706
if (expression == null) {
751-
error = "expression missing";
752-
} else {
753-
int frameId = getInt(args, "frameId", -1);
754-
var frame = _frameHandles.Get(frameId, null);
755-
if (frame != null) {
756-
if (frame.ValidateExpression(expression)) {
757-
var evaluationOptions = _debuggerSessionOptions.EvaluationOptions.Clone();
758-
evaluationOptions.EllipsizeStrings = false;
759-
var val = frame.GetExpressionValue(expression, evaluationOptions);
760-
val.WaitHandle.WaitOne();
761-
762-
var flags = val.Flags;
763-
if (flags.HasFlag(ObjectValueFlags.Error) || flags.HasFlag(ObjectValueFlags.NotSupported)) {
764-
error = val.DisplayValue;
765-
if (error.IndexOf("reference not available in the current evaluation context") > 0) {
766-
error = "not available";
767-
}
768-
}
769-
else if (flags.HasFlag(ObjectValueFlags.Unknown)) {
770-
error = "invalid expression";
771-
}
772-
else if (flags.HasFlag(ObjectValueFlags.Object) && flags.HasFlag(ObjectValueFlags.Namespace)) {
773-
error = "not available";
774-
}
775-
else {
776-
int handle = 0;
777-
if (val.HasChildren) {
778-
handle = _variableHandles.Create(val.GetAllChildren());
779-
}
780-
SendResponse(response, new EvaluateResponseBody(val.DisplayValue, handle));
781-
return;
782-
}
783-
}
784-
else {
785-
error = "invalid expression";
786-
}
787-
}
788-
else {
789-
error = "no active stackframe";
707+
SendError(response, "expression missing");
708+
return;
709+
}
710+
if (Frame == null)
711+
{
712+
SendError(response, "no active stackframe");
713+
return;
714+
}
715+
if (!Frame.ValidateExpression(expression))
716+
{
717+
SendError(response, "invalid expression");
718+
return;
719+
}
720+
SendOutput("stdout", "Valid expression " + args);
721+
722+
var evaluationOptions = _debuggerSessionOptions.EvaluationOptions.Clone();
723+
evaluationOptions.EllipsizeStrings = false;
724+
evaluationOptions.AllowMethodEvaluation = true;
725+
_session.Options.EvaluationOptions = evaluationOptions;
726+
_session.Options.ProjectAssembliesOnly = true;
727+
_session.Options.StepOverPropertiesAndOperators = false;
728+
var val = Frame.GetExpressionValue(expression, true);
729+
SendOutput("stdout", "Sent expression");
730+
val.WaitHandle.WaitOne();
731+
SendOutput("stdout", "Waiting");
732+
733+
var flags = val.Flags;
734+
if (flags.HasFlag(ObjectValueFlags.Error) || flags.HasFlag(ObjectValueFlags.NotSupported))
735+
{
736+
string error = val.DisplayValue;
737+
if (error.IndexOf("reference not available in the current evaluation context") > 0)
738+
{
739+
error = "not available";
790740
}
741+
SendError(response, error);
742+
return;
743+
}
744+
if (flags.HasFlag(ObjectValueFlags.Unknown))
745+
{
746+
SendError(response, "invalid expression");
747+
return;
791748
}
792-
SendErrorResponse(response, 3014, "Evaluate request failed ({_reason}).", new { _reason = error } );
749+
if (flags.HasFlag(ObjectValueFlags.Object) && flags.HasFlag(ObjectValueFlags.Namespace))
750+
{
751+
SendError(response, "not available");
752+
return;
753+
}
754+
755+
int handle = 0;
756+
if (val.HasChildren)
757+
{
758+
handle = _variableHandles.Create(val.GetAllChildren());
759+
}
760+
761+
SendResponse(response, new EvaluateResponseBody(val.DisplayValue, handle));
762+
}
763+
764+
void SendError(Response response, string error)
765+
{
766+
SendErrorResponse(response, 3014, "Evaluate request failed ({_reason}).", new { _reason = error });
793767
}
794768

795769
//---- private ------------------------------------------

0 commit comments

Comments
 (0)