Exemplo n.º 1
0
            public async Task <SyntaxTree> ReplaceVars(SyntaxTree syntaxTree, MonoProxy proxy, MessageId msg_id, int scope_id, CancellationToken token)
            {
                CompilationUnitSyntax root = syntaxTree.GetCompilationUnitRoot();

                foreach (var var in variables)
                {
                    ClassDeclarationSyntax  classDeclaration = root.Members.ElementAt(0) as ClassDeclarationSyntax;
                    MethodDeclarationSyntax method           = classDeclaration.Members.ElementAt(0) as MethodDeclarationSyntax;

                    JToken value = await proxy.TryGetVariableValue(msg_id, scope_id, var.Identifier.Text, false, token);

                    if (value == null)
                    {
                        throw new Exception($"The name {var.Identifier.Text} does not exist in the current context");
                    }

                    values.Add(ConvertJSToCSharpType(value["value"]));

                    var updatedMethod = method.AddParameterListParameters(
                        SyntaxFactory.Parameter(
                            SyntaxFactory.Identifier(var.Identifier.Text))
                        .WithType(SyntaxFactory.ParseTypeName(GetTypeFullName(value["value"]))));
                    root = root.ReplaceNode(method, updatedMethod);
                }
                syntaxTree = syntaxTree.WithRootAndOptions(root, syntaxTree.Options);
                return(syntaxTree);
            }
Exemplo n.º 2
0
 public MemberReferenceResolver(MonoProxy proxy, ExecutionContext ctx, SessionId sessionId, int scopeId, ILogger logger)
 {
     this.sessionId = sessionId;
     this.scopeId   = scopeId;
     this.proxy     = proxy;
     this.ctx       = ctx;
     this.logger    = logger;
     scopeCache     = ctx.GetCacheForScope(scopeId);
 }
 public MemberReferenceResolver(MonoProxy proxy, ExecutionContext ctx, MessageId msg_id, int scope_id, ILogger logger)
 {
     messageId   = msg_id;
     scopeId     = scope_id;
     this.proxy  = proxy;
     this.ctx    = ctx;
     this.logger = logger;
     scopeCache  = ctx.GetCacheForScope(scope_id);
 }
Exemplo n.º 4
0
        public DebuggerProxy(ILoggerFactory loggerFactory, IList <string> urlSymbolServerList, int runtimeId = 0, string loggerId = "", bool autoSetBreakpointOnEntryPoint = false)
        {
            string suffix = loggerId.Length > 0 ? $"-{loggerId}" : string.Empty;

            MonoProxy = new MonoProxy(loggerFactory.CreateLogger($"DevToolsProxy{suffix}"), urlSymbolServerList, runtimeId, loggerId)
            {
                AutoSetBreakpointOnEntryPoint = autoSetBreakpointOnEntryPoint
            };
        }
Exemplo n.º 5
0
 public MemberReferenceResolver(MonoProxy proxy, ExecutionContext ctx, SessionId sessionId, JArray objectValues, ILogger logger)
 {
     this.sessionId = sessionId;
     scopeId        = -1;
     this.proxy     = proxy;
     this.ctx       = ctx;
     this.logger    = logger;
     scopeCache     = new PerScopeCache(objectValues);
     localsFetched  = true;
 }
Exemplo n.º 6
0
        internal static async Task <string> CompileAndRunTheExpression(MonoProxy proxy, MessageId msg_id, int scope_id, string expression, CancellationToken token)
        {
            FindVariableNMethodCall findVarNMethodCall = new FindVariableNMethodCall();
            string     retString;
            SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(@"
				using System;
				public class CompileAndRunTheExpression
				{
					public string Evaluate()
					{
						return ("                         + expression + @").ToString(); 
					}
				}"                );

            FindThisExpression findThisExpression = new FindThisExpression(syntaxTree);
            var expressionTree = GetExpressionFromSyntaxTree(syntaxTree);

            findThisExpression.Visit(expressionTree);
            await findThisExpression.CheckIfIsProperty(proxy, msg_id, scope_id, token);

            syntaxTree = findThisExpression.syntaxTree;

            expressionTree = GetExpressionFromSyntaxTree(syntaxTree);
            findVarNMethodCall.Visit(expressionTree);

            syntaxTree = await findVarNMethodCall.ReplaceVars(syntaxTree, proxy, msg_id, scope_id, token);

            MetadataReference[] references = new MetadataReference[]
            {
                MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location)
            };

            CSharpCompilation compilation = CSharpCompilation.Create(
                "compileAndRunTheExpression",
                syntaxTrees: new [] { syntaxTree },
                references: references,
                options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

            using (var ms = new MemoryStream())
            {
                EmitResult result = compilation.Emit(ms);
                ms.Seek(0, SeekOrigin.Begin);
                Assembly assembly = Assembly.Load(ms.ToArray());
                Type     type     = assembly.GetType("CompileAndRunTheExpression");
                object   obj      = Activator.CreateInstance(type);
                var      ret      = type.InvokeMember("Evaluate",
                                                      BindingFlags.Default | BindingFlags.InvokeMethod,
                                                      null,
                                                      obj,
                                                      findVarNMethodCall.values.ToArray());
                retString = ret.ToString();
            }
            return(retString);
        }
Exemplo n.º 7
0
            public async Task CheckIfIsProperty(MonoProxy proxy, MessageId msg_id, int scope_id, CancellationToken token)
            {
                foreach (var var in thisExpressions)
                {
                    JToken value = await proxy.TryGetVariableValue(msg_id, scope_id, var, true, token);

                    if (value == null)
                    {
                        throw new Exception($"The property {var} does not exist in the current context");
                    }
                }
            }
Exemplo n.º 8
0
 public DebuggerProxy(ILoggerFactory loggerFactory)
 {
     proxy = new MonoProxy(loggerFactory);
 }
Exemplo n.º 9
0
 public DebuggerProxy(ILoggerFactory loggerFactory, IList <string> urlSymbolServerList, int runtimeId = 0)
 {
     proxy = new MonoProxy(loggerFactory, urlSymbolServerList, runtimeId);
 }
Exemplo n.º 10
0
        public DebuggerProxy(ILoggerFactory loggerFactory, IList <string> urlSymbolServerList, int runtimeId = 0, string loggerId = "", ProxyOptions options = null)
        {
            string suffix = loggerId.Length > 0 ? $"-{loggerId}" : string.Empty;

            MonoProxy = new MonoProxy(loggerFactory.CreateLogger($"DevToolsProxy{suffix}"), urlSymbolServerList, runtimeId, loggerId, options);
        }
Exemplo n.º 11
0
 public DebuggerProxy(ILoggerFactory loggerFactory, IList <string> urlSymbolServerList)
 {
     proxy = new MonoProxy(loggerFactory, urlSymbolServerList);
 }