public void SendBindBreakpoint(CSBindBreakpoint msg) { sendStream.Position = 0; bw.Write(msg.BreakpointHashCode); bw.Write(msg.TypeName); bw.Write(msg.MethodName); bw.Write(msg.StartLine); bw.Write(msg.EndLine); socket.Send(DebugMessageType.CSBindBreakpoint, sendStream.GetBuffer(), (int)sendStream.Position); }
void TryBindBreakpoint(CSBindBreakpoint msg) { var domain = ds.AppDomain; SCBindBreakpointResult res = new Protocol.SCBindBreakpointResult(); res.BreakpointHashCode = msg.BreakpointHashCode; IType type; if (domain.LoadedTypes.TryGetValue(msg.TypeName, out type)) { if (type is ILType) { ILType it = (ILType)type; ILMethod found = null; foreach (var i in it.GetMethods()) { if (i.Name == msg.MethodName) { ILMethod ilm = (ILMethod)i; if (ilm.StartLine <= (msg.StartLine + 1) && ilm.EndLine >= (msg.StartLine + 1)) { found = ilm; break; } } } if (found != null) { ds.SetBreakPoint(found.GetHashCode(), msg.BreakpointHashCode, msg.StartLine); res.Result = BindBreakpointResults.OK; } else { res.Result = BindBreakpointResults.CodeNotFound; } } else { res.Result = BindBreakpointResults.TypeNotFound; } } else { res.Result = BindBreakpointResults.TypeNotFound; } SendSCBindBreakpointResult(res); }
public override bool TryBind() { try { if (bindRequest == null) { bindRequest = CreateBindRequest(State == enum_BP_STATE.BPS_ENABLED, (BreakpointConditionStyle)_bpRequestInfo.bpCondition.styleCondition, _bpRequestInfo.bpCondition.bstrCondition); } _engine.DebuggedProcess.SendBindBreakpoint(bindRequest); return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } return(false); }
internal bool TryBind() { try { if (bindRequest == null) { 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); var method = GetParentMethod <MethodDeclarationSyntax>(node.Parent); string methodName = method.Identifier.Text; var cl = GetParentMethod <ClassDeclarationSyntax>(method); string className = cl.Identifier.Text; var ns = GetParentMethod <NamespaceDeclarationSyntax>(method); string nsname = ns.Name.ToString(); string name = string.Format("{0}.{1}", nsname, className); bindRequest = new CSBindBreakpoint(); bindRequest.BreakpointHashCode = this.GetHashCode(); bindRequest.TypeName = name; bindRequest.MethodName = methodName; bindRequest.StartLine = StartLine; bindRequest.EndLine = EndLine; } } _engine.DebuggedProcess.SendBindBreakpoint(bindRequest); return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } return(false); }
public override bool TryBind() { try { if (bindRequest == null) { bindRequest = CreateBindRequest(true, BreakpointConditionStyle.None, null); } debugged.SendBindBreakpoint(bindRequest); return(true); } catch (Exception ex) { bp.Verified = false; bp.Message = ex.ToString(); System.Diagnostics.Debug.WriteLine(ex.ToString()); } return(false); }
public void SendBindBreakpoint(CSBindBreakpoint msg) { sendStream.Position = 0; bw.Write(msg.BreakpointHashCode); bw.Write(msg.IsLambda); bw.Write(msg.NamespaceName); bw.Write(msg.TypeName); bw.Write(msg.MethodName); bw.Write(msg.StartLine); bw.Write(msg.EndLine); bw.Write(msg.Enabled); bw.Write((byte)msg.Condition.Style); if (msg.Condition.Style != BreakpointConditionStyle.None) { bw.Write(msg.Condition.Expression); } bw.Write(msg.UsingInfos.Length); foreach (var usingInfo in msg.UsingInfos) { bw.Write(usingInfo.Alias); bw.Write(usingInfo.Name); } socket.Send(DebugMessageType.CSBindBreakpoint, sendStream.GetBuffer(), (int)sendStream.Position); }
internal bool TryBind() { try { if (bindRequest == null) { 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.Name.ToString(); string name = string.Format("{0}.{1}", nsname, className); bindRequest = new CSBindBreakpoint(); bindRequest.BreakpointHashCode = this.GetHashCode(); bindRequest.IsLambda = isLambda; bindRequest.TypeName = name; bindRequest.MethodName = methodName; bindRequest.StartLine = StartLine; bindRequest.EndLine = EndLine; } } _engine.DebuggedProcess.SendBindBreakpoint(bindRequest); return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } return(false); }
void TryBindBreakpoint(CSBindBreakpoint msg) { var domain = ds.AppDomain; SCBindBreakpointResult res = new Protocol.SCBindBreakpointResult(); res.BreakpointHashCode = msg.BreakpointHashCode; IType type; if (msg.IsLambda) { ILMethod found = null; foreach (var i in domain.LoadedTypes.ToArray()) { var vt = i.Value as ILType; if (vt != null) { if (vt.FullName.Contains(msg.TypeName)) { foreach (var j in vt.GetMethods()) { if (j.Name.Contains(string.Format("<{0}>", msg.MethodName))) { ILMethod ilm = (ILMethod)j; if (ilm.StartLine <= (msg.StartLine + 1) && ilm.EndLine >= (msg.StartLine + 1)) { found = ilm; break; } else if (CheckCompilerGeneratedStateMachine(ilm, domain, msg.StartLine, out found)) { break; } } } } } if (found != null) { break; } } if (found != null) { ds.SetBreakPoint(found.GetHashCode(), msg.BreakpointHashCode, msg.StartLine, msg.Enabled, msg.Condition, msg.UsingInfos); res.Result = BindBreakpointResults.OK; } else { res.Result = BindBreakpointResults.CodeNotFound; } } else { if (domain.LoadedTypes.TryGetValue(msg.TypeName, out type)) { if (type is ILType) { ILType it = (ILType)type; ILMethod found = null; if (msg.MethodName == ".ctor") { foreach (var i in it.GetConstructors()) { ILMethod ilm = (ILMethod)i; if (ilm.StartLine <= (msg.StartLine + 1) && ilm.EndLine >= (msg.StartLine + 1)) { found = ilm; break; } } } else if (msg.MethodName == ".cctor") { ILMethod ilm = it.GetStaticConstroctor() as ILMethod; if (ilm.StartLine <= (msg.StartLine + 1) && ilm.EndLine >= (msg.StartLine + 1)) { found = ilm; } } else { foreach (var i in it.GetMethods()) { if (i.Name == msg.MethodName) { ILMethod ilm = (ILMethod)i; if (ilm.StartLine <= (msg.StartLine + 1) && ilm.EndLine >= (msg.StartLine + 1)) { found = ilm; break; } else if (CheckCompilerGeneratedStateMachine(ilm, domain, msg.StartLine, out found)) { break; } } } } if (found != null) { ds.SetBreakPoint(found.GetHashCode(), msg.BreakpointHashCode, msg.StartLine, msg.Enabled, msg.Condition, msg.UsingInfos); res.Result = BindBreakpointResults.OK; } else { res.Result = BindBreakpointResults.CodeNotFound; } } else { res.Result = BindBreakpointResults.TypeNotFound; } } else { res.Result = BindBreakpointResults.TypeNotFound; } } SendSCBindBreakpointResult(res); }
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); } }