public ObjectValue[] GetLocalVariables(int frameIndex, EvaluationOptions options)
		{
			List<ObjectValue> values = new List<ObjectValue>();
			if (Engine.Symbols.ScopeLocalSymbols == null)
				return values.ToArray();

			for (uint i = 0; i < Engine.Symbols.ScopeLocalSymbols.Count; i++)
			{
				if (Engine.Symbols.ScopeLocalSymbols.Symbols[i].Parent != null)
					continue;

				string name = Engine.Symbols.ScopeLocalSymbols.Symbols[i].Name;
				string typename = Engine.Symbols.ScopeLocalSymbols.Symbols[i].TypeName;
				string val = Engine.Symbols.ScopeLocalSymbols.Symbols[i].TextValue;
				ulong offset = Engine.Symbols.ScopeLocalSymbols.Symbols[i].Offset;
				DEW.DebugScopedSymbol parentSymbol = Engine.Symbols.ScopeLocalSymbols.Symbols[i].Parent;

				ObjectValue ov = symbolResolver.Resolve(offset, name, typename, val, parentSymbol);
				if (ov == null)
				{
					ObjectValueFlags flags = ObjectValueFlags.Variable;
					ov = ObjectValue.CreatePrimitive(this, new ObjectPath(name), typename, new EvaluationResult(val), flags);
				}

				if (ov != null)
					values.Add(ov);
			}
			return values.ToArray();
		}
Пример #2
0
		public object CallMethod (string name, object[] parameters, out object[] outArgs, EvaluationOptions options)
		{
			object[] tempOutArgs = null;
			var result = MtaThread.Run (() => source.CallMethod (name, parameters, out tempOutArgs, options));
			outArgs = tempOutArgs;
			return result;
		}
		public ObjectValue[] GetChildren (ObjectPath path, int index, int count, EvaluationOptions options)
		{
			EvaluationContext cctx = ctx.WithOptions (options);
			var names = new ObjectValueNameTracker (cctx);
			object tdataType = null;
			TypeDisplayData tdata = null;
			List<ObjectValue> list = new List<ObjectValue> ();
			foreach (ValueReference val in cctx.Adapter.GetMembersSorted (cctx, objectSource, type, obj, bindingFlags)) {
				object decType = val.DeclaringType;
				if (decType != null && decType != tdataType) {
					tdataType = decType;
					tdata = cctx.Adapter.GetTypeDisplayData (cctx, decType);
				}
				DebuggerBrowsableState state = tdata.GetMemberBrowsableState (val.Name);
				if (state == DebuggerBrowsableState.Never)
					continue;
				ObjectValue oval = val.CreateObjectValue (options);
				names.FixName (val, oval);
				list.Add (oval);
			}
			if ((bindingFlags & BindingFlags.NonPublic) == 0) {
				BindingFlags newFlags = bindingFlags | BindingFlags.NonPublic;
				newFlags &= ~BindingFlags.Public;
				list.Add (CreateNonPublicsNode (cctx, objectSource, type, obj, newFlags));
			}
			return list.ToArray ();
		}
Пример #4
0
        public SoftEvaluationContext(SoftDebuggerSession session, StackFrame frame, DC.EvaluationOptions options) : base(options)
        {
            Frame  = frame;
            Thread = frame.Thread;
            Domain = Thread.Domain;

            string method = frame.Method.Name;

            if (frame.Method.DeclaringType != null)
            {
                method = frame.Method.DeclaringType.FullName + "." + method;
            }
            var    location = new DC.SourceLocation(method, frame.FileName, frame.LineNumber, frame.ColumnNumber);
            string language;

            if (frame.Method != null)
            {
                language = frame.IsNativeTransition ? "Transition" : "Managed";
            }
            else
            {
                language = "Native";
            }

            Evaluator       = session.GetEvaluator(new DC.StackFrame(frame.ILOffset, location, language, session.IsExternalCode(frame), true));
            Adapter         = session.Adaptor;
            this.session    = session;
            stackVersion    = session.StackVersion;
            sourceAvailable = !string.IsNullOrEmpty(frame.FileName) && System.IO.File.Exists(frame.FileName);
        }
Пример #5
0
 public ObjectValue[] GetAllLocals(int frameIndex, EvaluationOptions options)
 {
     List<ObjectValue> locals = new List<ObjectValue> ();
     locals.AddRange (GetParameters (frameIndex, options));
     locals.AddRange (GetLocalVariables (frameIndex, options));
     return locals.ToArray ();
 }
		public ObjectValue[] GetParameters(int frameIndex, EvaluationOptions options)
		{
			List<ObjectValue> values = new List<ObjectValue>();

			SelectFrame(frameIndex);

			return values.ToArray();
		}
        public override ExceptionInfo GetException(int frameIndex, EvaluationOptions options)
        {

            ObjectValue val = CreateExceptionObject(exceptionRecord);
            ExceptionInfo result = new ExceptionInfo(val);

            return result;
        }
		public ObjectValue[] GetExpressionValues(int frameIndex, string[] expressions, EvaluationOptions options)
		{
			List<ObjectValue> values = new List<ObjectValue>();

			SelectFrame(frameIndex);
			foreach (string exp in expressions)
				values.Add(CreateVarObject(exp));
			return values.ToArray();
		}
		public EvaluationContext WithOptions (EvaluationOptions options)
		{
			if (options == null || Options == options)
				return this;

			EvaluationContext clone = Clone ();
			clone.Options = options;
			return clone;
		}
		public void SetMemberValue (string name, object value, EvaluationOptions options)
		{
			EvaluationContext localContext = ctx.WithOptions (options);
			object type = localContext.Adapter.GetValueType (localContext, targetObject);
			ValueReference val = localContext.Adapter.GetMember (localContext, source, type, targetObject, name);
			if (val == null)
				throw new EvaluatorException ("Member '{0}' not found", name);
			val.Value = localContext.Adapter.FromRawValue (localContext, value);
		}
Пример #11
0
		public ObjectValue[] GetLocalVariables (int frameIndex, EvaluationOptions options)
		{
			List<ObjectValue> values = new List<ObjectValue> ();
			SelectFrame (frameIndex);
			
			GdbCommandResult res = session.RunCommand ("-stack-list-locals", "0");
			foreach (ResultData data in res.GetObject ("locals"))
				values.Add (CreateVarObject (data.GetValue ("name")));
			
			return values.ToArray ();
		}
Пример #12
0
		public ObjectValue CreateObjectValue (bool withTimeout, EvaluationOptions options)
		{
			if (!CanEvaluate (options))
				return DC.ObjectValue.CreateImplicitNotSupported (this, new ObjectPath (Name), ctx.Adapter.GetTypeName (GetContext (options), Type), Flags);
			if (withTimeout) {
				return ctx.Adapter.CreateObjectValueAsync (Name, Flags, delegate {
					return CreateObjectValue (options);
				});
			} else
				return CreateObjectValue (options);
		}
Пример #13
0
        public object GetMemberValue(string name, EvaluationOptions options)
        {
            var localContext = ctx.WithOptions (options);
            var type = localContext.Adapter.GetValueType (localContext, targetObject);
            var val = localContext.Adapter.GetMember (localContext, source, type, targetObject, name);

            if (val == null)
                throw new EvaluatorException ("Member '{0}' not found", name);

            return localContext.Adapter.ToRawValue (localContext, val, val.Value);
        }
		public override ValueReference GetChild (string name, EvaluationOptions options)
		{
			string newNs = namspace + "." + name;

			var ctx = GetContext (options);
			var type = ctx.Adapter.GetType (ctx, newNs);

			if (type != null)
				return new TypeValueReference (ctx, type);
			
			return new NamespaceValueReference (ctx, newNs);
		}
		public object CallMethod (string name, object[] parameters, EvaluationOptions options)
		{
			EvaluationContext localContext = ctx.WithOptions (options);
			
			object[] argValues = new object [parameters.Length];
			object[] argTypes = new object [parameters.Length];
			for (int n=0; n<argValues.Length; n++) {
				argValues[n] = localContext.Adapter.FromRawValue (localContext, parameters[n]);
				argTypes[n] = localContext.Adapter.GetValueType (localContext, argValues[n]);
			}
			object type = localContext.Adapter.GetValueType (localContext, targetObject);
			object res = localContext.Adapter.RuntimeInvoke (localContext, type, targetObject, name, argTypes, argValues);
			return localContext.Adapter.ToRawValue (localContext, null, res);
		}
Пример #16
0
        public ObjectValue[] GetAllLocals(int frameIndex, EvaluationOptions options)
        {
            session.RunCommand (true, "vars");
            List<ObjectValue> locals = new List<ObjectValue> ();
            lock (syncLock) {
                foreach (string varName in session.lastResult.vars) {
                    ObjectValue val;
                    ObjectValueFlags flags = ObjectValueFlags.Variable;
                    val = ObjectValue.CreatePrimitive (this, new ObjectPath (varName), "dummyInt", new EvaluationResult ("test_val"), flags);
                    val.Name = varName;
                    locals.Add (val);
                }
            }

            return locals.ToArray ();
        }
        public ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options)
        {
            List<ObjectValue> children = new List<ObjectValue>();
            session.SelectThread(threadId);

            if (Engine.Symbols.ScopeLocalSymbols == null)
                return children.ToArray();

            DEW.DebugScopedSymbol parent = null;

            for (uint i = 0; i < Engine.Symbols.ScopeLocalSymbols.Symbols.Length; i++)
            {
                DEW.DebugScopedSymbol symbol = Engine.Symbols.ScopeLocalSymbols.Symbols[i];
                if (symbol.Name == path.LastName)
                {
                    parent = symbol;
                    break;
                }
            }

            if (parent == null || parent.ChildrenCount == 0)
                return children.ToArray();

            for (uint i = 0; i < parent.ChildrenCount; i++)
            {

                DEW.DebugScopedSymbol child = parent.Children[i];

                string name = child.Name;
                string typename = child.TypeName;
                string val = child.TextValue;
                ulong offset = child.Offset;

                ObjectValue ov = symbolResolver.Resolve(offset, name, typename, val, child.Parent);
                if (ov == null)
                {
                    ObjectValueFlags flags = ObjectValueFlags.Variable;
                    ov = ObjectValue.CreatePrimitive(this, new ObjectPath(name), typename, new EvaluationResult(val), flags);
                }

                if (ov != null)
                    children.Add(ov);
            }

            return children.ToArray();
        }
		public ObjectValue[] GetChildren (ObjectPath path, int index, int count, EvaluationOptions options)
		{
			var node = cacheRoot [path];

			if(node == null)
				return Backtrace.GetChildren(path, index, count, options);

			ObjectValue[] children;
			var t = node.NodeType;

			if (t is ArrayType)
				children = GetArrayChildren (node, path, index, count, options);
			else if (t is ClassType || t is StructType)
				children = GetClassInstanceChildren (node, path, options);
			else
				children = new ObjectValue[0];

			return children;
		}
Пример #19
0
        public virtual ObjectValue[] GetAllLocals(int frameIndex, EvaluationOptions options)
        {
            var locals = new List<ObjectValue> ();

            var excObj = GetExceptionInstance (frameIndex, options);
            if (excObj != null)
                locals.Insert (0, excObj);

            locals.AddRange (GetLocalVariables (frameIndex, options));
            locals.AddRange (GetParameters (frameIndex, options));

            locals.Sort ((v1, v2) => StringComparer.InvariantCulture.Compare (v1.Name, v2.Name));

            var thisObj = GetThisReference (frameIndex, options);
            if (thisObj != null)
                locals.Insert (0, thisObj);

            return locals.ToArray ();
        }
		public virtual ObjectValue[] GetLocalVariables (int frameIndex, EvaluationOptions options)
		{
			FrameInfo frame = GetFrameInfo (frameIndex, options, false);
			List<ObjectValue> list = new List<ObjectValue> ();
			
			if (frame == null) {
				ObjectValue val = Adaptor.CreateObjectValueAsync ("Local Variables", ObjectValueFlags.EvaluatingGroup, delegate {
					frame = GetFrameInfo (frameIndex, options, true);
					foreach (ValueReference var in frame.LocalVariables)
						list.Add (var.CreateObjectValue (false, options));
					return ObjectValue.CreateArray (null, new ObjectPath ("Local Variables"), "", list.Count, ObjectValueFlags.EvaluatingGroup, list.ToArray ());
				});
				return new ObjectValue [] { val };
			}
			
			foreach (ValueReference var in frame.LocalVariables)
				list.Add (var.CreateObjectValue (true, options));
			return list.ToArray ();
		}
		public virtual ObjectValue[] GetParameters (int frameIndex, EvaluationOptions options)
		{
			List<ObjectValue> vars = new List<ObjectValue> ();
			
			FrameInfo frame = GetFrameInfo (frameIndex, options, false);
			if (frame == null) {
				ObjectValue val = Adaptor.CreateObjectValueAsync ("Parameters", ObjectValueFlags.EvaluatingGroup, delegate {
					frame = GetFrameInfo (frameIndex, options, true);
					foreach (ValueReference var in frame.Parameters)
						vars.Add (var.CreateObjectValue (false, options));
					return ObjectValue.CreateArray (null, new ObjectPath ("Parameters"), "", vars.Count, ObjectValueFlags.EvaluatingGroup, vars.ToArray ());
				});
				return new ObjectValue [] { val };
			}
			
			foreach (ValueReference var in frame.Parameters)
				vars.Add (var.CreateObjectValue (true, options));
			return vars.ToArray ();
		}
        public SoftEvaluationContext(SoftDebuggerSession session, StackFrame frame, DC.EvaluationOptions options) : base(options)
        {
            Frame  = frame;
            Thread = frame.Thread;


            string method = frame.Method.Name;

            if (frame.Method.DeclaringType != null)
            {
                method = frame.Method.DeclaringType.FullName + "." + method;
            }
            var location = new DC.SourceLocation(method, frame.FileName, frame.LineNumber);
            var lang     = frame.Method != null? "Managed" : "Native";

            Evaluator         = session.GetResolver(new DC.StackFrame(frame.ILOffset, location, lang, session.IsExternalCode(frame), true));
            Adapter           = session.Adaptor;
            this.session      = session;
            this.stackVersion = session.StackVersion;
        }
Пример #23
0
        public ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options)
        {
            List<ObjectValue> children = new List<ObjectValue> ();
            session.SelectThread (threadId);
            return children.ToArray();

            /*
            DDebugCommandResult res = session.RunCommand("-var-list-children", "2", path.Join("."));
            ResultData cdata = res.GetObject ("children");

            // The response may not contain the "children" list at all.
            if (cdata == null)
                return children.ToArray ();

            if (index == -1) {
                index = 0;
                count = cdata.Count;
            }

            for (int n=index; n<cdata.Count && n<index+count; n++) {
                ResultData data = cdata.GetObject (n);
                ResultData child = data.GetObject ("child");

                string name = child.GetValue ("exp");
                if (name.Length > 0 && char.IsNumber (name [0]))
                    name = "[" + name + "]";

                // C++ structures may contain typeless children named
                // "public", "private" and "protected".
                if (child.GetValue("type") == null) {
                    ObjectPath childPath = new ObjectPath (child.GetValue ("name").Split ('.'));
                    ObjectValue[] subchildren = GetChildren (childPath, -1, -1, options);
                    children.AddRange(subchildren);
                } else {
                    ObjectValue val = CreateObjectValue (name, child);
                    children.Add (val);
                }
            }
            return children.ToArray ();
             */
        }
		public bool HasChildren (ObjectPath path, EvaluationOptions options)
		{
			EvaluationContext cctx = ctx.WithOptions (options);
			TypeDisplayData tdata = null;
			object tdataType = null;

			foreach (ValueReference val in cctx.Adapter.GetMembersSorted (cctx, objectSource, type, obj, bindingFlags)) {
				object decType = val.DeclaringType;
				if (decType != null && decType != tdataType) {
					tdataType = decType;
					tdata = cctx.Adapter.GetTypeDisplayData (cctx, decType);
				}

				DebuggerBrowsableState state = tdata.GetMemberBrowsableState (val.Name);
				if (state == DebuggerBrowsableState.Never)
					continue;

				return true;
			}

			return false;
		}
        public ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options)
        {
            List<ObjectValue> children = new List<ObjectValue>();
            session.SelectThread(threadId);

            string expression = path.Join(".");

            if (expression.Trim().Length == 0)
                return children.ToArray();

            List<DebugScopedSymbol> childSymbols = this.session.SymbolResolver.GetChildSymbols(expression);
            if (childSymbols.Count == 0)
                return children.ToArray();

            for (int i = 0; i < childSymbols.Count; i++)
            {
                DebugScopedSymbol child = childSymbols[i];

                ObjectValue ov = CreateObjectValue(child);
                children.Add(ov);
            }

            return children.ToArray();
        }
Пример #26
0
        public ObjectValue GetExpressionValue(string expression, EvaluationOptions options)
        {
            if (!hasDebugInfo)
                return ObjectValue.CreateUnknown (expression);

            if (options.UseExternalTypeResolver)
                expression = ResolveExpression (expression);

            var values = sourceBacktrace.GetExpressionValues (index, new [] { expression }, options);
            ObjectValue.ConnectCallbacks (this, values);
            return values [0];
        }
Пример #27
0
        public ExceptionInfo GetException(EvaluationOptions options)
        {
            var value = sourceBacktrace.GetException (index, options);
            if (value != null)
                value.ConnectCallback (this);

            return value;
        }
		public void SetRawValue (ObjectPath path, object value, EvaluationOptions options)
		{
			throw new System.NotImplementedException ();
		}
Пример #29
0
 void IRawObject.Connect(DebuggerSession session, EvaluationOptions options)
 {
     this.options = options;
     source       = session.WrapDebuggerObject(source);
 }
Пример #30
0
 public virtual string GetFullStackFrameText(EvaluationOptions options)
 {
     using (var cts = new CancellationTokenSource(options.MemberEvaluationTimeout))
         return(GetFullStackFrameTextAsync(options, false, cts.Token).GetAwaiter().GetResult());
 }
Пример #31
0
 /// <summary>
 /// Sets the raw value of this object
 /// </summary>
 /// <param name='value'>
 /// The value
 /// </param>
 /// <param name='options'>
 /// The evaluation options
 /// </param>
 /// <remarks>
 /// The provided value can be a primitive type, a RawValue object or a RawValueArray object.
 /// </remarks>
 public void SetRawValue(object value, EvaluationOptions options)
 {
     source.SetRawValue(path, value, options);
 }
Пример #32
0
        public ObjectValue[] GetExpressionValues(string[] expressions, EvaluationOptions options)
        {
            if (!hasDebugInfo) {
                var vals = new ObjectValue [expressions.Length];
                for (int n = 0; n < expressions.Length; n++)
                    vals[n] = ObjectValue.CreateUnknown (expressions[n]);

                return vals;
            }

            if (options.UseExternalTypeResolver) {
                var resolved = new string [expressions.Length];
                for (int n = 0; n < expressions.Length; n++)
                    resolved[n] = ResolveExpression (expressions[n]);

                expressions = resolved;
            }

            var values = sourceBacktrace.GetExpressionValues (index, expressions, options);
            ObjectValue.ConnectCallbacks (this, values);
            return values;
        }
Пример #33
0
        public ObjectValue GetThisReference(EvaluationOptions options)
        {
            if (!hasDebugInfo)
                return null;

            var value = sourceBacktrace.GetThisReference (index, options);
            if (value != null)
                ObjectValue.ConnectCallbacks (this, value);

            return value;
        }
Пример #34
0
        async Task <string> GetFullStackFrameTextAsync(EvaluationOptions options, bool doAsync, CancellationToken cancellationToken)
        {
            // If MethodName starts with "[", then it's something like [ExternalCode]
            if (SourceLocation.MethodName.StartsWith("[", StringComparison.Ordinal))
            {
                return(SourceLocation.MethodName);
            }

            options = options.Clone();
            if (options.StackFrameFormat.ParameterValues)
            {
                options.AllowMethodEvaluation = true;
                options.AllowToStringCalls    = true;
                options.AllowTargetInvoke     = true;
            }
            else
            {
                options.AllowMethodEvaluation = false;
                options.AllowToStringCalls    = false;
                options.AllowTargetInvoke     = false;
            }

            // Cache the method parameters. Only refresh the method params iff the cached args do not
            // already have parameter values. Once we have parameter values, we never have to
            // refresh the cached parameters because we can just omit the parameter values when
            // constructing the display string.
            if (parameters == null || (options.StackFrameFormat.ParameterValues && !haveParameterValues))
            {
                haveParameterValues = options.StackFrameFormat.ParameterValues;
                parameters          = GetParameters(options);
            }

            var methodNameBuilder = new StringBuilder();

            if (options.StackFrameFormat.Module && !string.IsNullOrEmpty(FullModuleName))
            {
                methodNameBuilder.Append(Path.GetFileName(FullModuleName));
                methodNameBuilder.Append('!');
            }

            methodNameBuilder.Append(SourceLocation.MethodName);

            if (options.StackFrameFormat.ParameterTypes || options.StackFrameFormat.ParameterNames || options.StackFrameFormat.ParameterValues)
            {
                methodNameBuilder.Append('(');
                for (int n = 0; n < parameters.Length; n++)
                {
                    if (parameters[n].IsEvaluating)
                    {
                        var          tcs     = new TaskCompletionSource <bool> ();
                        EventHandler updated = (s, e) => {
                            tcs.TrySetResult(true);
                        };
                        parameters[n].ValueChanged += updated;
                        try {
                            using (var registration = cancellationToken.Register(() => tcs.TrySetCanceled())) {
                                if (parameters[n].IsEvaluating)
                                {
                                    if (doAsync)
                                    {
                                        await tcs.Task.ConfigureAwait(false);
                                    }
                                    else
                                    {
                                        tcs.Task.Wait(cancellationToken);
                                    }
                                }
                            }
                        } finally {
                            parameters[n].ValueChanged -= updated;
                        }
                    }
                    if (n > 0)
                    {
                        methodNameBuilder.Append(", ");
                    }
                    if (options.StackFrameFormat.ParameterTypes)
                    {
                        methodNameBuilder.Append(parameters[n].TypeName);
                        if (options.StackFrameFormat.ParameterNames)
                        {
                            methodNameBuilder.Append(' ');
                        }
                    }
                    if (options.StackFrameFormat.ParameterNames)
                    {
                        methodNameBuilder.Append(parameters[n].Name);
                    }
                    if (options.StackFrameFormat.ParameterValues)
                    {
                        if (options.StackFrameFormat.ParameterTypes || options.StackFrameFormat.ParameterNames)
                        {
                            methodNameBuilder.Append(" = ");
                        }
                        var val = parameters[n].Value ?? string.Empty;
                        methodNameBuilder.Append(val.Replace("\r\n", " ").Replace("\n", " "));
                    }
                }
                methodNameBuilder.Append(')');
            }

            return(methodNameBuilder.ToString());
        }
Пример #35
0
        public ObjectValue[] GetParameters(EvaluationOptions options)
        {
            if (!hasDebugInfo)
                return new ObjectValue [0];

            var values = sourceBacktrace.GetParameters (index, options);
            ObjectValue.ConnectCallbacks (this, values);
            return values;
        }
 internal CorEvaluationContext(CorDebuggerSession session, CorBacktrace backtrace, int index, DC.EvaluationOptions ops) : base(ops)
 {
     Session        = session;
     base.Adapter   = session.ObjectAdapter;
     frameIndex     = index;
     this.backtrace = backtrace;
     evalTimestamp  = CorDebuggerSession.EvaluationTimestamp;
     Evaluator      = session.GetEvaluator(CorBacktrace.CreateFrame(session, Frame));
 }
Пример #37
0
        /// <summary>
        /// Returns True if the expression is valid and can be evaluated for this frame.
        /// </summary>
        public ValidationResult ValidateExpression(string expression, EvaluationOptions options)
        {
            if (options.UseExternalTypeResolver)
                expression = ResolveExpression (expression);

            return sourceBacktrace.ValidateExpression (index, expression, options);
        }
Пример #38
0
 public virtual Task <string> GetFullStackFrameTextAsync(EvaluationOptions options, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(GetFullStackFrameTextAsync(options, true, cancellationToken));
 }