public void ProcessBacktraceForStackFrames()
        {
            // Arrange
            const int commandId         = 3;
            const int fromFrame         = 0;
            const int toFrame           = 7;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()))
            .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            var     backtraceCommand = new BacktraceCommand(commandId, resultFactoryMock.Object, fromFrame, toFrame);
            JObject backtraceMessage = SerializationTestData.GetBacktraceResponse();

            // Act
            backtraceCommand.ProcessResponse(backtraceMessage);

            // Assert
            Assert.AreEqual(7, backtraceCommand.StackFrames.Count);
            NodeStackFrame firstFrame = backtraceCommand.StackFrames[0];

            Assert.AreEqual(NodeVariableType.AnonymousFunction, firstFrame.FunctionName);
            Assert.AreEqual(@"C:\Users\Tester\documents\visual studio 2012\Projects\NodejsApp1\NodejsApp1\server.js", firstFrame.FileName);
            Assert.AreEqual(22, firstFrame.Line);
            Assert.AreEqual(0, firstFrame.Column);
            Assert.AreEqual(15, firstFrame.Locals.Count);
            Assert.AreEqual(5, firstFrame.Parameters.Count);
            Assert.IsNotNull(backtraceCommand.Modules);
            Assert.AreEqual(3, backtraceCommand.Modules.Count);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Exactly(51));
        }
        public NodeBacktraceVariable(NodeStackFrame stackFrame, JToken parameter)
        {
            Utilities.ArgumentNotNull("stackFrame", stackFrame);
            Utilities.ArgumentNotNull("parameter", parameter);

            var value = parameter["value"];

            this.Id         = (int)value["ref"];
            this.Parent     = null;
            this.StackFrame = stackFrame;
            this.Name       = (string)parameter["name"] ?? NodeVariableType.AnonymousVariable;
            this.TypeName   = (string)value["type"];
            this.Value      = (string)value["value"];
            this.Class      = (string)value["className"];
            try
            {
                this.Text = (string)value["text"];
            }
            catch (ArgumentException)
            {
                this.Text = string.Empty;
            }
            this.Attributes = NodePropertyAttributes.None;
            this.Type       = NodePropertyType.Normal;
        }
        public void ProcessEvaluateResponseWithReferenceError()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()));
            const string expression      = "hello";
            var          stackFrame      = new NodeStackFrame(0);
            var          evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame);
            Exception    exception       = null;

            // Act
            try
            {
                evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponseWithReferenceError());
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(DebuggerCommandException));
            Assert.AreEqual("ReferenceError: hello is not defined", exception.Message);
            Assert.IsNull(evaluateCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Never);
        }
 private AD7MemoryAddress(AD7Engine engine, NodeStackFrame frame, string fileName, int line, int column) {
     _engine = engine;
     _frame = frame;
     _fileName = fileName;
     _line = line;
     _column = column;
 }
Beispiel #5
0
        /// <summary>
        ///     Returns information about the given stack frame for the given process and thread ID.
        ///     If the process, thread, or frame are unknown the null is returned.
        ///     New in 1.5.
        /// </summary>
        public static IDebugDocumentContext2 GetCodeMappingDocument(int processId, int threadId, int frame)
        {
            if (frame >= 0)
            {
                foreach (WeakReference engineRef in Engines)
                {
                    var engine = engineRef.Target as AD7Engine;
                    if (engine != null)
                    {
                        if (engine._process.Id == processId)
                        {
                            NodeThread thread = engine._threads.Item1;

                            if (thread.Id == threadId)
                            {
                                IList <NodeStackFrame> frames = thread.Frames;

                                if (frame < frames.Count)
                                {
                                    NodeStackFrame curFrame = thread.Frames[frame];
                                    return(null);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
Beispiel #6
0
        public override void ProcessResponse(JObject response)
        {
            base.ProcessResponse(response);

            var body = response["body"];

            this.CallstackDepth = (int)body["totalFrames"];

            // Collect frames only if required
            if (this._depthOnly)
            {
                this.Modules     = new Dictionary <int, NodeModule>();
                this.StackFrames = new List <NodeStackFrame>();
                return;
            }

            // Extract scripts (if not provided)
            this.Modules = GetModules((JArray)response["refs"]);

            // Extract frames
            var frames = (JArray)body["frames"] ?? new JArray();

            this.StackFrames = new List <NodeStackFrame>(frames.Count);

            foreach (var frame in frames)
            {
                // Create stack frame
                var functionName = GetFunctionName(frame);
                var moduleId     = (int?)frame["func"]["scriptId"];

                NodeModule module;
                if (!moduleId.HasValue || !this.Modules.TryGetValue(moduleId.Value, out module))
                {
                    module = this._unknownModule;
                }

                var line    = (int?)frame["line"] ?? 0;
                var column  = (int?)frame["column"] ?? 0;
                var frameId = (int?)frame["index"] ?? 0;

                var stackFrame = new NodeStackFrame(frameId)
                {
                    Column       = column,
                    FunctionName = functionName,
                    Line         = line,
                    Module       = module
                };

                // Locals
                var variables = (JArray)frame["locals"] ?? new JArray();
                stackFrame.Locals = GetVariables(stackFrame, variables);

                // Arguments
                variables             = (JArray)frame["arguments"] ?? new JArray();
                stackFrame.Parameters = GetVariables(stackFrame, variables);

                this.StackFrames.Add(stackFrame);
            }
        }
 private AD7MemoryAddress(AD7Engine engine, NodeStackFrame frame, string fileName, int line, int column)
 {
     _engine   = engine;
     _frame    = frame;
     _fileName = fileName;
     _line     = line;
     _column   = column;
 }
        public override void Execute(object[] arguments)
        {
            if (arguments.Length != 1)
            {
                throw new ArgumentOutOfRangeException("arguments");
            }

            var debugger = arguments[0] as IDebuggerManager;
            if (debugger == null)
            {
                string message = string.Format("Invalid arguments: {0}", arguments);
                throw new ArgumentException(message, "arguments");
            }

            // Extract scripts
            var references = (JArray) _message["refs"];
            Dictionary<int, NodeScript> scripts = GetScripts(references);
            Scripts = scripts.Values.ToList();

            // Extract frames
            var frames = (JArray) _message["body"]["frames"];
            if (frames == null)
            {
                StackFrames = new List<NodeStackFrame>();
                return;
            }

            var stackFrames = new List<NodeStackFrame>(frames.Count);

            for (int i = 0; i < frames.Count; i++)
            {
                JToken frame = frames[i];

                // Create stack frame
                string name = GetFrameName(frame);
                var scriptId = (int) frame["func"]["scriptId"];
                NodeScript script = scripts[scriptId];
                int line = (int) frame["line"] + 1;
                var stackFrameId = (int) frame["index"];

                var stackFrame = new NodeStackFrame(debugger, name, script.Filename, line, line, line, stackFrameId);

                // Locals
                var variables = (JArray) frame["locals"];
                List<NodeEvaluationResult> locals = GetVariables(variables, debugger, stackFrame);

                // Parameters
                variables = (JArray) frame["arguments"];
                List<NodeEvaluationResult> parameters = GetVariables(variables, debugger, stackFrame);

                stackFrame.Locals = locals;
                stackFrame.Parameters = parameters;

                stackFrames.Add(stackFrame);
            }

            StackFrames = stackFrames;
        }
Beispiel #9
0
        public AD7StackFrame(AD7Engine engine, AD7Thread thread, NodeStackFrame threadContext)
        {
            _engine     = engine;
            _thread     = thread;
            _stackFrame = threadContext;

            _parameters = threadContext.Parameters.ToArray();
            _locals     = threadContext.Locals.ToArray();
        }
        /// <summary>
        /// Handles backtrace response message.
        /// </summary>
        /// <param name="thread">Thread.</param>
        /// <param name="message">Message.</param>
        /// <returns>Array of stack frames.</returns>
        public void ProcessBacktrace(NodeThread thread, Dictionary<int, NodeModule> modules, JsonValue message, Action<NodeStackFrame[]> successHandler) {
            Utilities.ArgumentNotNull("thread", thread);
            Utilities.ArgumentNotNull("message", message);

            // Extract scripts (if not provided)
            if (modules == null) {
                JsonArray refs = message.GetArray("refs");
                modules = GetScripts(thread.Process, refs);
            }

            // Extract frames
            JsonValue body = message["body"];
            JsonArray frames = body.GetArray("frames");
            if (frames == null) {
                if (successHandler != null) {
                    successHandler(new NodeStackFrame[] { });
                }
                return;
            }

            var stackFrames = new List<NodeStackFrame>(frames.Count);

            for (int i = 0; i < frames.Count; i++) {
                JsonValue frame = frames[i];

                // Create stack frame
                string name = GetFrameName(frame);
                var moduleId = frame["func"].GetValue<int>("scriptId");
                NodeModule module;
                if (!modules.TryGetValue(moduleId, out module)) {
                    module = _unknownModule;
                }

                int line = frame.GetValue<int>("line") + 1;
                var stackFrameId = frame.GetValue<int>("index");

                var stackFrame = new NodeStackFrame(thread, module, name, line, line, line, stackFrameId);

                // Locals
                JsonArray variables = frame.GetArray("locals");
                List<NodeEvaluationResult> locals = GetVariables(stackFrame, variables);

                // Arguments
                variables = frame.GetArray("arguments");
                List<NodeEvaluationResult> parameters = GetVariables(stackFrame, variables);

                stackFrame.Locals = locals;
                stackFrame.Parameters = parameters;

                stackFrames.Add(stackFrame);
            }

            if (successHandler != null) {
                successHandler(stackFrames.ToArray());
            }
        }
        /// <summary>
        /// Handles evaluate response message.
        /// </summary>
        /// <param name="stackFrame">Stack frame.</param>
        /// <param name="expression">Expression.</param>
        /// <param name="message">Message.</param>
        /// <returns>Evaluation result.</returns>
        public NodeEvaluationResult ProcessEvaluate(NodeStackFrame stackFrame, string expression, JsonValue message)
        {
            Utilities.ArgumentNotNull("stackFrame", stackFrame);
            Utilities.ArgumentNotNull("expression", expression);
            Utilities.ArgumentNotNull("message", message);

            JsonValue body             = message["body"];
            var       variableProvider = new NodeEvaluationVariable(stackFrame, expression, body);

            return(_evaluationResultFactory.Create(variableProvider));
        }
        private List <NodeEvaluationResult> GetVariables(NodeStackFrame stackFrame, JsonArray variables)
        {
            var results = new List <NodeEvaluationResult>(variables.Count);

            for (int i = 0; i < variables.Count; i++)
            {
                var variableProvider        = new NodeBacktraceVariable(stackFrame, variables[i]);
                NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider);
                results.Add(result);
            }
            return(results.ToList());
        }
 public NodeSetValueVariable(NodeStackFrame stackFrame, string name, JToken message) {
     Id = (int)message["body"]["newValue"]["handle"];
     StackFrame = stackFrame;
     Parent = null;
     Name = name;
     TypeName = (string)message["body"]["newValue"]["type"];
     Value = (string)message["body"]["newValue"]["value"];
     Class = (string)message["body"]["newValue"]["className"];
     Text = (string)message["body"]["newValue"]["text"];
     Attributes = NodePropertyAttributes.None;
     Type = NodePropertyType.Normal;
 }
 public NodeSetValueVariable(NodeStackFrame stackFrame, string name, JToken message)
 {
     this.Id         = (int)message["body"]["newValue"]["handle"];
     this.StackFrame = stackFrame;
     this.Parent     = null;
     this.Name       = name;
     this.TypeName   = (string)message["body"]["newValue"]["type"];
     this.Value      = (string)message["body"]["newValue"]["value"];
     this.Class      = (string)message["body"]["newValue"]["className"];
     this.Text       = (string)message["body"]["newValue"]["text"];
     this.Attributes = NodePropertyAttributes.None;
     this.Type       = NodePropertyType.Normal;
 }
 public BacktraceVariableProvider(JToken parameter, IDebuggerManager debugger, NodeStackFrame stackFrame)
 {
     Id = (int) parameter["value"]["ref"];
     Debugger = debugger;
     StackFrame = stackFrame;
     Parent = null;
     Name = (string) parameter["name"] ?? AnonymousVariable;
     TypeName = (string) parameter["value"]["type"];
     Value = (string) parameter["value"]["value"];
     Class = (string) parameter["value"]["className"];
     Text = (string) parameter["value"]["text"];
     Attributes = PropertyAttribute.None;
     Type = PropertyType.Normal;
 }
 public EvaluateVariableProvider(JObject message, IDebuggerManager debugger, NodeStackFrame stackFrame, string name)
 {
     Id = (int) message["body"]["handle"];
     Debugger = debugger;
     StackFrame = stackFrame;
     Parent = null;
     Name = name;
     TypeName = (string) message["body"]["type"];
     Value = (string) message["body"]["value"];
     Class = (string) message["body"]["className"];
     Text = (string) message["body"]["text"];
     Attributes = PropertyAttribute.None;
     Type = PropertyType.Normal;
 }
Beispiel #17
0
        public EvaluateCommand(int id, IEvaluationResultFactory resultFactory, string expression, NodeStackFrame stackFrame = null)
            : base(id, "evaluate") {
            _resultFactory = resultFactory;
            _expression = expression;
            _stackFrame = stackFrame;

            _arguments = new Dictionary<string, object> {
                { "expression", _expression },
                { "frame", _stackFrame != null ? _stackFrame.FrameId : 0 },
                { "global", false },
                { "disable_break", true },
                { "maxStringLength", -1 }
            };
        }
Beispiel #18
0
 public BacktraceVariableProvider(JToken parameter, IDebuggerManager debugger, NodeStackFrame stackFrame)
 {
     Id         = (int)parameter["value"]["ref"];
     Debugger   = debugger;
     StackFrame = stackFrame;
     Parent     = null;
     Name       = (string)parameter["name"] ?? AnonymousVariable;
     TypeName   = (string)parameter["value"]["type"];
     Value      = (string)parameter["value"]["value"];
     Class      = (string)parameter["value"]["className"];
     Text       = (string)parameter["value"]["text"];
     Attributes = PropertyAttribute.None;
     Type       = PropertyType.Normal;
 }
Beispiel #19
0
 public NewValueVariableProvider(JObject message, IDebuggerManager debugger, NodeStackFrame stackFrame, string name)
 {
     Id         = (int)message["body"]["newValue"]["handle"];
     Debugger   = debugger;
     StackFrame = stackFrame;
     Parent     = null;
     Name       = name;
     TypeName   = (string)message["body"]["newValue"]["type"];
     Value      = (string)message["body"]["newValue"]["value"];
     Class      = (string)message["body"]["newValue"]["className"];
     Text       = (string)message["body"]["newValue"]["text"];
     Attributes = PropertyAttribute.None;
     Type       = PropertyType.Normal;
 }
        public NodeEvaluationVariable(NodeStackFrame stackFrame, string name, JToken message) {
            Utilities.ArgumentNotNull("name", name);
            Utilities.ArgumentNotNull("message", message);

            Id = (int)message["handle"];
            Parent = null;
            StackFrame = stackFrame;
            Name = name;
            TypeName = (string)message["type"];
            Value = (string)message["value"];
            Class = (string)message["className"];
            Text = (string)message["text"];
            Attributes = NodePropertyAttributes.None;
            Type = NodePropertyType.Normal;
        }
Beispiel #21
0
        public EvaluateCommand(int id, IEvaluationResultFactory resultFactory, int variableId, NodeStackFrame stackFrame = null)
            : base(id, "evaluate") {
            _resultFactory = resultFactory;
            _expression = "variable";
            _stackFrame = stackFrame;

            _arguments = new Dictionary<string, object> {
                { "expression", _expression + ".toString()" },
                { "frame", _stackFrame != null ? _stackFrame.FrameId : 0 },
                { "global", false },
                { "disable_break", true },
                { "additional_context", new[] { new { name = _expression, handle = variableId } } },
                { "maxStringLength", -1 }
            };
        }
Beispiel #22
0
        public EvaluateCommand(int id, IEvaluationResultFactory resultFactory, string expression, NodeStackFrame stackFrame = null)
            : base(id, "evaluate")
        {
            this._resultFactory = resultFactory;
            this._expression    = expression;
            this._stackFrame    = stackFrame;

            this._arguments = new Dictionary <string, object> {
                { "expression", _expression },
                { "frame", _stackFrame != null ? _stackFrame.FrameId : 0 },
                { "global", false },
                { "disable_break", true },
                { "maxStringLength", -1 }
            };
        }
        public SetVariableValueCommand(int id, IEvaluationResultFactory resultFactory, NodeStackFrame stackFrame, string name, int handle)
            : base(id, "setVariableValue") {
            Utilities.ArgumentNotNull("resultFactory", resultFactory);
            Utilities.ArgumentNotNull("stackFrame", stackFrame);
            Utilities.ArgumentNotNullOrEmpty("name", name);

            _resultFactory = resultFactory;
            _stackFrame = stackFrame;
            _name = name;

            _arguments = new Dictionary<string, object> {
                { "name", name },
                { "newValue", new { handle } },
                { "scope", new { frameNumber = stackFrame.FrameId, number = 0 } }
            };
        }
Beispiel #24
0
        public NodeEvaluationVariable(NodeStackFrame stackFrame, string name, JToken message)
        {
            Utilities.ArgumentNotNull("name", name);
            Utilities.ArgumentNotNull("message", message);

            this.Id         = (int)message["handle"];
            this.Parent     = null;
            this.StackFrame = stackFrame;
            this.Name       = name;
            this.TypeName   = (string)message["type"];
            this.Value      = (string)message["value"];
            this.Class      = (string)message["className"];
            this.Text       = (string)message["text"];
            this.Attributes = NodePropertyAttributes.None;
            this.Type       = NodePropertyType.Normal;
        }
Beispiel #25
0
        public EvaluateCommand(int id, IEvaluationResultFactory resultFactory, int variableId, NodeStackFrame stackFrame = null)
            : base(id, "evaluate")
        {
            this._resultFactory = resultFactory;
            this._expression    = "variable";
            this._stackFrame    = stackFrame;

            this._arguments = new Dictionary <string, object> {
                { "expression", _expression + ".toString()" },
                { "frame", _stackFrame != null ? _stackFrame.FrameId : 0 },
                { "global", false },
                { "disable_break", true },
                { "additional_context", new[] { new { name = _expression, handle = variableId } } },
                { "maxStringLength", -1 }
            };
        }
Beispiel #26
0
        public SetVariableValueCommand(int id, IEvaluationResultFactory resultFactory, NodeStackFrame stackFrame, string name, int handle)
            : base(id, "setVariableValue")
        {
            Utilities.ArgumentNotNull(nameof(resultFactory), resultFactory);
            Utilities.ArgumentNotNull(nameof(stackFrame), stackFrame);
            Utilities.ArgumentNotNullOrEmpty(nameof(name), name);

            this._resultFactory = resultFactory;
            this._stackFrame    = stackFrame;
            this._name          = name;

            this._arguments = new Dictionary <string, object> {
                { "name", name },
                { "newValue", new { handle } },
                { "scope", new { frameNumber = stackFrame.FrameId, number = 0 } }
            };
        }
Beispiel #27
0
        public void CreateBacktraceVariableWithNullJson()
        {
            // Arrange
            var                   stackFrame = new NodeStackFrame(0);
            Exception             exception  = null;
            NodeBacktraceVariable result     = null;

            // Act
            try {
                result = new NodeBacktraceVariable(stackFrame, null);
            } catch (Exception e) {
                exception = e;
            }

            // Assert
            Assert.IsNull(result);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(ArgumentNullException));
        }
        public void CreateSetVariableValueCommand()
        {
            // Arrange
            const int    commandId         = 3;
            const int    frameId           = 1;
            var          resultFactoryMock = new Mock <IEvaluationResultFactory>();
            var          stackFrame        = new NodeStackFrame(frameId);
            const string variableName      = "port";
            const int    handle            = 40;

            // Act
            var setVariableValueCommand = new SetVariableValueCommand(commandId, resultFactoryMock.Object, stackFrame, variableName, handle);

            // Assert
            Assert.AreEqual(commandId, setVariableValueCommand.Id);
            Assert.AreEqual(
                string.Format("{{\"command\":\"setVariableValue\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"name\":\"{1}\",\"newValue\":{{\"handle\":{2}}},\"scope\":{{\"frameNumber\":{3},\"number\":0}}}}}}",
                              commandId, variableName, handle, frameId),
                setVariableValueCommand.ToString());
        }
        public NodeBacktraceVariable(NodeStackFrame stackFrame, JToken parameter) {
            Utilities.ArgumentNotNull("stackFrame", stackFrame);
            Utilities.ArgumentNotNull("parameter", parameter);

            JToken value = parameter["value"];
            Id = (int)value["ref"];
            Parent = null;
            StackFrame = stackFrame;
            Name = (string)parameter["name"] ?? NodeVariableType.AnonymousVariable;
            TypeName = (string)value["type"];
            Value = (string)value["value"];
            Class = (string)value["className"];
            try {
                Text = (string)value["text"];
            } catch (ArgumentException) {
                Text = String.Empty;
            }
            Attributes = NodePropertyAttributes.None;
            Type = NodePropertyType.Normal;
        }
        public void ProcessEvaluateResponse()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()))
            .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            const string expression      = "expression";
            var          stackFrame      = new NodeStackFrame(0);
            var          evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame);

            // Act
            evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponse());

            // Assert
            Assert.AreEqual(commandId, evaluateCommand.Id);
            Assert.IsNotNull(evaluateCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Once);
        }
Beispiel #31
0
        public void CreateBacktraceVariableWithNullName()
        {
            // Arrange
            JObject json       = SerializationTestData.GetBacktraceJsonObjectWithNullName();
            var     stackFrame = new NodeStackFrame(0);

            // Act
            var result = new NodeBacktraceVariable(stackFrame, json);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(21, result.Id);
            Assert.AreEqual(NodeVariableType.AnonymousVariable, result.Name);
            Assert.IsNull(result.Parent);
            Assert.AreEqual(stackFrame, result.StackFrame);
            Assert.IsNull(result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("boolean", result.TypeName);
        }
        public void ProcessSetVariableValueResponse()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()))
            .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            var          stackFrame              = new NodeStackFrame(0);
            const string variableName            = "port";
            const int    handle                  = 40;
            var          setVariableValueCommand = new SetVariableValueCommand(commandId, resultFactoryMock.Object, stackFrame, variableName, handle);

            // Act
            setVariableValueCommand.ProcessResponse(SerializationTestData.GetSetVariableValueResponse());

            // Assert
            Assert.AreEqual(commandId, setVariableValueCommand.Id);
            Assert.IsNotNull(setVariableValueCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Once);
        }
Beispiel #33
0
        public void CreateEvaluationVariable()
        {
            // Arrange
            JObject      json       = SerializationTestData.GetEvaluationJsonObject();
            var          stackFrame = new NodeStackFrame(0);
            const string name       = "name";

            // Act
            var result = new NodeEvaluationVariable(stackFrame, name, json);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(16, result.Id);
            Assert.AreEqual(name, result.Name);
            Assert.IsNull(result.Parent);
            Assert.AreEqual(stackFrame, result.StackFrame);
            Assert.AreEqual("<tag>Value</tag>", result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("string", result.TypeName);
            Assert.AreEqual("<tag>Value</tag>", result.Value);
        }
        public void CreateSetVariableValue()
        {
            // Arrange
            JObject      json       = SerializationTestData.GetSetVariableValueResponse();
            const int    frameId    = 3;
            var          stackFrame = new NodeStackFrame(frameId);
            const string name       = "name";

            // Act
            var result = new NodeSetValueVariable(stackFrame, name, json);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(44, result.Id);
            Assert.AreEqual(name, result.Name);
            Assert.IsNull(result.Parent);
            Assert.AreEqual(stackFrame, result.StackFrame);
            Assert.AreEqual("55", result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("number", result.TypeName);
            Assert.AreEqual("55", result.Value);
        }
        /// <summary>
        /// Handles evaluate response message.
        /// </summary>
        /// <param name="stackFrame">Stack frame.</param>
        /// <param name="expression">Expression.</param>
        /// <param name="message">Message.</param>
        /// <returns>Evaluation result.</returns>
        public NodeEvaluationResult ProcessEvaluate(NodeStackFrame stackFrame, string expression, JsonValue message) {
            Utilities.ArgumentNotNull("stackFrame", stackFrame);
            Utilities.ArgumentNotNull("expression", expression);
            Utilities.ArgumentNotNull("message", message);

            JsonValue body = message["body"];
            var variableProvider = new NodeEvaluationVariable(stackFrame, expression, body);
            return _evaluationResultFactory.Create(variableProvider);
        }
 private List<NodeEvaluationResult> GetVariables(NodeStackFrame stackFrame, JsonArray variables) {
     var results = new List<NodeEvaluationResult>(variables.Count);
     for (int i = 0; i < variables.Count; i++) {
         var variableProvider = new NodeBacktraceVariable(stackFrame, variables[i]);
         NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider);
         results.Add(result);
     }
     return results.ToList();
 }
        /// <summary>
        ///     Gets a collection of descentants for a variable.
        /// </summary>
        /// <param name="variable">Variable.</param>
        /// <param name="stackFrame">Stack frame.</param>
        /// <returns>Collection of descendants.</returns>
        public async Task<IList<NodeEvaluationResult>> GetChildrenAsync(NodeEvaluationResult variable, NodeStackFrame stackFrame)
        {
            IResponseMessage response = await _client.SendMessage("lookup", new
                {
                    handles = new[] {variable.Id},
                    includeSource = false
                }, variable).ConfigureAwait(false);

            var lookupMessage = response as LookupMessage;
            if (lookupMessage == null || !lookupMessage.IsSuccessful)
            {
                string message = string.Format("Invalid lookup response: {0}", response);
                throw new InvalidOperationException(message);
            }

            IsRunning = response.IsRunning;
            return lookupMessage.Children;
        }
        /// <summary>
        /// Handles backtrace response message.
        /// </summary>
        /// <param name="thread">Thread.</param>
        /// <param name="message">Message.</param>
        /// <returns>Array of stack frames.</returns>
        public void ProcessBacktrace(NodeThread thread, Dictionary <int, NodeModule> modules, JsonValue message, Action <NodeStackFrame[]> successHandler)
        {
            Utilities.ArgumentNotNull("thread", thread);
            Utilities.ArgumentNotNull("message", message);

            // Extract scripts (if not provided)
            if (modules == null)
            {
                JsonArray refs = message.GetArray("refs");
                modules = GetScripts(thread.Process, refs);
            }

            // Extract frames
            JsonValue body   = message["body"];
            JsonArray frames = body.GetArray("frames");

            if (frames == null)
            {
                if (successHandler != null)
                {
                    successHandler(new NodeStackFrame[] { });
                }
                return;
            }

            var stackFrames = new List <NodeStackFrame>(frames.Count);

            for (int i = 0; i < frames.Count; i++)
            {
                JsonValue frame = frames[i];

                // Create stack frame
                string     name     = GetFrameName(frame);
                var        moduleId = frame["func"].GetValue <int>("scriptId");
                NodeModule module;
                if (!modules.TryGetValue(moduleId, out module))
                {
                    module = _unknownModule;
                }

                int line         = frame.GetValue <int>("line") + 1;
                var stackFrameId = frame.GetValue <int>("index");

                var stackFrame = new NodeStackFrame(thread, module, name, line, line, line, stackFrameId);

                // Locals
                JsonArray variables = frame.GetArray("locals");
                List <NodeEvaluationResult> locals = GetVariables(stackFrame, variables);

                // Arguments
                variables = frame.GetArray("arguments");
                List <NodeEvaluationResult> parameters = GetVariables(stackFrame, variables);

                stackFrame.Locals     = locals;
                stackFrame.Parameters = parameters;

                stackFrames.Add(stackFrame);
            }

            if (successHandler != null)
            {
                successHandler(stackFrames.ToArray());
            }
        }
Beispiel #39
0
 public AD7StackFrame(AD7Engine engine, AD7Thread thread, NodeStackFrame stackFrame)
 {
     this._engine     = engine;
     this._thread     = thread;
     this._stackFrame = stackFrame;
 }
Beispiel #40
0
 private List <NodeEvaluationResult> GetVariables(NodeStackFrame stackFrame, IEnumerable <JToken> variables)
 {
     return(variables.Select(t => new NodeBacktraceVariable(stackFrame, t))
            .Select(variableProvider => this._resultFactory.Create(variableProvider)).ToList());
 }
Beispiel #41
0
 public AD7MemoryAddress(AD7Engine engine, NodeStackFrame frame)
     : this(engine, frame, null, frame.Line, frame.Column)
 {
 }
 private List<NodeEvaluationResult> GetVariables(NodeStackFrame stackFrame, IEnumerable<JToken> variables) {
     return variables.Select(t => new NodeBacktraceVariable(stackFrame, t))
         .Select(variableProvider => _resultFactory.Create(variableProvider)).ToList();
 }
        public override void ProcessResponse(JObject response) {
            base.ProcessResponse(response);

            JToken body = response["body"];
            CallstackDepth = (int)body["totalFrames"];

            // Collect frames only if required
            if (_depthOnly) {
                Modules = new Dictionary<int, NodeModule>();
                StackFrames = new List<NodeStackFrame>();
                return;
            }

            // Extract scripts (if not provided)
            Modules = GetModules((JArray)response["refs"]);

            // Extract frames
            JArray frames = (JArray)body["frames"] ?? new JArray();
            StackFrames = new List<NodeStackFrame>(frames.Count);

            foreach (JToken frame in frames) {
                // Create stack frame
                string functionName = GetFunctionName(frame);
                var moduleId = (int?)frame["func"]["scriptId"];

                NodeModule module;
                if (!moduleId.HasValue || !Modules.TryGetValue(moduleId.Value, out module)) {
                    module = _unknownModule;
                }

                int line = (int?)frame["line"] ?? 0;
                int column = (int?)frame["column"] ?? 0;
                int frameId = (int?)frame["index"] ?? 0;

                var stackFrame = new NodeStackFrame(frameId) {
                    Column = column,
                    FunctionName = functionName,
                    Line = line,
                    Module = module
                };

                // Locals
                JArray variables = (JArray)frame["locals"] ?? new JArray();
                stackFrame.Locals = GetVariables(stackFrame, variables);

                // Arguments
                variables = (JArray)frame["arguments"] ?? new JArray();
                stackFrame.Parameters = GetVariables(stackFrame, variables);

                StackFrames.Add(stackFrame);
            }
        }
Beispiel #44
0
        private static List <NodeEvaluationResult> GetVariables(JArray variables, IDebuggerManager debugger, NodeStackFrame stackFrame)
        {
            var results = new List <NodeEvaluationResult>(variables.Count);

            for (int j = 0; j < variables.Count; j++)
            {
                JToken variable             = variables[j];
                var    variableProvider     = new BacktraceVariableProvider(variable, debugger, stackFrame);
                NodeEvaluationResult result = NodeMessageFactory.CreateVariable(variableProvider);
                results.Add(result);
            }
            return(results);
        }
Beispiel #45
0
        public override void Execute(object[] arguments)
        {
            if (arguments.Length != 1)
            {
                throw new ArgumentOutOfRangeException("arguments");
            }

            var debugger = arguments[0] as IDebuggerManager;

            if (debugger == null)
            {
                string message = string.Format("Invalid arguments: {0}", arguments);
                throw new ArgumentException(message, "arguments");
            }

            // Extract scripts
            var references = (JArray)_message["refs"];
            Dictionary <int, NodeScript> scripts = GetScripts(references);

            Scripts = scripts.Values.ToList();

            // Extract frames
            var frames = (JArray)_message["body"]["frames"];

            if (frames == null)
            {
                StackFrames = new List <NodeStackFrame>();
                return;
            }

            var stackFrames = new List <NodeStackFrame>(frames.Count);

            for (int i = 0; i < frames.Count; i++)
            {
                JToken frame = frames[i];

                // Create stack frame
                string     name         = GetFrameName(frame);
                var        scriptId     = (int)frame["func"]["scriptId"];
                NodeScript script       = scripts[scriptId];
                int        line         = (int)frame["line"] + 1;
                var        stackFrameId = (int)frame["index"];

                var stackFrame = new NodeStackFrame(debugger, name, script.Filename, line, line, line, stackFrameId);

                // Locals
                var variables = (JArray)frame["locals"];
                List <NodeEvaluationResult> locals = GetVariables(variables, debugger, stackFrame);

                // Parameters
                variables = (JArray)frame["arguments"];
                List <NodeEvaluationResult> parameters = GetVariables(variables, debugger, stackFrame);

                stackFrame.Locals     = locals;
                stackFrame.Parameters = parameters;

                stackFrames.Add(stackFrame);
            }

            StackFrames = stackFrames;
        }
Beispiel #46
0
 public AD7StackFrame(AD7Engine engine, AD7Thread thread, NodeStackFrame stackFrame) {
     _engine = engine;
     _thread = thread;
     _stackFrame = stackFrame;
 }
 public AD7MemoryAddress(AD7Engine engine, NodeStackFrame frame)
     : this(engine, frame, null, frame.Line, frame.Column) {
 }
        public async Task<NodeEvaluationResult> EvaluateExpressionAsync(string expression, NodeStackFrame stackFrame)
        {
            IResponseMessage response = await _client.SendMessage("evaluate", new
                {
                    expression,
                    frame = stackFrame.Id
                }, this, stackFrame, expression).ConfigureAwait(false);

            var evaluateMessage = response as EvaluateMessage;
            if (evaluateMessage == null || !evaluateMessage.IsSuccessful)
            {
                return null;
            }

            IsRunning = response.IsRunning;
            return evaluateMessage.Result;
        }
Beispiel #49
0
 public AD7StackFrame(AD7Engine engine, AD7Thread thread, NodeStackFrame stackFrame)
 {
     _engine     = engine;
     _thread     = thread;
     _stackFrame = stackFrame;
 }
 private static List<NodeEvaluationResult> GetVariables(JArray variables, IDebuggerManager debugger, NodeStackFrame stackFrame)
 {
     var results = new List<NodeEvaluationResult>(variables.Count);
     for (int j = 0; j < variables.Count; j++)
     {
         JToken variable = variables[j];
         var variableProvider = new BacktraceVariableProvider(variable, debugger, stackFrame);
         NodeEvaluationResult result = NodeMessageFactory.CreateVariable(variableProvider);
         results.Add(result);
     }
     return results;
 }