Exemplo n.º 1
0
 public void SendSetBreakpointCondition(int bpHash, BreakpointConditionStyle style, string expression)
 {
     sendStream.Position = 0;
     bw.Write(bpHash);
     bw.Write((byte)style);
     if (style != BreakpointConditionStyle.None)
     {
         bw.Write(expression);
     }
     socket.Send(DebugMessageType.CSSetBreakpointCondition, sendStream.GetBuffer(), (int)sendStream.Position);
 }
Exemplo n.º 2
0
        void OnReceive(DebugMessageType type, byte[] buffer)
        {
            if (clientSocket == null || clientSocket.Disconnected)
            {
                return;
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer);
            System.IO.BinaryReader br = new System.IO.BinaryReader(ms);

            switch (type)
            {
            case DebugMessageType.CSAttach:
            {
                SendAttachResult();
            }
            break;

            case DebugMessageType.CSBindBreakpoint:
            {
                CSBindBreakpoint msg = new Protocol.CSBindBreakpoint();
                msg.BreakpointHashCode = br.ReadInt32();
                msg.IsLambda           = br.ReadBoolean();
                msg.NamespaceName      = br.ReadString();
                var typeName = br.ReadString();
                msg.TypeName        = String.IsNullOrWhiteSpace(msg.NamespaceName) ? typeName : msg.NamespaceName + "." + typeName;
                msg.MethodName      = br.ReadString();
                msg.StartLine       = br.ReadInt32();
                msg.EndLine         = br.ReadInt32();
                msg.Enabled         = br.ReadBoolean();
                msg.Condition       = new BreakpointCondition();
                msg.Condition.Style = (BreakpointConditionStyle)br.ReadByte();
                if (msg.Condition.Style != BreakpointConditionStyle.None)
                {
                    msg.Condition.Expression = br.ReadString();
                }
                msg.UsingInfos    = new UsingInfo[br.ReadInt32() + 1];
                msg.UsingInfos[0] = new UsingInfo()
                {
                    Alias = null, Name = msg.NamespaceName
                };                                                                                      //当前命名空间具有最高优先级
                for (int i = 1; i < msg.UsingInfos.Length; i++)
                {
                    msg.UsingInfos[i] = new UsingInfo()
                    {
                        Alias = br.ReadString(), Name = br.ReadString()
                    };
                }
                TryBindBreakpoint(msg);
            }
            break;

            case DebugMessageType.CSSetBreakpointEnabled:
            {
                ds.SetBreakpointEnabled(br.ReadInt32(), br.ReadBoolean());
            }
            break;

            case DebugMessageType.CSSetBreakpointCondition:
            {
                int bpHash = br.ReadInt32();
                BreakpointConditionStyle style = (BreakpointConditionStyle)br.ReadByte();
                string expression = style != BreakpointConditionStyle.None ? br.ReadString() : null;
                ds.SetBreakpointCondition(bpHash, style, expression);
            }
            break;

            case DebugMessageType.CSDeleteBreakpoint:
            {
                CSDeleteBreakpoint msg = new Protocol.CSDeleteBreakpoint();
                msg.BreakpointHashCode = br.ReadInt32();
                ds.DeleteBreakpoint(msg.BreakpointHashCode);
            }
            break;

            case DebugMessageType.CSExecute:
            {
                CSExecute msg = new Protocol.CSExecute();
                msg.ThreadHashCode = br.ReadInt32();
                ds.ExecuteThread(msg.ThreadHashCode);
            }
            break;

            case DebugMessageType.CSStep:
            {
                CSStep msg = new CSStep();
                msg.ThreadHashCode = br.ReadInt32();
                msg.StepType       = (StepTypes)br.ReadByte();
                ds.StepThread(msg.ThreadHashCode, msg.StepType);
            }
            break;

            case DebugMessageType.CSResolveVariable:
            {
                CSResolveVariable msg = new CSResolveVariable();
                msg.ThreadHashCode = br.ReadInt32();
                msg.FrameIndex     = br.ReadInt32();
                msg.Variable       = ReadVariableReference(br);
                VariableInfo info;
                try
                {
                    object res;
                    info = ds.ResolveVariable(msg.ThreadHashCode, msg.FrameIndex, msg.Variable, out res);
                }
                catch (Exception ex)
                {
                    info = VariableInfo.GetException(ex);
                }
                if (info.Type != VariableTypes.Pending)
                {
                    SendSCResolveVariableResult(info);
                }
            }
            break;

            case DebugMessageType.CSResolveIndexAccess:
            {
                CSResolveIndexer msg = new CSResolveIndexer();
                msg.ThreadHashCode = br.ReadInt32();
                msg.FrameIndex     = br.ReadInt32();
                msg.Body           = ReadVariableReference(br);
                msg.Index          = ReadVariableReference(br);

                VariableInfo info;
                try
                {
                    object res;
                    info = ds.ResolveIndexAccess(msg.ThreadHashCode, msg.FrameIndex, new VariableReference {
                            Parent = msg.Body, Parameters = new VariableReference[1] {
                                msg.Index
                            }
                        }, out res);
                }
                catch (Exception ex)
                {
                    info = VariableInfo.GetException(ex);
                }
                if (info.Type != VariableTypes.Pending)
                {
                    SendSCResolveVariableResult(info);
                }
            }
            break;

            case DebugMessageType.CSEnumChildren:
            {
                int thId    = br.ReadInt32();
                int frameId = br.ReadInt32();
                var parent  = ReadVariableReference(br);

                VariableInfo[] info = null;
                try
                {
                    info = ds.EnumChildren(thId, frameId, parent);
                }
                catch (Exception ex)
                {
                    info = new VariableInfo[] { VariableInfo.GetException(ex) };
                }
                if (info != null)
                {
                    SendSCEnumChildrenResult(info);
                }
            }
            break;
            }
        }
Exemplo n.º 3
0
        protected CSBindBreakpoint CreateBindRequest(bool enabled, BreakpointConditionStyle style, string condition)
        {
            using (var stream = File.OpenRead(DocumentName))
            {
                SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(SourceText.From(stream), path: DocumentName);
                TextLine   textLine   = syntaxTree.GetText().Lines[StartLine];
                Location   location   = syntaxTree.GetLocation(textLine.Span);
                SyntaxTree sourceTree = location.SourceTree;
                SyntaxNode node       = location.SourceTree.GetRoot().FindNode(location.SourceSpan, true, true);

                bool isLambda = GetParentMethod <LambdaExpressionSyntax>(node.Parent) != null;
                BaseMethodDeclarationSyntax method = GetParentMethod <MethodDeclarationSyntax>(node.Parent);
                string methodName = null;
                if (method != null)
                {
                    methodName = ((MethodDeclarationSyntax)method).Identifier.Text;
                }
                else
                {
                    method = GetParentMethod <ConstructorDeclarationSyntax>(node.Parent);
                    if (method != null)
                    {
                        bool isStatic = false;
                        foreach (var i in method.Modifiers)
                        {
                            if (i.Text == "static")
                            {
                                isStatic = true;
                            }
                        }
                        if (isStatic)
                        {
                            methodName = ".cctor";
                        }
                        else
                        {
                            methodName = ".ctor";
                        }
                    }
                }

                string className = GetClassName(method);

                //var ns = GetParentMethod<NamespaceDeclarationSyntax>(method);
                //string nsname = ns != null ? ns.Name.ToString() : null;

                //string name = ns != null ? string.Format("{0}.{1}", nsname, className) : className;
                var nameSpaceStack  = new Stack <string>();
                var usingSyntaxList = new List <UsingDirectiveSyntax>(syntaxTree.GetCompilationUnitRoot().Usings);
                GetCurrentNameSpaceDeclaration(node.Parent, nameSpaceStack, usingSyntaxList);

                var bindRequest = new CSBindBreakpoint();
                bindRequest.BreakpointHashCode   = this.GetHashCode();
                bindRequest.IsLambda             = isLambda;
                bindRequest.NamespaceName        = string.Join(".", nameSpaceStack);
                bindRequest.TypeName             = className;
                bindRequest.MethodName           = methodName;
                bindRequest.StartLine            = StartLine;
                bindRequest.EndLine              = EndLine;
                bindRequest.Enabled              = enabled;
                bindRequest.Condition            = new BreakpointCondition();
                bindRequest.Condition.Style      = style;
                bindRequest.Condition.Expression = condition;
                bindRequest.UsingInfos           = usingSyntaxList.Select(n => new UsingInfo
                {
                    Alias = n.Alias != null ? n.Alias.Name.ToString() : "",
                    Name  = n.Name.ToString(),
                }).ToArray();

                return(bindRequest);
            }
        }